11<?php
2+ use \Firebase \JWT \JWT ;
23
34class JWTTest extends PHPUnit_Framework_TestCase
45{
@@ -37,7 +38,7 @@ public function testMalformedJsonThrowsException()
3738
3839 public function testExpiredToken ()
3940 {
40- $ this ->setExpectedException ('ExpiredException ' );
41+ $ this ->setExpectedException ('Firebase\JWT\ ExpiredException ' );
4142 $ payload = array (
4243 "message " => "abc " ,
4344 "exp " => time () - 20 ); // time in the past
@@ -47,7 +48,7 @@ public function testExpiredToken()
4748
4849 public function testBeforeValidTokenWithNbf ()
4950 {
50- $ this ->setExpectedException ('BeforeValidException ' );
51+ $ this ->setExpectedException ('Firebase\JWT\ BeforeValidException ' );
5152 $ payload = array (
5253 "message " => "abc " ,
5354 "nbf " => time () + 20 ); // time in the future
@@ -57,7 +58,7 @@ public function testBeforeValidTokenWithNbf()
5758
5859 public function testBeforeValidTokenWithIat ()
5960 {
60- $ this ->setExpectedException ('BeforeValidException ' );
61+ $ this ->setExpectedException ('Firebase\JWT\ BeforeValidException ' );
6162 $ payload = array (
6263 "message " => "abc " ,
6364 "iat " => time () + 20 ); // time in the future
@@ -93,7 +94,7 @@ public function testExpiredTokenWithLeeway()
9394 $ payload = array (
9495 "message " => "abc " ,
9596 "exp " => time () - 70 ); // time far in the past
96- $ this ->setExpectedException ('ExpiredException ' );
97+ $ this ->setExpectedException ('Firebase\JWT\ ExpiredException ' );
9798 $ encoded = JWT ::encode ($ payload , 'my_key ' );
9899 $ decoded = JWT ::decode ($ encoded , 'my_key ' , array ('HS256 ' ));
99100 $ this ->assertEquals ($ decoded ->message , 'abc ' );
@@ -141,7 +142,7 @@ public function testInvalidTokenWithNbfLeeway()
141142 "message " => "abc " ,
142143 "nbf " => time () + 65 ); // not before too far in future
143144 $ encoded = JWT ::encode ($ payload , 'my_key ' );
144- $ this ->setExpectedException ('BeforeValidException ' );
145+ $ this ->setExpectedException ('Firebase\JWT\ BeforeValidException ' );
145146 $ decoded = JWT ::decode ($ encoded , 'my_key ' , array ('HS256 ' ));
146147 JWT ::$ leeway = 0 ;
147148 }
@@ -165,7 +166,7 @@ public function testInvalidTokenWithIatLeeway()
165166 "message " => "abc " ,
166167 "iat " => time () + 65 ); // issued too far in future
167168 $ encoded = JWT ::encode ($ payload , 'my_key ' );
168- $ this ->setExpectedException ('BeforeValidException ' );
169+ $ this ->setExpectedException ('Firebase\JWT\ BeforeValidException ' );
169170 $ decoded = JWT ::decode ($ encoded , 'my_key ' , array ('HS256 ' ));
170171 JWT ::$ leeway = 0 ;
171172 }
@@ -176,7 +177,7 @@ public function testInvalidToken()
176177 "message " => "abc " ,
177178 "exp " => time () + 20 ); // time in the future
178179 $ encoded = JWT ::encode ($ payload , 'my_key ' );
179- $ this ->setExpectedException ('SignatureInvalidException ' );
180+ $ this ->setExpectedException ('Firebase\JWT\ SignatureInvalidException ' );
180181 $ decoded = JWT ::decode ($ encoded , 'my_key2 ' , array ('HS256 ' ));
181182 }
182183
@@ -234,4 +235,10 @@ public function testAdditionalHeaders()
234235 $ msg = JWT ::encode ('abc ' , 'my_key ' , 'HS256 ' , null , array ('cty ' => 'test-eit;v=1 ' ));
235236 $ this ->assertEquals (JWT ::decode ($ msg , 'my_key ' , array ('HS256 ' )), 'abc ' );
236237 }
238+
239+ public function testInvalidSegmentCount ()
240+ {
241+ $ this ->setExpectedException ('UnexpectedValueException ' );
242+ JWT ::decode ('brokenheader.brokenbody ' , 'my_key ' , array ('HS256 ' ));
243+ }
237244}
0 commit comments