From 11b5e8ccbc9d33ff655bacf2e4ac800bddc79d96 Mon Sep 17 00:00:00 2001 From: prashant-gurung899 Date: Thu, 2 Jan 2025 17:16:13 +0545 Subject: [PATCH] add test to check settings api response Signed-off-by: prashant-gurung899 --- .drone.star | 1 + .../acceptance/bootstrap/SettingsContext.php | 60 +++- tests/acceptance/config/behat.yml | 9 + .../assignRole.feature | 4 +- .../features/apiGraph/getAssignedRole.feature | 2 +- .../features/apiSettings/settings.feature | 277 ++++++++++++++++++ 6 files changed, 348 insertions(+), 5 deletions(-) create mode 100644 tests/acceptance/features/apiSettings/settings.feature diff --git a/.drone.star b/.drone.star index 2b9be9b12ea..c80d09103c1 100644 --- a/.drone.star +++ b/.drone.star @@ -88,6 +88,7 @@ config = { "apiDepthInfinity", "apiLocks", "apiActivities", + "apiSettings", ], "skip": False, }, diff --git a/tests/acceptance/bootstrap/SettingsContext.php b/tests/acceptance/bootstrap/SettingsContext.php index ab5838526aa..9e6243d6ad3 100644 --- a/tests/acceptance/bootstrap/SettingsContext.php +++ b/tests/acceptance/bootstrap/SettingsContext.php @@ -63,7 +63,7 @@ public function getRoles(string $user): ResponseInterface { } /** - * @When /^user "([^"]*)" tries to get all existing roles$/ + * @When /^user "([^"]*)" tries to get all existing roles using the settings API$/ * * @param string $user * @@ -139,6 +139,30 @@ public function theAdministratorHasGivenUserTheRole(string $user, string $role): ); } + /** + * @When user :assigner assigns the role :role to user :assignee using the settings API + * + * @param string $assigner + * @param string $role + * @param string $assignee + * + * @return void + * + * @throws Exception + */ + public function userAssignsTheRoleToUserUsingTheSettingsApi( + string $assigner, + string $role, + string $assignee + ): void { + $response = $this->assignRoleToUser( + $assigner, + $this->featureContext->getAttributeOfCreatedUser($assignee, 'id'), + $this->getRoleIdByRoleName($assigner, $role) + ); + $this->featureContext->setResponse($response); + } + /** * @param string $user * @param string $role @@ -232,7 +256,7 @@ public function userChangeRoleAnotherUser(string $user, string $role, string $as } /** - * @When /^user "([^"]*)" tries to get list of assignment$/ + * @When /^user "([^"]*)" tries to get list of assignment using the settings API$/ * * @param string $user * @@ -444,6 +468,22 @@ public function theUserHasSwitchedSystemLanguage(string $user, string $language) ); } + /** + * @When user :user switches the system language to :language using the settings API + * + * @param string $user + * @param string $language + * + * @return void + * + * @throws Exception + * @throws GuzzleException + */ + public function userSwitchesTheSystemLanguageUsingTheSettingsApi(string $user, string $language): void { + $response = $this->sendRequestToSwitchSystemLanguage($user, $language); + $this->featureContext->setResponse($response); + } + /** * @param string $user * @@ -497,4 +537,20 @@ public function theUserHasDisabledAutoAccepting(string $user): void { ); $this->featureContext->rememberUserAutoSyncSetting($user, false); } + + /** + * @When user :user disables the auto-sync share using the settings API + * + * @param string $user + * + * @return void + * + * @throws Exception + * @throws GuzzleException + */ + public function userDisablesAutoAcceptingUsingSettingsApi(string $user): void { + $response = $this->sendRequestToDisableAutoAccepting($user); + $this->featureContext->setResponse($response); + $this->featureContext->rememberUserAutoSyncSetting($user, false); + } } diff --git a/tests/acceptance/config/behat.yml b/tests/acceptance/config/behat.yml index 57948c74c69..4d3aab5c848 100644 --- a/tests/acceptance/config/behat.yml +++ b/tests/acceptance/config/behat.yml @@ -351,6 +351,15 @@ default: - OcisConfigContext: - SettingsContext: + apiSettings: + paths: + - "%paths.base%/../features/apiSettings" + context: *common_ldap_suite_context + contexts: + - FeatureContext: *common_feature_context_params + - GraphContext: + - SettingsContext: + apiSharingNgShareInvitation: paths: - "%paths.base%/../features/apiSharingNgShareInvitation" diff --git a/tests/acceptance/features/apiAccountsHashDifficulty/assignRole.feature b/tests/acceptance/features/apiAccountsHashDifficulty/assignRole.feature index c874f60b6fd..4154cb2ca90 100644 --- a/tests/acceptance/features/apiAccountsHashDifficulty/assignRole.feature +++ b/tests/acceptance/features/apiAccountsHashDifficulty/assignRole.feature @@ -7,7 +7,7 @@ Feature: assign role Scenario Outline: only admin user can see all existing roles Given user "Alice" has been created with default attributes And the administrator has given "Alice" the role "" using the settings api - When user "Alice" tries to get all existing roles + When user "Alice" tries to get all existing roles using the settings API Then the HTTP status code should be "" Examples: | user-role | http-status-code | @@ -19,7 +19,7 @@ Feature: assign role Scenario Outline: only admin user can see assignments list Given user "Alice" has been created with default attributes And the administrator has given "Alice" the role "" using the settings api - When user "Alice" tries to get list of assignment + When user "Alice" tries to get list of assignment using the settings API Then the HTTP status code should be "" Examples: | user-role | http-status-code | diff --git a/tests/acceptance/features/apiGraph/getAssignedRole.feature b/tests/acceptance/features/apiGraph/getAssignedRole.feature index 64f4a359113..315e004cb92 100644 --- a/tests/acceptance/features/apiGraph/getAssignedRole.feature +++ b/tests/acceptance/features/apiGraph/getAssignedRole.feature @@ -22,7 +22,7 @@ Feature: assign role @issue-5032 Scenario Outline: get assigned role of a user via setting api Given the administrator has assigned the role "" to user "Alice" using the Graph API - When user "Alice" tries to get list of assignment + When user "Alice" tries to get list of assignment using the settings API Then the HTTP status code should be "" And the setting API response should have the role "" Examples: diff --git a/tests/acceptance/features/apiSettings/settings.feature b/tests/acceptance/features/apiSettings/settings.feature new file mode 100644 index 00000000000..9ee66a84edf --- /dev/null +++ b/tests/acceptance/features/apiSettings/settings.feature @@ -0,0 +1,277 @@ +Feature: settings api + As a user, + I want to use settings api + So that I can manage user specific settings + + Background: + Given these users have been created with default attributes: + | username | + | Alice | + | Brian | + And using spaces DAV path + + + Scenario: disable auto-sync share + When user "Brian" disables the auto-sync share using the settings API + Then the HTTP status code should be "201" + And the JSON data of the response should match + """ + { + "type": "object", + "required": ["value"], + "properties": { + "value" : { + "type": "object", + "required": ["identifier","value"], + "properties": { + "identifier": { + "type": "object", + "required": [ "extension", "bundle", "setting"], + "properties": { + "extension": { "const": "ocis-accounts" }, + "bundle": { "const": "profile" }, + "setting": { "const": "auto-accept-shares" } + } + }, + "value": { + "type": "object", + "required": [ "id", "bundleId", "settingId", "accountUuid", "resource", "boolValue" ], + "properties": { + "id": { "pattern": "^%user_id_pattern%$" }, + "bundleId": { "pattern": "^%user_id_pattern%$" }, + "settingId": { "pattern": "^%user_id_pattern%$" }, + "accountUuid": { "pattern": "^%user_id_pattern%$" }, + "resource": { + "type": "object", + "required": ["type"], + "properties": { + "type": { "const": "TYPE_USER" } + } + }, + "boolValue": { "const": false } + } + } + } + } + } + } + """ + + + Scenario: assign role to user + When user "Admin" assigns the role "Admin" to user "Alice" using the settings API + Then the HTTP status code should be "201" + And the JSON data of the response should match + """ + { + "type": "object", + "required": ["assignment"], + "properties": { + "assignment" : { + "type": "object", + "required": [ "id", "accountUuid", "roleId" ], + "properties": { + "id": { "pattern": "^%user_id_pattern%$" }, + "accountUuid": { "pattern": "^%user_id_pattern%$" }, + "roleId": { "pattern": "^%user_id_pattern%$" } + } + } + } + } + """ + + @issue-5032 + Scenario: user lists assignments + Given the administrator has assigned the role "Admin" to user "Alice" using the Graph API + When user "Alice" tries to get list of assignment using the settings API + Then the HTTP status code should be "201" + And the JSON data of the response should match + """ + { + "type": "object", + "required": ["assignments"], + "properties": { + "assignments" : { + "type": "array", + "minItems": 1, + "maxItems": 1, + "uniqueItems": true, + "items": { + "type": "object", + "required": ["id","accountUuid","roleId"], + "properties": { + "id": { "pattern": "^%user_id_pattern%$" }, + "accountUuid": { "pattern": "^%user_id_pattern%$" }, + "roleId": { "pattern": "^%user_id_pattern%$" } + } + } + } + } + } + """ + + + Scenario: switch language + When user "Alice" switches the system language to "de" using the settings API + Then the HTTP status code should be "201" + And the JSON data of the response should match + """ + { + "type": "object", + "required": ["value"], + "properties": { + "value" : { + "type": "object", + "required": [ "identifier", "value"], + "properties": { + "identifier": { + "type": "object", + "required": [ "extension", "bundle", "setting"], + "properties": { + "extension": { "const": "ocis-accounts" }, + "bundle": { "const": "profile" }, + "setting": { "const": "language" } + } + }, + "value": { + "type": "object", + "required": [ "id", "bundleId", "settingId", "accountUuid", "resource", "listValue" ], + "properties": { + "id": { "pattern": "^%user_id_pattern%$" }, + "bundleId": { "pattern": "^%user_id_pattern%$" }, + "settingId": { "pattern": "^%user_id_pattern%$" }, + "accountUuid": { "pattern": "^%user_id_pattern%$" }, + "resource": { + "type": "object", + "required": ["type"], + "properties": { + "type": { "const": "TYPE_USER" } + } + }, + "listValue": { + "type": "object", + "required": ["values"], + "properties": { + "values": { + "type": "array", + "minItems": 1, + "maxItems": 1, + "items": { + "type": "object", + "required": ["stringValue"], + "properties": { + "stringValue": { "const": "de" } + } + } + } + } + } + } + } + } + } + } + } + """ + + @issue-5079 + Scenario Outline: user lists existing roles + Given the administrator has assigned the role "" to user "Alice" using the Graph API + When user "Alice" tries to get all existing roles using the settings API + Then the HTTP status code should be "201" + And the JSON data of the response should match + """ + { + "type": "object", + "required": ["bundles"], + "properties": { + "bundles" : { + "type": "array", + "minItems": 4, + "maxItems": 4, + "uniqueItems": true, + "items": { + "oneOf": [ + { + "type": "object", + "required": ["id", "name", "type", "extension", "displayName", "settings", "resource"], + "properties": { + "id": { "pattern": "^%user_id_pattern%$" }, + "name": { "const": "spaceadmin" }, + "type": { "const": "TYPE_ROLE" }, + "extension": { "const": "ocis-roles" }, + "displayName": { "const": "Space Admin" }, + "resource": { + "type": "object", + "required": ["type"], + "properties": { + "type": { "const": "TYPE_SYSTEM" } + } + } + } + }, + { + "type": "object", + "required": ["id", "name", "type", "extension", "displayName", "settings", "resource"], + "properties": { + "id": { "pattern": "^%user_id_pattern%$" }, + "name": { "const": "admin"}, + "type": { "const": "TYPE_ROLE" }, + "extension": { "const": "ocis-roles" }, + "displayName": { "const": "Admin" }, + "resource": { + "type": "object", + "required": ["type"], + "properties": { + "type": { "const": "TYPE_SYSTEM" } + } + } + } + }, + { + "type": "object", + "required": ["id", "name", "type", "extension", "displayName", "settings", "resource"], + "properties": { + "id": { "pattern": "^%user_id_pattern%$" }, + "name": { "const": "user-light" }, + "type": { "const": "TYPE_ROLE" }, + "extension": { "const": "ocis-roles" }, + "displayName": { "const": "User Light" }, + "resource": { + "type": "object", + "required": ["type"], + "properties": { + "type": { "const": "TYPE_SYSTEM" } + } + } + } + }, + { + "type": "object", + "required": ["id", "name", "type", "extension", "displayName", "settings", "resource"], + "properties": { + "id": { "pattern": "^%user_id_pattern%$" }, + "name": { "const": "user" }, + "type": { "const": "TYPE_ROLE" }, + "extension": { "const": "ocis-roles" }, + "displayName": { "const": "User" }, + "resource": { + "type": "object", + "required": ["type"], + "properties": { + "type": { "const": "TYPE_SYSTEM" } + } + } + } + } + ] + } + } + } + } + """ + Examples: + | user-role | + | Admin | + | Space Admin | + | User |