mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-02-28 00:39:16 -06:00
[tests-only][full-ci]Added tests for sharing with all allowed roles for the list permissions (#8477)
* Added tests for sharing with all allowed roles for the list permissions Signed-off-by: sagargurung1001@gmail.com <sagargurung1001@gmail.com> * Refactor code Signed-off-by: sagargurung1001@gmail.com <sagargurung1001@gmail.com> * Rebase and refactor code Signed-off-by: sagargurung1001@gmail.com <sagargurung1001@gmail.com> * Review address Signed-off-by: sagargurung1001@gmail.com <sagargurung1001@gmail.com> * Rebase code Signed-off-by: sagargurung1001@gmail.com <sagargurung1001@gmail.com> --------- Signed-off-by: sagargurung1001@gmail.com <sagargurung1001@gmail.com>
This commit is contained in:
@@ -1647,6 +1647,32 @@ class GraphHelper {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the role name by role id
|
||||
*
|
||||
* @param string $permissionsRoleId
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getPermissionNameByPermissionRoleId(
|
||||
string $permissionsRoleId
|
||||
): string {
|
||||
switch ($permissionsRoleId) {
|
||||
case 'b1e2218d-eef8-4d4c-b82d-0f1a1b48f3b5':
|
||||
return 'Viewer';
|
||||
case 'fb6c3e19-e378-47e5-b277-9732f9de6e21':
|
||||
return 'Editor';
|
||||
case '2d00ce52-1fc2-4dbc-8b95-a73b73395f5a':
|
||||
return 'File Editor';
|
||||
case '1c996275-f1c9-4e71-abdf-a42f6495e960':
|
||||
return 'Uploader';
|
||||
default:
|
||||
throw new \Exception('Role ' . $permissionsRoleId . ' not found');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $baseUrl
|
||||
* @param string $xRequestId
|
||||
|
||||
@@ -888,4 +888,28 @@ Feature: List a sharing permissions
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
"""
|
||||
|
||||
@issues-8331
|
||||
Scenario: user sends share invitation with all allowed roles for a file
|
||||
Given user "Alice" has uploaded file with content "hello text" to "textfile.txt"
|
||||
And user "Brian" has been created with default attributes and without skeleton files
|
||||
When user "Alice" gets permissions list for file "textfile.txt" of the space "Personal" using the Graph API
|
||||
Then the HTTP status code should be "200"
|
||||
And user "Alice" should be able to send share invitation with all allowed permission roles
|
||||
| resource | textfile.txt |
|
||||
| space | Personal |
|
||||
| sharee | Brian |
|
||||
| shareType | user |
|
||||
|
||||
@issues-8331
|
||||
Scenario: user sends share invitation with all allowed roles for a folder
|
||||
Given user "Alice" has created folder "folder"
|
||||
And user "Brian" has been created with default attributes and without skeleton files
|
||||
When user "Alice" gets permissions list for folder "folder" of the space "Personal" using the Graph API
|
||||
Then the HTTP status code should be "200"
|
||||
And user "Alice" should be able to send share invitation with all allowed permission roles
|
||||
| resource | folder |
|
||||
| space | Personal |
|
||||
| sharee | Brian |
|
||||
| shareType | user |
|
||||
|
||||
@@ -667,4 +667,51 @@ class SharingNgContext implements Context {
|
||||
"Expected property '@client.synchronize' to be '$expectedValue' but found '$actualValue'"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then user :user should be able to send share invitation with all allowed permission roles
|
||||
*
|
||||
* @param string $user
|
||||
* @param TableNode $table
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
*/
|
||||
public function userShouldBeAbleToSendShareInvitationWithAllAllowedPermissionRoles(string $user, TableNode $table): void {
|
||||
$listPermissionResponse = $this->featureContext->getJsonDecodedResponseBodyContent();
|
||||
if (!isset($listPermissionResponse->{'@libre.graph.permissions.roles.allowedValues'})) {
|
||||
Assert::fail(
|
||||
"The following response does not contain '@libre.graph.permissions.roles.allowedValues' property:\n" . $listPermissionResponse
|
||||
);
|
||||
}
|
||||
Assert::assertNotEmpty(
|
||||
$listPermissionResponse->{'@libre.graph.permissions.roles.allowedValues'},
|
||||
"'@libre.graph.permissions.roles.allowedValues' should not be empty"
|
||||
);
|
||||
$allowedPermissionRoles = $listPermissionResponse->{'@libre.graph.permissions.roles.allowedValues'};
|
||||
// this info is needed for log to see which roles allowed and which were not when tests fail
|
||||
$shareInvitationRequestResult = "From the given allowed role lists from the permissions:\n";
|
||||
$areAllSendInvitationSuccessFullForAllowedRoles = true;
|
||||
$rows = $table->getRowsHash();
|
||||
$resource = $rows['resource'];
|
||||
$shareType = $rows['shareType'];
|
||||
$space = $rows['space'];
|
||||
foreach ($allowedPermissionRoles as $role) {
|
||||
//we should be able to send share invitation for each of the role allowed for the files/folders which are listed in permissions (allowed)
|
||||
$roleAllowed = GraphHelper::getPermissionNameByPermissionRoleId($role->id);
|
||||
$responseSendInvitation = $this->sendShareInvitation($user, new TableNode(array_merge($table->getTable(), [['permissionsRole', $roleAllowed]])));
|
||||
$jsonResponseSendInvitation = $this->featureContext->getJsonDecodedResponseBodyContent($responseSendInvitation);
|
||||
$httpsStatusCode = $responseSendInvitation->getStatusCode();
|
||||
if ($httpsStatusCode === 200 && !empty($jsonResponseSendInvitation->value)) {
|
||||
// remove the share so that the same user can be share for the next allowed roles
|
||||
$removePermissionsResponse = $this->removeSharePermission($user, $shareType, $space, $resource);
|
||||
Assert::assertEquals(204, $removePermissionsResponse->getStatusCode());
|
||||
} else {
|
||||
$areAllSendInvitationSuccessFullForAllowedRoles = false;
|
||||
$shareInvitationRequestResult .= "\tShare invitation for resource '" . $resource . "' with role '" . $roleAllowed . "' failed and was not allowed.\n";
|
||||
}
|
||||
}
|
||||
Assert::assertTrue($areAllSendInvitationSuccessFullForAllowedRoles, $shareInvitationRequestResult);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user