2019-08-01 14:47:12 +05:30
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace api\tests\unit\components\Tokens;
|
|
|
|
|
|
|
|
use api\components\Tokens\TokensFactory;
|
|
|
|
use api\tests\unit\TestCase;
|
|
|
|
use common\models\Account;
|
|
|
|
use common\models\AccountSession;
|
|
|
|
|
|
|
|
class TokensFactoryTest extends TestCase {
|
|
|
|
|
|
|
|
public function testCreateForAccount() {
|
|
|
|
$account = new Account();
|
|
|
|
$account->id = 1;
|
|
|
|
|
2019-12-04 23:40:15 +05:30
|
|
|
$factory = new TokensFactory();
|
|
|
|
|
|
|
|
$token = $factory->createForWebAccount($account);
|
2019-08-01 14:47:12 +05:30
|
|
|
$this->assertEqualsWithDelta(time(), $token->getClaim('iat'), 1);
|
|
|
|
$this->assertEqualsWithDelta(time() + 60 * 60 * 24 * 7, $token->getClaim('exp'), 2);
|
|
|
|
$this->assertSame('ely|1', $token->getClaim('sub'));
|
|
|
|
$this->assertSame('accounts_web_user', $token->getClaim('ely-scopes'));
|
|
|
|
$this->assertArrayNotHasKey('jti', $token->getClaims());
|
|
|
|
|
|
|
|
$session = new AccountSession();
|
|
|
|
$session->id = 2;
|
|
|
|
|
2019-12-04 23:40:15 +05:30
|
|
|
$token = $factory->createForWebAccount($account, $session);
|
2019-08-01 14:47:12 +05:30
|
|
|
$this->assertEqualsWithDelta(time(), $token->getClaim('iat'), 1);
|
|
|
|
$this->assertEqualsWithDelta(time() + 3600, $token->getClaim('exp'), 2);
|
|
|
|
$this->assertSame('ely|1', $token->getClaim('sub'));
|
|
|
|
$this->assertSame('accounts_web_user', $token->getClaim('ely-scopes'));
|
|
|
|
$this->assertSame(2, $token->getClaim('jti'));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|