2016-05-31 03:33:30 +05:30
|
|
|
<?php
|
|
|
|
namespace codeception\api\unit\models\authentication;
|
|
|
|
|
2017-09-19 22:36:16 +05:30
|
|
|
use api\components\User\AuthenticationResult;
|
2016-05-31 03:33:30 +05:30
|
|
|
use api\models\authentication\RefreshTokenForm;
|
2019-02-23 04:41:57 +05:30
|
|
|
use api\tests\unit\TestCase;
|
2016-05-31 03:33:30 +05:30
|
|
|
use Codeception\Specify;
|
|
|
|
use common\models\AccountSession;
|
2019-02-21 01:28:52 +05:30
|
|
|
use common\tests\fixtures\AccountSessionFixture;
|
2016-05-31 03:33:30 +05:30
|
|
|
|
2016-10-29 03:17:31 +05:30
|
|
|
class RefreshTokenFormTest extends TestCase {
|
2016-05-31 03:33:30 +05:30
|
|
|
use Specify;
|
|
|
|
|
2019-05-14 04:28:29 +05:30
|
|
|
public function _fixtures(): array {
|
2016-05-31 03:33:30 +05:30
|
|
|
return [
|
|
|
|
'sessions' => AccountSessionFixture::class,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testValidateRefreshToken() {
|
|
|
|
$this->specify('error.refresh_token_not_exist if passed token not exists', function() {
|
|
|
|
/** @var RefreshTokenForm $model */
|
|
|
|
$model = new class extends RefreshTokenForm {
|
|
|
|
public function getSession() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
$model->validateRefreshToken();
|
2019-02-26 04:56:02 +05:30
|
|
|
$this->assertSame(['error.refresh_token_not_exist'], $model->getErrors('refresh_token'));
|
2016-05-31 03:33:30 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
$this->specify('no errors if token exists', function() {
|
|
|
|
/** @var RefreshTokenForm $model */
|
|
|
|
$model = new class extends RefreshTokenForm {
|
|
|
|
public function getSession() {
|
|
|
|
return new AccountSession();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
$model->validateRefreshToken();
|
2017-09-19 22:36:16 +05:30
|
|
|
$this->assertEmpty($model->getErrors('refresh_token'));
|
2016-05-31 03:33:30 +05:30
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRenew() {
|
2016-10-29 03:17:31 +05:30
|
|
|
$model = new RefreshTokenForm();
|
|
|
|
$model->refresh_token = $this->tester->grabFixture('sessions', 'admin')['refresh_token'];
|
2017-09-19 22:36:16 +05:30
|
|
|
$this->assertInstanceOf(AuthenticationResult::class, $model->renew());
|
2016-05-31 03:33:30 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
}
|