2019-08-02 21:02:08 +05:30
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace api\tests\unit\components\User;
|
|
|
|
|
2019-09-22 21:12:21 +05:30
|
|
|
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;
|
|
|
|
|
2019-09-22 21:12:21 +05:30
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
}
|