mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-02-28 00:39:16 -06:00
[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 <saw.jan.grg3e@gmail.com>
This commit is contained in:
committed by
GitHub
parent
73d9ace439
commit
3976c1c1fc
@@ -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()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
127
tests/acceptance/features/apiSharingNg/deletePermissions.feature
Normal file
127
tests/acceptance/features/apiSharingNg/deletePermissions.feature
Normal file
@@ -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-type> |
|
||||
| resource | <path> |
|
||||
| space | Personal |
|
||||
| sharee | Brian |
|
||||
| shareType | user |
|
||||
| permissionsRole | <permissionsRole> |
|
||||
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:
|
||||
| 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-type> |
|
||||
| resource | <path> |
|
||||
| space | NewSpace |
|
||||
| sharee | Brian |
|
||||
| shareType | user |
|
||||
| permissionsRole | <permissionsRole> |
|
||||
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:
|
||||
| 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-type> |
|
||||
| resource | <path> |
|
||||
| space | Personal |
|
||||
| sharee | group1 |
|
||||
| shareType | group |
|
||||
| permissionsRole | <permissionsRole> |
|
||||
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:
|
||||
| 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-type> |
|
||||
| resource | <path> |
|
||||
| space | NewSpace |
|
||||
| sharee | group1 |
|
||||
| shareType | group |
|
||||
| permissionsRole | <permissionsRole> |
|
||||
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:
|
||||
| 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 |
|
||||
@@ -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
|
||||
*
|
||||
|
||||
@@ -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
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user