From 131327dd09677f4bd19c050fb02d7f28d92db5de Mon Sep 17 00:00:00 2001 From: Swikriti Tripathi Date: Thu, 15 Dec 2022 14:20:04 +0545 Subject: [PATCH 1/5] Adds api tests to download folder from public link --- tests/acceptance/config/behat.yml | 3 +- ...ected-failures-localAPI-on-OCIS-storage.md | 3 ++ .../publicLinkDownload.feature | 43 +++++++++++++++++++ .../features/bootstrap/SpacesContext.php | 32 ++++++++++++++ 4 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 tests/acceptance/features/apiSpacesShares/publicLinkDownload.feature diff --git a/tests/acceptance/config/behat.yml b/tests/acceptance/config/behat.yml index 6527404c118..c443e647c68 100644 --- a/tests/acceptance/config/behat.yml +++ b/tests/acceptance/config/behat.yml @@ -73,7 +73,8 @@ default: - WebDavPropertiesContext: - TUSContext: - SpacesTUSContext: - + - ArchiverContext: + apiContract: paths: - '%paths.base%/../features/apiContract' diff --git a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md index bbf503974c9..d97fd0621ec 100644 --- a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md +++ b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md @@ -87,3 +87,6 @@ The expected failures in this file are from features in the owncloud/ocis repo. - [apiSpacesShares/shareSubItemOfSpaceViaPublicLink.feature:160](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpacesShares/shareSubItemOfSpaceViaPublicLink.feature#L160) - [apiSpacesShares/shareSubItemOfSpaceViaPublicLink.feature:161](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpacesShares/shareSubItemOfSpaceViaPublicLink.feature#L161) - [apiSpacesShares/shareSubItemOfSpaceViaPublicLink.feature:162](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpacesShares/shareSubItemOfSpaceViaPublicLink.feature#L162) + +#### [Public cannot download folder via the public link of the folder inside the project space](https://github.com/owncloud/ocis/issues/5229) +- [apiSpacesShares/publicLinkDownload.feature:31](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpacesShares/publicLinkDownload.feature#L31) diff --git a/tests/acceptance/features/apiSpacesShares/publicLinkDownload.feature b/tests/acceptance/features/apiSpacesShares/publicLinkDownload.feature new file mode 100644 index 00000000000..754bbd9e5db --- /dev/null +++ b/tests/acceptance/features/apiSpacesShares/publicLinkDownload.feature @@ -0,0 +1,43 @@ +@api @skipOnOcV10 +Feature: Public can download folders from project space public link + As a public + I want to be able to download folder from public link + So that I can gain access to it's contents + + 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 given "Alice" the role "Space Admin" using the settings api + And user "Alice" has created a space "new-space" with the default quota using the GraphApi + + + Scenario: download a folder from public link of a space + Given user "Alice" has created a public link share of the space "new-space" with settings: + | permissions | 1 | + | name | someName | + And user "Alice" has created a folder "NewFolder" in space "new-space" + And user "Alice" has uploaded a file inside space "new-space" with content "some content" to "NewFolder/test.txt" + When public downloads the folder "NewFolder" of space "new-space" from the last created public link of "Alice" using the resource id + Then the HTTP status code should be "200" + And the downloaded tar archive should contain these files: + | name | content | + | NewFolder/test.txt | some content | + + @issue-5229 + Scenario: download a folder from public link of a folder inside a space + Given user "Alice" has created a folder "NewFolder" in space "new-space" + And user "Alice" has created a folder "NewFolder/folder" in space "new-space" + And user "Alice" has uploaded a file inside space "new-space" with content "some content" to "NewFolder/folder/test.txt" + And user "Alice" has created a public link share inside of space "new-space" with settings: + | path | NewFolder | + | shareType | 3 | + | permissions | 1 | + | name | public link | + When public downloads the folder "NewFolder/folder" of space "new-space" from the last created public link of "Alice" using the resource id + Then the HTTP status code should be "200" + And the downloaded tar archive should contain these files: + | name | content | + | folder/test.txt | some content | diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index f588fd7bf63..74646277673 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -73,6 +73,12 @@ class SpacesContext implements Context { * @var FilesVersionsContext */ private FilesVersionsContext $filesVersionsContext; + + /** + * @var ArchiverContext + */ + private ArchiverContext $archiverContext; + /** * @var string */ @@ -469,6 +475,7 @@ class SpacesContext implements Context { $this->favoritesContext = $environment->getContext('FavoritesContext'); $this->checksumContext = $environment->getContext('ChecksumContext'); $this->filesVersionsContext = $environment->getContext('FilesVersionsContext'); + $this->archiverContext = $environment->getContext('ArchiverContext'); // Run the BeforeScenario function in OCSContext to set it up correctly $this->ocsContext->before($scope); $this->baseUrl = \trim($this->featureContext->getBaseUrl(), "/"); @@ -3028,4 +3035,29 @@ class SpacesContext implements Context { } } } + + /** + * @When /^public downloads the folder "([^"]*)" of space "([^"]*)" from the last created public link of "([^"]*)" using the resource id$/ + * @param string $resource + * @param string $space + * @param string $owner + * + * @return void + * @throws GuzzleException + */ + public function publicDownloadsTheFolderFromTheLastCreatedPublicLink(string $resource, string $space, string $owner) + { + $token = $this->featureContext->getLastPublicShareToken(); + $resourceId = $this->getFolderId($owner, $space, $resource); + $queryString = 'public-token='.$token.'&id='.$resourceId; + $this->featureContext->setResponse( + HttpRequestHelper::get( + $this->featureContext->getBaseUrl() . '/archiver?' . $queryString, + '', + '', + '', + ) + ); + } + } From 8222c4ee1729991d9c19936e5058ad899dd68592 Mon Sep 17 00:00:00 2001 From: Swikriti Tripathi Date: Thu, 15 Dec 2022 16:18:18 +0545 Subject: [PATCH 2/5] fex style --- ...ected-failures-localAPI-on-OCIS-storage.md | 2 +- .../features/bootstrap/SpacesContext.php | 53 ++++++++----------- 2 files changed, 24 insertions(+), 31 deletions(-) diff --git a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md index d97fd0621ec..b6ddac45724 100644 --- a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md +++ b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md @@ -89,4 +89,4 @@ The expected failures in this file are from features in the owncloud/ocis repo. - [apiSpacesShares/shareSubItemOfSpaceViaPublicLink.feature:162](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpacesShares/shareSubItemOfSpaceViaPublicLink.feature#L162) #### [Public cannot download folder via the public link of the folder inside the project space](https://github.com/owncloud/ocis/issues/5229) -- [apiSpacesShares/publicLinkDownload.feature:31](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpacesShares/publicLinkDownload.feature#L31) +- [apiSpacesShares/publicLinkDownload.feature:30](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpacesShares/publicLinkDownload.feature#L30) diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index 74646277673..7f793a8aeb9 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -74,11 +74,6 @@ class SpacesContext implements Context { */ private FilesVersionsContext $filesVersionsContext; - /** - * @var ArchiverContext - */ - private ArchiverContext $archiverContext; - /** * @var string */ @@ -475,7 +470,6 @@ class SpacesContext implements Context { $this->favoritesContext = $environment->getContext('FavoritesContext'); $this->checksumContext = $environment->getContext('ChecksumContext'); $this->filesVersionsContext = $environment->getContext('FilesVersionsContext'); - $this->archiverContext = $environment->getContext('ArchiverContext'); // Run the BeforeScenario function in OCSContext to set it up correctly $this->ocsContext->before($scope); $this->baseUrl = \trim($this->featureContext->getBaseUrl(), "/"); @@ -3036,28 +3030,27 @@ class SpacesContext implements Context { } } - /** - * @When /^public downloads the folder "([^"]*)" of space "([^"]*)" from the last created public link of "([^"]*)" using the resource id$/ - * @param string $resource - * @param string $space - * @param string $owner - * - * @return void - * @throws GuzzleException - */ - public function publicDownloadsTheFolderFromTheLastCreatedPublicLink(string $resource, string $space, string $owner) - { - $token = $this->featureContext->getLastPublicShareToken(); - $resourceId = $this->getFolderId($owner, $space, $resource); - $queryString = 'public-token='.$token.'&id='.$resourceId; - $this->featureContext->setResponse( - HttpRequestHelper::get( - $this->featureContext->getBaseUrl() . '/archiver?' . $queryString, - '', - '', - '', - ) - ); - } - + /** + * @When /^public downloads the folder "([^"]*)" of space "([^"]*)" from the last created public link of "([^"]*)" using the resource id$/ + * + * @param string $resource + * @param string $space + * @param string $owner + * + * @return void + * @throws GuzzleException + */ + public function publicDownloadsTheFolderFromTheLastCreatedPublicLink(string $resource, string $space, string $owner) { + $token = $this->featureContext->getLastPublicShareToken(); + $resourceId = $this->getFolderId($owner, $space, $resource); + $queryString = 'public-token=' . $token . '&id=' . $resourceId; + $this->featureContext->setResponse( + HttpRequestHelper::get( + $this->featureContext->getBaseUrl() . '/archiver?' . $queryString, + '', + '', + '', + ) + ); + } } From 4328b852b427de0876613b9544a55d47cf22be77 Mon Sep 17 00:00:00 2001 From: Swikriti Tripathi Date: Fri, 16 Dec 2022 15:59:58 +0545 Subject: [PATCH 3/5] Address review --- .../features/apiSpacesShares/publicLinkDownload.feature | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/acceptance/features/apiSpacesShares/publicLinkDownload.feature b/tests/acceptance/features/apiSpacesShares/publicLinkDownload.feature index 754bbd9e5db..e0dc710286e 100644 --- a/tests/acceptance/features/apiSpacesShares/publicLinkDownload.feature +++ b/tests/acceptance/features/apiSpacesShares/publicLinkDownload.feature @@ -15,11 +15,11 @@ Feature: Public can download folders from project space public link Scenario: download a folder from public link of a space - Given user "Alice" has created a public link share of the space "new-space" with settings: - | permissions | 1 | - | name | someName | - And user "Alice" has created a folder "NewFolder" in space "new-space" + Given user "Alice" has created a folder "NewFolder" in space "new-space" And user "Alice" has uploaded a file inside space "new-space" with content "some content" to "NewFolder/test.txt" + And user "Alice" has created a public link share of the space "new-space" with settings: + | permissions | 1 | + | name | someName | When public downloads the folder "NewFolder" of space "new-space" from the last created public link of "Alice" using the resource id Then the HTTP status code should be "200" And the downloaded tar archive should contain these files: From 563f7a83ca3f1bdb173cc5b083cdafe76a54a3db Mon Sep 17 00:00:00 2001 From: Swikriti Tripathi Date: Mon, 19 Dec 2022 10:00:08 +0545 Subject: [PATCH 4/5] adress review --- .../features/apiSpacesShares/publicLinkDownload.feature | 4 ++-- tests/acceptance/features/bootstrap/SpacesContext.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/acceptance/features/apiSpacesShares/publicLinkDownload.feature b/tests/acceptance/features/apiSpacesShares/publicLinkDownload.feature index e0dc710286e..5593a8803cb 100644 --- a/tests/acceptance/features/apiSpacesShares/publicLinkDownload.feature +++ b/tests/acceptance/features/apiSpacesShares/publicLinkDownload.feature @@ -20,7 +20,7 @@ Feature: Public can download folders from project space public link And user "Alice" has created a public link share of the space "new-space" with settings: | permissions | 1 | | name | someName | - When public downloads the folder "NewFolder" of space "new-space" from the last created public link of "Alice" using the resource id + When public downloads the folder "NewFolder" of space "new-space" from the last created public link of "Alice" Then the HTTP status code should be "200" And the downloaded tar archive should contain these files: | name | content | @@ -36,7 +36,7 @@ Feature: Public can download folders from project space public link | shareType | 3 | | permissions | 1 | | name | public link | - When public downloads the folder "NewFolder/folder" of space "new-space" from the last created public link of "Alice" using the resource id + When public downloads the folder "NewFolder/folder" of space "new-space" from the last created public link of "Alice" Then the HTTP status code should be "200" And the downloaded tar archive should contain these files: | name | content | diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index 7f793a8aeb9..95bef8b4a72 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -3031,7 +3031,7 @@ class SpacesContext implements Context { } /** - * @When /^public downloads the folder "([^"]*)" of space "([^"]*)" from the last created public link of "([^"]*)" using the resource id$/ + * @When /^public downloads the folder "([^"]*)" of space "([^"]*)" from the last created public link of "([^"]*)"$/ * * @param string $resource * @param string $space From d1a20549c53ec0998775d6cb8c82e457e16e91ca Mon Sep 17 00:00:00 2001 From: Swikriti Tripathi Date: Mon, 19 Dec 2022 15:46:51 +0545 Subject: [PATCH 5/5] get resource id as public --- .../publicLinkDownload.feature | 4 ++-- .../features/bootstrap/SpacesContext.php | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/tests/acceptance/features/apiSpacesShares/publicLinkDownload.feature b/tests/acceptance/features/apiSpacesShares/publicLinkDownload.feature index 5593a8803cb..588550aadc4 100644 --- a/tests/acceptance/features/apiSpacesShares/publicLinkDownload.feature +++ b/tests/acceptance/features/apiSpacesShares/publicLinkDownload.feature @@ -20,7 +20,7 @@ Feature: Public can download folders from project space public link And user "Alice" has created a public link share of the space "new-space" with settings: | permissions | 1 | | name | someName | - When public downloads the folder "NewFolder" of space "new-space" from the last created public link of "Alice" + When public downloads the folder "NewFolder" from the last created public link using the public files API Then the HTTP status code should be "200" And the downloaded tar archive should contain these files: | name | content | @@ -36,7 +36,7 @@ Feature: Public can download folders from project space public link | shareType | 3 | | permissions | 1 | | name | public link | - When public downloads the folder "NewFolder/folder" of space "new-space" from the last created public link of "Alice" + When public downloads the folder "folder" from the last created public link using the public files API Then the HTTP status code should be "200" And the downloaded tar archive should contain these files: | name | content | diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index 95bef8b4a72..08d1272e7b0 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -3031,19 +3031,24 @@ class SpacesContext implements Context { } /** - * @When /^public downloads the folder "([^"]*)" of space "([^"]*)" from the last created public link of "([^"]*)"$/ + * @When /^public downloads the folder "([^"]*)" from the last created public link using the public files API$/ * * @param string $resource - * @param string $space - * @param string $owner * * @return void - * @throws GuzzleException + * @throws GuzzleException|JsonException */ - public function publicDownloadsTheFolderFromTheLastCreatedPublicLink(string $resource, string $space, string $owner) { + public function publicDownloadsTheFolderFromTheLastCreatedPublicLink(string $resource) { $token = $this->featureContext->getLastPublicShareToken(); - $resourceId = $this->getFolderId($owner, $space, $resource); - $queryString = 'public-token=' . $token . '&id=' . $resourceId; + $response = $this->featureContext->listFolderAndReturnResponseXml( + $token, + $resource, + '0', + ['oc:fileid'], + $this->featureContext->getDavPathVersion() === 1 ? "public-files" : "public-files-new" + ); + $resourceId = json_decode(json_encode($response->xpath("//d:response/d:propstat/d:prop/oc:fileid")), true, 512, JSON_THROW_ON_ERROR); + $queryString = 'public-token=' . $token . '&id=' . $resourceId[0][0]; $this->featureContext->setResponse( HttpRequestHelper::get( $this->featureContext->getBaseUrl() . '/archiver?' . $queryString,