From 5c7c363e2bb7f550760455cb93b0a24202cc2970 Mon Sep 17 00:00:00 2001 From: Sawjan Gurung Date: Thu, 2 May 2024 12:21:35 +0545 Subject: [PATCH] [tests-only] add API tests for file download and rename edge cases (#9018) * test: add API tests to download deleted file * test: add more MOVE/rename API tests * do not reuse step def method * remove unused step * fix typo * fix tests * update expected failure * update expected failure --- tests/acceptance/config/behat-core.yml | 1 + .../expected-failures-API-on-OCIS-storage.md | 7 +- .../acceptance/features/bootstrap/WebDav.php | 157 +++++------------- .../coreApiWebdavMove1/moveFolder.feature | 152 +++++++++++++++++ .../downloadFile.feature | 7 + 5 files changed, 205 insertions(+), 119 deletions(-) diff --git a/tests/acceptance/config/behat-core.yml b/tests/acceptance/config/behat-core.yml index 7e99da03bd..b0071b5466 100644 --- a/tests/acceptance/config/behat-core.yml +++ b/tests/acceptance/config/behat-core.yml @@ -223,6 +223,7 @@ default: contexts: - FeatureContext: *common_feature_context_params - WebDavPropertiesContext: + - TrashbinContext: coreApiWebdavMove2: paths: diff --git a/tests/acceptance/expected-failures-API-on-OCIS-storage.md b/tests/acceptance/expected-failures-API-on-OCIS-storage.md index 87e4105e6f..4151817f41 100644 --- a/tests/acceptance/expected-failures-API-on-OCIS-storage.md +++ b/tests/acceptance/expected-failures-API-on-OCIS-storage.md @@ -71,7 +71,6 @@ File and sync features in a shared scenario - [coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature:159](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature#L159) - [coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature:160](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature#L160) - #### [file_target of an auto-renamed file is not correct directly after sharing](https://github.com/owncloud/core/issues/32322) - [coreApiShareManagementToShares/mergeShare.feature:112](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiShareManagementToShares/mergeShare.feature#L112) @@ -125,7 +124,6 @@ cannot share a folder with create permission - [coreApiTrashbin/trashbinSharingToShares.feature:201](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiTrashbin/trashbinSharingToShares.feature#L201) - [coreApiTrashbin/trashbinSharingToShares.feature:224](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiTrashbin/trashbinSharingToShares.feature#L224) - #### [Sharing folder and sub-folder with same user but different permission,the permission of sub-folder is not obeyed ](https://github.com/owncloud/ocis/issues/2440) - [coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature:213](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature#L213) @@ -395,9 +393,9 @@ Not everything needs to be implemented for ocis. While the oc10 testsuite covers #### [Renaming resource to banned name is allowed in spaces webdav](https://github.com/owncloud/ocis/issues/3099) -- [coreApiWebdavMove1/moveFolder.feature:26](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiWebdavMove1/moveFolder.feature#L26) - [coreApiWebdavMove1/moveFolder.feature:44](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiWebdavMove1/moveFolder.feature#L44) - [coreApiWebdavMove1/moveFolder.feature:62](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiWebdavMove1/moveFolder.feature#L62) +- [coreApiWebdavMove1/moveFolder.feature:80](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiWebdavMove1/moveFolder.feature#L80) - [coreApiWebdavMove2/moveFile.feature:158](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiWebdavMove2/moveFile.feature#L158) - [coreApiWebdavMove2/moveFileToBlacklistedName.feature:24](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiWebdavMove2/moveFileToBlacklistedName.feature#L24) @@ -427,6 +425,9 @@ Not everything needs to be implemented for ocis. While the oc10 testsuite covers - [coreApiWebdavMove2/moveFile.feature:120](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiWebdavMove2/moveFile.feature#L120) - [coreApiWebdavMove2/moveFile.feature:121](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiWebdavMove2/moveFile.feature#L121) - [coreApiWebdavMove2/moveFile.feature:126](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiWebdavMove2/moveFile.feature#L126) +- [coreApiWebdavMove1/moveFolder.feature:253](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiWebdavMove1/moveFolder.feature#L253) +- [coreApiWebdavMove1/moveFolder.feature:254](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiWebdavMove1/moveFolder.feature#L254) +- [coreApiWebdavMove1/moveFolder.feature:259](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiWebdavMove1/moveFolder.feature#L259) - [coreApiWebdavMove2/moveShareOnOcis.feature:283](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiWebdavMove2/moveShareOnOcis.feature#L283) - [coreApiWebdavMove2/moveShareOnOcis.feature:284](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiWebdavMove2/moveShareOnOcis.feature#L284) - [coreApiWebdavMove2/moveShareOnOcis.feature:286](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiWebdavMove2/moveShareOnOcis.feature#L286) diff --git a/tests/acceptance/features/bootstrap/WebDav.php b/tests/acceptance/features/bootstrap/WebDav.php index bfa3bafbe8..451a952d2c 100644 --- a/tests/acceptance/features/bootstrap/WebDav.php +++ b/tests/acceptance/features/bootstrap/WebDav.php @@ -627,110 +627,47 @@ trait WebDav { } /** - * @When /^user "([^"]*)" moves (file|folder|entry) "([^"]*)"\s?(asynchronously|) to these (?:filenames|foldernames|entries) using the webDAV API then the results should be as listed$/ - * * @param string $user - * @param string $entry - * @param string $fileSource - * @param string $type "asynchronously" or empty - * @param TableNode $table + * @param string $source + * @param string $destination * - * @return void - * @throws Exception + * @return ResponseInterface */ - public function userMovesEntriesUsingTheAPI( - string $user, - string $entry, - string $fileSource, - string $type, - TableNode $table - ):void { + public function moveResource(string $user, string $source, string $destination) { $user = $this->getActualUsername($user); - foreach ($table->getHash() as $row) { - // Allow the "filename" column to optionally be called "foldername" - // to help the readability of scenarios that test moving folders - $targetName = $row['foldername'] ?? $row['filename']; - $this->userMovesFileUsingTheAPI( - $user, - $fileSource, - $type, - $targetName - ); - $this->theHTTPStatusCodeShouldBe( - $row['http-code'], - "HTTP status code is not the expected value while trying to move " . $targetName - ); - if ($row['exists'] === "yes") { - $this->asFileOrFolderShouldExist($user, $entry, $targetName); - // The move was successful. - // Move the file/folder back so the source file/folder exists for the next move - $this->userMovesFileUsingTheAPI( - $user, - $targetName, - '', - $fileSource - ); - } else { - $this->asFileOrFolderShouldNotExist($user, $entry, $targetName); - } - } + $headers['Destination'] = $this->destinationHeaderValue( + $user, + $destination + ); + return $this->makeDavRequest( + $user, + "MOVE", + $source, + $headers + ); } /** - * @When /^user "([^"]*)" moves (?:file|folder|entry) "([^"]*)"\s?(asynchronously|) to "([^"]*)" using the WebDAV API$/ + * @When user :user moves file :source to :destination using the WebDAV API + * @When user :user moves folder :source to :destination using the WebDAV API + * @When user :user moves entry :source to :destination using the WebDAV API * * @param string $user - * @param string $fileSource - * @param string $type "asynchronously" or empty - * @param string $fileDestination + * @param string $source + * @param string $destination * * @return void * @throws JsonException * @throws GuzzleException */ - public function userMovesFileUsingTheAPI( + public function userMovesFileOrFolderUsingTheWebDavAPI( string $user, - string $fileSource, - string $type, - string $fileDestination + string $source, + string $destination ):void { - $user = $this->getActualUsername($user); - $headers['Destination'] = $this->destinationHeaderValue( - $user, - $fileDestination - ); - $stream = false; - if ($type === "asynchronously") { - $headers['OC-LazyOps'] = 'true'; - if ($this->httpRequestTimeout > 0) { - //LazyOps is set and a request timeout, so we want to use stream - //to be able to read data from the request before its times out - //when doing LazyOps the server does not close the connection - //before its really finished - //but we want to read JobStatus-Location before the end of the job - //to see if it reports the correct values - $stream = true; - } - } - try { - $this->response = $this->makeDavRequest( - $user, - "MOVE", - $fileSource, - $headers, - null, - "files", - null, - $stream - ); - $this->setResponseXml( - HttpRequestHelper::parseResponseAsXml($this->response) - ); - $this->pushToLastHttpStatusCodesArray( - (string) $this->getResponse()->getStatusCode() - ); - } catch (ConnectException $e) { - } + $response = $this->moveResource($user, $source, $destination); + $this->setResponse($response); + $this->pushToLastHttpStatusCodesArray(); } /** @@ -746,7 +683,11 @@ trait WebDav { $this->verifyTableNodeColumns($table, ["source", "destination"]); $rows = $table->getHash(); foreach ($rows as $row) { - $this->userMovesFileUsingTheAPI($user, $row["source"], "", $row["destination"]); + $response = $this->moveResource($user, $row["source"], $row["destination"]); + $this->setResponse($response); + $this->pushToLastHttpStatusCodesArray( + (string) $response->getStatusCode() + ); } } @@ -769,8 +710,10 @@ trait WebDav { $paths = $table->getHash(); foreach ($paths as $file) { - $this->userMovesFileUsingTheAPI($user, $file['from'], $type, $file['to']); - $this->pushToLastStatusCodesArrays(); + $response = $this->moveResource($user, $file['from'], $file['to']); + $this->pushToLastHttpStatusCodesArray( + (string) $response->getStatusCode() + ); } } @@ -788,7 +731,8 @@ trait WebDav { public function theUserShouldBeAbleToRenameEntryTo(string $user, string $entry, string $source, string $destination):void { $user = $this->getActualUsername($user); $this->asFileOrFolderShouldExist($user, $entry, $source); - $this->userMovesFileUsingTheAPI($user, $source, "", $destination); + $response = $this->moveResource($user, $source, $destination); + $this->theHTTPStatusCodeShouldBeBetween(201, 204, $response); $this->asFileOrFolderShouldNotExist($user, $entry, $source); $this->asFileOrFolderShouldExist($user, $entry, $destination); } @@ -806,32 +750,12 @@ trait WebDav { */ public function theUserShouldNotBeAbleToRenameEntryTo(string $user, string $entry, string $source, string $destination):void { $this->asFileOrFolderShouldExist($user, $entry, $source); - $this->userMovesFileUsingTheAPI($user, $source, "", $destination); + $response = $this->moveResource($user, $source, $destination); + $this->theHTTPStatusCodeShouldBeBetween(400, 499, $response); $this->asFileOrFolderShouldExist($user, $entry, $source); $this->asFileOrFolderShouldNotExist($user, $entry, $destination); } - /** - * @When /^user "([^"]*)" on "(LOCAL|REMOTE)" moves (?:file|folder|entry) "([^"]*)" to "([^"]*)" using the WebDAV API$/ - * - * @param string $user - * @param string $server - * @param string $fileSource - * @param string $fileDestination - * - * @return void - */ - public function userOnMovesFileUsingTheAPI( - string $user, - string $server, - string $fileSource, - string $fileDestination - ):void { - $previousServer = $this->usingServer($server); - $this->userMovesFileUsingTheAPI($user, $fileSource, "", $fileDestination); - $this->usingServer($previousServer); - } - /** * @param string $user * @param string $fileSource @@ -1482,6 +1406,7 @@ trait WebDav { /** * @When user :user downloads file :fileName using the WebDAV API + * @When user :user tries to download file :fileName using the WebDAV API * * @param string $user * @param string $fileName @@ -1705,7 +1630,7 @@ trait WebDav { } /** - * @Then /^as "([^"]*)" (file|folder|entry) "([^"]*)" should not exist$/ + * @Then as :user :entry :path should not exist * * @param string $user * @param string $entry @@ -1786,7 +1711,7 @@ trait WebDav { } /** - * @Then /^as "([^"]*)" (file|folder|entry) "([^"]*)" should exist$/ + * @Then as :user :entry :path should exist * * @param string $user * @param string $entry diff --git a/tests/acceptance/features/coreApiWebdavMove1/moveFolder.feature b/tests/acceptance/features/coreApiWebdavMove1/moveFolder.feature index 52474528c9..fe4af64bcd 100644 --- a/tests/acceptance/features/coreApiWebdavMove1/moveFolder.feature +++ b/tests/acceptance/features/coreApiWebdavMove1/moveFolder.feature @@ -8,6 +8,24 @@ Feature: move (rename) folder And user "Alice" has been created with default attributes and without skeleton files + Scenario Outline: rename a folder + Given using DAV path + And user "Alice" has created folder "testFolder" + When user "Alice" moves folder "testFolder" to "renamedFolder" using the WebDAV API + Then the HTTP status code should be "201" + And as "Alice" folder "renamedFolder" should exist + But as "Alice" folder "testFolder" should not exist + Examples: + | dav-path-version | + | old | + | new | + + @skipOnRevaMaster + Examples: + | dav-path-version | + | spaces | + + Scenario Outline: renaming a folder to a backslash should return an error Given using DAV path And user "Alice" has created folder "/testshare" @@ -146,3 +164,137 @@ Feature: move (rename) folder | old | | new | | spaces | + + + Scenario Outline: rename folder to/from special characters + Given using DAV path + And user "Alice" has created folder + When user "Alice" moves folder to using the WebDAV API + Then the HTTP status code should be "201" + And as "Alice" folder should exist + But as "Alice" folder should not exist + Examples: + | dav-path-version | from-folder-name | to-folder-name | + | old | "testFolder" | "'single'quotes" | + | old | "testFolder" | '"double"quotes' | + | old | "testFolder" | "strängé नेपाली folder" | + | old | "testFolder" | "$%#?&@" | + | old | "testFolder" | "Sample,Folder,With,Comma" | + | old | "testFolder" | " start with space" | + | old | "testFolder" | "renamed.part" | + | old | "'single'quotes" | "testFolder" | + | old | '"double"quotes' | "testFolder" | + | old | "strängé नेपाली folder" | "testFolder" | + | old | "$%#?&@" | "testFolder" | + | old | "Sample,Folder,With,Comma" | "testFolder" | + | old | " start with space" | "testFolder" | + | old | "renamed.part" | "testFolder" | + | new | "testFolder" | "'single'quotes" | + | new | "testFolder" | '"double"quotes' | + | new | "testFolder" | "strängé नेपाली folder" | + | new | "testFolder" | "$%#?&@" | + | new | "testFolder" | "Sample,Folder,With,Comma" | + | new | "testFolder" | " start with space" | + | new | "testFolder" | "renamed.part" | + | new | "'single'quotes" | "testFolder" | + | new | '"double"quotes' | "testFolder" | + | new | "strängé नेपाली folder" | "testFolder" | + | new | "$%#?&@" | "testFolder" | + | new | "Sample,Folder,With,Comma" | "testFolder" | + | new | " start with space" | "testFolder" | + | new | "renamed.part" | "testFolder" | + + @skipOnRevaMaster + Examples: + | dav-path-version | from-folder-name | to-folder-name | + | spaces | "testFolder" | "'single'quotes" | + | spaces | "testFolder" | '"double"quotes' | + | spaces | "testFolder" | "strängé नेपाली folder" | + | spaces | "testFolder" | "$%#?&@" | + | spaces | "testFolder" | "Sample,Folder,With,Comma" | + | spaces | "testFolder" | " start with space" | + | spaces | "testFolder" | "renamed.part" | + | spaces | "'single'quotes" | "testFolder" | + | spaces | '"double"quotes' | "testFolder" | + | spaces | "strängé नेपाली folder" | "testFolder" | + | spaces | "$%#?&@" | "testFolder" | + | spaces | "Sample,Folder,With,Comma" | "testFolder" | + | spaces | " start with space" | "testFolder" | + | spaces | "renamed.part" | "testFolder" | + + + Scenario Outline: try to rename folder to name having white space at the end + Given using DAV path + And user "Alice" has created folder "testFolder" + When user "Alice" moves folder "testFolder" to "space at end " using the WebDAV API + Then the HTTP status code should be "201" + And as "Alice" folder "space at end" should exist + But as "Alice" folder "testFolder" should not exist + And as "Alice" folder "space at end " should not exist + Examples: + | dav-path-version | + | old | + | new | + + @skipOnRevaMaster + Examples: + | dav-path-version | + | spaces | + + @issue-1976 + Scenario Outline: try to rename folder to same name + Given using DAV path + And user "Alice" has created folder "testFolder" + When user "Alice" moves folder "testFolder" to "testFolder" using the WebDAV API + Then the HTTP status code should be "404" + And as "Alice" the folder with original path "testFolder" should not exist in the trashbin + Examples: + | dav-path-version | + | old | + | new | + + @skipOnRevaMaster + Examples: + | dav-path-version | + | spaces | + + + Scenario Outline: rename a folder to existing folder name + Given using DAV path + And user "Alice" has created folder "testFolder" + And user "Alice" has uploaded file with content "some content" to "testFolder/lorem.txt" + And user "Alice" has created folder "renamedFolder" + When user "Alice" moves folder "testFolder" to "renamedFolder" using the WebDAV API + Then the HTTP status code should be "204" + And as "Alice" folder "renamedFolder" should exist + And the content of file "renamedFolder/lorem.txt" for user "Alice" should be "some content" + And as "Alice" the folder with original path "renamedFolder" should exist in the trashbin + But as "Alice" folder "testFolder" should not exist + Examples: + | dav-path-version | + | old | + | new | + + @skipOnRevaMaster + Examples: + | dav-path-version | + | spaces | + + + Scenario Outline: try to rename folder to . and .. + Given using DAV path + And user "Alice" has created folder "testFolder" + When user "Alice" moves folder "testFolder" to "" using the WebDAV API + Then the HTTP status code should be "" + Examples: + | dav-path-version | folder-name | http-status-code | + | old | /. | 409 | + | old | /.. | 404 | + | new | /. | 409 | + | new | /.. | 404 | + + @skipOnRevaMaster + Examples: + | dav-path-version | folder-name | http-status-code | + | spaces | /. | 409 | + | spaces | /.. | 400 | \ No newline at end of file diff --git a/tests/acceptance/features/coreApiWebdavOperations/downloadFile.feature b/tests/acceptance/features/coreApiWebdavOperations/downloadFile.feature index d682aefb1e..c2a787b210 100644 --- a/tests/acceptance/features/coreApiWebdavOperations/downloadFile.feature +++ b/tests/acceptance/features/coreApiWebdavOperations/downloadFile.feature @@ -328,3 +328,10 @@ Feature: download file When user "Alice" downloads file "/zerobyte.txt" using the WebDAV API Then the HTTP status code should be "200" And the size of the downloaded file should be 0 bytes + + + Scenario: try to download recently deleted file + When user "Alice" deletes file "textfile0.txt" using the WebDAV API + Then the HTTP status code should be "204" + When user "Alice" tries to download file "textfile0.txt" using the WebDAV API + Then the HTTP status code should be "404"