diff --git a/tests/acceptance/TestHelpers/GraphHelper.php b/tests/acceptance/TestHelpers/GraphHelper.php index cf2224b3ffe..c2dd8ba9db4 100644 --- a/tests/acceptance/TestHelpers/GraphHelper.php +++ b/tests/acceptance/TestHelpers/GraphHelper.php @@ -1181,6 +1181,37 @@ class GraphHelper { ); } + /** + * @param string $baseUrl + * @param string $user + * @param string $password + * @param string $newPassword + * + * @return ResponseInterface + * @throws GuzzleException + */ + public static function updateUserPasswordUsingPatch( + string $baseUrl, + string $user, + string $password, + string $newPassword, + ): ResponseInterface { + $url = self::getFullUrl($baseUrl, 'me'); + $payload = [ + 'passwordProfile' => [ + 'password' => $newPassword, + ], + ]; + return HttpRequestHelper::sendRequest( + $url, + 'PATCH', + $user, + $password, + self::getRequestHeaders(), + \json_encode($payload), + ); + } + /** * @param string $baseUrl * @param string $user diff --git a/tests/acceptance/bootstrap/GraphContext.php b/tests/acceptance/bootstrap/GraphContext.php index 041132ec5ca..0b02586261c 100644 --- a/tests/acceptance/bootstrap/GraphContext.php +++ b/tests/acceptance/bootstrap/GraphContext.php @@ -1009,6 +1009,26 @@ class GraphContext implements Context { $this->featureContext->setResponse($response); } + /** + * @When user :user tries to change their password to :new_password with patch request using the Graph API + * + * @param string $user + * @param string $newPassword + * + * @return void + * @throws GuzzleException + * @throws Exception + */ + public function usertriesToChangesOwnPassword(string $user, string $newPassword): void { + $response = GraphHelper::updateUserPasswordUsingPatch( + $this->featureContext->getBaseUrl(), + $user, + $this->featureContext->getPasswordForUser($user), + $newPassword, + ); + $this->featureContext->setResponse($response); + } + /** * @When user :user gets all the groups using the Graph API * diff --git a/tests/acceptance/features/apiGraphUser/changeOwnPassword.feature b/tests/acceptance/features/apiGraphUser/changeOwnPassword.feature index 5d50dd1ee09..25ee1b73f62 100644 --- a/tests/acceptance/features/apiGraphUser/changeOwnPassword.feature +++ b/tests/acceptance/features/apiGraphUser/changeOwnPassword.feature @@ -12,9 +12,20 @@ Feature: an user changes its own password | current-password | new-password | http-status-code | | 123456 | validPass | 204 | | 123456 | кириллица | 204 | - | 123456 | 密码 | 204 | + | 123456 | 密码 | 204 | | 123456 | ?&^%0 | 204 | | 123456 | | 400 | | 123456 | 123456 | 400 | | wrongPass | 123456 | 400 | | | validPass | 400 | + + + Scenario Outline: user tries to change password without current password using PATCH + Given user "Alice" has been created with default attributes + When user "Alice" tries to change their password to "" with patch request using the Graph API + Then the HTTP status code should be "" + Examples: + | new-password | http-status-code | + | 123456 | 400 | + | newPass | 400 | + | | 400 |