mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-03-29 21:02:06 -04:00
Merge pull request #6880 from owncloud/Forwardport-download-space
[full-ci][tests-only]Forward port download space
This commit is contained in:
@@ -109,6 +109,7 @@ config = {
|
||||
"apiSpacesShares",
|
||||
"apiCors",
|
||||
"apiAsyncUpload",
|
||||
"apiDownloads",
|
||||
],
|
||||
"skip": False,
|
||||
},
|
||||
|
||||
@@ -175,6 +175,26 @@ default:
|
||||
- OcisConfigContext:
|
||||
- PublicWebDavContext:
|
||||
|
||||
apiDownloads:
|
||||
paths:
|
||||
- '%paths.base%/../features/apiDownloads'
|
||||
context: *common_ldap_suite_context
|
||||
contexts:
|
||||
- NotificationContext:
|
||||
- SpacesContext:
|
||||
- FeatureContext: *common_feature_context_params
|
||||
- WebDavPropertiesContext:
|
||||
- OCSContext:
|
||||
- GraphContext:
|
||||
- TrashbinContext:
|
||||
- FavoritesContext:
|
||||
- ChecksumContext:
|
||||
- FilesVersionsContext:
|
||||
- SettingsContext:
|
||||
- OcisConfigContext:
|
||||
- PublicWebDavContext:
|
||||
- ArchiverContext:
|
||||
|
||||
apiFullTextSearch:
|
||||
paths:
|
||||
- '%paths.base%/../features/apiFullTextSearch'
|
||||
|
||||
62
tests/acceptance/features/apiDownloads/spaceDownload.feature
Normal file
62
tests/acceptance/features/apiDownloads/spaceDownload.feature
Normal file
@@ -0,0 +1,62 @@
|
||||
@api
|
||||
Feature: Download space
|
||||
As a user
|
||||
I want to download space
|
||||
So that I can store it locally
|
||||
|
||||
|
||||
Background:
|
||||
Given these users have been created with default attributes and without skeleton files:
|
||||
| username |
|
||||
| Alice |
|
||||
| Brian |
|
||||
And using spaces DAV path
|
||||
And the administrator has assigned the role "Space Admin" to user "Alice" using the Graph API
|
||||
And user "Alice" has created a space "Project-space" with the default quota using the GraphApi
|
||||
And user "Alice" has uploaded a file inside space "Project-space" with content "some data" to "file1.txt"
|
||||
And user "Alice" has created a folder ".space" in space "Project-space"
|
||||
And user "Alice" has uploaded a file inside space "Project-space" with content "space description" to ".space/readme.md"
|
||||
|
||||
|
||||
Scenario: user downloads a space
|
||||
Given user "Alice" has uploaded a file inside space "Project-space" with content "other data" to "file2.txt"
|
||||
When user "Alice" downloads the space "Project-space" using the WebDAV API
|
||||
Then the HTTP status code should be "200"
|
||||
And the downloaded "tar" archive should contain these files:
|
||||
| name | content |
|
||||
| file1.txt | some data |
|
||||
| file2.txt | other data |
|
||||
| .space/readme.md | space description |
|
||||
|
||||
|
||||
Scenario Outline: user downloads a shared space (shared by others)
|
||||
Given user "Alice" has shared a space "Project-space" with settings:
|
||||
| shareWith | Brian |
|
||||
| role | <role> |
|
||||
When user "Brian" downloads the space "Project-space" using the WebDAV API
|
||||
Then the HTTP status code should be "200"
|
||||
And the downloaded "tar" archive should contain these files:
|
||||
| name | content |
|
||||
| file1.txt | some data |
|
||||
| .space/readme.md | space description |
|
||||
Examples:
|
||||
| role |
|
||||
| manager |
|
||||
| editor |
|
||||
| viewer |
|
||||
|
||||
|
||||
Scenario Outline: admin/space-admin tries to download a space that they do not have access to
|
||||
Given the administrator has assigned the role "<userRole>" to user "Brian" using the Graph API
|
||||
When user "Brian" tries to download the space "Project-space" owned by user "Alice" using the WebDAV API
|
||||
Then the HTTP status code should be "404"
|
||||
Examples:
|
||||
| userRole |
|
||||
| Admin |
|
||||
| Space Admin |
|
||||
|
||||
|
||||
Scenario: user tries to download disabled space
|
||||
Given user "Alice" has disabled a space "Project-space"
|
||||
When user "Alice" tries to download the space "Project-space" using the WebDAV API
|
||||
Then the HTTP status code should be "404"
|
||||
@@ -26,7 +26,6 @@ use Behat\Gherkin\Node\TableNode;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use TestHelpers\HttpRequestHelper;
|
||||
use TestHelpers\SetupHelper;
|
||||
use wapmorgan\UnifiedArchive\UnifiedArchive;
|
||||
use PHPUnit\Framework\Assert;
|
||||
use \Psr\Http\Message\ResponseInterface;
|
||||
|
||||
@@ -219,18 +218,41 @@ class ArchiverContext implements Context {
|
||||
*/
|
||||
public function theDownloadedArchiveShouldContainTheseFiles(string $type, TableNode $expectedFiles):void {
|
||||
$this->featureContext->verifyTableNodeColumns($expectedFiles, ['name', 'content']);
|
||||
$contents = $this->featureContext->getResponse()->getBody()->getContents();
|
||||
$tempFile = \tempnam(\sys_get_temp_dir(), 'OcAcceptanceTests_');
|
||||
\unlink($tempFile); // we only need the name
|
||||
$tempFile = $tempFile . '.' . $type; // it needs the extension
|
||||
\file_put_contents($tempFile, $this->featureContext->getResponse()->getBody()->getContents());
|
||||
$archive = UnifiedArchive::open($tempFile);
|
||||
foreach ($expectedFiles->getHash() as $expectedFile) {
|
||||
Assert::assertEquals(
|
||||
$expectedFile['content'],
|
||||
$archive->getFileContent($expectedFile['name']),
|
||||
__METHOD__ .
|
||||
" content of '" . $expectedFile['name'] . "' not as expected"
|
||||
);
|
||||
\file_put_contents($tempFile, $contents);
|
||||
|
||||
// open the archive
|
||||
$archiveData = new RecursiveIteratorIterator(
|
||||
new PharData($tempFile),
|
||||
RecursiveIteratorIterator::SELF_FIRST
|
||||
);
|
||||
foreach ($expectedFiles->getHash() as $expectedItem) {
|
||||
$expectedPath = trim($expectedItem['name'], "/");
|
||||
$found = false;
|
||||
foreach ($archiveData as $info) {
|
||||
// get only the parent folder path for the given item
|
||||
$actualPath = explode(".$type", $info->getPathname())[1];
|
||||
$actualPath = trim($actualPath, "/");
|
||||
|
||||
if ($expectedPath === $actualPath) {
|
||||
if (!$info->isDir()) {
|
||||
Assert::assertEquals(
|
||||
$expectedItem['content'],
|
||||
$info->getContent(),
|
||||
__METHOD__ .
|
||||
" content of '" . $expectedPath . "' not as expected"
|
||||
);
|
||||
}
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$found) {
|
||||
Assert::fail("Resource '" . $expectedPath . "' is not in the downloaded archive.");
|
||||
}
|
||||
}
|
||||
\unlink($tempFile);
|
||||
}
|
||||
|
||||
@@ -3316,4 +3316,29 @@ class SpacesContext implements Context {
|
||||
}
|
||||
Assert::assertTrue($foundRoleInResponse, "the response does not contain the $recipientType $recipient");
|
||||
}
|
||||
|
||||
/**
|
||||
* @When user :user tries to download the space :spaceName owned by user :owner using the WebDAV API
|
||||
* @When /^user "([^"]*)" (?:downloads|tries to download) the space "([^"]*)" using the WebDAV API$/
|
||||
*
|
||||
* @param string $user
|
||||
* @param string $spaceName
|
||||
* @param string $owner
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function userDownloadsTheSpaceUsingTheWebdavApi(string $user, string $spaceName, string $owner = ''):void {
|
||||
$space = $this->getSpaceByName($owner ?: $user, $spaceName);
|
||||
$url = $this->featureContext->getBaseUrl() . '/archiver?id=' . $space['id'];
|
||||
$this->featureContext->setResponse(
|
||||
HttpRequestHelper::get(
|
||||
$url,
|
||||
'',
|
||||
$user,
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user