From 7b8b4faf059421bee1620874d0b28e16229da36f Mon Sep 17 00:00:00 2001 From: pradip Date: Thu, 18 Jul 2024 15:59:32 +0545 Subject: [PATCH] test: add test coverage for roleMangement endpoints --- tests/TestHelpers/GraphHelper.php | 53 ++ .../apiGraph/roleManagementEndpoint.feature | 603 ++++++++++++++++++ .../features/bootstrap/GraphContext.php | 43 ++ 3 files changed, 699 insertions(+) create mode 100644 tests/acceptance/features/apiGraph/roleManagementEndpoint.feature diff --git a/tests/TestHelpers/GraphHelper.php b/tests/TestHelpers/GraphHelper.php index 39ccf8de77..7e5c77b8d1 100644 --- a/tests/TestHelpers/GraphHelper.php +++ b/tests/TestHelpers/GraphHelper.php @@ -2240,4 +2240,57 @@ class GraphHelper { $body ); } + + /** + * @param string $baseUrl + * @param string $xRequestId + * @param string $user + * @param string $password + * + * @return ResponseInterface + * @throws GuzzleException + */ + public static function getPermissionsRoleDefinitions( + string $baseUrl, + string $xRequestId, + string $user, + string $password, + ): ResponseInterface { + $url = self::getBetaFullUrl($baseUrl, "roleManagement/permissions/roleDefinitions"); + return HttpRequestHelper::get( + $url, + $xRequestId, + $user, + $password, + self::getRequestHeaders() + ); + } + + /** + * @param string $permissionRole + * @param string $baseUrl + * @param string $xRequestId + * @param string $user + * @param string $password + * + * @return ResponseInterface + * @throws \Exception|GuzzleException + */ + public static function getPermissionRoleDefinition( + string $permissionRole, + string $baseUrl, + string $xRequestId, + string $user, + string $password, + ): ResponseInterface { + $roleId = self::getPermissionsRoleIdByName($permissionRole); + $url = self::getBetaFullUrl($baseUrl, "roleManagement/permissions/roleDefinitions/{$roleId}"); + return HttpRequestHelper::get( + $url, + $xRequestId, + $user, + $password, + self::getRequestHeaders() + ); + } } diff --git a/tests/acceptance/features/apiGraph/roleManagementEndpoint.feature b/tests/acceptance/features/apiGraph/roleManagementEndpoint.feature new file mode 100644 index 0000000000..2071ee413b --- /dev/null +++ b/tests/acceptance/features/apiGraph/roleManagementEndpoint.feature @@ -0,0 +1,603 @@ +Feature: permissions role definitions + As a user + I want to get the role management endpoints + So that I can find out if those endpoints are working correctly or not + + Background: + Given user "Alice" has been created with default attributes and without skeleton files + + + Scenario: get a list of permissions role definitions + When user "Alice" gets a list of permissions role definitions using the Graph API + Then the HTTP status code should be "200" + And the JSON data of the response should match + """ + { + "type": "array", + "maxItems": 8, + "minItems": 8, + "uniqueItems": true, + "items": { + "oneOf": [ + { + "type": "object", + "required": [ + "@libre.graph.weight", + "description", + "displayName", + "id", + "rolePermissions" + ], + "properties": { + "@libre.graph.weight": { + "const": 0 + }, + "description": { + "const": "View and download." + }, + "displayName": { + "const": "Can view" + }, + "id": { + "const": "b1e2218d-eef8-4d4c-b82d-0f1a1b48f3b5" + }, + "rolePermissions": { + "type": "array", + "maxItems": 2, + "minItems": 2, + "uniqueItems": true, + "items": { + "oneOf": [ + { + "type": "object", + "required": [ + "allowedResourceActions", + "condition" + ], + "properties": { + "allowedResourceActions": { + "const": [ + "libre.graph/driveItem/path/read", + "libre.graph/driveItem/quota/read", + "libre.graph/driveItem/content/read", + "libre.graph/driveItem/children/read", + "libre.graph/driveItem/deleted/read", + "libre.graph/driveItem/basic/read" + ] + }, + "condition": { + "const": "exists @Resource.File" + } + } + }, + { + "type": "object", + "required": [ + "allowedResourceActions", + "condition" + ], + "properties": { + "allowedResourceActions": { + "const": [ + "libre.graph/driveItem/path/read", + "libre.graph/driveItem/quota/read", + "libre.graph/driveItem/content/read", + "libre.graph/driveItem/children/read", + "libre.graph/driveItem/deleted/read", + "libre.graph/driveItem/basic/read" + ] + }, + "condition": { + "const": "exists @Resource.Folder" + } + } + } + ] + } + } + } + }, + { + "type": "object", + "required": [ + "@libre.graph.weight", + "description", + "displayName", + "id", + "rolePermissions" + ], + "properties": { + "@libre.graph.weight": { + "const": 0 + }, + "description": { + "const": "View and download." + }, + "displayName": { + "const": "Can view" + }, + "id": { + "const": "a8d5fe5e-96e3-418d-825b-534dbdf22b99" + }, + "rolePermissions": { + "type": "array", + "maxItems": 1, + "minItems": 1, + "uniqueItems": true, + "items": { + "type": "object", + "required": [ + "allowedResourceActions", + "condition" + ], + "properties": { + "allowedResourceActions": { + "const": [ + "libre.graph/driveItem/path/read", + "libre.graph/driveItem/quota/read", + "libre.graph/driveItem/content/read", + "libre.graph/driveItem/permissions/read", + "libre.graph/driveItem/children/read", + "libre.graph/driveItem/deleted/read", + "libre.graph/driveItem/basic/read" + ] + }, + "condition": { + "const": "exists @Resource.Root" + } + } + } + } + } + }, + { + "type": "object", + "required": [ + "@libre.graph.weight", + "description", + "displayName", + "id", + "rolePermissions" + ], + "properties": { + "@libre.graph.weight": { + "const": 0 + }, + "description": { + "const": "View, download, upload, edit, add and delete." + }, + "displayName": { + "const": "Can edit" + }, + "id": { + "const": "fb6c3e19-e378-47e5-b277-9732f9de6e21" + }, + "rolePermissions": { + "type": "array", + "maxItems": 1, + "minItems": 1, + "uniqueItems": true, + "items": { + "type": "object", + "required": [ + "allowedResourceActions", + "condition" + ], + "properties": { + "allowedResourceActions": { + "const": [ + "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/children/read", + "libre.graph/driveItem/deleted/read", + "libre.graph/driveItem/path/update", + "libre.graph/driveItem/deleted/update", + "libre.graph/driveItem/basic/read" + ] + }, + "condition": { + "const": "exists @Resource.Folder" + } + } + } + } + } + }, + { + "type": "object", + "required": [ + "@libre.graph.weight", + "description", + "displayName", + "id", + "rolePermissions" + ], + "properties": { + "@libre.graph.weight": { + "const": 0 + }, + "description": { + "const": "View, download, upload, edit, add and delete." + }, + "displayName": { + "const": "Can edit" + }, + "id": { + "const": "58c63c02-1d89-4572-916a-870abc5a1b7d" + }, + "rolePermissions": { + "type": "array", + "maxItems": 1, + "minItems": 1, + "uniqueItems": true, + "items": { + "type": "object", + "required": [ + "allowedResourceActions", + "condition" + ], + "properties": { + "allowedResourceActions": { + "const": [ + "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/versions/update", + "libre.graph/driveItem/deleted/update", + "libre.graph/driveItem/basic/read" + ] + }, + "condition": { + "const": "exists @Resource.Root" + } + } + } + } + } + }, + { + "type": "object", + "required": [ + "@libre.graph.weight", + "description", + "displayName", + "id", + "rolePermissions" + ], + "properties": { + "@libre.graph.weight": { + "const": 0 + }, + "description": { + "const": "View, download and edit." + }, + "displayName": { + "const": "Can edit" + }, + "id": { + "const": "2d00ce52-1fc2-4dbc-8b95-a73b73395f5a" + }, + "rolePermissions": { + "type": "array", + "maxItems": 1, + "minItems": 1, + "uniqueItems": true, + "items": { + "type": "object", + "required": [ + "allowedResourceActions", + "condition" + ], + "properties": { + "allowedResourceActions": { + "const": [ + "libre.graph/driveItem/path/read", + "libre.graph/driveItem/quota/read", + "libre.graph/driveItem/content/read", + "libre.graph/driveItem/upload/create", + "libre.graph/driveItem/children/read", + "libre.graph/driveItem/deleted/read", + "libre.graph/driveItem/deleted/update", + "libre.graph/driveItem/basic/read" + ] + }, + "condition": { + "const":"exists @Resource.File" + } + } + } + } + } + }, + { + "type": "object", + "required": [ + "@libre.graph.weight", + "description", + "displayName", + "id", + "rolePermissions" + ], + "properties": { + "@libre.graph.weight": { + "const": 0 + }, + "description": { + "const": "View, download and upload." + }, + "displayName": { + "const": "Can upload" + }, + "id": { + "const": "1c996275-f1c9-4e71-abdf-a42f6495e960" + }, + "rolePermissions": { + "type": "array", + "maxItems": 1, + "minItems": 1, + "uniqueItems": true, + "items": { + "type": "object", + "required": [ + "allowedResourceActions", + "condition" + ], + "properties": { + "allowedResourceActions": { + "const": [ + "libre.graph/driveItem/children/create", + "libre.graph/driveItem/path/read", + "libre.graph/driveItem/content/read", + "libre.graph/driveItem/upload/create", + "libre.graph/driveItem/children/read", + "libre.graph/driveItem/path/update", + "libre.graph/driveItem/basic/read" + ] + }, + "condition": { + "const": "exists @Resource.Folder" + } + } + } + } + } + }, + { + "type": "object", + "required": [ + "@libre.graph.weight", + "description", + "displayName", + "id", + "rolePermissions" + ], + "properties": { + "@libre.graph.weight": { + "const": 0 + }, + "description": { + "const": "View, download, upload, edit, add, delete and manage members." + }, + "displayName": { + "const": "Can manage" + }, + "id": { + "const": "312c0871-5ef7-4b3a-85b6-0e4074c64049" + }, + "rolePermissions": { + "type": "array", + "maxItems": 1, + "minItems": 1, + "uniqueItems": true, + "items": { + "type": "object", + "required": [ + "allowedResourceActions", + "condition" + ], + "properties": { + "allowedResourceActions": { + "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" + ] + }, + "condition": { + "const": "exists @Resource.Root" + } + } + } + } + } + }, + { + "type": "object", + "required": [ + "@libre.graph.weight", + "description", + "displayName", + "id", + "rolePermissions" + ], + "properties": { + "@libre.graph.weight": { + "const": 0 + }, + "description": { + "const": "View only documents, images and PDFs. Watermarks will be applied." + }, + "displayName": { + "const": "Can view (secure)" + }, + "id": { + "const": "aa97fe03-7980-45ac-9e50-b325749fd7e6" + }, + "rolePermissions": { + "type": "array", + "maxItems": 2, + "minItems": 2, + "uniqueItems": true, + "items": { + "oneOf": [ + { + "type": "object", + "required": [ + "allowedResourceActions", + "condition" + ], + "properties": { + "allowedResourceActions": { + "const": [ + "libre.graph/driveItem/path/read", + "libre.graph/driveItem/children/read", + "libre.graph/driveItem/basic/read" + ] + }, + "condition": { + "const": "exists @Resource.File" + } + } + }, + { + "type": "object", + "required": [ + "allowedResourceActions", + "condition" + ], + "properties": { + "allowedResourceActions": { + "const": [ + "libre.graph/driveItem/path/read", + "libre.graph/driveItem/children/read", + "libre.graph/driveItem/basic/read" + ] + }, + "condition": { + "const": "exists @Resource.Folder" + } + } + } + ] + } + } + } + } + ] + } + } + """ + + + Scenario: get details of a specific permission role definition + When user "Alice" gets the "Viewer" role definition using 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.weight", + "description", + "displayName", + "id", + "rolePermissions" + ], + "properties": { + "@libre.graph.weight":{ + "const": 0 + }, + "description": { + "const": "View and download." + }, + "displayName": { + "const": "Can view" + }, + "id": { + "const": "b1e2218d-eef8-4d4c-b82d-0f1a1b48f3b5" + }, + "rolePermissions": { + "type": "array", + "maxItems": 2, + "minItems": 2, + "uniqueItems": true, + "items": { + "oneOf": [ + { + "type": "object", + "required": [ + "allowedResourceActions", + "condition" + ], + "properties": { + "allowedResourceActions": { + "const": [ + "libre.graph/driveItem/path/read", + "libre.graph/driveItem/quota/read", + "libre.graph/driveItem/content/read", + "libre.graph/driveItem/children/read", + "libre.graph/driveItem/deleted/read", + "libre.graph/driveItem/basic/read" + ] + }, + "condition": { + "const": "exists @Resource.File" + } + } + }, + { + "type": "object", + "required": [ + "allowedResourceActions", + "condition" + ], + "properties": { + "allowedResourceActions": { + "const": [ + "libre.graph/driveItem/path/read", + "libre.graph/driveItem/quota/read", + "libre.graph/driveItem/content/read", + "libre.graph/driveItem/children/read", + "libre.graph/driveItem/deleted/read", + "libre.graph/driveItem/basic/read" + ] + }, + "condition": { + "const": "exists @Resource.Folder" + } + } + } + ] + } + } + } + } + """ diff --git a/tests/acceptance/features/bootstrap/GraphContext.php b/tests/acceptance/features/bootstrap/GraphContext.php index bf18bb7dcd..ee33aa7fe9 100644 --- a/tests/acceptance/features/bootstrap/GraphContext.php +++ b/tests/acceptance/features/bootstrap/GraphContext.php @@ -2732,4 +2732,47 @@ class GraphContext implements Context { $this->featureContext->theHTTPStatusCodeShouldBe(200, '', $response); $this->featureContext->updateUsernameInCreatedUserList($byUser, $userName); } + + /** + * @When user :user gets a list of permissions role definitions using the Graph API + * + * @param string $user + * + * @return void + * @throws GuzzleException + */ + public function getListOfPermissionRoleDefinitionsUsingTheGraphAPI(string $user): void { + $credentials = $this->getAdminOrUserCredentials($user); + $this->featureContext->setResponse( + GraphHelper::getPermissionsRoleDefinitions( + $this->featureContext->getBaseUrl(), + $this->featureContext->getStepLineRef(), + $credentials['username'], + $credentials['password'], + ) + ); + } + + /** + * @When user :user gets the :permissionRole role definition using the Graph API + * + * @param string $user + * @param string $permissionRole + * + * @return void + * @throws GuzzleException + * @throws Exception + */ + public function getPermissionRoleDefinitionUsingGraphAPI(string $user, string $permissionRole):void { + $credentials = $this->getAdminOrUserCredentials($user); + $this->featureContext->setResponse( + GraphHelper::getPermissionRoleDefinition( + $permissionRole, + $this->featureContext->getBaseUrl(), + $this->featureContext->getStepLineRef(), + $credentials['username'], + $credentials['password'], + ) + ); + } }