mirror of
https://github.com/elyby/accounts.git
synced 2024-12-27 23:50:19 +05:30
Исправлен тест для AccountIdentity
This commit is contained in:
parent
264cb25ddc
commit
8120e43bec
@ -7,7 +7,6 @@ use Emarref\Jwt\Algorithm\AlgorithmInterface;
|
||||
use Emarref\Jwt\Algorithm\Hs256;
|
||||
use Emarref\Jwt\Claim;
|
||||
use Emarref\Jwt\Encryption\Factory as EncryptionFactory;
|
||||
use Emarref\Jwt\Encryption\Factory;
|
||||
use Emarref\Jwt\Exception\VerificationException;
|
||||
use Emarref\Jwt\Jwt;
|
||||
use Emarref\Jwt\Token;
|
||||
@ -122,7 +121,7 @@ class Component extends YiiUserComponent {
|
||||
|
||||
$jwt = new Jwt();
|
||||
$token = $jwt->deserialize($jwtString);
|
||||
$context = new VerificationContext(Factory::create($this->getAlgorithm()));
|
||||
$context = new VerificationContext(EncryptionFactory::create($this->getAlgorithm()));
|
||||
$context->setAudience($hostInfo);
|
||||
$context->setIssuer($hostInfo);
|
||||
$jwt->verify($token, $context);
|
||||
|
@ -12,7 +12,7 @@ settings:
|
||||
memory_limit: 1024M
|
||||
log: true
|
||||
config:
|
||||
test_entry_url: http://localhost:8080/api/web/index.php
|
||||
test_entry_url: http://localhost/api/web/index.php
|
||||
coverage:
|
||||
enabled: true
|
||||
remote: true
|
||||
@ -24,4 +24,4 @@ coverage:
|
||||
- ../../../api/mails/*
|
||||
- ../../../api/web/*
|
||||
- ../../../api/runtime/*
|
||||
c3url: 'http://localhost:8080/api/web/index.php'
|
||||
c3url: 'http://localhost/api/web/index.php'
|
||||
|
@ -3,6 +3,10 @@ namespace codeception\api\unit\models;
|
||||
|
||||
use api\models\AccountIdentity;
|
||||
use Codeception\Specify;
|
||||
use Emarref\Jwt\Claim;
|
||||
use Emarref\Jwt\Encryption\Factory as EncryptionFactory;
|
||||
use Emarref\Jwt\Jwt;
|
||||
use Emarref\Jwt\Token;
|
||||
use tests\codeception\api\unit\DbTestCase;
|
||||
use tests\codeception\common\_support\ProtectedCaller;
|
||||
use tests\codeception\common\fixtures\AccountFixture;
|
||||
@ -33,9 +37,13 @@ class AccountIdentityTest extends DbTestCase {
|
||||
* @expectedExceptionMessage Token expired
|
||||
*/
|
||||
public function testFindIdentityByAccessTokenWithExpiredToken() {
|
||||
$expiredToken = 'eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJodHRwOlwvXC9sb2NhbGhvc3Q6ODA4MCIsImlzcyI6Imh0d' .
|
||||
'HA6XC9cL2xvY2FsaG9zdDo4MDgwIiwiaWF0IjoxNDY0NTkzMTkzLCJleHAiOjE0NjQ1OTY3OTN9.DV' .
|
||||
'8uwh0OQhBYXkrNvxwJeO-kEjb9MQeLr3-6GoHM7RY';
|
||||
$token = new Token();
|
||||
$token->addClaim(new Claim\Audience('http://localhost'));
|
||||
$token->addClaim(new Claim\Issuer('http://localhost'));
|
||||
$token->addClaim(new Claim\IssuedAt(1464593193));
|
||||
$token->addClaim(new Claim\Expiration(1464596793));
|
||||
$token->addClaim(new Claim\JwtId($this->accounts['admin']['id']));
|
||||
$expiredToken = (new Jwt())->serialize($token, EncryptionFactory::create(Yii::$app->user->getAlgorithm()));
|
||||
|
||||
AccountIdentity::findIdentityByAccessToken($expiredToken);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user