From a6e8408839ab9f49ee07d79c6f9c47c23a8198cf Mon Sep 17 00:00:00 2001 From: Viktor Scharf Date: Mon, 6 Feb 2023 23:48:30 +0100 Subject: [PATCH] [test-only]ApiTest. tests for spaceManagement (#5462) * tests for spaceManagement * put tests to expected failures * Empty-Commit --- ...ected-failures-localAPI-on-OCIS-storage.md | 3 + .../features/apiSpaces/restoreSpaces.feature | 2 +- .../apiSpaces/spaceManagement.feature | 171 ++++++++++++++++++ .../acceptance/features/apiSpaces/tag.feature | 3 +- .../features/bootstrap/SpacesContext.php | 104 +++++++---- 5 files changed, 241 insertions(+), 42 deletions(-) create mode 100644 tests/acceptance/features/apiSpaces/spaceManagement.feature diff --git a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md index 4add13232..cd1897b0b 100644 --- a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md +++ b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md @@ -103,5 +103,8 @@ The expected failures in this file are from features in the owncloud/ocis repo. #### [Sharing to a group with an expiration date does not work #5442](https://github.com/owncloud/ocis/issues/5442) - [apiSpacesShares/shareSubItemOfSpace.feature:99](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpacesShares/shareSubItemOfSpace.feature#L99) +#### [Space admin should not not be able to change the user quota](https://github.com/owncloud/ocis/issues/5475) +- [apiSpaces/spaceManagement.feature:69](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/spaceManagement.feature#L69) + Note: always have an empty line at the end of this file. The bash script that processes this file requires that the last line has a newline on the end. diff --git a/tests/acceptance/features/apiSpaces/restoreSpaces.feature b/tests/acceptance/features/apiSpaces/restoreSpaces.feature index e2a4b8db9..893f46dad 100644 --- a/tests/acceptance/features/apiSpaces/restoreSpaces.feature +++ b/tests/acceptance/features/apiSpaces/restoreSpaces.feature @@ -57,7 +57,7 @@ Feature: Restoring space Scenario Outline: User without space manager role cannot restore space Given user "Alice" has shared a space "restore a space" to user "Brian" with role "" And user "Alice" has disabled a space "restore a space" - When user "Brian" restores a disabled space "restore a space" without manager rights + When user "Brian" restores a disabled space "restore a space" owned by user "Alice" Then the HTTP status code should be "404" Examples: | role | diff --git a/tests/acceptance/features/apiSpaces/spaceManagement.feature b/tests/acceptance/features/apiSpaces/spaceManagement.feature new file mode 100644 index 000000000..b0b0307b9 --- /dev/null +++ b/tests/acceptance/features/apiSpaces/spaceManagement.feature @@ -0,0 +1,171 @@ +@api @skipOnOcV10 +Feature: Space management + As a user with space admin permission + I want to be able to manage all existing project space + - I can get all project space where I am not member using "graph/v1.0/drives" endpoint + - I can edit space: change quota, name, description + - I can enable, disable, delete space + + Note - this feature is run in CI with ACCOUNTS_HASH_DIFFICULTY set to the default for production + See https://github.com/owncloud/ocis/issues/1542 and https://github.com/owncloud/ocis/pull/839 + + Background: + Given these users have been created with default attributes and without skeleton files: + | username | + | Alice | + | Brian | + | Carol | + And using spaces DAV path + And the administrator has given "Alice" the role "Space Admin" using the settings api + And the administrator has given "Brian" the role "Space Admin" using the settings api + And user "Alice" has created a space "Project" of type "project" with quota "10" + + + Scenario: The space admin user can see another project space even if he is not member of the space + When user "Brian" lists all spaces via the GraphApi with query "$filter=driveType eq 'project'" + Then the HTTP status code should be "200" + And the json responded should contain a space "Project" with these key and value pairs: + | key | value | + | driveType | project | + | id | %space_id% | + | name | Project | + And the json responded should not contain a space with name "Alice Hansen" + + + Scenario: The space admin user can see another personal spaces + When user "Brian" lists all spaces via the GraphApi with query "$filter=driveType eq 'personal'" + Then the HTTP status code should be "200" + And the json responded should contain a space "Alice Hansen" with these key and value pairs: + | key | value | + | driveType | personal | + | id | %space_id% | + | name | Alice Hansen | + And the json responded should not contain a space with name "Project" + + + Scenario: The user without space admin permissions cannot see another spaces + When user "Carol" tries to list all spaces via the GraphApi + Then the HTTP status code should be "200" + And the json responded should not contain a space with name "Project" + And the json responded should not contain a space with name "Alice Hansen" + + + Scenario: The space admin user changes the quota of the project space + When user "Brian" changes the quota of the "Project" space to "20" owned by user "Alice" + Then the HTTP status code should be "200" + And the user "Alice" should have a space called "Project" with these key and value pairs: + | key | value | + | quota@@@total | 20 | + + + Scenario: The user without space admin permissions tries to change the quota of the project space + When user "Carol" tries to change the quota of the "Project" space to "20" owned by user "Alice" + Then the HTTP status code should be "401" + And the user "Alice" should have a space called "Project" with these key and value pairs: + | key | value | + | quota@@@total | 10 | + + + Scenario: The space admin user tries to change the quota of the personal space + When user "Brian" tries to change the quota of the "Alice Hansen" space to "20" owned by user "Alice" + Then the HTTP status code should be "401" + And the user "Alice" should have a space called "Alice Hansen" with these key and value pairs: + | key | value | + | quota@@@total | 10 | + + + Scenario: The user without space admin permissions tries to change the quota of the personal space + When user "Carol" tries to change the quota of the "Alice Hansen" space to "20" owned by user "Alice" + Then the HTTP status code should be "401" + And the user "Alice" should have a space called "Project" with these key and value pairs: + | key | value | + | quota@@@total | 10 | + + + Scenario: The space admin user changes the name of the project space + When user "Brian" changes the name of the "Project" space to "New Name" owned by user "Alice" + Then the HTTP status code should be "200" + And the user "Alice" should have a space called "New Name" with these key and value pairs: + | key | value | + | name | New Name | + + + Scenario: The user without space admin permissions tries to change the name of the project space + When user "Carol" tries to change the name of the "Project" space to "New Name" owned by user "Alice" + Then the HTTP status code should be "403" + And the user "Alice" should have a space called "Project" with these key and value pairs: + | key | value | + | name | Project | + + + Scenario: The space admin user changes the description of the project space + When user "Brian" changes the description of the "Project" space to "New description" owned by user "Alice" + Then the HTTP status code should be "200" + And the user "Alice" should have a space called "Project" with these key and value pairs: + | key | value | + | description | New description | + + + Scenario: The user without space admin permissions tries to change the description of the project space + Given user "Alice" has changed the description of the "Project" space to "old description" + When user "Carol" tries to change the description of the "Project" space to "New description" owned by user "Alice" + Then the HTTP status code should be "403" + And the user "Alice" should have a space called "Project" with these key and value pairs: + | key | value | + | description | old description | + + + Scenario: The space admin user disables the project space + When user "Brian" disables a space "Project" owned by user "Alice" + Then the HTTP status code should be "204" + And the user "Alice" should have a space called "Project" with these key and value pairs: + | key | value | + | name | Project | + | root@@@deleted@@@state | trashed | + + + Scenario: The user without space admin permissions tries to disable the project space + When user "Carol" tries to disable a space "Project" owned by user "Alice" + Then the HTTP status code should be "403" + + + Scenario Outline: The space admin user tries to disable the personal space + When user "" disables a space "Alice Hansen" owned by user "Alice" + Then the HTTP status code should be "403" + Examples: + | user | + | Brian | + | Carol | + + + Scenario: The space admin user deletes the project space + Given user "Alice" has disabled a space "Project" + When user "Brian" deletes a space "Project" owned by user "Alice" + Then the HTTP status code should be "204" + And the user "Alice" should not have a space called "Project" + + + Scenario: The user without space admin permissions tries to delete the project space + Given user "Alice" has disabled a space "Project" + When user "Carol" tries to delete a space "Project" owned by user "Alice" + Then the HTTP status code should be "403" + And the user "Alice" should have a space called "Project" with these key and value pairs: + | key | value | + | name | Project | + | root@@@deleted@@@state | trashed | + + + Scenario: The space admin user enables the project space + Given user "Alice" has disabled a space "Project" + When user "Brian" restores a disabled space "Project" owned by user "Alice" + Then the HTTP status code should be "200" + + + Scenario: The user without space admin permissions tries to enable the project space + Given user "Alice" has disabled a space "Project" + When user "Carol" tries to restore a disabled space "Project" owned by user "Alice" + Then the HTTP status code should be "404" + And the user "Alice" should have a space called "Project" with these key and value pairs: + | key | value | + | name | Project | + | root@@@deleted@@@state | trashed | diff --git a/tests/acceptance/features/apiSpaces/tag.feature b/tests/acceptance/features/apiSpaces/tag.feature index 70bd3f8c2..26f382004 100644 --- a/tests/acceptance/features/apiSpaces/tag.feature +++ b/tests/acceptance/features/apiSpaces/tag.feature @@ -222,8 +222,7 @@ Feature: Tag Given user "Alice" has created the following tags for folder "folderMain" of the space "use-tag": | folderTag | | marketing | - When user "Alice" disables a space "use-tag" - Then the HTTP status code should be "204" + And user "Alice" has disabled a space "use-tag" When user "Alice" lists all available tags via the GraphApi Then the HTTP status code should be "200" And the response should contain following tags: diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index fec8ffb46..a083e0bf0 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -590,6 +590,11 @@ class SpacesContext implements Context { } /** + * The method is used on the administration setting tab, which only the Admin user and the Space admin user have access to + * + * @When /^user "([^"]*)" lists all spaces via the GraphApi$/ + * @When /^user "([^"]*)" lists all spaces via the GraphApi with query "([^"]*)"$/ + * @When /^user "([^"]*)" tries to list all spaces via the GraphApi$/ * * @param string $user * @param string $query @@ -600,13 +605,15 @@ class SpacesContext implements Context { * @throws Exception */ public function theUserListsAllAvailableSpacesUsingTheGraphApi(string $user, string $query = ''): void { - $response = GraphHelper::getAllSpaces( - $this->featureContext->getBaseUrl(), - $user, - $this->featureContext->getPasswordForUser($user), - "?" . $query + $this->featureContext->setResponse( + GraphHelper::getAllSpaces( + $this->featureContext->getBaseUrl(), + $user, + $this->featureContext->getPasswordForUser($user), + "?" . $query + ) ); - $this->rememberTheAvailableSpaces($response); + $this->rememberTheAvailableSpaces(); } /** @@ -1289,10 +1296,12 @@ class SpacesContext implements Context { /** * @When /^user "([^"]*)" (?:changes|tries to change) the name of the "([^"]*)" space to "([^"]*)"$/ + * @When /^user "([^"]*)" (?:changes|tries to change) the name of the "([^"]*)" space to "([^"]*)" owned by user "([^"]*)"$/ * * @param string $user * @param string $spaceName * @param string $newName + * @param string $owner * * @return void * @throws GuzzleException @@ -1301,13 +1310,14 @@ class SpacesContext implements Context { public function updateSpaceName( string $user, string $spaceName, - string $newName + string $newName, + string $owner = '' ): void { if ($spaceName === "non-existing") { // check sending invalid data $spaceId = "39c49dd3-1f24-4687-97d1-42df43f71713"; } else { - $space = $this->getSpaceByName($user, $spaceName); + $space = $this->getSpaceByName(($owner !== "") ? $owner : $user, $spaceName); $spaceId = $space["id"]; } @@ -1327,10 +1337,12 @@ class SpacesContext implements Context { /** * @When /^user "([^"]*)" (?:changes|tries to change) the description of the "([^"]*)" space to "([^"]*)"$/ + * @When /^user "([^"]*)" (?:changes|tries to change) the description of the "([^"]*)" space to "([^"]*)" owned by user "([^"]*)"$/ * * @param string $user * @param string $spaceName * @param string $newDescription + * @param string $owner * * @return void * @throws GuzzleException @@ -1339,13 +1351,14 @@ class SpacesContext implements Context { public function updateSpaceDescription( string $user, string $spaceName, - string $newDescription + string $newDescription, + string $owner = '' ): void { if ($spaceName === "non-existing") { // check sending invalid data $spaceId = "39c49dd3-1f24-4687-97d1-42df43f71713"; } else { - $space = $this->getSpaceByName($user, $spaceName); + $space = $this->getSpaceByName(($owner !== "") ? $owner : $user, $spaceName); $spaceId = $space["id"]; } @@ -1363,12 +1376,37 @@ class SpacesContext implements Context { ); } + /** + * @Given /^user "([^"]*)" has changed the description of the "([^"]*)" space to "([^"]*)"$/ + * + * @param string $user + * @param string $spaceName + * @param string $newDescription + * + * @return void + * @throws GuzzleException + * @throws JsonException + */ + public function userHasChangedDescription( + string $user, + string $spaceName, + string $newDescription + ): void { + $this->updateSpaceDescription($user, $spaceName, $newDescription); + $this->featureContext->theHTTPStatusCodeShouldBe( + 200, + "Expected response status code should be 200" + ); + } + /** * @When /^user "([^"]*)" (?:changes|tries to change) the quota of the "([^"]*)" space to "([^"]*)"$/ + * @When /^user "([^"]*)" (?:changes|tries to change) the quota of the "([^"]*)" space to "([^"]*)" owned by user "([^"]*)"$/ * * @param string $user * @param string $spaceName * @param int $newQuota + * @param string $owner * * @return void * @throws GuzzleException @@ -1377,13 +1415,14 @@ class SpacesContext implements Context { public function updateSpaceQuota( string $user, string $spaceName, - int $newQuota + int $newQuota, + string $owner = '' ): void { if ($spaceName === "non-existing") { // check sending invalid data $spaceId = "39c49dd3-1f24-4687-97d1-42df43f71713"; } else { - $space = $this->getSpaceByName($user, $spaceName); + $space = $this->getSpaceByName(($owner !== "") ? $owner : $user, $spaceName); $spaceId = $space["id"]; } @@ -2143,18 +2182,21 @@ class SpacesContext implements Context { /** * @When /^user "([^"]*)" disables a space "([^"]*)"$/ + * @When /^user "([^"]*)" (?:disables|tries to disable) a space "([^"]*)" owned by user "([^"]*)"$/ * * @param string $user * @param string $spaceName + * @param string $owner * * @return void * @throws GuzzleException */ public function sendDisableSpaceRequest( string $user, - string $spaceName + string $spaceName, + string $owner = '' ): void { - $space = $this->getSpaceByName($user, $spaceName); + $space = $this->getSpaceByName(($owner !== "") ? $owner : $user, $spaceName); $this->featureContext->setResponse( GraphHelper::disableSpace( $this->featureContext->getBaseUrl(), @@ -2211,18 +2253,21 @@ class SpacesContext implements Context { /** * @When /^user "([^"]*)" deletes a space "([^"]*)"$/ + * @When /^user "([^"]*)" (?:deletes|tries to delete) a space "([^"]*)" owned by user "([^"]*)"$/ * * @param string $user * @param string $spaceName + * @param string $owner * * @return void * @throws GuzzleException */ public function sendDeleteSpaceRequest( string $user, - string $spaceName + string $spaceName, + $owner = '' ): void { - $space = $this->getSpaceByName($user, $spaceName); + $space = $this->getSpaceByName(($owner !== "") ? $owner : $user, $spaceName); $this->featureContext->setResponse( GraphHelper::deleteSpace( @@ -2236,10 +2281,11 @@ class SpacesContext implements Context { /** * @When /^user "([^"]*)" restores a disabled space "([^"]*)"$/ + * @When /^user "([^"]*)" (?:restores|tries to restore) a disabled space "([^"]*)" owned by user "([^"]*)"$/ * * @param string $user * @param string $spaceName - * @param string $userWithManagerRights + * @param string $owner * * @return void * @throws GuzzleException @@ -2247,13 +2293,9 @@ class SpacesContext implements Context { public function sendRestoreSpaceRequest( string $user, string $spaceName, - string $userWithManagerRights = '' + string $owner = '' ): void { - if (!empty($userWithManagerRights)) { - $space = $this->getSpaceByNameManager($userWithManagerRights, $spaceName); - } else { - $space = $this->getSpaceByName($user, $spaceName); - } + $space = $this->getSpaceByName(($owner !== "") ? $owner : $user, $spaceName); $this->featureContext->setResponse( GraphHelper::restoreSpace( $this->featureContext->getBaseUrl(), @@ -2264,22 +2306,6 @@ class SpacesContext implements Context { ); } - /** - * @When /^user "([^"]*)" restores a disabled space "([^"]*)" without manager rights$/ - * - * @param string $user - * @param string $spaceName - * - * @return void - * @throws GuzzleException - */ - public function sendRestoreSpaceWithoutRightsRequest( - string $user, - string $spaceName - ): void { - $this->sendRestoreSpaceRequest($user, $spaceName, $this->featureContext->getAdminUsername()); - } - /** * @Given /^user "([^"]*)" has restored a disabled space "([^"]*)"$/ *