Skip to content

Commit

Permalink
add tests for list permissions using root endpoint (#8824)
Browse files Browse the repository at this point in the history
  • Loading branch information
amrita-shrestha committed Apr 18, 2024
1 parent 65213ab commit da656cb
Show file tree
Hide file tree
Showing 4 changed files with 232 additions and 14 deletions.
27 changes: 27 additions & 0 deletions tests/TestHelpers/GraphHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1983,4 +1983,31 @@ public static function enableShareSync(
\json_encode($body)
);
}

/**
* @param string $baseUrl
* @param string $xRequestId
* @param string $user
* @param string $password
* @param string $spaceId
*
* @return ResponseInterface
* @throws GuzzleException
*/
public static function getDrivePermissionsList(
string $baseUrl,
string $xRequestId,
string $user,
string $password,
string $spaceId
): ResponseInterface {
$url = self::getBetaFullUrl($baseUrl, "drives/$spaceId/root/permissions");
return HttpRequestHelper::get(
$url,
$xRequestId,
$user,
$password,
self::getRequestHeaders()
);
}
}
166 changes: 166 additions & 0 deletions tests/acceptance/features/apiSharingNg/listPermissions.feature
Original file line number Diff line number Diff line change
Expand Up @@ -913,3 +913,169 @@ Feature: List a sharing permissions
| space | Personal |
| sharee | Brian |
| shareType | user |

@issues-8351
Scenario: user lists permissions of a project space using root endpoint
Given using spaces DAV path
And the administrator has assigned the role "Space Admin" to user "Alice" using the Graph API
And user "Alice" has created a space "new-space" with the default quota using the Graph API
When user "Alice" lists the permissions of space "new-space" using root endpoint of the Graph API
Then the HTTP status code should be "200"
And the JSON data of the response should match
"""
{
"type": "object",
"required": [
"@libre.graph.permissions.actions.allowedValues",
"@libre.graph.permissions.roles.allowedValues"
],
"properties": {
"@libre.graph.permissions.actions.allowedValues": {
"const": [
"libre.graph/driveItem/permissions/create",
"libre.graph/driveItem/children/create",
"libre.graph/driveItem/standard/delete",
"libre.graph/driveItem/path/read",
"libre.graph/driveItem/quota/read",
"libre.graph/driveItem/content/read",
"libre.graph/driveItem/upload/create",
"libre.graph/driveItem/permissions/read",
"libre.graph/driveItem/children/read",
"libre.graph/driveItem/versions/read",
"libre.graph/driveItem/deleted/read",
"libre.graph/driveItem/path/update",
"libre.graph/driveItem/permissions/delete",
"libre.graph/driveItem/deleted/delete",
"libre.graph/driveItem/versions/update",
"libre.graph/driveItem/deleted/update",
"libre.graph/driveItem/basic/read",
"libre.graph/driveItem/permissions/update",
"libre.graph/driveItem/permissions/deny"
]
},
"@libre.graph.permissions.roles.allowedValues": {
"type": "array",
"minItems": 3,
"maxItems": 3,
"uniqueItems": true,
"items": {
"oneOf": [
{
"type": "object",
"required": [
"@libre.graph.weight",
"description",
"displayName",
"id"
],
"properties": {
"@libre.graph.weight": {
"const": 1
},
"description": {
"const": "View and download."
},
"displayName": {
"const": "Can view"
},
"id": {
"const": "a8d5fe5e-96e3-418d-825b-534dbdf22b99"
}
}
},
{
"type": "object",
"required": [
"@libre.graph.weight",
"description",
"displayName",
"id"
],
"properties": {
"@libre.graph.weight": {
"const": 2
},
"description": {
"const": "View, download, upload, edit, add and delete."
},
"displayName": {
"const": "Can edit"
},
"id": {
"const": "58c63c02-1d89-4572-916a-870abc5a1b7d"
}
}
},
{
"type": "object",
"required": [
"@libre.graph.weight",
"description",
"displayName",
"id"
],
"properties": {
"@libre.graph.weight": {
"const": 3
},
"description": {
"const": "View, download, upload, edit, add, delete and manage members."
},
"displayName": {
"const": "Can manage"
},
"id": {
"const": "312c0871-5ef7-4b3a-85b6-0e4074c64049"
}
}
}
]
}
}
}
}
"""


Scenario Outline: try to lists the permissions of a Personal/Shares drive using root endpoint
Given using spaces DAV path
And the administrator has assigned the role "Space Admin" to user "Alice" using the Graph API
And user "Alice" has created a space "new-space" with the default quota using the Graph API
When user "Alice" tries to list the permissions of space "<drive>" using root endpoint of the Graph API
Then the HTTP status code should be "400"
And the JSON data of the response should match
"""
{
"type": "object",
"required": ["error"],
"properties": {
"error": {
"type": "object",
"required": [
"code",
"innererror",
"message"
],
"properties": {
"code": {
"const": "invalidRequest"
},
"innererror": {
"type": "object",
"required": [
"date",
"request-id"
]
},
"message": {
"const": "unsupported space type"
}
}
}
}
}
"""
Examples:
| drive |
| Personal |
| Shares |
4 changes: 2 additions & 2 deletions tests/acceptance/features/apiSharingNg/sharedWithMe.feature
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Feature: an user gets the resources shared to them
| space | Personal |
| sharee | Brian |
| shareType | user |
| permissionsRole | Viewer |
| permissionsRole | Viewer |
When user "Brian" lists the shares shared with him after clearing user cache using the Graph API
Then the HTTP status code should be "200"
And the JSON data of the response should match
Expand Down Expand Up @@ -3540,7 +3540,7 @@ Feature: an user gets the resources shared to them
}
"""


@issue-8027
Scenario: user lists the file shared with them from project space
Given using spaces DAV path
And the administrator has assigned the role "Space Admin" to user "Alice" using the Graph API
Expand Down
49 changes: 37 additions & 12 deletions tests/acceptance/features/bootstrap/SharingNgContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use GuzzleHttp\Exception\GuzzleException;
use Psr\Http\Message\ResponseInterface;
use TestHelpers\GraphHelper;
use TestHelpers\WebDavHelper;
Expand Down Expand Up @@ -60,7 +61,7 @@ public function before(BeforeScenarioScope $scope): void {
*
* @return ResponseInterface
* @throws Exception
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
*/
public function createLinkShare(string $user, TableNode $body): ResponseInterface {
$bodyRows = $body->getRowsHash();
Expand Down Expand Up @@ -159,7 +160,7 @@ public function userListsThePermissionsOfSpaceUsingTheGraphApi($user, $space):vo
* @return ResponseInterface
*
* @throws JsonException
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
* @throws Exception
*/
public function sendShareInvitation(string $user, TableNode $table, string $fileId = null): ResponseInterface {
Expand Down Expand Up @@ -230,7 +231,7 @@ public function sendShareInvitation(string $user, TableNode $table, string $file
*
* @return void
* @throws Exception
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
*/
public function userHasSentTheFollowingShareInvitation(string $user, TableNode $table): void {
$response = $this->sendShareInvitation($user, $table);
Expand All @@ -247,7 +248,7 @@ public function userHasSentTheFollowingShareInvitation(string $user, TableNode $
*
* @return void
* @throws Exception
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
*/
public function userSendsTheFollowingShareInvitationUsingTheGraphApi(string $user, TableNode $table): void {
$this->featureContext->setResponse(
Expand Down Expand Up @@ -319,7 +320,7 @@ public function updateResourceShare(string $user, TableNode $body, string $perm
*
* @return void
* @throws JsonException
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
*/
public function userSendsTheFollowingShareInvitationWithFileIdUsingTheGraphApi(string $user, string $fileId, TableNode $table): void {
$this->featureContext->setResponse(
Expand All @@ -334,7 +335,7 @@ public function userSendsTheFollowingShareInvitationWithFileIdUsingTheGraphApi(s
* @param TableNode|null $body
*
* @return void
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
*/
public function userCreatesAPublicLinkShareWithSettings(string $user, TableNode $body):void {
$response = $this->createLinkShare($user, $body);
Expand All @@ -348,7 +349,7 @@ public function userCreatesAPublicLinkShareWithSettings(string $user, TableNode
* @param TableNode|null $body
*
* @return void
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
*/
public function userHasCreatedTheFollowingLinkShare(string $user, TableNode $body): void {
$response = $this->createLinkShare($user, $body);
Expand Down Expand Up @@ -418,7 +419,7 @@ public function updateLinkShare(string $user, TableNode $body, string $permissi
*
* @return void
* @throws Exception
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
*/
public function userSetsOrUpdatesFollowingPasswordForLastLinkShareUsingTheGraphApi(string $user, TableNode $body):void {
$bodyRows = $body->getRowsHash();
Expand Down Expand Up @@ -495,7 +496,7 @@ public function removeSharePermission(
*
* @return void
* @throws JsonException
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
*/
public function userRemovesSharePermissionOfUserFromResourceOfSpaceUsingGraphAPI(
string $sharer,
Expand All @@ -519,7 +520,7 @@ public function userRemovesSharePermissionOfUserFromResourceOfSpaceUsingGraphAPI
*
* @return void
* @throws JsonException
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
*/
public function userRemovesSharePermissionOfUserFromSpaceUsingGraphAPI(
string $sharer,
Expand Down Expand Up @@ -641,7 +642,7 @@ public function userEnablesSyncOfShareUsingTheGraphApi(string $user, string $sha
* @param string $resource
*
* @return void
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
*/
public function userShouldHaveSyncEnabledOrDisabledForShare(string $user, string $status, string $resource):void {
$response = GraphHelper::getSharesSharedWithMe(
Expand Down Expand Up @@ -676,7 +677,7 @@ public function userShouldHaveSyncEnabledOrDisabledForShare(string $user, string
*
* @return void
* @throws Exception
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
*/
public function userShouldBeAbleToSendShareInvitationWithAllAllowedPermissionRoles(string $user, TableNode $table): void {
$listPermissionResponse = $this->featureContext->getJsonDecodedResponseBodyContent();
Expand Down Expand Up @@ -714,4 +715,28 @@ public function userShouldBeAbleToSendShareInvitationWithAllAllowedPermissionRol
}
Assert::assertTrue($areAllSendInvitationSuccessFullForAllowedRoles, $shareInvitationRequestResult);
}

/**
* @When /^user "([^"]*)" (?:tries to list|lists) the permissions of space "([^"]*)" using root endpoint of the Graph API$/
*
* @param string $user
* @param string $space
*
* @return void
* @throws Exception
* @throws GuzzleException
*
*/
public function userListsThePermissionsOfDriveUsingRootEndPointOFTheGraphApi(string $user, string $space):void {
$spaceId = ($this->spacesContext->getSpaceByName($user, $space))["id"];

$response = GraphHelper::getDrivePermissionsList(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$user,
$this->featureContext->getPasswordForUser($user),
$spaceId
);
$this->featureContext->setResponse($response);
}
}

0 comments on commit da656cb

Please sign in to comment.