@@ -107,6 +107,40 @@ public function testExpiredTokenWithLeeway()
107107 $ this ->assertSame ($ decoded ->message , 'abc ' );
108108 }
109109
110+ public function testExpiredExceptionPayload ()
111+ {
112+ $ this ->expectException (ExpiredException::class);
113+ $ payload = [
114+ 'message ' => 'abc ' ,
115+ 'exp ' => time () - 100 , // time in the past
116+ ];
117+ $ encoded = JWT ::encode ($ payload , 'my_key ' , 'HS256 ' );
118+ try {
119+ JWT ::decode ($ encoded , new Key ('my_key ' , 'HS256 ' ));
120+ } catch (ExpiredException $ e ) {
121+ $ exceptionPayload = (array ) $ e ->getPayload ();
122+ $ this ->assertEquals ($ exceptionPayload , $ payload );
123+ throw $ e ;
124+ }
125+ }
126+
127+ public function testBeforeValidExceptionPayload ()
128+ {
129+ $ this ->expectException (BeforeValidException::class);
130+ $ payload = [
131+ 'message ' => 'abc ' ,
132+ 'iat ' => time () + 100 , // time in the future
133+ ];
134+ $ encoded = JWT ::encode ($ payload , 'my_key ' , 'HS256 ' );
135+ try {
136+ JWT ::decode ($ encoded , new Key ('my_key ' , 'HS256 ' ));
137+ } catch (BeforeValidException $ e ) {
138+ $ exceptionPayload = (array ) $ e ->getPayload ();
139+ $ this ->assertEquals ($ exceptionPayload , $ payload );
140+ throw $ e ;
141+ }
142+ }
143+
110144 public function testValidTokenWithNbf ()
111145 {
112146 $ payload = [
0 commit comments