From 5b99be378d4000b4e58ec1be798e39e39b782a1c Mon Sep 17 00:00:00 2001 From: Ilja Neumann Date: Thu, 14 Sep 2017 18:24:12 +0200 Subject: [PATCH 1/3] Return privatelink in dav interface #28984 --- apps/dav/lib/Connector/Sabre/FilesPlugin.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/apps/dav/lib/Connector/Sabre/FilesPlugin.php b/apps/dav/lib/Connector/Sabre/FilesPlugin.php index 28554bf3f1cd..082ebeacd344 100644 --- a/apps/dav/lib/Connector/Sabre/FilesPlugin.php +++ b/apps/dav/lib/Connector/Sabre/FilesPlugin.php @@ -61,6 +61,7 @@ class FilesPlugin extends ServerPlugin { 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'; + const PRIVATE_LINK_PROPERTYNAME = '{http://owncloud.org/ns}privatelink'; /** * Reference to main server object @@ -140,6 +141,7 @@ public function initialize(\Sabre\DAV\Server $server) { $server->protectedProperties[] = self::OWNER_DISPLAY_NAME_PROPERTYNAME; $server->protectedProperties[] = self::CHECKSUMS_PROPERTYNAME; $server->protectedProperties[] = self::DATA_FINGERPRINT_PROPERTYNAME; + $server->protectedProperties[] = self::PRIVATE_LINK_PROPERTYNAME; // normally these cannot be changed (RFC4918), but we want them modifiable through PROPPATCH $allowedProperties = ['{DAV:}getetag']; @@ -308,6 +310,11 @@ public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node) $propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) { return $node->getSize(); }); + + $propFind->handle(self::PRIVATE_LINK_PROPERTYNAME, function() use ($node) { + return \OC::$server->getURLGenerator() + ->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileId' => $node->getInternalFileId()]); + }); } if ($node instanceof \OCA\DAV\Connector\Sabre\Node) { From bb4560c8fa38f6c1b6133ac0e33f5f8a1850cc1b Mon Sep 17 00:00:00 2001 From: Ilja Neumann Date: Thu, 14 Sep 2017 19:18:29 +0200 Subject: [PATCH 2/3] Adding privateLinks to capabilities #28984 --- apps/files/lib/Capabilities.php | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/files/lib/Capabilities.php b/apps/files/lib/Capabilities.php index 9a2d90039230..983f10d57f14 100644 --- a/apps/files/lib/Capabilities.php +++ b/apps/files/lib/Capabilities.php @@ -57,6 +57,7 @@ public function getCapabilities() { 'preferredUploadType' => 'SHA1' ], 'files' => [ + 'privateLinks' => true, 'bigfilechunking' => true, 'blacklisted_files' => $this->config->getSystemValue('blacklisted_files', ['.htaccess']), ], From 8957cae9f97b90e4a7ece4d92af9137a4ace8fe1 Mon Sep 17 00:00:00 2001 From: Ilja Neumann Date: Fri, 15 Sep 2017 13:52:24 +0200 Subject: [PATCH 3/3] Tests for privatelink retrieval via dav #28984 --- .../integration/features/bootstrap/WebDav.php | 30 +++++++++++++++++++ .../webdav-related-new-endpoint.feature | 9 ++++++ .../webdav-related-old-endpoint.feature | 11 +++++++ 3 files changed, 50 insertions(+) diff --git a/tests/integration/features/bootstrap/WebDav.php b/tests/integration/features/bootstrap/WebDav.php index 7b2c87f7df32..eb2cdb931521 100644 --- a/tests/integration/features/bootstrap/WebDav.php +++ b/tests/integration/features/bootstrap/WebDav.php @@ -393,6 +393,36 @@ public function theSingleResponseShouldContainAPropertyWithValue($key, $expected } } + /** + * @Then the single response should contain a property :key with value like :regex + * @param string $key + * @param string $regex + * @throws \Exception + */ + public function theSingleResponseShouldContainAPropertyWithValueLike($key, $regex) { + $keys = $this->response; + if (!array_key_exists($key, $keys)) { + throw new \Exception("Cannot find property \"$key\" with \"$regex\""); + } + + $value = $keys[$key]; + if ($value instanceof ResourceType) { + $value = $value->getValue(); + if (empty($value)) { + $value = ''; + } else { + $value = $value[0]; + } + } + + if (preg_match($regex, $value)) { + return 0; + } else { + throw new \Exception("Property \"$key\" found with value \"$value\", expected \"$regex\""); + } + } + + /** * @Then the response should contain a share-types property with */ diff --git a/tests/integration/features/webdav-related-new-endpoint.feature b/tests/integration/features/webdav-related-new-endpoint.feature index 1c1a4d1b7d0f..914f1e50ee70 100644 --- a/tests/integration/features/webdav-related-new-endpoint.feature +++ b/tests/integration/features/webdav-related-new-endpoint.feature @@ -593,3 +593,12 @@ Feature: webdav-related-new-endpoint And user "user0" uploads new chunk file "3" with "CCCCC" to id "chunking-42" When user "user0" moves new chunk file with id "chunking-42" to "/myChunkedFile.txt" with size 15 Then the HTTP status code should be "201" + + Scenario: Retrieving private link + Given using new dav path + And user "user0" exists + And as an "user0" + And user "user0" uploads file "data/textfile.txt" to "/somefile.txt" + Then as "user0" gets properties of file "/somefile.txt" with + |{http://owncloud.org/ns}privatelink| + And the single response should contain a property "{http://owncloud.org/ns}privatelink" with value like "/(\/index.php\/f\/[0-9]*)/" diff --git a/tests/integration/features/webdav-related-old-endpoint.feature b/tests/integration/features/webdav-related-old-endpoint.feature index cf9c4883dffb..461091b419fe 100644 --- a/tests/integration/features/webdav-related-old-endpoint.feature +++ b/tests/integration/features/webdav-related-old-endpoint.feature @@ -507,3 +507,14 @@ Feature: webdav-related-old-endpoint And as "user1" the folder "/folderB/ONE" exists And as "user1" the folder "/folderB/ONE/TWO" exists And user "user1" checks id of file "/folderB/ONE" + + + Scenario: Retrieving private link + Given using old dav path + And user "user0" exists + And as an "user0" + And user "user0" uploads file "data/textfile.txt" to "/somefile.txt" + Then as "user0" gets properties of file "/somefile.txt" with + |{http://owncloud.org/ns}privatelink| + And the single response should contain a property "{http://owncloud.org/ns}privatelink" with value like "/(\/index.php\/f\/[0-9]*)/" +