Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: use short classname for config() #803

Merged
merged 1 commit into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function testCheckNoToken(): void

$this->assertFalse($result->isOK());
$this->assertSame(
\lang('Auth.noToken', [config(AuthJWT::class)->authenticatorHeader]),
\lang('Auth.noToken', [config('AuthJWT')->authenticatorHeader]),
$result->reason()
);
}
Expand Down
3 changes: 2 additions & 1 deletion tests/Authentication/Filters/JWTFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ protected function setUp(): void
$_SESSION = [];

// Add JWT Authenticator
$config = config(Auth::class);
/** @var Auth $config */
$config = config('Auth');
$config->authenticators['jwt'] = JWT::class;

// Register our filter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ public function testDecodeInvalidTokenExceptionUnexpectedValueException(): void
$token = $this->generateJWT();

// Change algorithm and it makes the key invalid.
$config = config(AuthJWT::class);
/** @var AuthJWT $config */
$config = config('AuthJWT');
$config->keys['default'][0]['alg'] = 'ES256';

$adapter = new FirebaseAdapter();
Expand Down Expand Up @@ -110,7 +111,8 @@ public function testDecodeInvalidArgumentException(): void
$token = $this->generateJWT();

// Set invalid key.
$config = config(AuthJWT::class);
/** @var AuthJWT $config */
$config = config('AuthJWT');
$config->keys['default'][0] = [
'alg' => '',
'secret' => '',
Expand All @@ -128,7 +130,8 @@ public function testEncodeLogicExceptionLogicException(): void
$this->expectExceptionMessage('Cannot encode JWT: Algorithm not supported');

// Set unsupported algorithm.
$config = config(AuthJWT::class);
/** @var AuthJWT $config */
$config = config('AuthJWT');
$config->keys['default'][0]['alg'] = 'PS256';

$adapter = new FirebaseAdapter();
Expand Down
21 changes: 14 additions & 7 deletions tests/Unit/Authentication/JWT/JWTManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public function testGenerateTokenPayload(array $data): void
$manager = $this->createJWTManager();
$payload = $manager->parse($token);

$config = config(AuthJWT::class);
/** @var AuthJWT $config */
$config = config('AuthJWT');
$expected = [
'iss' => $config->defaultClaims['iss'],
'sub' => '1',
Expand Down Expand Up @@ -121,7 +122,8 @@ public function testIssuePayload(array $data): void
$manager = $this->createJWTManager();
$payload = $manager->parse($token);

$config = config(AuthJWT::class);
/** @var AuthJWT $config */
$config = config('AuthJWT');
$expected = [
'iss' => $config->defaultClaims['iss'],
'user_id' => '1',
Expand All @@ -137,7 +139,8 @@ public function testIssueSetKid(): void
$manager = $this->createJWTManager();

// Set kid
$config = config(AuthJWT::class);
/** @var AuthJWT $config */
$config = config('AuthJWT');
$config->keys['default'][0]['kid'] = 'Key01';

$payload = [
Expand Down Expand Up @@ -181,7 +184,8 @@ public function testIssueWithAsymmetricKey(): void
{
$manager = $this->createJWTManager();

$config = config(AuthJWT::class);
/** @var AuthJWT $config */
$config = config('AuthJWT');
$config->keys['default'][0] = [
'alg' => 'RS256', // algorithm.
'public' => '', // Public Key
Expand Down Expand Up @@ -257,7 +261,8 @@ private function decodeJWT(string $token, $part): array

public function testParseCanDecodeTokenSignedByOldKey(): void
{
$config = config(AuthJWT::class);
/** @var AuthJWT $config */
$config = config('AuthJWT');
$config->keys['default'] = [
[
'kid' => 'Key01',
Expand Down Expand Up @@ -294,7 +299,8 @@ public function testParseCanDecodeTokenSignedByOldKey(): void

public function testParseCanSpecifyKey(): void
{
$config = config(AuthJWT::class);
/** @var AuthJWT $config */
$config = config('AuthJWT');
$config->keys['mobile'] = [
[
'kid' => 'Key01',
Expand Down Expand Up @@ -329,7 +335,8 @@ private function generateJWTWithAsymmetricKey(): string
{
$manager = $this->createJWTManager();

$config = config(AuthJWT::class);
/** @var AuthJWT $config */
$config = config('AuthJWT');
$config->keys['default'][0] = [
'alg' => 'RS256', // algorithm.
'public' => <<<'EOD'
Expand Down
Loading