2016-05-11 01:55:04 +05:30
|
|
|
<?php
|
|
|
|
namespace codeception\api\functional;
|
|
|
|
|
2017-01-24 02:20:13 +05:30
|
|
|
use OTPHP\TOTP;
|
2016-05-11 01:55:04 +05:30
|
|
|
use tests\codeception\api\_pages\AuthenticationRoute;
|
|
|
|
use tests\codeception\api\FunctionalTester;
|
|
|
|
|
|
|
|
class ForgotPasswordCest {
|
|
|
|
|
2017-01-24 02:20:13 +05:30
|
|
|
/**
|
|
|
|
* @var AuthenticationRoute
|
|
|
|
*/
|
|
|
|
private $route;
|
2016-05-11 01:55:04 +05:30
|
|
|
|
2017-01-24 02:20:13 +05:30
|
|
|
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();
|
2016-05-11 01:55:04 +05:30
|
|
|
$I->canSeeResponseContainsJson([
|
2017-01-24 02:20:13 +05:30
|
|
|
'success' => false,
|
|
|
|
'errors' => [
|
|
|
|
'login' => 'error.login_required',
|
|
|
|
],
|
2016-05-11 01:55:04 +05:30
|
|
|
]);
|
|
|
|
|
2017-01-24 02:20:13 +05:30
|
|
|
$this->route->forgotPassword('becauseimbatman!');
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'success' => false,
|
|
|
|
'errors' => [
|
|
|
|
'login' => 'error.login_not_exist',
|
|
|
|
],
|
|
|
|
]);
|
2016-05-11 01:55:04 +05:30
|
|
|
|
2017-01-24 02:20:13 +05:30
|
|
|
$this->route->forgotPassword('AccountWithEnabledOtp');
|
2016-05-11 01:55:04 +05:30
|
|
|
$I->canSeeResponseContainsJson([
|
2017-01-24 02:20:13 +05:30
|
|
|
'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',
|
|
|
|
],
|
2016-05-11 01:55:04 +05:30
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2017-01-24 02:20:13 +05:30
|
|
|
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);
|
|
|
|
}
|
2016-05-11 01:55:04 +05:30
|
|
|
|
2017-01-24 02:20:13 +05:30
|
|
|
public function testForgotPasswordByUsername(FunctionalTester $I) {
|
|
|
|
$I->wantTo('create new password recover request by passing username');
|
|
|
|
$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) {
|
2016-05-11 01:55:04 +05:30
|
|
|
$I->wantTo('get info about time to repeat recover password request');
|
2017-01-24 02:20:13 +05:30
|
|
|
$this->route->forgotPassword('Notch');
|
2016-05-11 01:55:04 +05:30
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'success' => false,
|
|
|
|
'errors' => [
|
2016-06-17 01:06:52 +05:30
|
|
|
'login' => 'error.recently_sent_message',
|
2016-05-11 01:55:04 +05:30
|
|
|
],
|
|
|
|
]);
|
|
|
|
$I->canSeeResponseJsonMatchesJsonPath('$.data.canRepeatIn');
|
|
|
|
$I->canSeeResponseJsonMatchesJsonPath('$.data.repeatFrequency');
|
|
|
|
}
|
|
|
|
|
2017-01-24 02:20:13 +05:30
|
|
|
/**
|
|
|
|
* @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');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-11 01:55:04 +05:30
|
|
|
}
|