From 4c828d36f03f1ac5e7c6046df764cf5bebb00b6f Mon Sep 17 00:00:00 2001 From: prashant-gurung899 Date: Tue, 3 Sep 2024 12:50:59 +0545 Subject: [PATCH] add tests for new role space editor withour versions Signed-off-by: prashant-gurung899 --- tests/acceptance/TestHelpers/GraphHelper.php | 73 +++++++------------ .../bootstrap/OcisConfigContext.php | 26 +++++++ tests/acceptance/config/behat.yml | 1 + .../shareInvitations.feature | 1 - .../fileVersionByFileID.feature | 11 +++ 5 files changed, 65 insertions(+), 47 deletions(-) diff --git a/tests/acceptance/TestHelpers/GraphHelper.php b/tests/acceptance/TestHelpers/GraphHelper.php index ec05c2046..e3efbf54f 100644 --- a/tests/acceptance/TestHelpers/GraphHelper.php +++ b/tests/acceptance/TestHelpers/GraphHelper.php @@ -16,6 +16,21 @@ use Psr\Http\Message\ResponseInterface; * A helper class for managing Graph API requests */ class GraphHelper { + public const DEFAULT_PERMISSIONS_ROLES = [ + 'Viewer' => 'b1e2218d-eef8-4d4c-b82d-0f1a1b48f3b5', + 'Editor' => 'fb6c3e19-e378-47e5-b277-9732f9de6e21', + 'File Editor' => '2d00ce52-1fc2-4dbc-8b95-a73b73395f5a', + 'Uploader' => '1c996275-f1c9-4e71-abdf-a42f6495e960', + 'Space Viewer' => 'a8d5fe5e-96e3-418d-825b-534dbdf22b99', + 'Space Editor' => '58c63c02-1d89-4572-916a-870abc5a1b7d', + 'Manager' => '312c0871-5ef7-4b3a-85b6-0e4074c64049', + ]; + + public const ADDITIONAL_PERMISSIONS_ROLES = [ + 'Secure viewer' => 'aa97fe03-7980-45ac-9e50-b325749fd7e6', + 'Space Editor Without Versions' => '3284f2d5-0070-4ad8-ac40-c247f7c1fb27', + ]; + /** * @return string[] */ @@ -1657,31 +1672,13 @@ class GraphHelper { * * @throws \Exception */ - public static function getPermissionsRoleIdByName( - string $permissionsRole - ): string { - switch ($permissionsRole) { - case 'Viewer': - return 'b1e2218d-eef8-4d4c-b82d-0f1a1b48f3b5'; - case 'Space Viewer': - return 'a8d5fe5e-96e3-418d-825b-534dbdf22b99'; - case 'Editor': - return 'fb6c3e19-e378-47e5-b277-9732f9de6e21'; - case 'Space Editor': - return '58c63c02-1d89-4572-916a-870abc5a1b7d'; - case 'File Editor': - return '2d00ce52-1fc2-4dbc-8b95-a73b73395f5a'; - case 'Co Owner': - return '3a4ba8e9-6a0d-4235-9140-0e7a34007abe'; - case 'Uploader': - return '1c996275-f1c9-4e71-abdf-a42f6495e960'; - case 'Manager': - return '312c0871-5ef7-4b3a-85b6-0e4074c64049'; - case 'Secure viewer': - return 'aa97fe03-7980-45ac-9e50-b325749fd7e6'; - default: - throw new \Exception('Role ' . $permissionsRole . ' not found'); + public static function getPermissionsRoleIdByName(string $permissionsRole): string { + $allPermissionsRoles = array_merge(self::DEFAULT_PERMISSIONS_ROLES, self::ADDITIONAL_PERMISSIONS_ROLES); + if (\array_key_exists($permissionsRole, $allPermissionsRoles)) { + return $allPermissionsRoles[$permissionsRole]; } + + throw new \Exception("Role '$permissionsRole' not found"); } /** @@ -1693,29 +1690,13 @@ class GraphHelper { * * @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'; - case 'a8d5fe5e-96e3-418d-825b-534dbdf22b99': - return 'Space Viewer'; - case '58c63c02-1d89-4572-916a-870abc5a1b7d': - return 'Space Editor'; - case '312c0871-5ef7-4b3a-85b6-0e4074c64049': - return 'Manager'; - case 'aa97fe03-7980-45ac-9e50-b325749fd7e6': - return 'Secure viewer'; - default: - throw new \Exception('Permission role id: ' . $permissionsRoleId . ' not found'); + public static function getPermissionNameByPermissionRoleId(string $permissionsRoleId): string { + $allPermissionsRoles = array_merge(self::DEFAULT_PERMISSIONS_ROLES, self::ADDITIONAL_PERMISSIONS_ROLES); + $roleName = array_search($permissionsRoleId, $allPermissionsRoles); + if ($roleName) { + return $roleName; } + throw new \Exception("Permission role id: '$permissionsRoleId' not found"); } /** diff --git a/tests/acceptance/bootstrap/OcisConfigContext.php b/tests/acceptance/bootstrap/OcisConfigContext.php index c5b97e41c..4a7a32172 100644 --- a/tests/acceptance/bootstrap/OcisConfigContext.php +++ b/tests/acceptance/bootstrap/OcisConfigContext.php @@ -24,6 +24,7 @@ use Behat\Behat\Context\Context; use Behat\Gherkin\Node\TableNode; use GuzzleHttp\Exception\GuzzleException; use TestHelpers\OcisConfigHelper; +use TestHelpers\GraphHelper; use PHPUnit\Framework\Assert; /** @@ -75,6 +76,31 @@ class OcisConfigContext implements Context { ); } + /** + * @Given the administrator has enabled the permissions role :role + * + * @param string $role + * + * @return void + */ + public function theAdministratorHasEnabledTheRole(string $role): void { + $roleId = GraphHelper::getPermissionsRoleIdByName($role); + $defaultRoles = array_values(GraphHelper::DEFAULT_PERMISSIONS_ROLES); + + if (!\in_array($role, $defaultRoles)) { + $defaultRoles[] = $roleId; + } + $envs = [ + "GRAPH_AVAILABLE_ROLES" => implode(',', $defaultRoles), + ]; + $response = OcisConfigHelper::reConfigureOcis($envs); + Assert::assertEquals( + 200, + $response->getStatusCode(), + "Failed to enable role $role" + ); + } + /** * @Given the config :configVariable has been set to path :path * diff --git a/tests/acceptance/config/behat.yml b/tests/acceptance/config/behat.yml index 74cc8b559..aed0c8034 100644 --- a/tests/acceptance/config/behat.yml +++ b/tests/acceptance/config/behat.yml @@ -315,6 +315,7 @@ default: - FilesVersionsContext: - SharingNgContext: - SettingsContext: + - OcisConfigContext: apiLocks: paths: diff --git a/tests/acceptance/features/apiSharingNgShareInvitation/shareInvitations.feature b/tests/acceptance/features/apiSharingNgShareInvitation/shareInvitations.feature index 72dd20656..e3aff5c96 100644 --- a/tests/acceptance/features/apiSharingNgShareInvitation/shareInvitations.feature +++ b/tests/acceptance/features/apiSharingNgShareInvitation/shareInvitations.feature @@ -2248,7 +2248,6 @@ Feature: Send a sharing invitations | Space Viewer | role not applicable to this resource | | Space Editor | role not applicable to this resource | | Manager | role not applicable to this resource | - | Co Owner | Key: 'DriveItemInvite.Roles' Error:Field validation for 'Roles' failed on the 'available_role' tag | Scenario Outline: try to send share invitation with different re-sharing permissions diff --git a/tests/acceptance/features/apiSpacesDavOperation/fileVersionByFileID.feature b/tests/acceptance/features/apiSpacesDavOperation/fileVersionByFileID.feature index 3ba7c906f..3f384d811 100644 --- a/tests/acceptance/features/apiSpacesDavOperation/fileVersionByFileID.feature +++ b/tests/acceptance/features/apiSpacesDavOperation/fileVersionByFileID.feature @@ -164,3 +164,14 @@ Feature: checking file versions using file id | source | destination | | / | folder/ | | folder/ | / | + + @env-config + Scenario: check the versions of a file in a shared space as editor without versions role + Given the administrator has enabled the permissions role "Space Editor Without Versions" + And user "Alice" has sent the following space share invitation: + | space | Project1 | + | sharee | Brian | + | shareType | user | + | permissionsRole | Space Editor Without Versions | + When user "Brian" gets the number of versions of file "/text.txt" using file-id path "/meta/<>/v" + Then the HTTP status code should be "403"