@@ -38,7 +38,7 @@ public function testMalformedJsonThrowsException()
38
38
public function testExpiredToken ()
39
39
{
40
40
$ this ->setExpectedException ('ExpiredException ' );
41
- $ timeInPast = time () - JWT :: LEEWAYTIME - 20 ;
41
+ $ timeInPast = time () - 20 ;
42
42
$ payload = array (
43
43
"message " => "abc " ,
44
44
"exp " => $ timeInPast // time in the past
@@ -50,7 +50,7 @@ public function testExpiredToken()
50
50
public function testBeforeValidTokenWithNbf ()
51
51
{
52
52
$ this ->setExpectedException ('BeforeValidException ' );
53
- $ timeInFuture = time () + JWT :: LEEWAYTIME + 20 ;
53
+ $ timeInFuture = time () + 20 ;
54
54
$ payload = array (
55
55
"message " => "abc " ,
56
56
"nbf " => $ timeInFuture // time in the future
@@ -62,7 +62,7 @@ public function testBeforeValidTokenWithNbf()
62
62
public function testBeforeValidTokenWithIat ()
63
63
{
64
64
$ this ->setExpectedException ('BeforeValidException ' );
65
- $ timeInFuture = time () + JWT :: LEEWAYTIME + 20 ;
65
+ $ timeInFuture = time () + 20 ;
66
66
$ payload = array (
67
67
"message " => "abc " ,
68
68
"iat " => $ timeInFuture // time in the future
@@ -75,7 +75,30 @@ public function testValidToken()
75
75
{
76
76
$ payload = array (
77
77
"message " => "abc " ,
78
- "exp " => time () + 20 ); // time in the future
78
+ "exp " => time () + JWT ::$ leeway + 20 ); // time in the future
79
+ $ encoded = JWT ::encode ($ payload , 'my_key ' );
80
+ $ decoded = JWT ::decode ($ encoded , 'my_key ' , array ('HS256 ' ));
81
+ $ this ->assertEquals ($ decoded ->message , 'abc ' );
82
+ }
83
+
84
+ public function testValidTokenWithLeeway ()
85
+ {
86
+ JWT ::$ leeway = 60 ;
87
+ $ payload = array (
88
+ "message " => "abc " ,
89
+ "exp " => time () - 20 ); // time in the past
90
+ $ encoded = JWT ::encode ($ payload , 'my_key ' );
91
+ $ decoded = JWT ::decode ($ encoded , 'my_key ' , array ('HS256 ' ));
92
+ $ this ->assertEquals ($ decoded ->message , 'abc ' );
93
+ }
94
+
95
+ public function testExpiredTokenWithLeeway ()
96
+ {
97
+ JWT ::$ leeway = 60 ;
98
+ $ payload = array (
99
+ "message " => "abc " ,
100
+ "exp " => time () - 70 ); // time far in the past
101
+ $ this ->setExpectedException ('ExpiredException ' );
79
102
$ encoded = JWT ::encode ($ payload , 'my_key ' );
80
103
$ decoded = JWT ::decode ($ encoded , 'my_key ' , array ('HS256 ' ));
81
104
$ this ->assertEquals ($ decoded ->message , 'abc ' );
0 commit comments