2017-01-23 04:37:29 +05:30
|
|
|
<?php
|
|
|
|
namespace tests\codeception\api\functional;
|
|
|
|
|
|
|
|
use OTPHP\TOTP;
|
|
|
|
use tests\codeception\api\_pages\TwoFactorAuthRoute;
|
|
|
|
use tests\codeception\api\FunctionalTester;
|
|
|
|
|
|
|
|
class TwoFactorAuthEnableCest {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var TwoFactorAuthRoute
|
|
|
|
*/
|
|
|
|
private $route;
|
|
|
|
|
|
|
|
public function _before(FunctionalTester $I) {
|
|
|
|
$this->route = new TwoFactorAuthRoute($I);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testFails(FunctionalTester $I) {
|
2017-01-24 04:30:08 +05:30
|
|
|
$I->amAuthenticated('AccountWithOtpSecret');
|
2017-01-23 04:37:29 +05:30
|
|
|
|
|
|
|
$this->route->enable();
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'success' => false,
|
|
|
|
'errors' => [
|
2017-09-06 22:47:52 +05:30
|
|
|
'totp' => 'error.totp_required',
|
2017-01-23 04:37:29 +05:30
|
|
|
'password' => 'error.password_required',
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->route->enable('123456', 'invalid_password');
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'success' => false,
|
|
|
|
'errors' => [
|
2017-09-06 22:47:52 +05:30
|
|
|
'totp' => 'error.totp_incorrect',
|
2017-01-23 04:37:29 +05:30
|
|
|
'password' => 'error.password_incorrect',
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
2017-01-24 04:30:08 +05:30
|
|
|
$I->amAuthenticated('AccountWithEnabledOtp');
|
2017-01-23 04:37:29 +05:30
|
|
|
$this->route->enable('123456', 'invalid_password');
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'success' => false,
|
|
|
|
'errors' => [
|
|
|
|
'account' => 'error.otp_already_enabled',
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSuccessEnable(FunctionalTester $I) {
|
2017-01-24 04:30:08 +05:30
|
|
|
$I->amAuthenticated('AccountWithOtpSecret');
|
2017-08-08 22:48:44 +05:30
|
|
|
$totp = TOTP::create('AAAA');
|
2017-01-23 04:37:29 +05:30
|
|
|
$this->route->enable($totp->now(), 'password_0');
|
|
|
|
$I->canSeeResponseCodeIs(200);
|
|
|
|
$I->canSeeResponseIsJson();
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'success' => true,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|