Skip to content

Commit

Permalink
Add tests to ensure the numeric value of iat, nbf and exp parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaruesweg committed Sep 8, 2022
1 parent 48ae348 commit 2c181f3
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions tests/JWTTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,4 +394,58 @@ public function testEncodeDecodeWithResource()

$this->assertEquals('bar', $decoded->foo);
}

public function testEncodeExpectsIntegerIat()
{
$this->expectException(UnexpectedValueException::class);
$payload = [
'iat' => 'abc',
];
JWT::encode($payload, 'my_key', 'HS256');
}

public function testDecodeExpectsIntegerIat()
{
$this->expectException(UnexpectedValueException::class);
JWT::decode(
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMzM3IiwibmFtZSI6IkpvaG4gU25vdyIsImlhdCI6InRlc3QifQ.B8cbURVQAPay3-Ep0DAm1Ji2rhij-hxfNA5PIDarf5o',
new Key('a', 'secret')
);
}

public function testEncodeExpectsIntegerNbf()
{
$this->expectException(UnexpectedValueException::class);
$payload = [
'nbf' => 'abc',
];
JWT::encode($payload, 'my_key', 'HS256');
}

public function testDecodeExpectsIntegerNbf()
{
$this->expectException(UnexpectedValueException::class);
JWT::decode(
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMzM3IiwibmFtZSI6IkpvaG4gU25vdyIsIm5iZiI6InRlc3QifQ.9KdFz3ktQoPO5QFG3E7J86PEuw5Vmx0VPrUKszP7DDs',
new Key('a', 'secret')
);
}

public function testEncodeExpectsIntegerExp()
{
$this->expectException(UnexpectedValueException::class);
$payload = [
'exp' => 'abc',
];
JWT::encode($payload, 'my_key', 'HS256');
}

public function testDecodeExpectsIntegerExp()
{
$this->expectException(UnexpectedValueException::class);
JWT::decode(
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMzM3IiwibmFtZSI6IkpvaG4gU25vdyIsImV4cCI6InRlc3QifQ.LXevvGvchI3PTBZo9jZ5-4d0OvONVU-_8Tbg_22-PTo',
new Key('a', 'secret')
);
}
}

0 comments on commit 2c181f3

Please sign in to comment.