mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Replace emarref/jwt with lcobucci/jwt
Refactor all JWT-related components Replace RS256 with ES256 as a preferred JWT algorithm
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace api\tests\unit\models\authentication;
|
||||
|
||||
use api\models\authentication\AuthenticationResult;
|
||||
use api\tests\unit\TestCase;
|
||||
use Lcobucci\JWT\Token;
|
||||
use Yii;
|
||||
|
||||
class AuthenticationResultTest extends TestCase {
|
||||
|
||||
public function testGetters() {
|
||||
$token = new Token();
|
||||
$model = new AuthenticationResult($token);
|
||||
$this->assertSame($token, $model->getToken());
|
||||
$this->assertNull($model->getRefreshToken());
|
||||
|
||||
$model = new AuthenticationResult($token, 'refresh_token');
|
||||
$this->assertSame('refresh_token', $model->getRefreshToken());
|
||||
}
|
||||
|
||||
public function testGetAsResponse() {
|
||||
$token = Yii::$app->tokens->create();
|
||||
$jwt = (string)$token;
|
||||
|
||||
$model = new AuthenticationResult($token);
|
||||
$result = $model->formatAsOAuth2Response();
|
||||
$this->assertSame($jwt, $result['access_token']);
|
||||
$this->assertEqualsWithDelta(3600, $result['expires_in'], 1);
|
||||
$this->assertArrayNotHasKey('refresh_token', $result);
|
||||
|
||||
$model = new AuthenticationResult($token, 'refresh_token');
|
||||
$result = $model->formatAsOAuth2Response();
|
||||
$this->assertSame($jwt, $result['access_token']);
|
||||
$this->assertEqualsWithDelta(3600, $result['expires_in'], 1);
|
||||
$this->assertSame('refresh_token', $result['refresh_token']);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user