From d7c406edde9959008fecfe87daf8fe3714bff092 Mon Sep 17 00:00:00 2001 From: Viktor Scharf Date: Thu, 4 Aug 2022 13:11:51 +0200 Subject: [PATCH] add tests changing quota --- ...ected-failures-localAPI-on-OCIS-storage.md | 6 + .../features/apiSpaces/changeSpaces.feature | 30 ++- .../features/bootstrap/SpacesContext.php | 207 +++++++++++------- 3 files changed, 161 insertions(+), 82 deletions(-) diff --git a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md index 39900e8cfb..b36b50d723 100644 --- a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md +++ b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md @@ -38,3 +38,9 @@ The expected failures in this file are from features in the owncloud/ocis repo. - [apiSpaces/moveSpaces.feature:185](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/moveSpaces.feature#L185) - [apiSpaces/moveSpaces.feature:186](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/moveSpaces.feature#L186) - [apiSpaces/moveSpaces.feature:189](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/moveSpaces.feature#L189) + +### [Changing personal drive quota on another user as admin is not possible](https://github.com/owncloud/ocis/issues/4325) +- [apiSpaces/changeSpaces.feature:221](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/changeSpaces.feature#L221) +- [apiSpaces/changeSpaces.feature:222](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/changeSpaces.feature#L222) +- [apiSpaces/changeSpaces.feature:223](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/changeSpaces.feature#L223) +- [apiSpaces/changeSpaces.feature:224](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/changeSpaces.feature#L224) diff --git a/tests/acceptance/features/apiSpaces/changeSpaces.feature b/tests/acceptance/features/apiSpaces/changeSpaces.feature index 73535e1262..2ea08dfb43 100644 --- a/tests/acceptance/features/apiSpaces/changeSpaces.feature +++ b/tests/acceptance/features/apiSpaces/changeSpaces.feature @@ -183,7 +183,7 @@ Feature: Change data of space When user "" has uploaded a file inside space "Project Jupiter" with content "" to ".space/newSpaceImage.png" And user "" sets the file ".space/newSpaceImage.png" as a space image in a special section of the "Project Jupiter" space Then the HTTP status code should be "200" - And the user "" should have a space called "Project Jupiter" owned by "Alice" with space image ".space/newSpaceImage.png" with these key and value pairs: + And the user "" should have a space called "Project Jupiter" owned by "Alice" with space image ".space/newSpaceImage.png" with these key and value pairs: | key | value | | name | Project Jupiter | | special@@@0@@@size | 0 | @@ -195,4 +195,30 @@ Feature: Change data of space Examples: | user | | Alice | - | Brian | \ No newline at end of file + | Brian | + + + Scenario Outline: An admin user set own quota of a personal space via the Graph API + When user "Admin" changes the quota of the "Admin" space to "" + Then the HTTP status code should be "200" + When user "Admin" uploads a file inside space "Admin" with content "file is more than 15 bytes" to "file.txt" using the WebDAV API + Then the HTTP status code should be + Examples: + | quotaValue | code | + | 15 | "507" | + | 10000 | between "201" and "204" | + | 0 | between "201" and "204" | + | -1 | between "201" and "204" | + + + Scenario Outline: An admin user set an user personal space quota of via the Graph API + When user "Admin" changes the quota of the "Brian Murphy" space to "" + Then the HTTP status code should be "200" + When user "Brian" uploads a file inside space "Brian Murphy" with content "file is more than 15 bytes" to "file.txt" using the WebDAV API + Then the HTTP status code should be + Examples: + | quotaValue | code | + | 15 | "507" | + | 10000 | between "201" and "204" | + | 0 | between "201" and "204" | + | -1 | between "201" and "204" | diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index b95f252295..df6d7fdddb 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -91,11 +91,11 @@ class SpacesContext implements Context { */ private $storedEtags = []; - private $etagPropfindBody = '' - . '' - .''; + private $etagPropfindBody = '' + . '' + . ''; /** * @param string $spaceName @@ -246,7 +246,11 @@ class SpacesContext implements Context { if ($spaceName === "Personal") { $spaceName = $this->featureContext->getUserDisplayName($user); } - $this->theUserListsAllHisAvailableSpacesUsingTheGraphApi($user); + if (strtolower($user) === 'admin') { + $this->theUserListsAllAvailableSpacesUsingTheGraphApi($user); + } else { + $this->theUserListsAllHisAvailableSpacesUsingTheGraphApi($user); + } $spaces = $this->getAvailableSpaces(); Assert::assertIsArray($spaces[$spaceName], "Space with name $spaceName for user $user not found"); Assert::assertNotEmpty($spaces[$spaceName]["root"]["webDavUrl"], "WebDavUrl for space with name $spaceName for user $user not found"); @@ -393,6 +397,51 @@ class SpacesContext implements Context { ); } + /** + * @AfterScenario + * + * @return void + * + * @throws Exception|GuzzleException + */ + public function cleanDataAfterTests(): void { + // TODO enable when admin can disable and delete spaces + // $this->deleteAllSpacesOfTheType('project'); + // $this->deleteAllSpacesOfTheType('personal'); + } + + /** + * The method first disables and then deletes spaces + * + * @param string $driveType + * + * @return void + * + * @throws Exception|GuzzleException + */ + public function deleteAllSpacesOfTheType(string $driveType): void { + $query = "\$filter=driveType eq $driveType"; + $userAdmin = $this->featureContext->getAdminUsername(); + + for ($i = 0; $i < 2; ++$i) { + $this->theUserListsAllAvailableSpacesUsingTheGraphApi( + $userAdmin, + $query + ); + $drives = $this->getAvailableSpaces(); + + if (!empty($drives)) { + foreach ($drives as $value) { + if (!\array_key_exists("deleted", $value["root"])) { + $this->sendDisableSpaceRequest($userAdmin, $value["name"]); + } else { + $this->sendDeleteSpaceRequest($userAdmin, $value["name"]); + } + } + } + } + } + /** * Send Graph List My Spaces Request * @@ -560,7 +609,6 @@ class SpacesContext implements Context { * @param string $xRequestId * @param array $headers * - * * @return ResponseInterface * * @throws GuzzleException @@ -1748,55 +1796,55 @@ class SpacesContext implements Context { $this->copyFilesAndFoldersRequest($user, $fullUrl, $headers); } - /** - * @When /^user "([^"]*)" moves (?:file|folder) "([^"]*)" to "([^"]*)" in space "([^"]*)" using the WebDAV API$/ - * - * @param string $user - * @param string $fileSource - * @param string $fileDestination - * @param string $spaceName - * - * @return void - */ - public function userMovesFileWithinSpaceUsingTheWebDAVAPI( - string $user, - string $fileSource, - string $fileDestination, - string $spaceName - ):void { - $space = $this->getSpaceByName($user, $spaceName); - $headers['Destination'] = $this->destinationHeaderValueWithSpaceName( - $user, - $fileDestination, - $spaceName - ); + /** + * @When /^user "([^"]*)" moves (?:file|folder) "([^"]*)" to "([^"]*)" in space "([^"]*)" using the WebDAV API$/ + * + * @param string $user + * @param string $fileSource + * @param string $fileDestination + * @param string $spaceName + * + * @return void + */ + public function userMovesFileWithinSpaceUsingTheWebDAVAPI( + string $user, + string $fileSource, + string $fileDestination, + string $spaceName + ):void { + $space = $this->getSpaceByName($user, $spaceName); + $headers['Destination'] = $this->destinationHeaderValueWithSpaceName( + $user, + $fileDestination, + $spaceName + ); - $fullUrl = $space["root"]["webDavUrl"] . '/' . \trim($fileSource, "/"); - $this->moveFilesAndFoldersRequest($user, $fullUrl, $headers); - } + $fullUrl = $space["root"]["webDavUrl"] . '/' . \trim($fileSource, "/"); + $this->moveFilesAndFoldersRequest($user, $fullUrl, $headers); + } - /** - * MOVE request for files|folders - * - * @param string $user - * @param string $fullUrl - * @param string $headers - * - * @return void - * @throws GuzzleException - */ - public function moveFilesAndFoldersRequest(string $user, string $fullUrl, array $headers):void { - $this->featureContext->setResponse( - HttpRequestHelper::sendRequest( - $fullUrl, - $this->featureContext->getStepLineRef(), - 'MOVE', - $user, - $this->featureContext->getPasswordForUser($user), - $headers, - ) - ); - } + /** + * MOVE request for files|folders + * + * @param string $user + * @param string $fullUrl + * @param string $headers + * + * @return void + * @throws GuzzleException + */ + public function moveFilesAndFoldersRequest(string $user, string $fullUrl, array $headers):void { + $this->featureContext->setResponse( + HttpRequestHelper::sendRequest( + $fullUrl, + $this->featureContext->getStepLineRef(), + 'MOVE', + $user, + $this->featureContext->getPasswordForUser($user), + $headers, + ) + ); + } /** * @When /^user "([^"]*)" copies (?:file|folder) "([^"]*)" from space "([^"]*)" to "([^"]*)" inside space "([^"]*)" using the WebDAV API$/ @@ -1823,31 +1871,30 @@ class SpacesContext implements Context { $this->copyFilesAndFoldersRequest($user, $fullUrl, $headers); } - - /** - * @When /^user "([^"]*)" moves (?:file|folder) "([^"]*)" from space "([^"]*)" to "([^"]*)" inside space "([^"]*)" using the WebDAV API$/ - * - * @param string $user - * @param string $fileSource - * @param string $fromSpaceName - * @param string $fileDestination - * @param string $toSpaceName - * - * @return void - * @throws GuzzleException - */ - public function userMovesFileFromAndToSpaceBetweenSpaces( - string $user, - string $fileSource, - string $fromSpaceName, - string $fileDestination, - string $toSpaceName - ):void { - $space = $this->getSpaceByName($user, $fromSpaceName); - $headers['Destination'] = $this->destinationHeaderValueWithSpaceName($user, $fileDestination, $toSpaceName); - $fullUrl = $space["root"]["webDavUrl"] . '/' . \ltrim($fileSource, "/"); - $this->moveFilesAndFoldersRequest($user, $fullUrl, $headers); - } + /** + * @When /^user "([^"]*)" moves (?:file|folder) "([^"]*)" from space "([^"]*)" to "([^"]*)" inside space "([^"]*)" using the WebDAV API$/ + * + * @param string $user + * @param string $fileSource + * @param string $fromSpaceName + * @param string $fileDestination + * @param string $toSpaceName + * + * @return void + * @throws GuzzleException + */ + public function userMovesFileFromAndToSpaceBetweenSpaces( + string $user, + string $fileSource, + string $fromSpaceName, + string $fileDestination, + string $toSpaceName + ):void { + $space = $this->getSpaceByName($user, $fromSpaceName); + $headers['Destination'] = $this->destinationHeaderValueWithSpaceName($user, $fileDestination, $toSpaceName); + $fullUrl = $space["root"]["webDavUrl"] . '/' . \ltrim($fileSource, "/"); + $this->moveFilesAndFoldersRequest($user, $fullUrl, $headers); + } /** * returns a url for destination with spacename @@ -2852,7 +2899,7 @@ class SpacesContext implements Context { ); $should = ($shouldOrNot !== "not"); - $responseArray = json_decode(json_encode($this->featureContext->getResponseXml()->data),true, 512, JSON_THROW_ON_ERROR); + $responseArray = json_decode(json_encode($this->featureContext->getResponseXml()->data), true, 512, JSON_THROW_ON_ERROR); if ($should) { Assert::assertNotEmpty($responseArray, __METHOD__ . ' Response should contain a link, but it is empty');