From 3976c1c1fc0b97b3c351f8c2a69f7baf9d7c8d7d Mon Sep 17 00:00:00 2001 From: Swikriti Tripathi <41103328+SwikritiT@users.noreply.github.com> Date: Thu, 11 Jan 2024 11:31:28 +0545 Subject: [PATCH] [tests-only] tests: add tests for removing share permission (#8130) * tests: add tests for removing share permission * tests: add tests for removing share permission in group share * tests: refactor test script for removing permission from share * address reviews --------- Co-authored-by: Saw-jan --- tests/TestHelpers/GraphHelper.php | 32 +++++ .../apiSharingNg/deletePermissions.feature | 127 ++++++++++++++++++ .../acceptance/features/bootstrap/Sharing.php | 34 ++++- .../features/bootstrap/SharingNgContext.php | 108 ++++++++++++--- 4 files changed, 283 insertions(+), 18 deletions(-) create mode 100644 tests/acceptance/features/apiSharingNg/deletePermissions.feature diff --git a/tests/TestHelpers/GraphHelper.php b/tests/TestHelpers/GraphHelper.php index 075c226571..a99cfd95fe 100644 --- a/tests/TestHelpers/GraphHelper.php +++ b/tests/TestHelpers/GraphHelper.php @@ -1735,4 +1735,36 @@ class GraphHelper { $body ); } + + /** + * @param string $baseUrl + * @param string $xRequestId + * @param string $user + * @param string $password + * @param string $spaceId + * @param string $itemId + * @param string $permissionId + * + * @return ResponseInterface + * + * @throws GuzzleException + */ + public static function deleteSharePermission( + string $baseUrl, + string $xRequestId, + string $user, + string $password, + string $spaceId, + string $itemId, + string $permissionId + ): ResponseInterface { + $url = self::getBetaFullUrl($baseUrl, "drives/$spaceId/items/$itemId/permissions/$permissionId"); + return HttpRequestHelper::delete( + $url, + $xRequestId, + $user, + $password, + self::getRequestHeaders() + ); + } } diff --git a/tests/acceptance/features/apiSharingNg/deletePermissions.feature b/tests/acceptance/features/apiSharingNg/deletePermissions.feature new file mode 100644 index 0000000000..9cd1a3c4cf --- /dev/null +++ b/tests/acceptance/features/apiSharingNg/deletePermissions.feature @@ -0,0 +1,127 @@ +Feature: Remove access to a drive item + https://owncloud.dev/libre-graph-api/#/drives.permissions/DeletePermission + + Background: + Given these users have been created with default attributes and without skeleton files: + | username | + | Alice | + | Brian | + And using spaces DAV path + + + Scenario Outline: user removes access to resource in the user share + Given user "Alice" has created folder "FolderToShare" + And user "Alice" has uploaded file "filesForUpload/textfile.txt" to "textfile.txt" + And user "Alice" has sent the following share invitation: + | resourceType | | + | resource | | + | space | Personal | + | sharee | Brian | + | shareType | user | + | permissionsRole | | + When user "Alice" removes the share permission of user "Brian" from "" of space "Personal" using the Graph API + Then the HTTP status code should be "204" + And for user "Brian" the space "Shares" should not contain these entries: + | | + Examples: + | permissionsRole | resource-type | path | + | Viewer | file | textfile.txt | + | File Editor | file | textfile.txt | + | Co Owner | file | textfile.txt | + | Manager | file | textfile.txt | + | Viewer | folder | FolderToShare | + | Editor | folder | FolderToShare | + | Co Owner | folder | FolderToShare | + | Uploader | folder | FolderToShare | + | Manager | folder | FolderToShare | + + + Scenario Outline: user removes access to resource inside of a project space in the user share + Given 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 "Alice" has created a folder "FolderToShare" in space "NewSpace" + And user "Alice" has uploaded a file inside space "NewSpace" with content "some content" to "textfile.txt" + And user "Alice" has sent the following share invitation: + | resourceType | | + | resource | | + | space | NewSpace | + | sharee | Brian | + | shareType | user | + | permissionsRole | | + When user "Alice" removes the share permission of user "Brian" from "" of space "NewSpace" using the Graph API + Then the HTTP status code should be "204" + And for user "Brian" the space "Shares" should not contain these entries: + | | + Examples: + | permissionsRole | resource-type | path | + | Viewer | file | textfile.txt | + | File Editor | file | textfile.txt | + | Co Owner | file | textfile.txt | + | Manager | file | textfile.txt | + | Viewer | folder | FolderToShare | + | Editor | folder | FolderToShare | + | Co Owner | folder | FolderToShare | + | Uploader | folder | FolderToShare | + | Manager | folder | FolderToShare | + + + Scenario Outline: user removes access to a resource in a group share + Given group "group1" has been created + And user "Brian" has been added to group "group1" + And user "Alice" has been added to group "group1" + And user "Alice" has created folder "FolderToShare" + And user "Alice" has uploaded file "filesForUpload/textfile.txt" to "textfile.txt" + And user "Alice" has sent the following share invitation: + | resourceType | | + | resource | | + | space | Personal | + | sharee | group1 | + | shareType | group | + | permissionsRole | | + When user "Alice" removes the share permission of group "group1" from "" of space "Personal" using the Graph API + Then the HTTP status code should be "204" + And for user "Brian" the space "Shares" should not contain these entries: + | | + Examples: + | permissionsRole | resource-type | path | + | Viewer | file | textfile.txt | + | File Editor | file | textfile.txt | + | Co Owner | file | textfile.txt | + | Manager | file | textfile.txt | + | Viewer | folder | FolderToShare | + | Editor | folder | FolderToShare | + | Co Owner | folder | FolderToShare | + | Uploader | folder | FolderToShare | + | Manager | folder | FolderToShare | + + + Scenario Outline: user removes access to a resource inside of a project space in group share + Given 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 "Alice" has created a folder "FolderToShare" in space "NewSpace" + And user "Alice" has uploaded a file inside space "NewSpace" with content "some content" to "textfile.txt" + And group "group1" has been created + And user "Brian" has been added to group "group1" + And user "Alice" has been added to group "group1" + And user "Alice" has sent the following share invitation: + | resourceType | | + | resource | | + | space | NewSpace | + | sharee | group1 | + | shareType | group | + | permissionsRole | | + When user "Alice" removes the share permission of group "group1" from "" of space "NewSpace" using the Graph API + Then the HTTP status code should be "204" + And for user "Brian" the space "Shares" should not contain these entries: + | | + Examples: + | permissionsRole | resource-type | path | + | Viewer | file | textfile.txt | + | File Editor | file | textfile.txt | + | Co Owner | file | textfile.txt | + | Manager | file | textfile.txt | + | Viewer | folder | FolderToShare | + | Editor | folder | FolderToShare | + | Co Owner | folder | FolderToShare | + | Uploader | folder | FolderToShare | + | Manager | folder | FolderToShare | diff --git a/tests/acceptance/features/bootstrap/Sharing.php b/tests/acceptance/features/bootstrap/Sharing.php index b450427224..0b6ec311a3 100755 --- a/tests/acceptance/features/bootstrap/Sharing.php +++ b/tests/acceptance/features/bootstrap/Sharing.php @@ -80,6 +80,11 @@ trait Sharing { */ private array $shareNgCreatedLinkShares = []; + /** + * @var array + */ + private array $shareNgCreatedUserGroupShares = []; + /** * @return string */ @@ -119,6 +124,22 @@ trait Sharing { return \end($this->shareNgCreatedLinkShares); } + /** + * @param ResponseInterface $response + * + * @return void + */ + public function shareNgAddToCreatedUserGroupShares(ResponseInterface $response): void { + $this->shareNgCreatedUserGroupShares[] = $response; + } + + /** + * @return ResponseInterface|null + */ + public function shareNgGetLastCreatedUserGroupShare():?ResponseInterface { + return \end($this->shareNgCreatedUserGroupShares); + } + /** * @param string $sharer * @param SimpleXMLElement $shareData @@ -179,7 +200,7 @@ trait Sharing { public function shareNgGetLastCreatedLinkShareID(): string { $lastResponse = $this->shareNgGetLastCreatedLinkShare(); if (!isset($this->getJsonDecodedResponse($lastResponse)['id'])) { - throw new Error('Response did not contain share id ' . $this->getJsonDecodedResponse($lastResponse)['id'] . ' for the created public link'); + throw new Error('Response did not contain share id for the created public link'); } return $this->getJsonDecodedResponse($lastResponse)['id']; } @@ -196,6 +217,17 @@ trait Sharing { return substr(strrchr($last_created_link_webURL, "/"), 1); } + /** + * @return string + */ + public function shareNgGetLastCreatedUserGroupShareID(): string { + $lastResponse = $this->shareNgGetLastCreatedUserGroupShare(); + if (!isset($this->getJsonDecodedResponse($lastResponse)['value'][0]['id'])) { + throw new Error('Response did not contain share id for the last created share.'); + } + return $this->getJsonDecodedResponse($lastResponse)['value'][0]['id']; + } + /** * Split given permissions string each separated with "," into array of strings * diff --git a/tests/acceptance/features/bootstrap/SharingNgContext.php b/tests/acceptance/features/bootstrap/SharingNgContext.php index 3c40a1a795..deec2f47d4 100644 --- a/tests/acceptance/features/bootstrap/SharingNgContext.php +++ b/tests/acceptance/features/bootstrap/SharingNgContext.php @@ -126,15 +126,16 @@ class SharingNgContext implements Context { } /** - * @When /^user "([^"]*)" sends the following share invitation using the Graph API:$/ - * * @param string $user * @param TableNode $table * - * @return void + * @return ResponseInterface + * + * @throws JsonException + * @throws \GuzzleHttp\Exception\GuzzleException * @throws Exception */ - public function userSendsTheFollowingShareInvitationUsingTheGraphApi(string $user, TableNode $table): void { + public function sendShareInvitation(string $user, TableNode $table): ResponseInterface { $rows = $table->getRowsHash(); $spaceId = ($this->spacesContext->getSpaceByName($user, $rows['space']))["id"]; @@ -150,20 +151,53 @@ class SharingNgContext implements Context { $permissionsAction = $rows['permissionsAction'] ?? null; $expireDate = $rows["expireDate"] ?? null; + $response = GraphHelper::sendSharingInvitation( + $this->featureContext->getBaseUrl(), + $this->featureContext->getStepLineRef(), + $user, + $this->featureContext->getPasswordForUser($user), + $spaceId, + $itemId, + $shareeId, + $rows['shareType'], + $permissionsRole, + $permissionsAction, + $expireDate + ); + if ($response->getStatusCode() === 200) { + $this->featureContext->shareNgAddToCreatedUserGroupShares($response); + } + return $response; + } + + /** + * @Given /^user "([^"]*)" has sent the following share invitation:$/ + * + * @param string $user + * @param TableNode $table + * + * @return void + * @throws Exception + * @throws \GuzzleHttp\Exception\GuzzleException + */ + public function userHasSentTheFollowingShareInvitation(string $user, TableNode $table): void { + $response = $this->sendShareInvitation($user, $table); + $this->featureContext->theHTTPStatusCodeShouldBe(200, "", $response); + } + + /** + * @When /^user "([^"]*)" sends the following share invitation using the Graph API:$/ + * + * @param string $user + * @param TableNode $table + * + * @return void + * @throws Exception + * @throws \GuzzleHttp\Exception\GuzzleException + */ + public function userSendsTheFollowingShareInvitationUsingTheGraphApi(string $user, TableNode $table): void { $this->featureContext->setResponse( - GraphHelper::sendSharingInvitation( - $this->featureContext->getBaseUrl(), - $this->featureContext->getStepLineRef(), - $user, - $this->featureContext->getPasswordForUser($user), - $spaceId, - $itemId, - $shareeId, - $rows['shareType'], - $permissionsRole, - $permissionsAction, - $expireDate - ) + $this->sendShareInvitation($user, $table) ); } @@ -293,4 +327,44 @@ class SharingNgContext implements Context { ); $this->featureContext->setResponse($response); } + + /** + * @When /^user "([^"]*)" removes the share permission of (user|group) "([^"]*)" from (file|folder) "([^"]*)" of space "([^"]*)" using the Graph API$/ + * + * @param string $sharer + * @param string $shareType (user|group) + * @param string $sharee can be both user or group + * @param string $resourceType + * @param string $resource + * @param string $space + * + * @return void + * @throws JsonException + * @throws \GuzzleHttp\Exception\GuzzleException + */ + public function userRemovesSharePermissionOfUserFromResourceOfSpaceUsingGraphAPI( + string $sharer, + string $shareType, + string $sharee, + string $resourceType, + string $resource, + string $space + ): void { + $spaceId = ($this->spacesContext->getSpaceByName($sharer, $space))["id"]; + $itemId = ($resourceType === 'folder') + ? $this->spacesContext->getResourceId($sharer, $space, $resource) + : $this->spacesContext->getFileId($sharer, $space, $resource); + $permId = $this->featureContext->shareNgGetLastCreatedUserGroupShareID(); + $this->featureContext->setResponse( + GraphHelper::deleteSharePermission( + $this->featureContext->getBaseUrl(), + $this->featureContext->getStepLineRef(), + $sharer, + $this->featureContext->getPasswordForUser($sharer), + $spaceId, + $itemId, + $permId + ) + ); + } }