From 73564f3113230ae3c4a47f8ec7fd5f5ce99bf7b5 Mon Sep 17 00:00:00 2001 From: Artur Neumann Date: Thu, 1 Jul 2021 12:22:45 +0200 Subject: [PATCH 1/5] construct versions path inside of 'listVersionFolder()' --- .../bootstrap/FilesVersionsContext.php | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/acceptance/features/bootstrap/FilesVersionsContext.php b/tests/acceptance/features/bootstrap/FilesVersionsContext.php index 373de4d3116f..fc6acf9a894c 100644 --- a/tests/acceptance/features/bootstrap/FilesVersionsContext.php +++ b/tests/acceptance/features/bootstrap/FilesVersionsContext.php @@ -52,7 +52,7 @@ class FilesVersionsContext implements Context { public function userRestoresVersionIndexOfFile($user, $versionIndex, $path) { $user = $this->featureContext->getActualUsername($user); $fileId = $this->featureContext->getFileIdForPath($user, $path); - $responseXml = $this->listVersionFolder($user, "/meta/$fileId/v", 1); + $responseXml = $this->listVersionFolder($user, (int)$fileId, 1); $xmlPart = $responseXml->xpath("//d:response/d:href"); //restoring the version only works with dav path v2 $destinationUrl = $this->featureContext->getBaseUrl() . "/" . @@ -102,7 +102,7 @@ public function theVersionFolderOfFileIdShouldContainElements( $user, $count ) { - $responseXml = $this->listVersionFolder($user, "/meta/$fileId/v", 1); + $responseXml = $this->listVersionFolder($user, (int)$fileId, 1); $xmlPart = $responseXml->xpath("//d:prop/d:getetag"); Assert::assertEquals( $count, @@ -131,7 +131,7 @@ public function theContentLengthOfFileForUserInVersionsFolderIs( $fileId = $this->featureContext->getFileIdForPath($user, $path); $responseXml = $this->listVersionFolder( $user, - "/meta/$fileId/v", + (int)$fileId, 1, ['getcontentlength'] ); @@ -149,17 +149,17 @@ public function theContentLengthOfFileForUserInVersionsFolderIs( * with an registered namespace with 'd' as prefix and 'DAV:' as namespace * * @param string $user - * @param string $path + * @param int $fileId * @param int $folderDepth - * @param string[] $properties + * @param string[]|null $properties * * @return SimpleXMLElement */ public function listVersionFolder( - $user, - $path, - $folderDepth, - $properties = null + string $user, + int $fileId, + int $folderDepth, + array $properties = null ) { if (!$properties) { $properties = [ @@ -172,7 +172,7 @@ public function listVersionFolder( $this->featureContext->getBaseUrl(), $user, $password, - $path, + "/meta/$fileId/v", $properties, $folderDepth, "versions" From da02512c26ca37772fea05edc744bbaff6d1c840 Mon Sep 17 00:00:00 2001 From: Artur Neumann Date: Thu, 1 Jul 2021 12:57:54 +0200 Subject: [PATCH 2/5] move versions related steps to 'FilesVersionsContext' --- .../bootstrap/FilesVersionsContext.php | 53 ++++++++++++++++++- .../acceptance/features/bootstrap/WebDav.php | 52 ------------------ 2 files changed, 52 insertions(+), 53 deletions(-) diff --git a/tests/acceptance/features/bootstrap/FilesVersionsContext.php b/tests/acceptance/features/bootstrap/FilesVersionsContext.php index fc6acf9a894c..60d54a3c7210 100644 --- a/tests/acceptance/features/bootstrap/FilesVersionsContext.php +++ b/tests/acceptance/features/bootstrap/FilesVersionsContext.php @@ -32,13 +32,64 @@ * Steps that relate to files_versions app */ class FilesVersionsContext implements Context { - /** * * @var FeatureContext */ private $featureContext; + /** + * @When user :user tries to get versions of file :file from :fileOwner + * + * @param string $user + * @param string $file + * @param string $fileOwner + * + * @return void + * @throws Exception + */ + public function userTriesToGetFileVersions($user, $file, $fileOwner) { + $user = $this->featureContext->getActualUsername($user); + $fileOwner = $this->featureContext->getActualUsername($fileOwner); + $fileId = $this->featureContext->getFileIdForPath($fileOwner, $file); + $path = "/meta/" . $fileId . "/v"; + $response = $this->featureContext->makeDavRequest( + $user, + "PROPFIND", + $path, + null, + null, + null, + 2 + ); + $this->featureContext->setResponse($response); + } + + /** + * @When user :user gets the number of versions of file :file + * + * @param string $user + * @param string $file + * + * @return void + * @throws Exception + */ + public function userGetsFileVersions($user, $file) { + $user = $this->featureContext->getActualUsername($user); + $fileId = $this->featureContext->getFileIdForPath($user, $file); + $path = "/meta/" . $fileId . "/v"; + $response = $this->featureContext->makeDavRequest( + $user, + "PROPFIND", + $path, + null, + null, + null, + 2 + ); + $this->featureContext->setResponse($response); + } + /** * @When user :user restores version index :versionIndex of file :path using the WebDAV API * @Given user :user has restored version index :versionIndex of file :path diff --git a/tests/acceptance/features/bootstrap/WebDav.php b/tests/acceptance/features/bootstrap/WebDav.php index 82edc5a4e6ad..302073a268a8 100644 --- a/tests/acceptance/features/bootstrap/WebDav.php +++ b/tests/acceptance/features/bootstrap/WebDav.php @@ -396,58 +396,6 @@ public function downloadPreviews($user, $path, $doDavRequestAsUser, $width, $hei ); } - /** - * @When user :user tries to get versions of file :file from :fileOwner - * - * @param string $user - * @param string $file - * @param string $fileOwner - * - * @return void - * @throws Exception - */ - public function userTriesToGetFileVersions($user, $file, $fileOwner) { - $user = $this->getActualUsername($user); - $fileOwner = $this->getActualUsername($fileOwner); - $fileId = $this->getFileIdForPath($fileOwner, $file); - $path = "/meta/" . $fileId . "/v"; - $response = $this->makeDavRequest( - $user, - "PROPFIND", - $path, - null, - null, - null, - 2 - ); - $this->setResponse($response); - } - - /** - * @When user :user gets the number of versions of file :file - * - * @param string $user - * @param string $file - * - * @return void - * @throws Exception - */ - public function userGetsFileVersions($user, $file) { - $user = $this->getActualUsername($user); - $fileId = $this->getFileIdForPath($user, $file); - $path = "/meta/" . $fileId . "/v"; - $response = $this->makeDavRequest( - $user, - "PROPFIND", - $path, - null, - null, - null, - 2 - ); - $this->setResponse($response); - } - /** * @Then the number of versions should be :arg1 * From 6e8e845773b90413d46553197114490c3fb4b3a3 Mon Sep 17 00:00:00 2001 From: Artur Neumann Date: Thu, 1 Jul 2021 13:05:14 +0200 Subject: [PATCH 3/5] generate versions path only in one place --- .../features/bootstrap/FilesVersionsContext.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tests/acceptance/features/bootstrap/FilesVersionsContext.php b/tests/acceptance/features/bootstrap/FilesVersionsContext.php index 60d54a3c7210..a6e0e16ae195 100644 --- a/tests/acceptance/features/bootstrap/FilesVersionsContext.php +++ b/tests/acceptance/features/bootstrap/FilesVersionsContext.php @@ -38,6 +38,15 @@ class FilesVersionsContext implements Context { */ private $featureContext; + /** + * @param int $fileId + * + * @return string + */ + private function getVersionsPathForFileId(int $fileId) { + return "/meta/$fileId/v"; + } + /** * @When user :user tries to get versions of file :file from :fileOwner * @@ -52,11 +61,10 @@ public function userTriesToGetFileVersions($user, $file, $fileOwner) { $user = $this->featureContext->getActualUsername($user); $fileOwner = $this->featureContext->getActualUsername($fileOwner); $fileId = $this->featureContext->getFileIdForPath($fileOwner, $file); - $path = "/meta/" . $fileId . "/v"; $response = $this->featureContext->makeDavRequest( $user, "PROPFIND", - $path, + $this->getVersionsPathForFileId($fileId), null, null, null, @@ -77,11 +85,10 @@ public function userTriesToGetFileVersions($user, $file, $fileOwner) { public function userGetsFileVersions($user, $file) { $user = $this->featureContext->getActualUsername($user); $fileId = $this->featureContext->getFileIdForPath($user, $file); - $path = "/meta/" . $fileId . "/v"; $response = $this->featureContext->makeDavRequest( $user, "PROPFIND", - $path, + $this->getVersionsPathForFileId($fileId), null, null, null, @@ -223,7 +230,7 @@ public function listVersionFolder( $this->featureContext->getBaseUrl(), $user, $password, - "/meta/$fileId/v", + $this->getVersionsPathForFileId($fileId), $properties, $folderDepth, "versions" From db37e5b31a5c694fcde5f3b55216ca0d35a4b958 Mon Sep 17 00:00:00 2001 From: Artur Neumann Date: Thu, 1 Jul 2021 13:22:30 +0200 Subject: [PATCH 4/5] test downloading old versions of a file --- .../features/apiVersions/fileVersions.feature | 37 +++++++++++++++++++ .../fileVersionsSharingToShares.feature | 21 +++++++++++ ...eVersionsSharingToSharesIssue36228.feature | 28 ++++++++++++++ .../bootstrap/FilesVersionsContext.php | 32 ++++++++++++++++ 4 files changed, 118 insertions(+) create mode 100644 tests/acceptance/features/apiVersions/fileVersionsSharingToSharesIssue36228.feature diff --git a/tests/acceptance/features/apiVersions/fileVersions.feature b/tests/acceptance/features/apiVersions/fileVersions.feature index b6b514cb2348..19ea1978a622 100644 --- a/tests/acceptance/features/apiVersions/fileVersions.feature +++ b/tests/acceptance/features/apiVersions/fileVersions.feature @@ -415,3 +415,40 @@ Feature: dav-versions Then the HTTP status code should be "207" And the number of etag elements in the response should be "2" And the number of versions should be "2" + + + Scenario: download old versions of a file + Given user "Alice" has uploaded file with content "uploaded content" to "textfile0.txt" + And user "Alice" has uploaded file with content "version 1" to "textfile0.txt" + And user "Alice" has uploaded file with content "version 2" to "textfile0.txt" + When user "Alice" downloads the version of file "textfile0.txt" with the index "1" + Then the HTTP status code should be "200" + And the following headers should be set + | header | value | + | Content-Disposition | attachment; filename*=UTF-8''textfile0.txt; filename="textfile0.txt" | + And the downloaded content should be "version 1" + When user "Alice" downloads the version of file "textfile0.txt" with the index "2" + Then the HTTP status code should be "200" + And the following headers should be set + | header | value | + | Content-Disposition | attachment; filename*=UTF-8''textfile0.txt; filename="textfile0.txt" | + And the downloaded content should be "uploaded content" + + + Scenario: download an old version of a restored file + Given user "Alice" has uploaded file with content "uploaded content" to "textfile0.txt" + And user "Alice" has uploaded file with content "version 1" to "textfile0.txt" + And user "Alice" has uploaded file with content "version 2" to "textfile0.txt" + And user "Alice" has restored version index "1" of file "textfile0.txt" + When user "Alice" downloads the version of file "textfile0.txt" with the index "1" + Then the HTTP status code should be "200" + And the following headers should be set + | header | value | + | Content-Disposition | attachment; filename*=UTF-8''textfile0.txt; filename="textfile0.txt" | + And the downloaded content should be "version 2" + When user "Alice" downloads the version of file "textfile0.txt" with the index "2" + Then the HTTP status code should be "200" + And the following headers should be set + | header | value | + | Content-Disposition | attachment; filename*=UTF-8''textfile0.txt; filename="textfile0.txt" | + And the downloaded content should be "uploaded content" diff --git a/tests/acceptance/features/apiVersions/fileVersionsSharingToShares.feature b/tests/acceptance/features/apiVersions/fileVersionsSharingToShares.feature index 97efdac5de72..e1366006aabf 100644 --- a/tests/acceptance/features/apiVersions/fileVersionsSharingToShares.feature +++ b/tests/acceptance/features/apiVersions/fileVersionsSharingToShares.feature @@ -296,3 +296,24 @@ Feature: dav-versions Then the HTTP status code should be "204" And the version folder of file "/Shares/sharefile.txt" for user "Brian" should contain "1" element And the version folder of file "/sharefile.txt" for user "Alice" should contain "1" element + + @issue-36228 @skipOnOcV10 + Scenario: download old versions of a shared file as share receiver + Given user "Brian" has been created with default attributes and without skeleton files + And user "Alice" has uploaded file with content "uploaded content" to "textfile0.txt" + And user "Alice" has uploaded file with content "version 1" to "textfile0.txt" + And user "Alice" has uploaded file with content "version 2" to "textfile0.txt" + And user "Alice" has shared file "textfile0.txt" with user "Brian" + And user "Brian" has accepted share "/textfile0.txt" offered by user "Alice" + When user "Brian" downloads the version of file "/Shares/textfile0.txt" with the index "1" + Then the HTTP status code should be "200" + And the following headers should be set + | header | value | + | Content-Disposition | attachment; filename*=UTF-8''textfile0.txt; filename="textfile0.txt" | + And the downloaded content should be "version 1" + When user "Brian" downloads the version of file "/Shares/textfile0.txt" with the index "2" + Then the HTTP status code should be "200" + And the following headers should be set + | header | value | + | Content-Disposition | attachment; filename*=UTF-8''textfile0.txt; filename="textfile0.txt" | + And the downloaded content should be "uploaded content" diff --git a/tests/acceptance/features/apiVersions/fileVersionsSharingToSharesIssue36228.feature b/tests/acceptance/features/apiVersions/fileVersionsSharingToSharesIssue36228.feature new file mode 100644 index 000000000000..3482750c24f6 --- /dev/null +++ b/tests/acceptance/features/apiVersions/fileVersionsSharingToSharesIssue36228.feature @@ -0,0 +1,28 @@ +@api @files_versions-app-required @issue-36228 @notToImplementOnOCIS + +Feature: dav-versions + + Background: + Given the administrator has set the default folder for received shares to "Shares" + And auto-accept shares has been disabled + And user "Alice" has been created with default attributes and without skeleton files + + Scenario: download old versions of a shared file as share receiver + Given user "Brian" has been created with default attributes and without skeleton files + And user "Alice" has uploaded file with content "uploaded content" to "textfile0.txt" + And user "Alice" has uploaded file with content "version 1" to "textfile0.txt" + And user "Alice" has uploaded file with content "version 2" to "textfile0.txt" + And user "Alice" has shared file "textfile0.txt" with user "Brian" + And user "Brian" has accepted share "/textfile0.txt" offered by user "Alice" + When user "Brian" downloads the version of file "/Shares/textfile0.txt" with the index "1" + Then the HTTP status code should be "200" + And the following headers should be set + | header | value | + | Content-Disposition | attachment; filename*=UTF-8''; filename="" | + And the downloaded content should be "version 1" + When user "Brian" downloads the version of file "/Shares/textfile0.txt" with the index "2" + Then the HTTP status code should be "200" + And the following headers should be set + | header | value | + | Content-Disposition | attachment; filename*=UTF-8''; filename="" | + And the downloaded content should be "uploaded content" diff --git a/tests/acceptance/features/bootstrap/FilesVersionsContext.php b/tests/acceptance/features/bootstrap/FilesVersionsContext.php index a6e0e16ae195..9636a2e2e988 100644 --- a/tests/acceptance/features/bootstrap/FilesVersionsContext.php +++ b/tests/acceptance/features/bootstrap/FilesVersionsContext.php @@ -202,6 +202,38 @@ public function theContentLengthOfFileForUserInVersionsFolderIs( ); } + /** + * @When user :user downloads the version of file :path with the index :index + * + * @param string $user + * @param string $path + * @param string $index + * + * @return void + */ + public function downloadVersion(string $user, string $path, string $index) { + $user = $this->featureContext->getActualUsername($user); + $fileId = $this->featureContext->getFileIdForPath($user, $path); + $index = (int)$index; + $responseXml = $this->listVersionFolder($user, $fileId, 1); + $xmlPart = $responseXml->xpath("//d:response/d:href"); + if (!isset($xmlPart[$index])) { + Assert::fail( + 'could not find version of path "' . $path . '" with index "' . $index . '"' + ); + } + // the href already contains the path + $url = WebDavHelper::sanitizeUrl( + $this->featureContext->getBaseUrlWithoutPath() . $xmlPart[$index] + ); + $response = HttpRequestHelper::get( + $url, + $user, + $this->featureContext->getPasswordForUser($user) + ); + $this->featureContext->setResponse($response); + } + /** * returns the result parsed into an SimpleXMLElement * with an registered namespace with 'd' as prefix and 'DAV:' as namespace From 3c27fbd9486227b55d0f6bda3b798f618c38c15c Mon Sep 17 00:00:00 2001 From: Artur Neumann Date: Mon, 5 Jul 2021 12:02:27 +0200 Subject: [PATCH 5/5] make the fileId to be a string ocis does not use an int as file-id --- .../features/bootstrap/FilesVersionsContext.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/acceptance/features/bootstrap/FilesVersionsContext.php b/tests/acceptance/features/bootstrap/FilesVersionsContext.php index 9636a2e2e988..6f3ecdcfca1d 100644 --- a/tests/acceptance/features/bootstrap/FilesVersionsContext.php +++ b/tests/acceptance/features/bootstrap/FilesVersionsContext.php @@ -39,11 +39,11 @@ class FilesVersionsContext implements Context { private $featureContext; /** - * @param int $fileId + * @param string $fileId * * @return string */ - private function getVersionsPathForFileId(int $fileId) { + private function getVersionsPathForFileId(string $fileId) { return "/meta/$fileId/v"; } @@ -110,7 +110,7 @@ public function userGetsFileVersions($user, $file) { public function userRestoresVersionIndexOfFile($user, $versionIndex, $path) { $user = $this->featureContext->getActualUsername($user); $fileId = $this->featureContext->getFileIdForPath($user, $path); - $responseXml = $this->listVersionFolder($user, (int)$fileId, 1); + $responseXml = $this->listVersionFolder($user, $fileId, 1); $xmlPart = $responseXml->xpath("//d:response/d:href"); //restoring the version only works with dav path v2 $destinationUrl = $this->featureContext->getBaseUrl() . "/" . @@ -149,7 +149,7 @@ public function theVersionFolderOfFileShouldContainElements( /** * @Then the version folder of fileId :fileId for user :user should contain :count element(s) * - * @param int $fileId + * @param string $fileId * @param string $user * @param int $count * @@ -160,7 +160,7 @@ public function theVersionFolderOfFileIdShouldContainElements( $user, $count ) { - $responseXml = $this->listVersionFolder($user, (int)$fileId, 1); + $responseXml = $this->listVersionFolder($user, $fileId, 1); $xmlPart = $responseXml->xpath("//d:prop/d:getetag"); Assert::assertEquals( $count, @@ -189,7 +189,7 @@ public function theContentLengthOfFileForUserInVersionsFolderIs( $fileId = $this->featureContext->getFileIdForPath($user, $path); $responseXml = $this->listVersionFolder( $user, - (int)$fileId, + $fileId, 1, ['getcontentlength'] ); @@ -239,7 +239,7 @@ public function downloadVersion(string $user, string $path, string $index) { * with an registered namespace with 'd' as prefix and 'DAV:' as namespace * * @param string $user - * @param int $fileId + * @param string $fileId * @param int $folderDepth * @param string[]|null $properties * @@ -247,7 +247,7 @@ public function downloadVersion(string $user, string $path, string $index) { */ public function listVersionFolder( string $user, - int $fileId, + string $fileId, int $folderDepth, array $properties = null ) {