summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@owncloud.com>2016-04-18 11:18:50 +0200
committerRoeland Jago Douma <rullzer@owncloud.com>2016-04-18 16:08:11 +0200
commitdcb2b37e248b912e05d6f74e9f69c605b13f9082 (patch)
treeae2f5adeb86bcd5cfb9ff5b73afe616916d89e90 /apps
parentfd1740deb604894a8bef515d98c5992a392e6f0a (diff)
downloadnextcloud-server-dcb2b37e248b912e05d6f74e9f69c605b13f9082.tar.gz
nextcloud-server-dcb2b37e248b912e05d6f74e9f69c605b13f9082.zip
Add data-fingerprint property to webdav
Diffstat (limited to 'apps')
-rw-r--r--apps/dav/lib/connector/sabre/filesplugin.php22
-rw-r--r--apps/dav/lib/connector/sabre/serverfactory.php11
-rw-r--r--apps/dav/lib/server.php11
-rw-r--r--apps/dav/tests/unit/connector/sabre/filesplugin.php59
-rw-r--r--apps/dav/tests/unit/connector/sabre/filesreportplugin.php10
5 files changed, 101 insertions, 12 deletions
diff --git a/apps/dav/lib/connector/sabre/filesplugin.php b/apps/dav/lib/connector/sabre/filesplugin.php
index 686d0863f91..dd4670da5fa 100644
--- a/apps/dav/lib/connector/sabre/filesplugin.php
+++ b/apps/dav/lib/connector/sabre/filesplugin.php
@@ -39,6 +39,7 @@ use Sabre\DAV\Tree;
use \Sabre\HTTP\RequestInterface;
use \Sabre\HTTP\ResponseInterface;
use OCP\Files\StorageNotAvailableException;
+use OCP\IConfig;
class FilesPlugin extends ServerPlugin {
@@ -55,6 +56,7 @@ class FilesPlugin extends ServerPlugin {
const OWNER_ID_PROPERTYNAME = '{http://owncloud.org/ns}owner-id';
const OWNER_DISPLAY_NAME_PROPERTYNAME = '{http://owncloud.org/ns}owner-display-name';
const CHECKSUMS_PROPERTYNAME = '{http://owncloud.org/ns}checksums';
+ const DATA_FINGERPRINT_PROPERTYNAME = '{http://owncloud.org/ns}data-fingerprint';
/**
* Reference to main server object
@@ -87,6 +89,11 @@ class FilesPlugin extends ServerPlugin {
private $downloadAttachment;
/**
+ * @var IConfig
+ */
+ private $config;
+
+ /**
* @param Tree $tree
* @param View $view
* @param bool $isPublic
@@ -94,10 +101,12 @@ class FilesPlugin extends ServerPlugin {
*/
public function __construct(Tree $tree,
View $view,
+ IConfig $config,
$isPublic = false,
$downloadAttachment = true) {
$this->tree = $tree;
$this->fileView = $view;
+ $this->config = $config;
$this->isPublic = $isPublic;
$this->downloadAttachment = $downloadAttachment;
}
@@ -125,6 +134,7 @@ class FilesPlugin extends ServerPlugin {
$server->protectedProperties[] = self::OWNER_ID_PROPERTYNAME;
$server->protectedProperties[] = self::OWNER_DISPLAY_NAME_PROPERTYNAME;
$server->protectedProperties[] = self::CHECKSUMS_PROPERTYNAME;
+ $server->protectedProperties[] = self::DATA_FINGERPRINT_PROPERTYNAME;
// normally these cannot be changed (RFC4918), but we want them modifiable through PROPPATCH
$allowedProperties = ['{DAV:}getetag'];
@@ -272,6 +282,18 @@ class FilesPlugin extends ServerPlugin {
$displayName = $owner->getDisplayName();
return $displayName;
});
+
+ $propFind->handle(self::DATA_FINGERPRINT_PROPERTYNAME, function() use ($node) {
+ if ($node->getPath() === '/') {
+ return $this->config->getSystemValue('data-fingerprint', '');
+ }
+ });
+ }
+
+ if ($node instanceof \OCA\DAV\Files\FilesHome) {
+ $propFind->handle(self::DATA_FINGERPRINT_PROPERTYNAME, function() use ($node) {
+ return $this->config->getSystemValue('data-fingerprint', '');
+ });
}
if ($node instanceof \OCA\DAV\Connector\Sabre\File) {
diff --git a/apps/dav/lib/connector/sabre/serverfactory.php b/apps/dav/lib/connector/sabre/serverfactory.php
index cab7a85d19f..5853370778d 100644
--- a/apps/dav/lib/connector/sabre/serverfactory.php
+++ b/apps/dav/lib/connector/sabre/serverfactory.php
@@ -137,8 +137,15 @@ class ServerFactory {
}
$objectTree->init($root, $view, $this->mountManager);
- $server->addPlugin(new \OCA\DAV\Connector\Sabre\FilesPlugin($objectTree, $view, false,
- !$this->config->getSystemValue('debug', false)));
+ $server->addPlugin(
+ new \OCA\DAV\Connector\Sabre\FilesPlugin(
+ $objectTree,
+ $view,
+ $this->config,
+ false,
+ !$this->config->getSystemValue('debug', false)
+ )
+ );
$server->addPlugin(new \OCA\DAV\Connector\Sabre\QuotaPlugin($view));
if($this->userSession->isLoggedIn()) {
diff --git a/apps/dav/lib/server.php b/apps/dav/lib/server.php
index e6668556448..73e24c9a292 100644
--- a/apps/dav/lib/server.php
+++ b/apps/dav/lib/server.php
@@ -132,8 +132,15 @@ class Server {
$user = \OC::$server->getUserSession()->getUser();
if (!is_null($user)) {
$view = \OC\Files\Filesystem::getView();
- $this->server->addPlugin(new FilesPlugin($this->server->tree, $view, false,
- !\OC::$server->getConfig()->getSystemValue('debug', false)));
+ $this->server->addPlugin(
+ new FilesPlugin(
+ $this->server->tree,
+ $view,
+ \OC::$server->getConfig(),
+ false,
+ !\OC::$server->getConfig()->getSystemValue('debug', false)
+ )
+ );
$this->server->addPlugin(
new \Sabre\DAV\PropertyStorage\Plugin(
diff --git a/apps/dav/tests/unit/connector/sabre/filesplugin.php b/apps/dav/tests/unit/connector/sabre/filesplugin.php
index 63ee5a53c17..fb5d658b39c 100644
--- a/apps/dav/tests/unit/connector/sabre/filesplugin.php
+++ b/apps/dav/tests/unit/connector/sabre/filesplugin.php
@@ -43,6 +43,7 @@ class FilesPlugin extends TestCase {
const DOWNLOADURL_PROPERTYNAME = \OCA\DAV\Connector\Sabre\FilesPlugin::DOWNLOADURL_PROPERTYNAME;
const OWNER_ID_PROPERTYNAME = \OCA\DAV\Connector\Sabre\FilesPlugin::OWNER_ID_PROPERTYNAME;
const OWNER_DISPLAY_NAME_PROPERTYNAME = \OCA\DAV\Connector\Sabre\FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME;
+ const DATA_FINGERPRINT_PROPERTYNAME = \OCA\DAV\Connector\Sabre\FilesPlugin::DATA_FINGERPRINT_PROPERTYNAME;
/**
* @var \Sabre\DAV\Server | \PHPUnit_Framework_MockObject_MockObject
@@ -64,6 +65,11 @@ class FilesPlugin extends TestCase {
*/
private $view;
+ /**
+ * @var \OCP\IConfig | \PHPUnit_Framework_MockObject_MockObject
+ */
+ private $config;
+
public function setUp() {
parent::setUp();
$this->server = $this->getMockBuilder('\Sabre\DAV\Server')
@@ -75,8 +81,16 @@ class FilesPlugin extends TestCase {
$this->view = $this->getMockBuilder('\OC\Files\View')
->disableOriginalConstructor()
->getMock();
-
- $this->plugin = new \OCA\DAV\Connector\Sabre\FilesPlugin($this->tree, $this->view);
+ $this->config = $this->getMock('\OCP\IConfig');
+ $this->config->method('getSystemValue')
+ ->with($this->equalTo('data-fingerprint'), $this->equalTo(''))
+ ->willReturn('my_fingerprint');
+
+ $this->plugin = new \OCA\DAV\Connector\Sabre\FilesPlugin(
+ $this->tree,
+ $this->view,
+ $this->config
+ );
$this->plugin->initialize($this->server);
}
@@ -128,7 +142,8 @@ class FilesPlugin extends TestCase {
self::PERMISSIONS_PROPERTYNAME,
self::DOWNLOADURL_PROPERTYNAME,
self::OWNER_ID_PROPERTYNAME,
- self::OWNER_DISPLAY_NAME_PROPERTYNAME
+ self::OWNER_DISPLAY_NAME_PROPERTYNAME,
+ self::DATA_FINGERPRINT_PROPERTYNAME,
),
0
);
@@ -166,7 +181,7 @@ class FilesPlugin extends TestCase {
$this->assertEquals('http://example.com/', $propFind->get(self::DOWNLOADURL_PROPERTYNAME));
$this->assertEquals('foo', $propFind->get(self::OWNER_ID_PROPERTYNAME));
$this->assertEquals('M. Foo', $propFind->get(self::OWNER_DISPLAY_NAME_PROPERTYNAME));
- $this->assertEquals(array(self::SIZE_PROPERTYNAME), $propFind->get404Properties());
+ $this->assertEquals([self::SIZE_PROPERTYNAME, self::DATA_FINGERPRINT_PROPERTYNAME], $propFind->get404Properties());
}
public function testGetPropertiesForFileHome() {
@@ -185,7 +200,8 @@ class FilesPlugin extends TestCase {
self::PERMISSIONS_PROPERTYNAME,
self::DOWNLOADURL_PROPERTYNAME,
self::OWNER_ID_PROPERTYNAME,
- self::OWNER_DISPLAY_NAME_PROPERTYNAME
+ self::OWNER_DISPLAY_NAME_PROPERTYNAME,
+ self::DATA_FINGERPRINT_PROPERTYNAME,
),
0
);
@@ -217,6 +233,7 @@ class FilesPlugin extends TestCase {
'{http://owncloud.org/ns}owner-id',
'{http://owncloud.org/ns}owner-display-name'
], $propFind->get404Properties());
+ $this->assertEquals('my_fingerprint', $propFind->get(self::DATA_FINGERPRINT_PROPERTYNAME));
}
public function testGetPropertiesStorageNotAvailable() {
@@ -244,7 +261,11 @@ class FilesPlugin extends TestCase {
}
public function testGetPublicPermissions() {
- $this->plugin = new \OCA\DAV\Connector\Sabre\FilesPlugin($this->tree, $this->view, true);
+ $this->plugin = new \OCA\DAV\Connector\Sabre\FilesPlugin(
+ $this->tree,
+ $this->view,
+ $this->config,
+ true);
$this->plugin->initialize($this->server);
$propFind = new PropFind(
@@ -281,6 +302,7 @@ class FilesPlugin extends TestCase {
self::SIZE_PROPERTYNAME,
self::PERMISSIONS_PROPERTYNAME,
self::DOWNLOADURL_PROPERTYNAME,
+ self::DATA_FINGERPRINT_PROPERTYNAME,
),
0
);
@@ -299,7 +321,30 @@ class FilesPlugin extends TestCase {
$this->assertEquals(1025, $propFind->get(self::SIZE_PROPERTYNAME));
$this->assertEquals('DWCKMSR', $propFind->get(self::PERMISSIONS_PROPERTYNAME));
$this->assertEquals(null, $propFind->get(self::DOWNLOADURL_PROPERTYNAME));
- $this->assertEquals(array(self::DOWNLOADURL_PROPERTYNAME), $propFind->get404Properties());
+ $this->assertEquals([self::DOWNLOADURL_PROPERTYNAME, self::DATA_FINGERPRINT_PROPERTYNAME], $propFind->get404Properties());
+ }
+
+ public function testGetPropertiesForRootDirectory() {
+ /** @var \OCA\DAV\Connector\Sabre\Directory | \PHPUnit_Framework_MockObject_MockObject $node */
+ $node = $this->getMockBuilder('\OCA\DAV\Connector\Sabre\Directory')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $node->method('getPath')->willReturn('/');
+
+ $propFind = new PropFind(
+ '/',
+ [
+ self::DATA_FINGERPRINT_PROPERTYNAME,
+ ],
+ 0
+ );
+
+ $this->plugin->handleGetProperties(
+ $propFind,
+ $node
+ );
+
+ $this->assertEquals('my_fingerprint', $propFind->get(self::DATA_FINGERPRINT_PROPERTYNAME));
}
public function testUpdateProps() {
diff --git a/apps/dav/tests/unit/connector/sabre/filesreportplugin.php b/apps/dav/tests/unit/connector/sabre/filesreportplugin.php
index 87973ef0071..ffe1a19ee56 100644
--- a/apps/dav/tests/unit/connector/sabre/filesreportplugin.php
+++ b/apps/dav/tests/unit/connector/sabre/filesreportplugin.php
@@ -336,7 +336,15 @@ class FilesReportPlugin extends \Test\TestCase {
->method('getSize')
->will($this->returnValue(1024));
- $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\FilesPlugin($this->tree, $this->view));
+ $config = $this->getMock('\OCP\IConfig');
+
+ $this->server->addPlugin(
+ new \OCA\DAV\Connector\Sabre\FilesPlugin(
+ $this->tree,
+ $this->view,
+ $config
+ )
+ );
$this->plugin->initialize($this->server);
$responses = $this->plugin->prepareResponses($requestedProps, [$node1, $node2]);