accounts/api/tests/unit/components/User/LegacyOAuth2IdentityTest.php

40 lines
1.3 KiB
PHP
Raw Normal View History

2019-08-02 21:02:08 +05:30
<?php
declare(strict_types=1);
namespace api\tests\unit\components\User;
use api\components\User\LegacyOAuth2Identity;
2019-08-02 21:02:08 +05:30
use api\tests\unit\TestCase;
2019-09-23 03:23:13 +05:30
use common\tests\fixtures;
2019-08-02 21:02:08 +05:30
use yii\web\UnauthorizedHttpException;
class LegacyOAuth2IdentityTest extends TestCase {
2019-08-02 21:02:08 +05:30
2019-09-23 03:23:13 +05:30
public function _fixtures(): array {
return [
fixtures\LegacyOauthAccessTokenFixture::class,
fixtures\LegacyOauthAccessTokenScopeFixture::class,
];
}
2019-08-02 21:02:08 +05:30
2019-09-23 03:23:13 +05:30
public function testFindIdentityByAccessToken() {
$identity = LegacyOAuth2Identity::findIdentityByAccessToken('ZZQP8sS9urzriy8N9h6FwFNMOH3PkZ5T5PLqS6SX');
$this->assertSame('ZZQP8sS9urzriy8N9h6FwFNMOH3PkZ5T5PLqS6SX', $identity->getId());
2019-08-02 21:02:08 +05:30
}
public function testFindIdentityByAccessTokenWithNonExistsToken() {
$this->expectException(UnauthorizedHttpException::class);
$this->expectExceptionMessage('Incorrect token');
2019-09-23 03:23:13 +05:30
LegacyOAuth2Identity::findIdentityByAccessToken('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
2019-08-02 21:02:08 +05:30
}
public function testFindIdentityByAccessTokenWithExpiredToken() {
$this->expectException(UnauthorizedHttpException::class);
$this->expectExceptionMessage('Token expired');
2019-09-23 03:23:13 +05:30
LegacyOAuth2Identity::findIdentityByAccessToken('rc0sOF1SLdOxuD3bJcCQENmGTeYrGgy12qJScMx4');
2019-08-02 21:02:08 +05:30
}
}