From 3b548c9be3e38f887a2ff698885b5ff58d89047f Mon Sep 17 00:00:00 2001 From: Viktor Scharf Date: Wed, 31 Aug 2022 13:02:33 +0200 Subject: [PATCH] [test-only] apiTest. change own password (#4480) * apiTest. change own password * fix --- tests/TestHelpers/GraphHelper.php | 34 +++++++++++++++++++ .../apiGraph/changeOwnPassword.feature | 17 ++++++++++ .../features/bootstrap/GraphContext.php | 21 ++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 tests/acceptance/features/apiGraph/changeOwnPassword.feature diff --git a/tests/TestHelpers/GraphHelper.php b/tests/TestHelpers/GraphHelper.php index e815fb2fef..c6f5b75620 100644 --- a/tests/TestHelpers/GraphHelper.php +++ b/tests/TestHelpers/GraphHelper.php @@ -523,4 +523,38 @@ class GraphHelper { } return \json_encode($payload); } + + /** + * @param string $baseUrl + * @param string $xRequestId + * @param string $user + * @param string $password + * @param string $currentPassword + * @param string $newPassword + * + * @return ResponseInterface + * @throws GuzzleException + */ + public static function changeOwnPassword( + string $baseUrl, + string $xRequestId, + string $user, + string $password, + string $currentPassword, + string $newPassword + ): ResponseInterface { + $url = self::getFullUrl($baseUrl, 'me/changePassword'); + $payload['currentPassword'] = $currentPassword; + $payload['newPassword'] = $newPassword; + + return HttpRequestHelper::sendRequest( + $url, + $xRequestId, + "POST", + $user, + $password, + self::getRequestHeaders(), + \json_encode($payload) + ); + } } diff --git a/tests/acceptance/features/apiGraph/changeOwnPassword.feature b/tests/acceptance/features/apiGraph/changeOwnPassword.feature new file mode 100644 index 0000000000..a0351cc8d1 --- /dev/null +++ b/tests/acceptance/features/apiGraph/changeOwnPassword.feature @@ -0,0 +1,17 @@ +@api +Feature: an user changes its own password + + Scenario Outline: change own password + Given user "Alice" has been created with default attributes and without skeleton files + When the user "Alice" changes its own password "" to "" using the Graph API + Then the HTTP status code should be "" + Examples: + | currentPassword | newPassword | code | + | 123456 | validPass | 204 | + | 123456 | кириллица | 204 | + | 123456 | 密码 | 204 | + | 123456 | ?&^%0 | 204 | + | 123456 | | 400 | + | 123456 | 123456 | 400 | + | wrongPass | 123456 | 500 | + | | validPass | 400 | diff --git a/tests/acceptance/features/bootstrap/GraphContext.php b/tests/acceptance/features/bootstrap/GraphContext.php index ac45b1e7e8..a2a3b5c33f 100644 --- a/tests/acceptance/features/bootstrap/GraphContext.php +++ b/tests/acceptance/features/bootstrap/GraphContext.php @@ -536,4 +536,25 @@ class GraphContext implements Context { } } } + + /** + * @When /^the user "([^"]*)" changes its own password "([^"]*)" to "([^"]*)" using the Graph API$/ + * @param string $user + * @param string $currentPassword + * @param string $newPassword + * + * @throws GuzzleException + * @throws Exception + */ + public function userChangesOwnPassword(string $user, string $currentPassword, $newPassword): void { + $response = GraphHelper::changeOwnPassword( + $this->featureContext->getBaseUrl(), + $this->featureContext->getStepLineRef(), + $user, + $this->featureContext->getPasswordForUser($user), + $currentPassword, + $newPassword + ); + $this->featureContext->setResponse($response); + } }