From f056d6c79ee1427b6067973702bbbc04ec0e1442 Mon Sep 17 00:00:00 2001 From: Artur Neumann Date: Thu, 11 Nov 2021 12:45:52 +0545 Subject: [PATCH] [tests-only] test downloading a file as not owner --- .../features/apiArchiver/downloadById.feature | 7 +++++ .../features/bootstrap/ArchiverContext.php | 28 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/tests/acceptance/features/apiArchiver/downloadById.feature b/tests/acceptance/features/apiArchiver/downloadById.feature index 355783f62..fe46f6a9c 100644 --- a/tests/acceptance/features/apiArchiver/downloadById.feature +++ b/tests/acceptance/features/apiArchiver/downloadById.feature @@ -61,3 +61,10 @@ Feature: download multiple resources bundled into an archive | textfile1.txt | other data | | my_data/textfile2.txt | some data | | more_data/an_other_file.txt | more data | + + Scenario: download a single file as different user + Given user "Brian" has been created with default attributes and without skeleton files + And user "Alice" has uploaded file with content "some data" to "/textfile0.txt" + When user "Brian" downloads the archive of "/textfile0.txt" of user "Alice" using the resource id + Then the HTTP status code should be "400" + diff --git a/tests/acceptance/features/bootstrap/ArchiverContext.php b/tests/acceptance/features/bootstrap/ArchiverContext.php index 4202c26b6..f2c5f9ed9 100644 --- a/tests/acceptance/features/bootstrap/ArchiverContext.php +++ b/tests/acceptance/features/bootstrap/ArchiverContext.php @@ -99,6 +99,34 @@ class ArchiverContext implements Context { ); } + /** + * @When user :downloader downloads the archive of :item of user :owner using the resource id + * + * @param string $downloader Who sends the request + * @param string $resource + * @param string $owner Who is the real owner of the file + * + * @return void + * + * @throws \GuzzleHttp\Exception\GuzzleException + */ + public function userDownloadsTheArchiveOfItemOfUserUsingTheResourceId( + string $downloader, + string $resource, + string $owner + ): void { + $resourceId = $this->featureContext->getFileIdForPath($owner, $resource); + $downloader = $this->featureContext->getActualUsername($downloader); + $this->featureContext->setResponse( + HttpRequestHelper::get( + $this->featureContext->getBaseUrl() . '/archiver?id=' . $resourceId, + '', + $downloader, + $this->featureContext->getPasswordForUser($downloader), + ) + ); + } + /** * @When user :arg1 downloads the archive of these items using the resource ids *