mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Внедрена валидация OTP в процесс восстановления пароля
This commit is contained in:
@@ -1,41 +1,87 @@
|
||||
<?php
|
||||
namespace codeception\api\functional;
|
||||
|
||||
use OTPHP\TOTP;
|
||||
use tests\codeception\api\_pages\AuthenticationRoute;
|
||||
use tests\codeception\api\FunctionalTester;
|
||||
|
||||
class ForgotPasswordCest {
|
||||
|
||||
public function testForgotPasswordByEmail(FunctionalTester $I) {
|
||||
$route = new AuthenticationRoute($I);
|
||||
/**
|
||||
* @var AuthenticationRoute
|
||||
*/
|
||||
private $route;
|
||||
|
||||
$I->wantTo('create new password recover request by passing email');
|
||||
$route->forgotPassword('admin@ely.by');
|
||||
public function _before(FunctionalTester $I) {
|
||||
$this->route = new AuthenticationRoute($I);
|
||||
}
|
||||
|
||||
public function testWrongInput(FunctionalTester $I) {
|
||||
$I->wantTo('see reaction on invalid input');
|
||||
|
||||
$this->route->forgotPassword();
|
||||
$I->canSeeResponseContainsJson([
|
||||
'success' => true,
|
||||
'success' => false,
|
||||
'errors' => [
|
||||
'login' => 'error.login_required',
|
||||
],
|
||||
]);
|
||||
$I->canSeeResponseJsonMatchesJsonPath('$.data.canRepeatIn');
|
||||
$I->canSeeResponseJsonMatchesJsonPath('$.data.repeatFrequency');
|
||||
|
||||
$this->route->forgotPassword('becauseimbatman!');
|
||||
$I->canSeeResponseContainsJson([
|
||||
'success' => false,
|
||||
'errors' => [
|
||||
'login' => 'error.login_not_exist',
|
||||
],
|
||||
]);
|
||||
|
||||
$this->route->forgotPassword('AccountWithEnabledOtp');
|
||||
$I->canSeeResponseContainsJson([
|
||||
'success' => false,
|
||||
'errors' => [
|
||||
'token' => 'error.token_required',
|
||||
],
|
||||
]);
|
||||
|
||||
$this->route->forgotPassword('AccountWithEnabledOtp');
|
||||
$I->canSeeResponseContainsJson([
|
||||
'success' => false,
|
||||
'errors' => [
|
||||
'token' => 'error.token_required',
|
||||
],
|
||||
]);
|
||||
|
||||
$this->route->forgotPassword('AccountWithEnabledOtp', '123456');
|
||||
$I->canSeeResponseContainsJson([
|
||||
'success' => false,
|
||||
'errors' => [
|
||||
'token' => 'error.token_incorrect',
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function testForgotPasswordByEmail(FunctionalTester $I) {
|
||||
$I->wantTo('create new password recover request by passing email');
|
||||
$this->route->forgotPassword('admin@ely.by');
|
||||
$this->assertSuccessResponse($I, false);
|
||||
}
|
||||
|
||||
public function testForgotPasswordByUsername(FunctionalTester $I) {
|
||||
$route = new AuthenticationRoute($I);
|
||||
|
||||
$I->wantTo('create new password recover request by passing username');
|
||||
$route->forgotPassword('Admin');
|
||||
$I->canSeeResponseContainsJson([
|
||||
'success' => true,
|
||||
]);
|
||||
$I->canSeeResponseJsonMatchesJsonPath('$.data.canRepeatIn');
|
||||
$I->canSeeResponseJsonMatchesJsonPath('$.data.repeatFrequency');
|
||||
$I->canSeeResponseJsonMatchesJsonPath('$.data.emailMask');
|
||||
$this->route->forgotPassword('Admin');
|
||||
$this->assertSuccessResponse($I, true);
|
||||
}
|
||||
|
||||
public function testForgotPasswordByAccountWithOtp(FunctionalTester $I) {
|
||||
$I->wantTo('create new password recover request by passing username and otp token');
|
||||
$totp = new TOTP(null, 'secret-secret-secret');
|
||||
$this->route->forgotPassword('AccountWithEnabledOtp', $totp->now());
|
||||
$this->assertSuccessResponse($I, true);
|
||||
}
|
||||
|
||||
public function testDataForFrequencyError(FunctionalTester $I) {
|
||||
$route = new AuthenticationRoute($I);
|
||||
|
||||
$I->wantTo('get info about time to repeat recover password request');
|
||||
$route->forgotPassword('Notch');
|
||||
$this->route->forgotPassword('Notch');
|
||||
$I->canSeeResponseContainsJson([
|
||||
'success' => false,
|
||||
'errors' => [
|
||||
@@ -46,4 +92,18 @@ class ForgotPasswordCest {
|
||||
$I->canSeeResponseJsonMatchesJsonPath('$.data.repeatFrequency');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FunctionalTester $I
|
||||
*/
|
||||
private function assertSuccessResponse(FunctionalTester $I, bool $expectEmailMask = false): void {
|
||||
$I->canSeeResponseContainsJson([
|
||||
'success' => true,
|
||||
]);
|
||||
$I->canSeeResponseJsonMatchesJsonPath('$.data.canRepeatIn');
|
||||
$I->canSeeResponseJsonMatchesJsonPath('$.data.repeatFrequency');
|
||||
if ($expectEmailMask) {
|
||||
$I->canSeeResponseJsonMatchesJsonPath('$.data.emailMask');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user