[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
This commit is contained in:
Sawjan Gurung
2024-05-02 12:21:35 +05:45
committed by GitHub
parent 3309b9c93c
commit 5c7c363e2b
5 changed files with 205 additions and 119 deletions

View File

@@ -223,6 +223,7 @@ default:
contexts:
- FeatureContext: *common_feature_context_params
- WebDavPropertiesContext:
- TrashbinContext:
coreApiWebdavMove2:
paths:

View File

@@ -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)

View File

@@ -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

View File

@@ -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-version> 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-version> 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-version> DAV path
And user "Alice" has created folder <from-folder-name>
When user "Alice" moves folder <from-folder-name> to <to-folder-name> using the WebDAV API
Then the HTTP status code should be "201"
And as "Alice" folder <to-folder-name> should exist
But as "Alice" folder <from-folder-name> 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-version> 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-version> 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-version> 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-version> DAV path
And user "Alice" has created folder "testFolder"
When user "Alice" moves folder "testFolder" to "<folder-name>" using the WebDAV API
Then the HTTP status code should be "<http-status-code>"
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 |

View File

@@ -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"