From 5a5e950cca15ee48dab12922dcc999de3f0d4c1e Mon Sep 17 00:00:00 2001 From: Viktor Scharf Date: Wed, 22 Feb 2023 10:09:19 +0100 Subject: [PATCH] [test-only] increase coverage test for creating space (#5616) --- .../features/apiSpaces/listSpaces.feature | 57 +++++++++++++++---- .../features/bootstrap/SpacesContext.php | 16 ++++-- 2 files changed, 55 insertions(+), 18 deletions(-) diff --git a/tests/acceptance/features/apiSpaces/listSpaces.feature b/tests/acceptance/features/apiSpaces/listSpaces.feature index dc94063b00..3c4efc9d11 100644 --- a/tests/acceptance/features/apiSpaces/listSpaces.feature +++ b/tests/acceptance/features/apiSpaces/listSpaces.feature @@ -33,10 +33,10 @@ Feature: List and create spaces And user "Brian" has shared folder "folder" with user "Alice" with permissions "31" And user "Alice" has accepted share "/folder" offered by user "Brian" Then the user "Alice" should have a space called "Shares" with these key and value pairs: - | key | value | - | driveType | virtual | - | id | %space_id% | - | name | Shares | + | key | value | + | driveType | virtual | + | id | %space_id% | + | name | Shares | When user "Alice" lists all available 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: @@ -70,13 +70,19 @@ Feature: List and create spaces Then the HTTP status code should be "207" - Scenario: An ordinary user cannot create a Space via Graph API + Scenario Outline: The user without permissions to create space cannot create a Space via Graph API + Given the administrator has given "Alice" the role "" using the settings api When user "Alice" creates a space "Project Mars" of type "project" with the default quota using the GraphApi Then the HTTP status code should be "401" + And the user "Alice" should not have a space called "share space" + Examples: + | role | + | User | + | Guest | - Scenario: An admin user can create a Space via the Graph API with default quota - Given the administrator has given "Alice" the role "Admin" using the settings api + Scenario Outline: An admin or space admin user can create a Space via the Graph API with default quota + Given the administrator has given "Alice" the role "" using the settings api When user "Alice" creates a space "Project Mars" of type "project" with the default quota using the GraphApi Then the HTTP status code should be "201" And the json responded should contain a space "Project Mars" with these key and value pairs: @@ -87,10 +93,14 @@ Feature: List and create spaces | quota@@@total | 1000000000 | | root@@@webDavUrl | %base_url%/dav/spaces/%space_id% | | webUrl | %base_url%/f/%space_id% | + Examples: + | role | + | Admin | + | Space Admin | - Scenario: An admin user can create a Space via the Graph API with certain quota - Given the administrator has given "Alice" the role "Admin" using the settings api + Scenario Outline: An admin or space admin user can create a Space via the Graph API with certain quota + Given the administrator has given "Alice" the role "" using the settings api When user "Alice" creates a space "Project Venus" of type "project" with quota "2000" using the GraphApi Then the HTTP status code should be "201" And the json responded should contain a space "Project Venus" with these key and value pairs: @@ -100,6 +110,10 @@ Feature: List and create spaces | quota@@@total | 2000 | | root@@@webDavUrl | %base_url%/dav/spaces/%space_id% | | webUrl | %base_url%/f/%space_id% | + Examples: + | role | + | Admin | + | Space Admin | Scenario: A user can list his personal space via multiple endpoints @@ -120,8 +134,8 @@ Feature: List and create spaces | webUrl | %base_url%/f/%space_id% | - Scenario: A user can list his created spaces via multiple endpoints - Given the administrator has given "Alice" the role "Admin" using the settings api + Scenario Outline: A user can list his created spaces via multiple endpoints + Given the administrator has given "Alice" the role "" using the settings api When user "Alice" creates a space "Project Venus" of type "project" with quota "2000" using the GraphApi Then the HTTP status code should be "201" And the json responded should contain a space "Project Venus" with these key and value pairs: @@ -133,7 +147,8 @@ Feature: List and create spaces | root@@@webDavUrl | %base_url%/dav/spaces/%space_id% | | webUrl | %base_url%/f/%space_id% | When user "Alice" looks up the single space "Project Venus" via the GraphApi by using its id - Then the json responded should contain a space "Project Venus" with these key and value pairs: + Then the HTTP status code should be "200" + And the json responded should contain a space "Project Venus" with these key and value pairs: | key | value | | driveType | project | | driveAlias | project/project-venus | @@ -141,3 +156,21 @@ Feature: List and create spaces | quota@@@total | 2000 | | root@@@webDavUrl | %base_url%/dav/spaces/%space_id% | | webUrl | %base_url%/f/%space_id% | + Examples: + | role | + | Admin | + | Space Admin | + + + Scenario Outline: A user cannot list space by id if he is not member of the space + Given the administrator has given "Alice" the role "" using the settings api + And user "Admin" has created a space "Project Venus" with the default quota using the GraphApi + When user "Alice" tries to look up the single space "Project Venus" owned by the user "Admin" by using its id + Then the HTTP status code should be "404" + And the json responded should not contain a space with name "Project Venus" + Examples: + | role | + | Admin | + | Space Admin | + | User | + | Guest | diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index ab77c6ddab..e92912ceab 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -223,9 +223,11 @@ class SpacesContext implements Context { if (isset($response['name']) && $response['name'] === $name) { return $response; } - foreach ($spaceAsArray["value"] as $spaceCandidate) { - if ($spaceCandidate['name'] === $name) { - return $spaceCandidate; + if (isset($spaceAsArray["value"])) { + foreach ($spaceAsArray["value"] as $spaceCandidate) { + if ($spaceCandidate['name'] === $name) { + return $spaceCandidate; + } } } return []; @@ -598,15 +600,17 @@ class SpacesContext implements Context { /** * @When /^user "([^"]*)" looks up the single space "([^"]*)" via the GraphApi by using its id$/ + * @When /^user "([^"]*)" tries to look up the single space "([^"]*)" owned by the user "([^"]*)" by using its id$/ * * @param string $user * @param string $spaceName + * @param string $ownerUser * * @return void * @throws GuzzleException */ - public function theUserLooksUpTheSingleSpaceUsingTheGraphApiByUsingItsId(string $user, string $spaceName): void { - $space = $this->getSpaceByName($user, $spaceName); + public function theUserLooksUpTheSingleSpaceUsingTheGraphApiByUsingItsId(string $user, string $spaceName, string $ownerUser = ''): void { + $space = $this->getSpaceByName(($ownerUser !== "") ? $ownerUser : $user, $spaceName); Assert::assertIsArray($space); Assert::assertNotEmpty($spaceId = $space["id"]); Assert::assertNotEmpty($space["root"]["webDavUrl"]); @@ -615,7 +619,7 @@ class SpacesContext implements Context { $this->featureContext->getBaseUrl(), $user, $this->featureContext->getPasswordForUser($user), - $spaceId + $space["id"] ) ); }