From f19546bf6bd2797bc28f69dd2c3f0571744d2e44 Mon Sep 17 00:00:00 2001 From: Kavita Gautam Date: Wed, 18 Mar 2026 10:35:14 +0545 Subject: [PATCH] test: public link multifile download Signed-off-by: Kavita Gautam test: public link multifile download Signed-off-by: Kavita Gautam Apply suggestions from code review Co-authored-by: Sawjan Gurung --- .../acceptance/bootstrap/ArchiverContext.php | 104 ++++++++++++++++++ .../publicLinkDownload.feature | 26 +++++ 2 files changed, 130 insertions(+) diff --git a/tests/acceptance/bootstrap/ArchiverContext.php b/tests/acceptance/bootstrap/ArchiverContext.php index c2384a5f901..2e14f33eefc 100644 --- a/tests/acceptance/bootstrap/ArchiverContext.php +++ b/tests/acceptance/bootstrap/ArchiverContext.php @@ -31,6 +31,7 @@ use Psr\Http\Message\ResponseInterface; use splitbrain\PHPArchive\Tar; use splitbrain\PHPArchive\Zip; use splitbrain\PHPArchive\Archive; +use TestHelpers\WebDavHelper; require_once 'bootstrap.php'; @@ -256,6 +257,109 @@ class ArchiverContext implements Context { ); } + /** + * Sends a PROPFIND request to the public WebDAV endpoint for the last created public link + * and extracts archive-related metadata from the XML response. + * + * The returned data includes: + * - fileIds: IDs of all files included in the public link + * - signature: signature required for archive download + * - expiration: expiration timestamp required for archive download + * + * @param string $password + * + * @return array { + * fileIds: string[], + * signature: string|null, + * expiration: string|null + * } + * + * @throws GuzzleException + */ + private function fetchPublicLinkArchiveData(string $password = ''): array { + $token = $this->featureContext->isUsingSharingNG() + ? $this->featureContext->shareNgGetLastCreatedLinkShareToken() + : $this->featureContext->getLastCreatedPublicShareToken(); + $password = $this->featureContext->getActualPassword($password); + $response = WebDavHelper::propfind( + $this->featureContext->getBaseUrl(), + null, + (string) $password, + (string) $token, + ['oc:public-link-item-type', 'oc:fileid', 'oc:downloadURL', 'oc:signature-auth'], + null, + null, + "public-files", + ); + $xmlDocument = HttpRequestHelper::getResponseXml($response); + + $fileIds = []; + $signature = null; + $expiration = null; + + foreach ($xmlDocument->xpath('//d:response') as $responseNode) { + $type = $responseNode->xpath('.//oc:public-link-item-type'); + $fileId = $responseNode->xpath('.//oc:fileid'); + + $sig = $responseNode->xpath('.//oc:signature-auth/oc:signature'); + $exp = $responseNode->xpath('.//oc:signature-auth/oc:expiration'); + + if (!empty($type) && (string)$type[0] === 'file' && !empty($fileId)) { + $fileIds[] = (string)$fileId[0]; + } + + if ($signature === null && !empty($sig)) { + $signature = (string)$sig[0]; + } + + if ($expiration === null && !empty($exp)) { + $expiration = (string)$exp[0]; + } + } + + return [ + 'fileIds' => $fileIds, + 'signature' => $signature, + 'expiration' => $expiration, + ]; + } + + /** + * @When /^the public downloads the archive of the last created public link with password "([^"]*)"$/ + * + * @param string $password + * + * @return void + * + * @throws GuzzleException|Exception + */ + public function publicDownloadsTheArchiveOfTheLastCreatedPublicLink(string $password = ""): void { + $data = $this->fetchPublicLinkArchiveData($password); + $fileIds = $data['fileIds']; + $signature = $data['signature']; + $expiration = $data['expiration']; + + $token = $this->featureContext->isUsingSharingNG() + ? $this->featureContext->shareNgGetLastCreatedLinkShareToken() + : $this->featureContext->getLastCreatedPublicShareToken(); + $password = $this->featureContext->getActualPassword($password); + $queryParts = []; + $queryParts[] = "public-token=" . urlencode($token); + + foreach ($fileIds as $fileId) { + $queryParts[] = "id=" . urlencode($fileId); + } + + $queryParts[] = "signature=" . urlencode($signature); + $queryParts[] = "expiration=" . urlencode($expiration); + $queryString = implode('&', $queryParts); + $url = $this->featureContext->getBaseUrl() . "/archiver?" . $queryString; + + $this->featureContext->setResponse( + HttpRequestHelper::get($url, 'public', $password), + ); + } + /** * @Then the downloaded :type archive should contain these files: * diff --git a/tests/acceptance/features/apiSpacesShares/publicLinkDownload.feature b/tests/acceptance/features/apiSpacesShares/publicLinkDownload.feature index ed7b1f5534f..608690b25fb 100644 --- a/tests/acceptance/features/apiSpacesShares/publicLinkDownload.feature +++ b/tests/acceptance/features/apiSpacesShares/publicLinkDownload.feature @@ -45,3 +45,29 @@ Feature: Public can download folders from project space public link And the downloaded zip archive should contain these files: | name | content | | folder/test.txt | some content | + + @env-config + Scenario Outline: download an archive of a password protected public link share (project space) + And using SharingNG + And user "Alice" has created a folder "project-folder" in space "new-space" + And user "Alice" has uploaded a file inside space "new-space" with content "some content1" to "project-folder/test1.txt" + And user "Alice" has uploaded a file inside space "new-space" with content "some content2" to "project-folder/test2.txt" + And user "Alice" has uploaded a file inside space "new-space" with content "some content3" to "project-folder/test3.txt" + And user "Alice" has created the following resource link share: + | resource | project-folder | + | space | new-space | + | permissionsRole | | + | password | %public% | + When the public downloads the archive of the last created public link with password "%public%" + Then the HTTP status code should be "200" + And the downloaded "zip" archive should contain these files: + | name | content | + | test1.txt | some content1 | + | test2.txt | some content2 | + | test3.txt | some content3 | + + Examples: + | permissionsRole | + | Edit | + | View | + | Upload | \ No newline at end of file