From 926e547f99d7112ed37ce033381376b6b82ffa47 Mon Sep 17 00:00:00 2001 From: Salipa-Gurung Date: Fri, 30 Jun 2023 14:27:53 +0545 Subject: [PATCH 1/3] add test for downloading space --- tests/acceptance/config/behat.yml | 1 + .../features/apiSpaces/spaceDownload.feature | 22 ++++++++++ .../features/bootstrap/ArchiverContext.php | 42 ++++++++++++++----- .../features/bootstrap/SpacesContext.php | 23 ++++++++++ 4 files changed, 78 insertions(+), 10 deletions(-) create mode 100644 tests/acceptance/features/apiSpaces/spaceDownload.feature diff --git a/tests/acceptance/config/behat.yml b/tests/acceptance/config/behat.yml index aca23fc38cd..8a48af363f9 100644 --- a/tests/acceptance/config/behat.yml +++ b/tests/acceptance/config/behat.yml @@ -47,6 +47,7 @@ default: - SpacesTUSContext: - GraphContext: - OcisConfigContext: + - ArchiverContext: apiSpacesShares: paths: diff --git a/tests/acceptance/features/apiSpaces/spaceDownload.feature b/tests/acceptance/features/apiSpaces/spaceDownload.feature new file mode 100644 index 00000000000..a0b037c29c7 --- /dev/null +++ b/tests/acceptance/features/apiSpaces/spaceDownload.feature @@ -0,0 +1,22 @@ +@api +Feature: Download space + As a user + I want to download space + So that I can store it locally + + + Scenario: user downloads a space + Given user "Alice" has been created with default attributes and without skeleton files + 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 uploaded a file inside space "project-space" with content "other data" to "file2.txt" + And user "Alice" has uploaded a file inside space "project-space" with content "more data" to "file3.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 | + | file3.txt | more data | diff --git a/tests/acceptance/features/bootstrap/ArchiverContext.php b/tests/acceptance/features/bootstrap/ArchiverContext.php index fbd93b3d2aa..8c854bf7a57 100644 --- a/tests/acceptance/features/bootstrap/ArchiverContext.php +++ b/tests/acceptance/features/bootstrap/ArchiverContext.php @@ -26,7 +26,6 @@ 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 @@ public function userDownloadsTheArchiveOfTheseItems( */ 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); } diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index bea2fd4c80f..0085a376ebc 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -3316,4 +3316,27 @@ public function theUserShouldHaveSpaceWithRecipient( } Assert::assertTrue($foundRoleInResponse, "the response does not contain the $recipientType $recipient"); } + + /** + * @When user :user downloads the space :spaceName using the WebDAV API + * + * @param string $user + * @param string $spaceName + * + * @return void + * + * @throws GuzzleException + */ + public function userDownloadsTheSpaceUsingTheWebdavApi(string $user, string $spaceName):void { + $space = $this->getSpaceByName($user, $spaceName); + $url = $this->featureContext->getBaseUrl() . '/archiver?id=' . $space["id"]; + $this->featureContext->setResponse( + HttpRequestHelper::get( + $url, + '', + $user, + $this->featureContext->getPasswordForUser($user), + ) + ); + } } From 1138412affae42961e90eb1ffe0877e80dea8a00 Mon Sep 17 00:00:00 2001 From: amrita Date: Thu, 20 Jul 2023 10:25:30 +0545 Subject: [PATCH 2/3] Add hidden file also --- .../features/apiSpaces/spaceDownload.feature | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/tests/acceptance/features/apiSpaces/spaceDownload.feature b/tests/acceptance/features/apiSpaces/spaceDownload.feature index a0b037c29c7..c6dbba9ccb7 100644 --- a/tests/acceptance/features/apiSpaces/spaceDownload.feature +++ b/tests/acceptance/features/apiSpaces/spaceDownload.feature @@ -9,14 +9,17 @@ Feature: Download space Given user "Alice" has been created with default attributes and without skeleton files 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 uploaded a file inside space "project-space" with content "other data" to "file2.txt" - And user "Alice" has uploaded a file inside space "project-space" with content "more data" to "file3.txt" - When user "Alice" downloads the space "project-space" using the WebDAV 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 uploaded a file inside space "Project-space" with content "other data" to "file2.txt" + And user "Alice" has uploaded a file inside space "Project-space" with content "more data" to "file3.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" + 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 | - | file3.txt | more data | + | name | content | + | file1.txt | some data | + | file2.txt | other data | + | file3.txt | more data | + | .space/readme.md | space description | From 6900a805119bee403c1467ff73237ca18eeeeaec Mon Sep 17 00:00:00 2001 From: Amrita <54478846+amrita-shrestha@users.noreply.github.com> Date: Mon, 24 Jul 2023 16:12:22 +0545 Subject: [PATCH 3/3] Add more tests coverage (#6854) --- .drone.star | 1 + tests/acceptance/config/behat.yml | 21 ++++++- .../download.feature | 0 .../apiDownloads/spaceDownload.feature | 62 +++++++++++++++++++ .../features/apiSpaces/spaceDownload.feature | 25 -------- .../features/bootstrap/SpacesContext.php | 10 +-- 6 files changed, 89 insertions(+), 30 deletions(-) rename tests/acceptance/features/{apiSpaces => apiDownloads}/download.feature (100%) create mode 100644 tests/acceptance/features/apiDownloads/spaceDownload.feature delete mode 100644 tests/acceptance/features/apiSpaces/spaceDownload.feature diff --git a/.drone.star b/.drone.star index e8bf22ef8ff..ea271f4dc90 100644 --- a/.drone.star +++ b/.drone.star @@ -109,6 +109,7 @@ config = { "apiSpacesShares", "apiCors", "apiAsyncUpload", + "apiDownloads", ], "skip": False, }, diff --git a/tests/acceptance/config/behat.yml b/tests/acceptance/config/behat.yml index 8a48af363f9..c42a4e7c56d 100644 --- a/tests/acceptance/config/behat.yml +++ b/tests/acceptance/config/behat.yml @@ -47,7 +47,6 @@ default: - SpacesTUSContext: - GraphContext: - OcisConfigContext: - - ArchiverContext: apiSpacesShares: paths: @@ -176,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' diff --git a/tests/acceptance/features/apiSpaces/download.feature b/tests/acceptance/features/apiDownloads/download.feature similarity index 100% rename from tests/acceptance/features/apiSpaces/download.feature rename to tests/acceptance/features/apiDownloads/download.feature diff --git a/tests/acceptance/features/apiDownloads/spaceDownload.feature b/tests/acceptance/features/apiDownloads/spaceDownload.feature new file mode 100644 index 00000000000..dee327260fc --- /dev/null +++ b/tests/acceptance/features/apiDownloads/spaceDownload.feature @@ -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 | | + 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 "" 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" diff --git a/tests/acceptance/features/apiSpaces/spaceDownload.feature b/tests/acceptance/features/apiSpaces/spaceDownload.feature deleted file mode 100644 index c6dbba9ccb7..00000000000 --- a/tests/acceptance/features/apiSpaces/spaceDownload.feature +++ /dev/null @@ -1,25 +0,0 @@ -@api -Feature: Download space - As a user - I want to download space - So that I can store it locally - - - Scenario: user downloads a space - Given user "Alice" has been created with default attributes and without skeleton files - 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 uploaded a file inside space "Project-space" with content "other data" to "file2.txt" - And user "Alice" has uploaded a file inside space "Project-space" with content "more data" to "file3.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" - 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 | - | file3.txt | more data | - | .space/readme.md | space description | diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index 0085a376ebc..f460b5e4485 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -3318,18 +3318,20 @@ public function theUserShouldHaveSpaceWithRecipient( } /** - * @When user :user downloads the space :spaceName using the WebDAV API + * @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):void { - $space = $this->getSpaceByName($user, $spaceName); - $url = $this->featureContext->getBaseUrl() . '/archiver?id=' . $space["id"]; + 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,