Skip to content

Commit aa46214

Browse files
author
Azure Pipeplines CI
committed
Add tests with JWT decode with invalid iat, nbf and exp properties
1 parent f0d5ea1 commit aa46214

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/JWTTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,4 +546,34 @@ public function testAdditionalHeaderOverrides()
546546
$this->assertEquals('my_key_id', $headers->kid, 'key param not overridden');
547547
$this->assertEquals('HS256', $headers->alg, 'alg param not overridden');
548548
}
549+
550+
public function testDecodeExpectsIntegerIat()
551+
{
552+
$this->expectException(UnexpectedValueException::class);
553+
$this->expectExceptionMessage('Payload iat must be a number');
554+
JWT::decode(
555+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMzM3IiwibmFtZSI6IkpvaG4gU25vdyIsImlhdCI6InRlc3QifQ.B8cbURVQAPay3-Ep0DAm1Ji2rhij-hxfNA5PIDarf5o',
556+
new Key('secret', 'HS256')
557+
);
558+
}
559+
560+
public function testDecodeExpectsIntegerNbf()
561+
{
562+
$this->expectException(UnexpectedValueException::class);
563+
$this->expectExceptionMessage('Payload nbf must be a number');
564+
JWT::decode(
565+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMzM3IiwibmFtZSI6IkpvaG4gU25vdyIsIm5iZiI6InRlc3QifQ.9KdFz3ktQoPO5QFG3E7J86PEuw5Vmx0VPrUKszP7DDs',
566+
new Key('secret', 'HS256')
567+
);
568+
}
569+
570+
public function testDecodeExpectsIntegerExp()
571+
{
572+
$this->expectException(UnexpectedValueException::class);
573+
$this->expectExceptionMessage('Payload exp must be a number');
574+
JWT::decode(
575+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMzM3IiwibmFtZSI6IkpvaG4gU25vdyIsImV4cCI6InRlc3QifQ.LXevvGvchI3PTBZo9jZ5-4d0OvONVU-_8Tbg_22-PTo',
576+
new Key('secret', 'HS256')
577+
);
578+
}
549579
}

0 commit comments

Comments
 (0)