[tests-only]tests: add tests for removing share permission (#8098)

* tests: add tests for removing share permission

* tests: add cases for project space share

* tests: update test step to use the sharingNg invite endpoint

* tests: address reviews

* tests: address reviews
This commit is contained in:
Swikriti Tripathi
2024-01-04 12:28:07 +05:45
committed by GitHub
parent 7eeb61bcb7
commit 672a38bf98
3 changed files with 221 additions and 17 deletions

View File

@@ -1540,6 +1540,42 @@ class GraphHelper {
);
}
/**
* @param string $baseUrl
* @param string $xRequestId
* @param string $user
* @param string $userIdOfShareeUser
* @param string $password
* @param string $spaceId
* @param string $itemId
*
* @return string
*
* @throws GuzzleException
* @throws \JsonException
*/
public static function getSharePermissionId(
string $baseUrl,
string $xRequestId,
string $user,
string $userIdOfShareeUser,
string $password,
string $spaceId,
string $itemId
): string {
$response = self::getPermissionsList($baseUrl, $xRequestId, $user, $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) {
return $value["id"];
}
}
throw new \Exception(
__METHOD__
. " Cannot find share permission id for user '$user'"
);
}
/**
* Get the role id by name
*
@@ -1701,4 +1737,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()
);
}
}

View File

@@ -0,0 +1,65 @@
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-type> |
| resource | <path> |
| space | Personal |
| sharee | Brian |
| shareType | user |
| role | <role> |
When user "Alice" removes the share permission of user "Brian" 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 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-type> |
| resource | <path> |
| space | NewSpace |
| sharee | Brian |
| shareType | user |
| role | <role> |
When user "Alice" removes the share permission of user "Brian" 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

@@ -127,15 +127,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"];
@@ -151,20 +152,49 @@ class SharingNgContext implements Context {
$permission = $rows['permission'] ?? null;
$expireDate = $rows["expireDate"] ?? null;
return GraphHelper::sendSharingInvitation(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$user,
$this->featureContext->getPasswordForUser($user),
$spaceId,
$itemId,
$shareeId,
$rows['shareType'],
$role,
$permission,
$expireDate
);
}
/**
* @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'],
$role,
$permission,
$expireDate
)
$this->sendShareInvitation($user, $table)
);
}
@@ -252,4 +282,45 @@ class SharingNgContext implements Context {
)
);
}
/**
* @When /^user "([^"]*)" removes the share permission of user "([^"]*)" from (file|folder) "([^"]*)" of space "([^"]*)" using the Graph API$/
*
* @param string $user
* @param string $shareeUser
* @param string $resourceType
* @param string $resource
* @param string $space
*
* @return void
* @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"];
$itemId = ($resourceType === 'folder')
? $this->spacesContext->getResourceId($user, $space, $resource)
: $this->spacesContext->getFileId($user, $space, $resource);
$userIdOfShareeUser = $this->featureContext->getUserIdByUserName($shareeUser);
$permId = GraphHelper::getSharePermissionId(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$user,
$userIdOfShareeUser,
$this->featureContext->getPasswordForUser($user),
$spaceId,
$itemId
);
$this->featureContext->setResponse(
GraphHelper::deleteSharePermission(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$user,
$this->featureContext->getPasswordForUser($user),
$spaceId,
$itemId,
$permId
)
);
}
}