Исправлен тест для AccountIdentity

This commit is contained in:
ErickSkrauch 2016-09-19 11:18:52 +03:00
parent 264cb25ddc
commit 8120e43bec
3 changed files with 14 additions and 7 deletions

View File

@ -7,7 +7,6 @@ use Emarref\Jwt\Algorithm\AlgorithmInterface;
use Emarref\Jwt\Algorithm\Hs256; use Emarref\Jwt\Algorithm\Hs256;
use Emarref\Jwt\Claim; use Emarref\Jwt\Claim;
use Emarref\Jwt\Encryption\Factory as EncryptionFactory; use Emarref\Jwt\Encryption\Factory as EncryptionFactory;
use Emarref\Jwt\Encryption\Factory;
use Emarref\Jwt\Exception\VerificationException; use Emarref\Jwt\Exception\VerificationException;
use Emarref\Jwt\Jwt; use Emarref\Jwt\Jwt;
use Emarref\Jwt\Token; use Emarref\Jwt\Token;
@ -122,7 +121,7 @@ class Component extends YiiUserComponent {
$jwt = new Jwt(); $jwt = new Jwt();
$token = $jwt->deserialize($jwtString); $token = $jwt->deserialize($jwtString);
$context = new VerificationContext(Factory::create($this->getAlgorithm())); $context = new VerificationContext(EncryptionFactory::create($this->getAlgorithm()));
$context->setAudience($hostInfo); $context->setAudience($hostInfo);
$context->setIssuer($hostInfo); $context->setIssuer($hostInfo);
$jwt->verify($token, $context); $jwt->verify($token, $context);

View File

@ -12,7 +12,7 @@ settings:
memory_limit: 1024M memory_limit: 1024M
log: true log: true
config: config:
test_entry_url: http://localhost:8080/api/web/index.php test_entry_url: http://localhost/api/web/index.php
coverage: coverage:
enabled: true enabled: true
remote: true remote: true
@ -24,4 +24,4 @@ coverage:
- ../../../api/mails/* - ../../../api/mails/*
- ../../../api/web/* - ../../../api/web/*
- ../../../api/runtime/* - ../../../api/runtime/*
c3url: 'http://localhost:8080/api/web/index.php' c3url: 'http://localhost/api/web/index.php'

View File

@ -3,6 +3,10 @@ namespace codeception\api\unit\models;
use api\models\AccountIdentity; use api\models\AccountIdentity;
use Codeception\Specify; 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\api\unit\DbTestCase;
use tests\codeception\common\_support\ProtectedCaller; use tests\codeception\common\_support\ProtectedCaller;
use tests\codeception\common\fixtures\AccountFixture; use tests\codeception\common\fixtures\AccountFixture;
@ -33,9 +37,13 @@ class AccountIdentityTest extends DbTestCase {
* @expectedExceptionMessage Token expired * @expectedExceptionMessage Token expired
*/ */
public function testFindIdentityByAccessTokenWithExpiredToken() { public function testFindIdentityByAccessTokenWithExpiredToken() {
$expiredToken = 'eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJodHRwOlwvXC9sb2NhbGhvc3Q6ODA4MCIsImlzcyI6Imh0d' . $token = new Token();
'HA6XC9cL2xvY2FsaG9zdDo4MDgwIiwiaWF0IjoxNDY0NTkzMTkzLCJleHAiOjE0NjQ1OTY3OTN9.DV' . $token->addClaim(new Claim\Audience('http://localhost'));
'8uwh0OQhBYXkrNvxwJeO-kEjb9MQeLr3-6GoHM7RY'; $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); AccountIdentity::findIdentityByAccessToken($expiredToken);
} }