Skip to content

Commit ab2170d

Browse files
committed
Add tests to ensure the numeric value of iat, nbf and exp parameters
1 parent 48ae348 commit ab2170d

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

tests/JWTTest.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,4 +394,58 @@ public function testEncodeDecodeWithResource()
394394

395395
$this->assertEquals('bar', $decoded->foo);
396396
}
397+
398+
public function testEncodeExpectsIntegerIat()
399+
{
400+
$this->expectException(UnexpectedValueException::class);
401+
$payload = [
402+
'iat' => 'abc',
403+
];
404+
JWT::encode($payload, 'my_key', 'HS256');
405+
}
406+
407+
public function testDecodeExpectsIntegerIat()
408+
{
409+
$this->expectException(UnexpectedValueException::class);
410+
JWT::decode(
411+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMzM3IiwibmFtZSI6IkpvaG4gU25vdyIsImlhdCI6InRlc3QifQ.B8cbURVQAPay3-Ep0DAm1Ji2rhij-hxfNA5PIDarf5o',
412+
new Key('secret', 'HS256')
413+
);
414+
}
415+
416+
public function testEncodeExpectsIntegerNbf()
417+
{
418+
$this->expectException(UnexpectedValueException::class);
419+
$payload = [
420+
'nbf' => 'abc',
421+
];
422+
JWT::encode($payload, 'my_key', 'HS256');
423+
}
424+
425+
public function testDecodeExpectsIntegerNbf()
426+
{
427+
$this->expectException(UnexpectedValueException::class);
428+
JWT::decode(
429+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMzM3IiwibmFtZSI6IkpvaG4gU25vdyIsIm5iZiI6InRlc3QifQ.9KdFz3ktQoPO5QFG3E7J86PEuw5Vmx0VPrUKszP7DDs',
430+
new Key('secret', 'HS256')
431+
);
432+
}
433+
434+
public function testEncodeExpectsIntegerExp()
435+
{
436+
$this->expectException(UnexpectedValueException::class);
437+
$payload = [
438+
'exp' => 'abc',
439+
];
440+
JWT::encode($payload, 'my_key', 'HS256');
441+
}
442+
443+
public function testDecodeExpectsIntegerExp()
444+
{
445+
$this->expectException(UnexpectedValueException::class);
446+
JWT::decode(
447+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMzM3IiwibmFtZSI6IkpvaG4gU25vdyIsImV4cCI6InRlc3QifQ.LXevvGvchI3PTBZo9jZ5-4d0OvONVU-_8Tbg_22-PTo',
448+
new Key('secret', 'HS256')
449+
);
450+
}
397451
}

0 commit comments

Comments
 (0)