ApiTest. download files (#3809)
* add tests download file * added ability to download different versions of files * fix after review
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
@api @skipOnOcV10
|
||||
Feature: Download file in project space
|
||||
As a user, I want to be able to download files
|
||||
|
||||
Note - this feature is run in CI with ACCOUNTS_HASH_DIFFICULTY set to the default for production
|
||||
See https://github.com/owncloud/ocis/issues/1542 and https://github.com/owncloud/ocis/pull/839
|
||||
|
||||
Background:
|
||||
Given these users have been created with default attributes and without skeleton files:
|
||||
| username |
|
||||
| Alice |
|
||||
| Brian |
|
||||
And the administrator has given "Alice" the role "Admin" using the settings api
|
||||
And user "Alice" has created a space "download file" with the default quota using the GraphApi
|
||||
And user "Alice" has uploaded a file inside space "download file" with content "some content" to "file.txt"
|
||||
|
||||
|
||||
Scenario: An user downloads a file in the project space
|
||||
When user "Alice" downloads the file "file.txt" of the space "download file" using the WebDAV API
|
||||
Then the HTTP status code should be "200"
|
||||
And the following headers should be set
|
||||
| header | value |
|
||||
| Content-Length | 12 |
|
||||
|
||||
|
||||
Scenario: An user downloads an old version of the file in the project space
|
||||
Given user "Alice" has uploaded a file inside space "download file" with content "new content" to "file.txt"
|
||||
And user "Alice" has uploaded a file inside space "download file" with content "newest content" to "file.txt"
|
||||
When user "Alice" downloads version of the file "file.txt" with the index "1" of the space "download file" using the WebDAV API
|
||||
Then the HTTP status code should be "200"
|
||||
And the following headers should be set
|
||||
| header | value |
|
||||
| Content-Length | 11 |
|
||||
When user "Alice" downloads version of the file "file.txt" with the index "2" of the space "download file" using the WebDAV API
|
||||
Then the HTTP status code should be "200"
|
||||
And the following headers should be set
|
||||
| header | value |
|
||||
| Content-Length | 12 |
|
||||
@@ -54,11 +54,11 @@ Feature: List and create spaces
|
||||
When user "Alice" creates a space "Project Mars" of type "project" with the default quota using the GraphApi
|
||||
Then the HTTP status code should be "201"
|
||||
And the json responded should contain a space "Project Mars" with these key and value pairs:
|
||||
| key | value |
|
||||
| driveType | project |
|
||||
| driveAlias | project/project-mars |
|
||||
| name | Project Mars |
|
||||
| quota@@@total | 1000000000 |
|
||||
| key | value |
|
||||
| driveType | project |
|
||||
| driveAlias | project/project-mars |
|
||||
| name | Project Mars |
|
||||
| quota@@@total | 1000000000 |
|
||||
| root@@@webDavUrl | %base_url%/dav/spaces/%space_id% |
|
||||
|
||||
Scenario: An admin user can create a Space via the Graph API with certain quota
|
||||
@@ -66,25 +66,25 @@ Feature: List and create spaces
|
||||
When user "Alice" creates a space "Project Venus" of type "project" with quota "2000" using the GraphApi
|
||||
Then the HTTP status code should be "201"
|
||||
And the json responded should contain a space "Project Venus" with these key and value pairs:
|
||||
| key | value |
|
||||
| driveType | project |
|
||||
| name | Project Venus |
|
||||
| quota@@@total | 2000 |
|
||||
| key | value |
|
||||
| driveType | project |
|
||||
| name | Project Venus |
|
||||
| quota@@@total | 2000 |
|
||||
| root@@@webDavUrl | %base_url%/dav/spaces/%space_id% |
|
||||
|
||||
Scenario: A user can list his personal space via multiple endpoints
|
||||
When user "Alice" lists all available spaces via the GraphApi with query "$filter=driveType eq 'personal'"
|
||||
Then the json responded should contain a space "Alice Hansen" owned by "Alice" with these key and value pairs:
|
||||
| key | value |
|
||||
| driveType | personal |
|
||||
| name | Alice Hansen |
|
||||
| root@@@webDavUrl | %base_url%/dav/spaces/%space_id% |
|
||||
| owner@@@user@@@id | %user_id% |
|
||||
| key | value |
|
||||
| driveType | personal |
|
||||
| name | Alice Hansen |
|
||||
| root@@@webDavUrl | %base_url%/dav/spaces/%space_id% |
|
||||
| owner@@@user@@@id | %user_id% |
|
||||
When user "Alice" looks up the single space "Alice Hansen" via the GraphApi by using its id
|
||||
Then the json responded should contain a space "Alice Hansen" with these key and value pairs:
|
||||
| key | value |
|
||||
| driveType | personal |
|
||||
| name | Alice Hansen |
|
||||
| key | value |
|
||||
| driveType | personal |
|
||||
| name | Alice Hansen |
|
||||
| root@@@webDavUrl | %base_url%/dav/spaces/%space_id% |
|
||||
|
||||
Scenario: A user can list his created spaces via multiple endpoints
|
||||
@@ -92,17 +92,17 @@ Feature: List and create spaces
|
||||
When user "Alice" creates a space "Project Venus" of type "project" with quota "2000" using the GraphApi
|
||||
Then the HTTP status code should be "201"
|
||||
And the json responded should contain a space "Project Venus" with these key and value pairs:
|
||||
| key | value |
|
||||
| driveType | project |
|
||||
| driveAlias | project/project-venus |
|
||||
| name | Project Venus |
|
||||
| quota@@@total | 2000 |
|
||||
| key | value |
|
||||
| driveType | project |
|
||||
| driveAlias | project/project-venus |
|
||||
| name | Project Venus |
|
||||
| quota@@@total | 2000 |
|
||||
| root@@@webDavUrl | %base_url%/dav/spaces/%space_id% |
|
||||
When user "Alice" looks up the single space "Project Venus" via the GraphApi by using its id
|
||||
Then the json responded should contain a space "Project Venus" with these key and value pairs:
|
||||
| key | value |
|
||||
| driveType | project |
|
||||
| driveAlias | project/project-venus |
|
||||
| name | Project Venus |
|
||||
| quota@@@total | 2000 |
|
||||
| key | value |
|
||||
| driveType | project |
|
||||
| driveAlias | project/project-venus |
|
||||
| name | Project Venus |
|
||||
| quota@@@total | 2000 |
|
||||
| root@@@webDavUrl | %base_url%/dav/spaces/%space_id% |
|
||||
|
||||
@@ -2268,4 +2268,108 @@ class SpacesContext implements Context {
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^user "([^"]*)" downloads the file "([^"]*)" of the space "([^"]*)" using the WebDAV API$/
|
||||
*
|
||||
* @param string $user
|
||||
* @param string $fileName
|
||||
* @param string $spaceName
|
||||
*
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function downloadFile(
|
||||
string $user,
|
||||
string $fileName,
|
||||
string $spaceName
|
||||
): void {
|
||||
$space = $this->getSpaceByName($user, $spaceName);
|
||||
$fullUrl = $this->baseUrl . $this->davSpacesUrl . $space['id'] . '/' . $fileName;
|
||||
|
||||
$this->featureContext->setResponse(
|
||||
HttpRequestHelper::sendRequest(
|
||||
$fullUrl,
|
||||
"",
|
||||
'HEAD',
|
||||
$user,
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
[],
|
||||
""
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^user "([^"]*)" downloads version of the file "([^"]*)" with the index "([^"]*)" of the space "([^"]*)" using the WebDAV API$/
|
||||
*
|
||||
* @param string $user
|
||||
* @param string $fileName
|
||||
* @param string $index
|
||||
* @param string $spaceName
|
||||
*
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function downloadVersionOfTheFile(
|
||||
string $user,
|
||||
string $fileName,
|
||||
string $index,
|
||||
string $spaceName
|
||||
): void {
|
||||
$fileVersion = $this->listFileVersion($user, $fileName, $spaceName);
|
||||
if (!isset($fileVersion[$index])) {
|
||||
Assert::fail(
|
||||
'could not find version of file "' . $fileName . '" with index "' . $index . '"'
|
||||
);
|
||||
}
|
||||
$url = $this->baseUrl . $fileVersion[$index][0];
|
||||
|
||||
$this->featureContext->setResponse(
|
||||
HttpRequestHelper::sendRequest(
|
||||
$url,
|
||||
"",
|
||||
'HEAD',
|
||||
$user,
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
[],
|
||||
""
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method returns an array with url values from the propfind request
|
||||
* like: /remote.php/dav/meta/spaceUuid%fileUuid/v/fileUuid.REV.2022-05-17T10:39:49.672285951Z
|
||||
|
||||
*
|
||||
* @param string $user
|
||||
* @param string $fileName
|
||||
* @param string $spaceName
|
||||
*
|
||||
* @return array
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function listFileVersion(
|
||||
string $user,
|
||||
string $fileName,
|
||||
string $spaceName
|
||||
): array {
|
||||
|
||||
$fileId = $this->getFileId($user, $spaceName, $fileName);
|
||||
$fullUrl = $this->baseUrl . '/remote.php/dav/meta/' . $fileId . '/v';
|
||||
|
||||
$this->featureContext->setResponse(
|
||||
HttpRequestHelper::sendRequest(
|
||||
$fullUrl,
|
||||
"",
|
||||
'PROPFIND',
|
||||
$user,
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
[],
|
||||
""
|
||||
)
|
||||
);
|
||||
|
||||
$responseXml = HttpRequestHelper::getResponseXml($this->featureContext->getResponse());
|
||||
return $responseXml->xpath("//d:response/d:href");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user