Skip to content

Commit

Permalink
[tests-only][full-ci]Added tests for sharing with all allowed roles f…
Browse files Browse the repository at this point in the history
…or the list permissions (#8477)

* Added tests for sharing with all allowed roles for the list permissions

Signed-off-by: [email protected] <[email protected]>

* Refactor code

Signed-off-by: [email protected] <[email protected]>

* Rebase and refactor code

Signed-off-by: [email protected] <[email protected]>

* Review address

Signed-off-by: [email protected] <[email protected]>

* Rebase code

Signed-off-by: [email protected] <[email protected]>

---------

Signed-off-by: [email protected] <[email protected]>
  • Loading branch information
SagarGi authored Apr 17, 2024
1 parent 1d388a0 commit 0972b7c
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 1 deletion.
26 changes: 26 additions & 0 deletions tests/TestHelpers/GraphHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1647,6 +1647,32 @@ public static function getPermissionsRoleIdByName(
}
}

/**
* 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
Expand Down
26 changes: 25 additions & 1 deletion tests/acceptance/features/apiSharingNg/listPermissions.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
47 changes: 47 additions & 0 deletions tests/acceptance/features/bootstrap/SharingNgContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -667,4 +667,51 @@ public function userShouldHaveSyncEnabledOrDisabledForShare(string $user, string
"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);
}
}

0 comments on commit 0972b7c

Please sign in to comment.