Fix revokation validation. Add additional tests cases

This commit is contained in:
ErickSkrauch
2019-12-10 22:51:11 +03:00
parent 016a193263
commit d27070630c
9 changed files with 85 additions and 41 deletions

View File

@@ -6,7 +6,10 @@ namespace codeception\api\unit\modules\authserver\models;
use api\modules\authserver\exceptions\ForbiddenOperationException;
use api\modules\authserver\models\AuthenticationForm;
use api\tests\unit\TestCase;
use common\models\OauthClient;
use common\models\OauthSession;
use common\tests\fixtures\AccountFixture;
use common\tests\fixtures\OauthClientFixture;
use Ramsey\Uuid\Uuid;
class AuthenticationFormTest extends TestCase {
@@ -14,6 +17,7 @@ class AuthenticationFormTest extends TestCase {
public function _fixtures(): array {
return [
'accounts' => AccountFixture::class,
'oauthClients' => OauthClientFixture::class,
];
}
@@ -28,14 +32,18 @@ class AuthenticationFormTest extends TestCase {
$this->assertSame('df936908-b2e1-544d-96f8-2977ec213022', $result['selectedProfile']['id']);
$this->assertSame('Admin', $result['selectedProfile']['name']);
$this->assertFalse($result['selectedProfile']['legacy']);
$this->assertTrue(OauthSession::find()->andWhere([
'account_id' => 1,
'client_id' => OauthClient::UNAUTHORIZED_MINECRAFT_GAME_LAUNCHER,
])->exists());
}
/**
* @dataProvider getInvalidCredentialsCases
*/
public function testAuthenticateByWrongNicknamePass(string $expectedFieldError, string $login, string $password) {
public function testAuthenticateByWrongNicknamePass(string $expectedExceptionMessage, string $login, string $password) {
$this->expectException(ForbiddenOperationException::class);
$this->expectExceptionMessage("Invalid credentials. Invalid {$expectedFieldError} or password.");
$this->expectExceptionMessage($expectedExceptionMessage);
$authForm = new AuthenticationForm();
$authForm->username = $login;
@@ -45,19 +53,10 @@ class AuthenticationFormTest extends TestCase {
}
public function getInvalidCredentialsCases() {
yield ['nickname', 'wrong-username', 'wrong-password'];
yield ['email', 'wrong-email@ely.by', 'wrong-password'];
}
public function testAuthenticateByValidCredentialsIntoBlockedAccount() {
$this->expectException(ForbiddenOperationException::class);
$this->expectExceptionMessage('This account has been suspended.');
$authForm = new AuthenticationForm();
$authForm->username = 'Banned';
$authForm->password = 'password_0';
$authForm->clientToken = Uuid::uuid4()->toString();
$authForm->authenticate();
yield ['Invalid credentials. Invalid nickname or password.', 'wrong-username', 'wrong-password'];
yield ['Invalid credentials. Invalid email or password.', 'wrong-email@ely.by', 'wrong-password'];
yield ['This account has been suspended.', 'Banned', 'password_0'];
yield ['Account protected with two factor auth.', 'AccountWithEnabledOtp', 'password_0'];
}
}