2017-01-23 04:37:29 +05:30
|
|
|
<?php
|
|
|
|
namespace tests\codeception\api\functional;
|
|
|
|
|
|
|
|
use OTPHP\TOTP;
|
2017-10-01 05:54:23 +05:30
|
|
|
use tests\codeception\api\_pages\AccountsRoute;
|
2017-01-23 04:37:29 +05:30
|
|
|
use tests\codeception\api\FunctionalTester;
|
|
|
|
|
2017-10-01 05:54:23 +05:30
|
|
|
class AccountsDisableTwoFactorAuthCest {
|
2017-01-23 04:37:29 +05:30
|
|
|
|
|
|
|
/**
|
2017-10-01 05:54:23 +05:30
|
|
|
* @var AccountsRoute
|
2017-01-23 04:37:29 +05:30
|
|
|
*/
|
|
|
|
private $route;
|
|
|
|
|
|
|
|
public function _before(FunctionalTester $I) {
|
2017-10-01 05:54:23 +05:30
|
|
|
$this->route = new AccountsRoute($I);
|
2017-01-23 04:37:29 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
public function testFails(FunctionalTester $I) {
|
2017-09-19 22:36:16 +05:30
|
|
|
$accountId = $I->amAuthenticated('AccountWithEnabledOtp');
|
2017-01-23 04:37:29 +05:30
|
|
|
|
2017-10-01 05:54:23 +05:30
|
|
|
$this->route->disableTwoFactorAuth($accountId);
|
2017-01-23 04:37:29 +05:30
|
|
|
$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',
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
2017-10-01 05:54:23 +05:30
|
|
|
$this->route->disableTwoFactorAuth($accountId, '123456', 'invalid_password');
|
2017-01-23 04:37:29 +05:30
|
|
|
$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-09-19 22:36:16 +05:30
|
|
|
$accountId = $I->amAuthenticated('AccountWithOtpSecret');
|
2017-10-01 05:54:23 +05:30
|
|
|
$this->route->disableTwoFactorAuth($accountId, '123456', 'invalid_password');
|
2017-01-23 04:37:29 +05:30
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'success' => false,
|
|
|
|
'errors' => [
|
|
|
|
'account' => 'error.otp_not_enabled',
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSuccessEnable(FunctionalTester $I) {
|
2017-09-19 22:36:16 +05:30
|
|
|
$accountId = $I->amAuthenticated('AccountWithEnabledOtp');
|
2017-08-08 22:48:44 +05:30
|
|
|
$totp = TOTP::create('BBBB');
|
2017-10-01 05:54:23 +05:30
|
|
|
$this->route->disableTwoFactorAuth($accountId, $totp->now(), 'password_0');
|
2017-01-23 04:37:29 +05:30
|
|
|
$I->canSeeResponseCodeIs(200);
|
|
|
|
$I->canSeeResponseIsJson();
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'success' => true,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|