[tests-only]tests: add tests for removing share permission in group share (#8099)

* tests: add tests for removing share permission in group share

* tests: address reviews
This commit is contained in:
Swikriti Tripathi
2024-01-04 17:03:39 +05:45
committed by GitHub
parent 672a38bf98
commit 2b78753a12
3 changed files with 98 additions and 23 deletions

View File

@@ -1543,11 +1543,12 @@ class GraphHelper {
/**
* @param string $baseUrl
* @param string $xRequestId
* @param string $user
* @param string $userIdOfShareeUser
* @param string $sharer
* @param string $userIdOfShareeUser this is a uuidv4 of sharee
* @param string $password
* @param string $spaceId
* @param string $itemId
* @param string $shareType (user|group)
*
* @return string
*
@@ -1557,22 +1558,23 @@ class GraphHelper {
public static function getSharePermissionId(
string $baseUrl,
string $xRequestId,
string $user,
string $sharer,
string $userIdOfShareeUser,
string $password,
string $spaceId,
string $itemId
string $itemId,
string $shareType
): string {
$response = self::getPermissionsList($baseUrl, $xRequestId, $user, $password, $spaceId, $itemId);
$response = self::getPermissionsList($baseUrl, $xRequestId, $sharer, $password, $spaceId, $itemId);
$permissionList = json_decode($response->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR);
foreach ($permissionList["value"] as $value) {
if ($value["grantedToV2"]["user"]["id"] === $userIdOfShareeUser) {
if ($value["grantedToV2"][$shareType]["id"] === $userIdOfShareeUser) {
return $value["id"];
}
}
throw new \Exception(
__METHOD__
. " Cannot find share permission id for user '$user'"
. " Cannot find share permission id for user"
);
}
@@ -1751,7 +1753,7 @@ class GraphHelper {
*
* @throws GuzzleException
*/
public static function deleteSharePermission(
public static function removeSharePermission(
string $baseUrl,
string $xRequestId,
string $user,

View File

@@ -63,3 +63,65 @@ Feature: Remove access to a drive item
| 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-type> |
| resource | <path> |
| space | Personal |
| sharee | group1 |
| shareType | group |
| role | <role> |
When user "Alice" removes the share permission of group "group1" from <resource-type> "<path>" 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:
| <path> |
Examples:
| role | 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-type> |
| resource | <path> |
| space | NewSpace |
| sharee | group1 |
| shareType | group |
| role | <role> |
When user "Alice" removes the share permission of group "group1" from <resource-type> "<path>" 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:
| <path> |
Examples:
| role | 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 |

View File

@@ -284,10 +284,11 @@ class SharingNgContext implements Context {
}
/**
* @When /^user "([^"]*)" removes the share permission of user "([^"]*)" from (file|folder) "([^"]*)" of space "([^"]*)" using the Graph API$/
* @When /^user "([^"]*)" removes the share permission of (user|group) "([^"]*)" from (file|folder) "([^"]*)" of space "([^"]*)" using the Graph API$/
*
* @param string $user
* @param string $shareeUser
* @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
@@ -296,27 +297,37 @@ class SharingNgContext implements Context {
* @throws JsonException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function userRemovesSharePermissionOfUserFromResourceOfSpaceUsingGraphAPI(string $user, string $shareeUser, string $resourceType, string $resource, string $space): void {
$spaceId = ($this->spacesContext->getSpaceByName($user, $space))["id"];
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($user, $space, $resource)
: $this->spacesContext->getFileId($user, $space, $resource);
$userIdOfShareeUser = $this->featureContext->getUserIdByUserName($shareeUser);
? $this->spacesContext->getResourceId($sharer, $space, $resource)
: $this->spacesContext->getFileId($sharer, $space, $resource);
$userIdOfSharee = ($shareType === 'user')
? $this->featureContext->getUserIdByUserName($sharee)
: $this->featureContext->getGroupIdByGroupName($sharee);
$permId = GraphHelper::getSharePermissionId(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$user,
$userIdOfShareeUser,
$this->featureContext->getPasswordForUser($user),
$sharer,
$userIdOfSharee,
$this->featureContext->getPasswordForUser($sharer),
$spaceId,
$itemId
$itemId,
$shareType
);
$this->featureContext->setResponse(
GraphHelper::deleteSharePermission(
GraphHelper::removeSharePermission(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$user,
$this->featureContext->getPasswordForUser($user),
$sharer,
$this->featureContext->getPasswordForUser($sharer),
$spaceId,
$itemId,
$permId