@@ -120,6 +120,50 @@ public function testValidTokenWithNbf()
120120 $ this ->assertEquals ($ decoded ->message , 'abc ' );
121121 }
122122
123+ public function testValidTokenWithNbfLeeway ()
124+ {
125+ JWT ::$ leeway = 60 ;
126+ $ payload = array (
127+ "message " => "abc " ,
128+ "nbf " => time () + 20 ); // not before in near (leeway) future
129+ $ encoded = JWT ::encode ($ payload , 'my_key ' );
130+ $ decoded = JWT ::decode ($ encoded , 'my_key ' , array ('HS256 ' ));
131+ $ this ->assertEquals ($ decoded ->message , 'abc ' );
132+ }
133+
134+ public function testInvalidTokenWithNbfLeeway ()
135+ {
136+ JWT ::$ leeway = 60 ;
137+ $ payload = array (
138+ "message " => "abc " ,
139+ "nbf " => time () + 65 ); // not before too far in future
140+ $ encoded = JWT ::encode ($ payload , 'my_key ' );
141+ $ this ->setExpectedException ('BeforeValidException ' );
142+ $ decoded = JWT ::decode ($ encoded , 'my_key ' , array ('HS256 ' ));
143+ }
144+
145+ public function testValidTokenWithIatLeeway ()
146+ {
147+ JWT ::$ leeway = 60 ;
148+ $ payload = array (
149+ "message " => "abc " ,
150+ "iat " => time () + 20 ); // issued in near (leeway) future
151+ $ encoded = JWT ::encode ($ payload , 'my_key ' );
152+ $ decoded = JWT ::decode ($ encoded , 'my_key ' , array ('HS256 ' ));
153+ $ this ->assertEquals ($ decoded ->message , 'abc ' );
154+ }
155+
156+ public function testInvalidTokenWithIatLeeway ()
157+ {
158+ JWT ::$ leeway = 60 ;
159+ $ payload = array (
160+ "message " => "abc " ,
161+ "iat " => time () + 65 ); // issued too far in future
162+ $ encoded = JWT ::encode ($ payload , 'my_key ' );
163+ $ this ->setExpectedException ('BeforeValidException ' );
164+ $ decoded = JWT ::decode ($ encoded , 'my_key ' , array ('HS256 ' ));
165+ }
166+
123167 public function testInvalidToken ()
124168 {
125169 $ payload = array (
0 commit comments