Skip to content

Commit 2490881

Browse files
author
Redian Ibra
committed
Writing some unittests to make sure the token expiry logic works as it should.
1 parent 280bf6b commit 2490881

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

tests/JWTTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,25 @@ function testMalformedJsonThrowsException() {
2828
$this->setExpectedException('DomainException');
2929
JWT::jsonDecode('this is not valid JSON string');
3030
}
31+
32+
function testExpiredToken(){
33+
$this->setExpectedException('UnexpectedValueException');
34+
$payload = array(
35+
"message"=> "abc",
36+
"exp"=> time()-20); // time in the past
37+
$encoded = JWT::encode($payload, 'my_key');
38+
JWT::decode($encoded);
39+
}
40+
41+
function testValidToken(){
42+
$payload = array(
43+
"message"=> "abc",
44+
"exp"=> time()+20); // time in the future
45+
$encoded = JWT::encode($payload, 'my_key');
46+
$decoded = JWT::decode($encoded, 'my_key');
47+
$this->assertEquals($decoded->message, 'abc');
48+
}
49+
3150
}
3251

3352
?>

0 commit comments

Comments
 (0)