From abc1a446cac334b1544b83e3743d94ef83a8d6d6 Mon Sep 17 00:00:00 2001 From: Viktor Scharf Date: Tue, 7 Feb 2023 11:53:14 +0100 Subject: [PATCH] [test-only] ApiTests. check group in the space request (#5492) * check response * fix test --- tests/TestHelpers/GraphHelper.php | 27 ++++++++ .../apiSpacesShares/shareSpaces.feature | 13 +++- .../features/bootstrap/SpacesContext.php | 62 ++++++++++++++++++- 3 files changed, 100 insertions(+), 2 deletions(-) diff --git a/tests/TestHelpers/GraphHelper.php b/tests/TestHelpers/GraphHelper.php index a929ac1416..6f50d085cb 100644 --- a/tests/TestHelpers/GraphHelper.php +++ b/tests/TestHelpers/GraphHelper.php @@ -446,6 +446,33 @@ class GraphHelper { ); } + /** + * @param string $baseUrl + * @param string $xRequestId + * @param string $adminUser + * @param string $adminPassword + * @param string $groupName + * + * @return ResponseInterface + * @throws GuzzleException + */ + public static function getGroup( + string $baseUrl, + string $xRequestId, + string $adminUser, + string $adminPassword, + string $groupName + ): ResponseInterface { + $url = self::getFullUrl($baseUrl, 'groups/' . $groupName); + return HttpRequestHelper::get( + $url, + $xRequestId, + $adminUser, + $adminPassword, + self::getRequestHeaders() + ); + } + /** * @param string $baseUrl * @param string $xRequestId diff --git a/tests/acceptance/features/apiSpacesShares/shareSpaces.feature b/tests/acceptance/features/apiSpacesShares/shareSpaces.feature index 75b03955c7..3e838818d3 100644 --- a/tests/acceptance/features/apiSpacesShares/shareSpaces.feature +++ b/tests/acceptance/features/apiSpacesShares/shareSpaces.feature @@ -17,7 +17,7 @@ Feature: Share spaces And using spaces DAV path - Scenario Outline:: A Space Admin can share a space to another user + Scenario Outline: A Space Admin can share a space to another user When user "Alice" shares a space "share space" to user "Brian" with role "" Then the HTTP status code should be "200" And the OCS status code should be "200" @@ -42,6 +42,17 @@ Feature: Share spaces | root@@@permissions@@@1@@@roles@@@0 | viewer | + Scenario: A user can see that the group has been granted access + Given group "sales" has been created + When user "Alice" shares a space "share space" to group "sales" with role "viewer" + Then the HTTP status code should be "200" + And the OCS status code should be "200" + And the user "Alice" should have a space called "share space" granted to group "sales" with these key and value pairs: + | key | value | + | root@@@permissions@@@1@@@grantedToIdentities@@@0@@@group@@@id | %group_id% | + | root@@@permissions@@@1@@@roles@@@0 | viewer | + + Scenario: A user can see a file in a received shared space Given user "Alice" has uploaded a file inside space "share space" with content "Test" to "test.txt" And user "Alice" has created a folder "Folder Main" in space "share space" diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index a083e0bf08..189588d7a1 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -424,6 +424,33 @@ class SpacesContext implements Context { throw new Exception(__METHOD__ . " user with name $userName not found"); } + /** + * The method returns groupId + * + * @param string $groupName + * + * @return string + * @throws Exception|GuzzleException + */ + public function getGroupIdByGroupName(string $groupName): string { + $response = GraphHelper::getGroup( + $this->featureContext->getBaseUrl(), + $this->featureContext->getStepLineRef(), + $this->featureContext->getAdminUsername(), + $this->featureContext->getAdminPassword(), + $groupName + ); + if ($response) { + $data = $this->featureContext->getJsonDecodedResponse($response); + if (isset($data["id"])) { + return $data["id"]; + } else { + throw new Exception(__METHOD__ . " accounts-list is empty"); + } + } + throw new Exception(__METHOD__ . " Group with name $groupName not found"); + } + /** * using method from core to set share data * @@ -934,6 +961,7 @@ class SpacesContext implements Context { * @param string $spaceName * @param string|null $userName * @param string|null $fileName + * @param string|null $groupName * @param TableNode $table * * @return void @@ -943,6 +971,7 @@ class SpacesContext implements Context { string $spaceName, ?string $userName = null, ?string $fileName = null, + ?string $groupName = null, TableNode $table ): void { $this->featureContext->verifyTableNodeColumns($table, ['key', 'value']); @@ -979,6 +1008,12 @@ class SpacesContext implements Context { [$this, "getETag"], "parameter" => [$userName, $spaceName, $fileName] ], + [ + "code" => "%group_id%", + "function" => + [$this, "getGroupIdByGroupName"], + "parameter" => [$groupName] + ] ] ); $segments = explode("@@@", $row["key"]); @@ -1024,7 +1059,32 @@ class SpacesContext implements Context { 200, "Expected response status code should be 200" ); - $this->jsonRespondedShouldContain($spaceName, $grantedUser, $fileName, $table); + $this->jsonRespondedShouldContain($spaceName, $grantedUser, $fileName, null, $table); + } + + /** + * @Then /^the user "([^"]*)" should have a space called "([^"]*)" granted to group "([^"]*)" with these key and value pairs:$/ + * + * @param string $user + * @param string $spaceName + * @param string $grantedGroup + * @param TableNode $table + * + * @return void + * @throws Exception|GuzzleException + */ + public function userHasSpaceGrantedToGroup( + string $user, + string $spaceName, + string $grantedGroup, + TableNode $table + ): void { + $this->theUserListsAllHisAvailableSpacesUsingTheGraphApi($user); + $this->featureContext->theHTTPStatusCodeShouldBe( + 200, + "Expected response status code should be 200" + ); + $this->jsonRespondedShouldContain($spaceName, null, null, $grantedGroup, $table); } /**