diff --git a/tests/TestHelpers/GraphHelper.php b/tests/TestHelpers/GraphHelper.php index 0b8446e4f53..eb2b721f783 100644 --- a/tests/TestHelpers/GraphHelper.php +++ b/tests/TestHelpers/GraphHelper.php @@ -171,6 +171,7 @@ class GraphHelper { * @param string|null $password * @param string|null $email * @param string|null $displayName + * @param bool|true $accountEnabled * * @return ResponseInterface * @throws GuzzleException @@ -184,13 +185,15 @@ class GraphHelper { ?string $userName = null, ?string $password = null, ?string $email = null, - ?string $displayName = null + ?string $displayName = null, + ?bool $accountEnabled = true ): ResponseInterface { $payload = self::preparePatchUserPayload( $userName, $password, $email, - $displayName + $displayName, + $accountEnabled ); $url = self::getFullUrl($baseUrl, 'users/' . $userId); return HttpRequestHelper::sendRequest( @@ -674,6 +677,7 @@ class GraphHelper { if (!empty($email)) { $payload['mail'] = $email ?? $userName . '@example.com'; } + $payload['accountEnabled'] = true; return \json_encode($payload); } @@ -684,6 +688,7 @@ class GraphHelper { * @param string|null $password * @param string|null $email * @param string|null $displayName + * @param bool|true $accountEnabled * * @return string */ @@ -691,7 +696,8 @@ class GraphHelper { ?string $userName, ?string $password, ?string $email, - ?string $displayName + ?string $displayName, + ?bool $accountEnabled ): string { $payload = []; if ($userName) { @@ -706,6 +712,8 @@ class GraphHelper { if ($email) { $payload['mail'] = $email; } + $payload['accountEnabled'] = $accountEnabled; + return \json_encode($payload); } diff --git a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md index 109d10e6a9e..b24fc241b33 100644 --- a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md +++ b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md @@ -23,7 +23,6 @@ The expected failures in this file are from features in the owncloud/ocis repo. - [apiGraph/createGroupCaseSensitive.feature:21](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/createGroupCaseSensitive.feature#L21) - [apiGraph/createGroupCaseSensitive.feature:22](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/createGroupCaseSensitive.feature#L22) - [apiGraph/createGroup.feature:26](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/createGroup.feature#L26) -- [apiGraph/createUser.feature:28](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/createUser.feature#L28) ### [PROPFIND on accepted shares with identical names containing brackets exit with 404](https://github.com/owncloud/ocis/issues/4421) - [apiSpacesShares/changingFilesShare.feature:12](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpacesShares/changingFilesShare.feature#L12) @@ -93,7 +92,7 @@ The expected failures in this file are from features in the owncloud/ocis repo. #### [A User can get information of another user with Graph API](https://github.com/owncloud/ocis/issues/5125) - [apiGraph/getUser.feature:23](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L23) -- [apiGraph/getUser.feature:92](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L92) +- [apiGraph/getUser.feature:102](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L102) #### [GET a file while it's in processing doesn't return 425 code (async uploads)](https://github.com/owncloud/ocis/issues/5326) - [apiAsyncUpload/delayPostprocessing.feature:14](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiAsyncUpload/delayPostprocessing.feature#L14) @@ -109,5 +108,8 @@ The expected failures in this file are from features in the owncloud/ocis repo. #### [Space admin should not not be able to change the user quota](https://github.com/owncloud/ocis/issues/5475) - [apiSpaces/spaceManagement.feature:69](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/spaceManagement.feature#L69) +#### Change editUser test where we set empty value +- [apiGraph/editUser.feature:33](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/editUser.feature#L33) +- [apiGraph/editUser.feature:80](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/editUser.feature#L80) Note: always have an empty line at the end of this file. The bash script that processes this file requires that the last line has a newline on the end. diff --git a/tests/acceptance/features/apiGraph/addUserToGroup.feature b/tests/acceptance/features/apiGraph/addUserToGroup.feature index 2fe439b6721..f38b95d6138 100644 --- a/tests/acceptance/features/apiGraph/addUserToGroup.feature +++ b/tests/acceptance/features/apiGraph/addUserToGroup.feature @@ -69,14 +69,14 @@ Feature: add users to group Scenario: adding a user to a group with % and # in its name Given these groups have been created: - | groupname | comment | - | maintenance#123 | Hash sign | - | 50%pass | Percent sign (special escaping happens) | - | 50%25=0 | %25 literal looks like an escaped "%" | - | 50%2Eagle | %2E literal looks like an escaped "." | - | 50%2Fix | %2F literal looks like an escaped slash | - | Mgmt\Middle | Backslash | - | staff?group | Question mark | + | groupname | comment | + | maintenance#123 | Hash sign | + | 50%pass | Percent sign (special escaping happens) | + | 50%25=0 | %25 literal looks like an escaped "%" | + | 50%2Eagle | %2E literal looks like an escaped "." | + | 50%2Fix | %2F literal looks like an escaped slash | + | Mgmt\Middle | Backslash | + | staff?group | Question mark | When the administrator adds the following users to the following groups using the Graph API | username | groupname | | Alice | maintenance#123 | @@ -203,3 +203,18 @@ Feature: add users to group | Brian | | Carol | Then the HTTP status code should be "404" + + @skipOnStable2.0 + Scenario: adding a disabled user to a group + Given these groups have been created: + | groupname | comment | + | sales | normal group | + And the user "Admin" has disabled user "Alice" using the Graph API + When the administrator adds the following users to the following groups using the Graph API + | username | groupname | + | Alice | sales | + Then the HTTP status code of responses on all endpoints should be "204" + And the following users should be listed in the following groups + | username | groupname | + | Alice | sales | + \ No newline at end of file diff --git a/tests/acceptance/features/apiGraph/createUser.feature b/tests/acceptance/features/apiGraph/createUser.feature index 1378a4be7de..9ed79441134 100644 --- a/tests/acceptance/features/apiGraph/createUser.feature +++ b/tests/acceptance/features/apiGraph/createUser.feature @@ -1,4 +1,4 @@ -@api @skipOnOcV10 +@api @skipOnOcV10 @skipOnStable2.0 Feature: create user Only user with admin permissions can create new user @@ -8,47 +8,78 @@ Feature: create user Background: Given user "Alice" has been created with default attributes and without skeleton files - + Scenario Outline: the admin creates a user Given the administrator has given "Alice" the role "Admin" using the settings api When the user "Alice" creates a new user using GraphAPI with the following settings: - | userName | | - | displayName | | - | email | | - | password | | + | userName | | + | displayName | | + | email | | + | password | | + | accountEnabled | | Then the HTTP status code should be "" And user "" exist Examples: - | userName | displayName | email | password | code | shouldOrNot | - | SameDisplayName | Alice Hansen | new@example.org | containsCharacters(*:!;_+-&) | 200 | should | - | withoutPassSameEmail | without pass | alice@example.org | | 200 | should | - | name | pass with space | example@example.org | my pass | 200 | should | - | nameWithCharacters(*:!;_+-&) | user | new@example.org | 123 | 400 | should not | - | withoutEmail | without email | | 123 | 400 | should not | - | Alice | same userName | new@example.org | 123 | 400 | should | - | name with space | name with space | example@example.org | 123 | 400 | should not | - + | userName | displayName | email | password | code | enable | shouldOrNot | + | SameDisplayName | Alice Hansen | new@example.org | containsCharacters(*:!;_+-&) | 200 | true | should | + | withoutPassSameEmail | without pass | alice@example.org | | 200 | true | should | + | name | pass with space | example@example.org | my pass | 200 | true | should | + | nameWithCharacters(*:!;_+-&) | user | new@example.org | 123 | 400 | true | should not | + | withoutEmail | without email | | 123 | 200 | true | should | + | Alice | same userName | new@example.org | 123 | 400 | true | should | + | name with space | name with space | example@example.org | 123 | 400 | true | should not | + | createDisabledUser | disabled user | example@example.org | 123 | 200 | false | should | + Scenario: a user cannot be created with empty name Given the administrator has given "Alice" the role "Admin" using the settings api When the user "Alice" creates a new user using GraphAPI with the following settings: - | userName | | - | displayName | emptyName | - | email | @example.org | - | password | 123 | + | userName | | + | displayName | emptyName | + | email | @example.org | + | password | 123 | + | accountEnabled | true | Then the HTTP status code should be "400" - + Scenario Outline: a user without admin right cannot create a user Given the administrator has given "Alice" the role "" using the settings api When the user "Alice" creates a new user using GraphAPI with the following settings: - | userName | user | - | displayName | user | - | email | @example.org | - | password | 123 | + | userName | user | + | displayName | user | + | email | @example.org | + | password | 123 | + | accountEnabled | true | Then the HTTP status code should be "401" And user "user" should not exist Examples: | role | | Space Admin | | User | + + + Scenario: a user cannot be created with the name of the disabled user + Given user "Brian" has been created with default attributes and without skeleton files + And the administrator has given "Alice" the role "Admin" using the settings api + And the user "Alice" has disabled user "Brian" using the Graph API + When the user "Alice" creates a new user using GraphAPI with the following settings: + | userName | Brian | + | displayName | This is another Brian | + | email | brian@example.com | + | password | 123 | + | accountEnabled | true | + Then the HTTP status code should be "400" + + + Scenario: a user can be created with the name of the deleted user + Given user "Brian" has been created with default attributes and without skeleton files + And the administrator has given "Alice" the role "Admin" using the settings api + And the user "Alice" has deleted a user "Brian" using the Graph API + When the user "Alice" creates a new user using GraphAPI with the following settings: + | userName | Brian | + | displayName | This is another Brian | + | email | brian@example.com | + | password | 123 | + | accountEnabled | true | + Then the HTTP status code should be "200" + And user "Brian" should exist diff --git a/tests/acceptance/features/apiGraph/deleteUser.feature b/tests/acceptance/features/apiGraph/deleteUser.feature index 45a549f5472..64664b97a56 100644 --- a/tests/acceptance/features/apiGraph/deleteUser.feature +++ b/tests/acceptance/features/apiGraph/deleteUser.feature @@ -71,3 +71,13 @@ Feature: delete user | role | | Space Admin | | User | + + @skipOnStable2.0 + Scenario: the admin user deletes a disabled user + Given the administrator has given "Alice" the role "Admin" using the settings api + And user "Brian" has been created with default attributes and without skeleton files + And the user "Alice" has disabled user "Brian" using the Graph API + When the user "Alice" deletes a user "Brian" using the Graph API + Then the HTTP status code should be "204" + And user "Brian" should not exist + \ No newline at end of file diff --git a/tests/acceptance/features/apiGraph/editUser.feature b/tests/acceptance/features/apiGraph/editUser.feature index 9156316afe6..a2a92048df1 100644 --- a/tests/acceptance/features/apiGraph/editUser.feature +++ b/tests/acceptance/features/apiGraph/editUser.feature @@ -139,3 +139,59 @@ Feature: edit user | role | | Space Admin | | User | + + @skipOnStable2.0 + Scenario: the admin user disables another user + When the user "Alice" disables user "Brian" using the Graph API + Then the HTTP status code should be "200" + When user "Alice" gets information of user "Brian" using Graph API + Then the HTTP status code should be "200" + And the user retrieve API response should contain the following information: + | displayName | id | mail | onPremisesSamAccountName | accountEnabled | + | Brian Murphy | %uuid_v4% | brian@example.com | Brian | false | + + @skipOnStable2.0 + Scenario Outline: a normal user should not be able to disable another user + Given user "Carol" has been created with default attributes and without skeleton files + And the administrator has given "Brian" the role "" using the settings api + When the user "Brian" tries to disable user "Carol" using the Graph API + Then the HTTP status code should be "401" + When user "Alice" gets information of user "Carol" using Graph API + Then the HTTP status code should be "200" + And the user retrieve API response should contain the following information: + | displayName | id | mail | onPremisesSamAccountName | accountEnabled | + | Carol King | %uuid_v4% | carol@example.org | Carol | true | + Examples: + | role | + | Space Admin | + | User | + | Guest | + + @skipOnStable2.0 + Scenario: the admin user enables disabled user + Given the user "Alice" has disabled user "Brian" using the Graph API + When the user "Alice" enables user "Brian" using the Graph API + Then the HTTP status code should be "200" + When user "Alice" gets information of user "Brian" using Graph API + Then the HTTP status code should be "200" + And the user retrieve API response should contain the following information: + | displayName | id | mail | onPremisesSamAccountName | accountEnabled | + | Brian Murphy | %uuid_v4% | brian@example.com | Brian | true | + + @skipOnStable2.0 + Scenario Outline: a normal user should not be able to enable another user + Given user "Carol" has been created with default attributes and without skeleton files + And the user "Alice" has disabled user "Carol" using the Graph API + And the administrator has given "Brian" the role "" using the settings api + When the user "Brian" tries to enable user "Carol" using the Graph API + Then the HTTP status code should be "401" + When user "Alice" gets information of user "Carol" using Graph API + Then the HTTP status code should be "200" + And the user retrieve API response should contain the following information: + | displayName | id | mail | onPremisesSamAccountName | accountEnabled | + | Carol King | %uuid_v4% | carol@example.org | Carol | false | + Examples: + | role | + | Space Admin | + | User | + | Guest | diff --git a/tests/acceptance/features/apiGraph/getUser.feature b/tests/acceptance/features/apiGraph/getUser.feature index a53dcf36621..3f088ae420b 100644 --- a/tests/acceptance/features/apiGraph/getUser.feature +++ b/tests/acceptance/features/apiGraph/getUser.feature @@ -11,13 +11,13 @@ Feature: get users | Brian | And the administrator has given "Alice" the role "Admin" using the settings api - + @skipOnStable2.0 Scenario: admin user gets the information of a user When user "Alice" gets information of user "Brian" using Graph API Then the HTTP status code should be "200" And the user retrieve API response should contain the following information: - | displayName | id | mail | onPremisesSamAccountName | - | Brian Murphy | %uuid_v4% | brian@example.org | Brian | + | displayName | id | mail | onPremisesSamAccountName | accountEnabled | + | Brian Murphy | %uuid_v4% | brian@example.org | Brian | true | Scenario: non-admin user tries to get the information of a user @@ -25,14 +25,24 @@ Feature: get users Then the HTTP status code should be "401" And the last response should be an unauthorized response - + @skipOnStable2.0 Scenario: admin user gets all users When user "Alice" gets all users using the Graph API Then the HTTP status code should be "200" And the API response should contain following users with the information: - | displayName | id | mail | onPremisesSamAccountName | - | Alice Hansen | %uuid_v4% | alice@example.org | Alice | - | Brian Murphy | %uuid_v4% | brian@example.org | Brian | + | displayName | id | mail | onPremisesSamAccountName | accountEnabled | + | Alice Hansen | %uuid_v4% | alice@example.org | Alice | true | + | Brian Murphy | %uuid_v4% | brian@example.org | Brian | true | + + @skipOnStable2.0 + Scenario: admin user gets all users include disabled users + Given the user "Alice" has disabled user "Brian" using the Graph API + When user "Alice" gets all users using the Graph API + Then the HTTP status code should be "200" + And the API response should contain following users with the information: + | displayName | id | mail | onPremisesSamAccountName | accountEnabled | + | Alice Hansen | %uuid_v4% | alice@example.org | Alice | true | + | Brian Murphy | %uuid_v4% | brian@example.org | Brian | false | Scenario: non-admin user tries to get all users @@ -40,13 +50,13 @@ Feature: get users Then the HTTP status code should be "401" And the last response should be an unauthorized response - + @skipOnStable2.0 Scenario: admin user gets the drive information of a user When the user "Alice" gets user "Brian" along with his drive information using Graph API Then the HTTP status code should be "200" And the user retrieve API response should contain the following information: - | displayName | id | mail | onPremisesSamAccountName | - | Brian Murphy | %uuid_v4% | brian@example.org | Brian | + | displayName | id | mail | onPremisesSamAccountName | accountEnabled | + | Brian Murphy | %uuid_v4% | brian@example.org | Brian | true | And the user retrieve API response should contain the following drive information: | driveType | personal | | driveAlias | personal/brian | @@ -58,13 +68,13 @@ Feature: get users | root@@@webDavUrl | %base_url%/dav/spaces/%space_id% | | webUrl | %base_url%/f/%space_id% | - + @skipOnStable2.0 Scenario: normal user gets his/her own drive information When the user "Brian" gets his drive information using Graph API Then the HTTP status code should be "200" And the user retrieve API response should contain the following information: - | displayName | id | mail | onPremisesSamAccountName | - | Brian Murphy | %uuid_v4% | brian@example.org | Brian | + | displayName | id | mail | onPremisesSamAccountName | accountEnabled | + | Brian Murphy | %uuid_v4% | brian@example.org | Brian | true | And the user retrieve API response should contain the following drive information: | driveType | personal | | driveAlias | personal/brian | @@ -76,7 +86,7 @@ Feature: get users | root@@@webDavUrl | %base_url%/dav/spaces/%space_id% | | webUrl | %base_url%/f/%space_id% | - + @skipOnStable2.0 Scenario: admin user gets the group information of a user Given group "tea-lover" has been created And group "coffee-lover" has been created @@ -85,8 +95,8 @@ Feature: get users When the user "Alice" gets user "Brian" along with his group information using Graph API Then the HTTP status code should be "200" And the user retrieve API response should contain the following information: - | displayName | id | mail | onPremisesSamAccountName | memberOf | - | Brian Murphy | %uuid_v4% | brian@example.org | Brian | tea-lover, coffee-lover | + | displayName | id | mail | onPremisesSamAccountName | accountEnabled | memberOf | + | Brian Murphy | %uuid_v4% | brian@example.org | Brian | true | tea-lover, coffee-lover | Scenario: non-admin user tries to get the group information of a user @@ -100,6 +110,7 @@ Feature: get users @skipOnStable2.0 Scenario: admin user gets all users of certain groups Given user "Carol" has been created with default attributes and without skeleton files + And the user "Alice" has disabled user "Carol" using the Graph API And group "tea-lover" has been created And group "coffee-lover" has been created And user "Alice" has been added to group "tea-lover" @@ -108,21 +119,21 @@ Feature: get users When the user "Alice" gets all users of the group "tea-lover" using the Graph API Then the HTTP status code should be "200" And the API response should contain following users with the information: - | displayName | id | mail | onPremisesSamAccountName | - | Alice Hansen | %uuid_v4% | alice@example.org | Alice | - | Brian Murphy | %uuid_v4% | brian@example.org | Brian | + | displayName | id | mail | onPremisesSamAccountName | accountEnabled | + | Alice Hansen | %uuid_v4% | alice@example.org | Alice | true | + | Brian Murphy | %uuid_v4% | brian@example.org | Brian | true | But the API response should not contain following user with the information: - | displayName | id | mail | onPremisesSamAccountName | - | Carol King | %uuid_v4% | carol@example.org | Carol | + | displayName | id | mail | onPremisesSamAccountName | accountEnabled | + | Carol King | %uuid_v4% | carol@example.org | Carol | false | When the user "Alice" gets all users of two groups "tea-lover,coffee-lover" using the Graph API Then the HTTP status code should be "200" And the API response should contain following user with the information: - | displayName | id | mail | onPremisesSamAccountName | - | Brian Murphy | %uuid_v4% | brian@example.org | Brian | + | displayName | id | mail | onPremisesSamAccountName | accountEnabled | + | Brian Murphy | %uuid_v4% | brian@example.org | Brian | true | But the API response should not contain following users with the information: - | displayName | id | mail | onPremisesSamAccountName | - | Alice Hansen | %uuid_v4% | alice@example.org | Alice | - | Carol King | %uuid_v4% | carol@example.org | Carol | + | displayName | id | mail | onPremisesSamAccountName | accountEnabled | + | Alice Hansen | %uuid_v4% | alice@example.org | Alice | true | + | Carol King | %uuid_v4% | carol@example.org | Carol | true | Scenario Outline: non admin user tries to get users of certain groups @@ -148,20 +159,20 @@ Feature: get users When the user "Alice" gets all users with role "Space Admin" using the Graph API Then the HTTP status code should be "200" And the API response should contain following users with the information: - | displayName | id | mail | onPremisesSamAccountName | - | Brian Murphy | %uuid_v4% | brian@example.org | Brian | - | Carol King | %uuid_v4% | carol@example.org | Carol | + | displayName | id | mail | onPremisesSamAccountName | accountEnabled | + | Brian Murphy | %uuid_v4% | brian@example.org | Brian | true | + | Carol King | %uuid_v4% | carol@example.org | Carol | true | But the API response should not contain following user with the information: | displayName | id | mail | onPremisesSamAccountName | | Alice Hansen | %uuid_v4% | alice@example.org | Alice | When the user "Alice" gets all users with role "Space Admin" and member of the group "tea-lover" using the Graph API Then the HTTP status code should be "200" And the API response should contain following users with the information: - | displayName | id | mail | onPremisesSamAccountName | - | Brian Murphy | %uuid_v4% | brian@example.org | Brian | + | displayName | id | mail | onPremisesSamAccountName | accountEnabled | + | Brian Murphy | %uuid_v4% | brian@example.org | Brian | true | But the API response should not contain following user with the information: - | displayName | id | mail | onPremisesSamAccountName | - | Carol King | %uuid_v4% | carol@example.org | Carol | + | displayName | id | mail | onPremisesSamAccountName | accountEnabled | + | Carol King | %uuid_v4% | carol@example.org | Carol | true | @skipOnStable2.0 Scenario Outline: non-admin user tries to get users with a certain role diff --git a/tests/acceptance/features/apiGraph/removeUserFromGroup.feature b/tests/acceptance/features/apiGraph/removeUserFromGroup.feature index e19b23219c8..8e511e95c4e 100644 --- a/tests/acceptance/features/apiGraph/removeUserFromGroup.feature +++ b/tests/acceptance/features/apiGraph/removeUserFromGroup.feature @@ -166,3 +166,21 @@ Feature: remove a user from a group Then the HTTP status code should be "401" And the last response should be an unauthorized response And user "Brian" should belong to group "grp1" + + + @skipOnStable2.0 + Scenario: admin removes a disabled user from a group + Given these groups have been created: + | groupname | comment | + | brand-new-group | nothing special here | + And the following users have been added to the following groups + | username | groupname | + | Alice | brand-new-group | + And the user "Admin" has disabled user "Alice" using the Graph API + When the administrator removes the following users from the following groups using the Graph API + | username | groupname | + | Alice | brand-new-group | + Then the HTTP status code of responses on all endpoints should be "204" + And the following users should not belong to the following groups + | username | groupname | + | Alice | brand-new-group | diff --git a/tests/acceptance/features/bootstrap/GraphContext.php b/tests/acceptance/features/bootstrap/GraphContext.php index 0210c2e7f29..50832806f0b 100644 --- a/tests/acceptance/features/bootstrap/GraphContext.php +++ b/tests/acceptance/features/bootstrap/GraphContext.php @@ -128,6 +128,53 @@ class GraphContext implements Context { $this->featureContext->setResponse($response); } + /** + * @When /^the user "([^"]*)" disables user "([^"]*)" using the Graph API$/ + * @When /^the user "([^"]*)" tries to disable user "([^"]*)" using the Graph API$/ + * + * @param string $byUser + * @param string $user + * + * @return void + * @throws GuzzleException + * @throws Exception + */ + public function theUserDisablesUserToUsingTheGraphApi(string $byUser, string $user): void { + $response = $this->editUserUsingTheGraphApi($byUser, $user, null, null, null, null, false); + $this->featureContext->setResponse($response); + } + + /** + * @Given /^the user "([^"]*)" has disabled user "([^"]*)" using the Graph API$/ + * + * @param string $byUser + * @param string $user + * + * @return void + * @throws GuzzleException + * @throws Exception + */ + public function theUserHasDisabledUserToUsingTheGraphApi(string $byUser, string $user): void { + $this->theUserDisablesUserToUsingTheGraphApi($byUser, $user); + $this->featureContext->thenTheHTTPStatusCodeShouldBe(200); + } + + /** + * @When /^the user "([^"]*)" enables user "([^"]*)" using the Graph API$/ + * @When /^the user "([^"]*)" tries to enable user "([^"]*)" using the Graph API$/ + * + * @param string $byUser + * @param string $user + * + * @return void + * @throws GuzzleException + * @throws Exception + */ + public function theUserEnablesUserToUsingTheGraphApi(string $byUser, string $user): void { + $response = $this->editUserUsingTheGraphApi($byUser, $user, null, null, null, null, true); + $this->featureContext->setResponse($response); + } + /** * @Then /^the user "([^"]*)" should have information with these key and value pairs:$/ * @@ -162,11 +209,12 @@ class GraphContext implements Context { * @param string|null $password * @param string|null $email * @param string|null $displayName + * @param bool|true $accountEnabled * * @return void * @throws GuzzleException */ - public function editUserUsingTheGraphApi(string $byUser, string $user, string $userName = null, string $password = null, string $email = null, string $displayName = null): ResponseInterface { + public function editUserUsingTheGraphApi(string $byUser, string $user, string $userName = null, string $password = null, string $email = null, string $displayName = null, bool $accountEnabled = true): ResponseInterface { $user = $this->featureContext->getActualUsername($user); $userId = $this->featureContext->getAttributeOfCreatedUser($user, 'id'); $userId = $userId ?? $user; @@ -179,7 +227,8 @@ class GraphContext implements Context { $userName, $password, $email, - $displayName + $displayName, + $accountEnabled ); } @@ -369,6 +418,21 @@ class GraphContext implements Context { $this->adminDeletesUserUsingTheGraphApi($user, $byUser); } + /** + * @Given /^the user "([^"]*)" has deleted a user "([^"]*)" using the Graph API$/ + * + * @param string $byUser + * @param string $user + * + * @return void + * @throws Exception + * @throws GuzzleException + */ + public function theUserHasDeletesAUserUsingTheGraphAPI(string $byUser, string $user): void { + $this->adminDeletesUserUsingTheGraphApi($user, $byUser); + $this->featureContext->thenTheHTTPStatusCodeShouldBe(204); + } + /** * @param string $user * @param string $group @@ -1352,12 +1416,19 @@ class GraphContext implements Context { } Assert::assertTrue(GraphHelper::isUUIDv4($actualValue['id']), __METHOD__ . ' Expected user_id to have UUIDv4 pattern but found: ' . $actualValue['id']); break; + case "accountEnabled": + if ($expectedValue[$keyName] === 'true') { + Assert::assertTrue($actualValue[$keyName], ' Expected ' . $keyName . ' is not true '); + } else { + Assert::assertFalse($actualValue[$keyName], ' Expected ' . $keyName . ' is not false '); + } + break; default: Assert::assertEquals( $expectedValue[$keyName], $actualValue[$keyName], __METHOD__ . - ' Expected ' . $keyName . 'to have value' . $expectedValue[$keyName] + ' Expected ' . $keyName . ' to have value ' . $expectedValue[$keyName] . ' but got ' . $actualValue[$keyName] ); break;