Skip to content

Commit 0d2e3fc

Browse files
committed
Fix JWT tests for php-jwt 7.0 minimum key size requirement
php-jwt 7.0 enforces minimum key sizes for security. HS256 now requires at least 32 bytes. Update test secret keys to meet this requirement.
1 parent a0c0459 commit 0d2e3fc

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

tests/TestCase/Authenticator/JwtAuthenticatorTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function setUp(): void
7979
'firstname' => 'larry',
8080
];
8181

82-
$this->tokenHS256 = JWT::encode($data, 'secretKey', 'HS256');
82+
$this->tokenHS256 = JWT::encode($data, 'secretKey0123456789secretKey0123456789', 'HS256');
8383

8484
$privKey1 = file_get_contents(__DIR__ . '/../../data/rsa1-private.pem');
8585
$this->tokenRS256 = JWT::encode($data, $privKey1, 'RS256', 'jwk1');
@@ -100,7 +100,7 @@ public function testAuthenticateViaHeaderToken()
100100
$this->request = $this->request->withAddedHeader('Authorization', 'Bearer ' . $this->tokenHS256);
101101

102102
$authenticator = new JwtAuthenticator($this->identifiers, [
103-
'secretKey' => 'secretKey',
103+
'secretKey' => 'secretKey0123456789secretKey0123456789',
104104
'subjectKey' => 'subjectId',
105105
]);
106106

@@ -123,7 +123,7 @@ public function testAuthenticateViaQueryParamToken()
123123
);
124124

125125
$authenticator = new JwtAuthenticator($this->identifiers, [
126-
'secretKey' => 'secretKey',
126+
'secretKey' => 'secretKey0123456789secretKey0123456789',
127127
'subjectKey' => 'subjectId',
128128
]);
129129

@@ -159,7 +159,7 @@ public function testAuthenticationViaIdentifierAndSubject()
159159
]));
160160

161161
$authenticator = new JwtAuthenticator($this->identifiers, [
162-
'secretKey' => 'secretKey',
162+
'secretKey' => 'secretKey0123456789secretKey0123456789',
163163
'returnPayload' => false,
164164
'subjectKey' => 'subjectId',
165165
]);
@@ -242,7 +242,7 @@ public function testInvalidToken()
242242
);
243243

244244
$authenticator = new JwtAuthenticator($this->identifiers, [
245-
'secretKey' => 'secretKey',
245+
'secretKey' => 'secretKey0123456789secretKey0123456789',
246246
]);
247247

248248
$result = $authenticator->authenticate($this->request);
@@ -268,7 +268,7 @@ public function testGetPayloadHS256()
268268
);
269269

270270
$authenticator = new JwtAuthenticator($this->identifiers, [
271-
'secretKey' => 'secretKey',
271+
'secretKey' => 'secretKey0123456789secretKey0123456789',
272272
]);
273273

274274
$result = $authenticator->getPayload();

tests/TestCase/Middleware/AuthenticationMiddlewareTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,13 +576,13 @@ public function testJwtTokenAuthorizationThroughTheMiddlewareStack()
576576
'firstname' => 'larry',
577577
];
578578

579-
$token = JWT::encode($data, 'secretKey', 'HS256');
579+
$token = JWT::encode($data, 'secretKey0123456789secretKey0123456789', 'HS256');
580580

581581
$this->service = new AuthenticationService([
582582
'authenticators' => [
583583
'Authentication.Form' => ['identifier' => 'Authentication.Password'],
584584
'Authentication.Jwt' => [
585-
'secretKey' => 'secretKey',
585+
'secretKey' => 'secretKey0123456789secretKey0123456789',
586586
'identifier' => 'Authentication.JwtSubject',
587587
],
588588
],

0 commit comments

Comments
 (0)