From 95b6190ff07ca14170acc6bf26315d89ea75f88e Mon Sep 17 00:00:00 2001 From: Prajwol Amatya <83579989+PrajwolAmatya@users.noreply.github.com> Date: Wed, 31 Jan 2024 16:26:29 +0545 Subject: [PATCH] [tests-only][full-ci] added test to share a disabled project space (#8319) * added test to share a disabled project space * added test to share deleted project space --- .../apiSharingNg/shareInvitations.feature | 95 +++++++++++++++++++ .../features/bootstrap/SharingNgContext.php | 15 ++- .../features/bootstrap/SpacesContext.php | 47 +++++---- 3 files changed, 139 insertions(+), 18 deletions(-) diff --git a/tests/acceptance/features/apiSharingNg/shareInvitations.feature b/tests/acceptance/features/apiSharingNg/shareInvitations.feature index cff81f73e..c4a5fb3d8 100644 --- a/tests/acceptance/features/apiSharingNg/shareInvitations.feature +++ b/tests/acceptance/features/apiSharingNg/shareInvitations.feature @@ -1664,3 +1664,98 @@ Feature: Send a sharing invitations | Space Editor | | Co Owner | | Manager | + + + Scenario Outline: send share invitation for disabled project space to user with different roles + Given using spaces DAV path + And the administrator has assigned the role "Space Admin" to user "Alice" using the Graph API + And user "Alice" has created a space "NewSpace" with the default quota using the Graph API + And user "Admin" has disabled a space "NewSpace" + When user "Alice" sends the following share invitation for space using the Graph API: + | space | NewSpace | + | sharee | Brian | + | shareType | user | + | permissionsRole | | + Then the HTTP status code should be "404" + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "error" + ], + "properties": { + "error": { + "type": "object", + "required": [ + "code", + "message" + ], + "properties": { + "code": { + "type": "string", + "enum": ["itemNotFound"] + }, + "message": { + "type": "string", + "pattern": "^stat: error: not found: %user_id_pattern%$" + } + } + } + } + } + """ + Examples: + | permissions-role | + | Space Viewer | + | Space Editor | + | Co Owner | + | Manager | + + + Scenario Outline: send share invitation for deleted project space to user with different roles + Given using spaces DAV path + And the administrator has assigned the role "Space Admin" to user "Alice" using the Graph API + And user "Alice" has created a space "NewSpace" with the default quota using the Graph API + And user "Admin" has disabled a space "NewSpace" + And user "Admin" has deleted a space "NewSpace" + When user "Alice" sends the following share invitation for space using the Graph API: + | space | NewSpace | + | sharee | Brian | + | shareType | user | + | permissionsRole | | + Then the HTTP status code should be "404" + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "error" + ], + "properties": { + "error": { + "type": "object", + "required": [ + "code", + "message" + ], + "properties": { + "code": { + "type": "string", + "enum": ["itemNotFound"] + }, + "message": { + "type": "string", + "enum": ["stat: error: not found: "] + } + } + } + } + } + """ + Examples: + | permissions-role | + | Space Viewer | + | Space Editor | + | Co Owner | + | Manager | diff --git a/tests/acceptance/features/bootstrap/SharingNgContext.php b/tests/acceptance/features/bootstrap/SharingNgContext.php index bc9bbedb1..d8b261ea3 100644 --- a/tests/acceptance/features/bootstrap/SharingNgContext.php +++ b/tests/acceptance/features/bootstrap/SharingNgContext.php @@ -139,7 +139,12 @@ class SharingNgContext implements Context { */ public function sendShareInvitation(string $user, TableNode $table): ResponseInterface { $rows = $table->getRowsHash(); - $spaceId = ($this->spacesContext->getSpaceByName($user, $rows['space']))["id"]; + if ($rows['space'] === 'Personal' || $rows['space'] === 'Shares') { + $space = $this->spacesContext->getSpaceByName($user, $rows['space']); + } else { + $space = $this->spacesContext->getCreatedSpace($rows['space']); + } + $spaceId = $space['id']; // for resharing a resource, "item-id" in API endpoint takes shareMountId if ($rows['space'] === 'Shares') { @@ -152,7 +157,13 @@ class SharingNgContext implements Context { ); } else { $resource = $rows['resource'] ?? ''; - $itemId = $this->spacesContext->getResourceId($user, $rows['space'], $resource); + + // for a disabled and deleted space, resource id is not accessible, so get resource id from the saved response + if ($resource === '' && $rows['space'] !== 'Personal') { + $itemId = $space['fileId']; + } else { + $itemId = $this->spacesContext->getResourceId($user, $rows['space'], $resource); + } } if (\array_key_exists('shareeId', $rows)) { diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index 23107d7fe..de0020bb5 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -83,17 +83,31 @@ class SpacesContext implements Context { if (!\array_key_exists($spaceName, $this->createdSpaces)) { throw new Exception(__METHOD__ . " space '$spaceName' has not been created in this scenario"); } - return $this->createdSpaces[$spaceName]; + return $this->createdSpaces[$spaceName]['spaceCreator']; + } + + /** + * @param string $spaceCreator + * @param ResponseInterface $response + * + * @return void + */ + public function addCreatedSpace(string $spaceCreator, ResponseInterface $response): void { + $response = $this->featureContext->getJsonDecodedResponseBodyContent($response); + $spaceName = $response->name; + $this->createdSpaces[$spaceName] = []; + $this->createdSpaces[$spaceName]['id'] = $response->id; + $this->createdSpaces[$spaceName]['spaceCreator'] = $spaceCreator; + $this->createdSpaces[$spaceName]['fileId'] = $response->id . '!' . $response->owner->user->id; } /** * @param string $spaceName - * @param string $spaceCreator * - * @return void + * @return array */ - public function setSpaceCreator(string $spaceName, string $spaceCreator): void { - $this->createdSpaces[$spaceName] = $spaceCreator; + public function getCreatedSpace(string $spaceName): array { + return $this->createdSpaces[$spaceName]; } private array $availableSpaces = []; @@ -695,16 +709,17 @@ class SpacesContext implements Context { ): void { $space = ["Name" => $spaceName, "driveType" => $spaceType, "quota" => ["total" => $quota]]; $body = json_encode($space); - $this->featureContext->setResponse( - GraphHelper::createSpace( - $this->featureContext->getBaseUrl(), - $user, - $this->featureContext->getPasswordForUser($user), - $body, - $this->featureContext->getStepLineRef() - ) + $response = GraphHelper::createSpace( + $this->featureContext->getBaseUrl(), + $user, + $this->featureContext->getPasswordForUser($user), + $body, + $this->featureContext->getStepLineRef() ); - $this->setSpaceCreator($spaceName, $user); + $this->featureContext->setResponse($response); + if ($response->getStatusCode() === '201') { + $this->addCreatedSpace($user, $response); + } } /** @@ -1645,7 +1660,7 @@ class SpacesContext implements Context { ): void { $space = ["Name" => $spaceName, "driveType" => $spaceType, "quota" => ["total" => $quota]]; $response = $this->createSpace($user, $space); - $this->setSpaceCreator($spaceName, $user); + $this->addCreatedSpace($user, $response); $this->featureContext->theHTTPStatusCodeShouldBe( 201, "Expected response status code should be 201 (Created)", @@ -1670,7 +1685,7 @@ class SpacesContext implements Context { ): void { $space = ["Name" => $spaceName]; $response = $this->createSpace($user, $space); - $this->setSpaceCreator($spaceName, $user); + $this->addCreatedSpace($user, $response); $this->featureContext->theHTTPStatusCodeShouldBe( 201, "Expected response status code should be 201 (Created)",