Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ApiTest. download files #3809

Merged
merged 3 commits into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions tests/acceptance/features/apiSpaces/download.feature
Original file line number Diff line number Diff line change
@@ -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 changes: 27 additions & 27 deletions tests/acceptance/features/apiSpaces/listSpaces.feature
Original file line number Diff line number Diff line change
Expand Up @@ -54,55 +54,55 @@ 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
Given the administrator has given "Alice" the role "Admin" using the settings api
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
Given the administrator has given "Alice" the role "Admin" using the settings api
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% |
104 changes: 104 additions & 0 deletions tests/acceptance/features/bootstrap/SpacesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -2268,4 +2268,108 @@ public function downloadPreview(
)
);
}

/**
* @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");
}
}