@@ -115,7 +115,7 @@ describe('verify', function() {
115115
116116 describe ( 'option: maxAge' , function ( ) {
117117
118- [ '3s' , 3 ] . forEach ( function ( maxAge ) {
118+ [ String ( '3s' ) , '3s' , 3 ] . forEach ( function ( maxAge ) {
119119 it ( `should error for claims issued before a certain timespan (${ typeof maxAge } type)` , function ( done ) {
120120 clock = sinon . useFakeTimers ( 1437018587000 ) ; // iat + 5s, exp - 5s
121121 var options = { algorithms : [ 'HS256' ] , maxAge : maxAge } ;
@@ -131,7 +131,7 @@ describe('verify', function() {
131131 } ) ;
132132 } ) ;
133133
134- [ '5s' , 5 ] . forEach ( function ( maxAge ) {
134+ [ String ( '5s' ) , '5s' , 5 ] . forEach ( function ( maxAge ) {
135135 it ( `should not error for claims issued before a certain timespan but still inside clockTolerance timespan (${ typeof maxAge } type)` , function ( done ) {
136136 clock = sinon . useFakeTimers ( 1437018587500 ) ; // iat + 5.5s, exp - 4.5s
137137 var options = { algorithms : [ 'HS256' ] , maxAge : maxAge , clockTolerance : 1 } ;
@@ -144,7 +144,7 @@ describe('verify', function() {
144144 } ) ;
145145 } ) ;
146146
147- [ '6s' , 6 ] . forEach ( function ( maxAge ) {
147+ [ String ( '6s' ) , '6s' , 6 ] . forEach ( function ( maxAge ) {
148148 it ( `should not error if within maxAge timespan (${ typeof maxAge } type)` , function ( done ) {
149149 clock = sinon . useFakeTimers ( 1437018587500 ) ; // iat + 5.5s, exp - 4.5s
150150 var options = { algorithms : [ 'HS256' ] , maxAge : maxAge } ;
@@ -157,7 +157,7 @@ describe('verify', function() {
157157 } ) ;
158158 } ) ;
159159
160- [ '8s' , 8 ] . forEach ( function ( maxAge ) {
160+ [ String ( '8s' ) , '8s' , 8 ] . forEach ( function ( maxAge ) {
161161 it ( `can be more restrictive than expiration (${ typeof maxAge } type)` , function ( done ) {
162162 clock = sinon . useFakeTimers ( 1437018591900 ) ; // iat + 9.9s, exp - 0.1s
163163 var options = { algorithms : [ 'HS256' ] , maxAge : maxAge } ;
@@ -173,7 +173,7 @@ describe('verify', function() {
173173 } ) ;
174174 } ) ;
175175
176- [ '12s' , 12 ] . forEach ( function ( maxAge ) {
176+ [ String ( '12s' ) , '12s' , 12 ] . forEach ( function ( maxAge ) {
177177 it ( `cannot be more permissive than expiration (${ typeof maxAge } type)` , function ( done ) {
178178 clock = sinon . useFakeTimers ( 1437018593000 ) ; // iat + 11s, exp + 1s
179179 var options = { algorithms : [ 'HS256' ] , maxAge : '12s' } ;
@@ -190,6 +190,20 @@ describe('verify', function() {
190190 } ) ;
191191 } ) ;
192192
193+ [ new String ( '1s' ) , 'no-timespan-string' ] . forEach ( function ( maxAge ) {
194+ it ( `should error if maxAge is specified with a wrong string format/type (value: ${ maxAge } , type: ${ typeof maxAge } )` , function ( done ) {
195+ clock = sinon . useFakeTimers ( 1437018587000 ) ; // iat + 5s, exp - 5s
196+ var options = { algorithms : [ 'HS256' ] , maxAge : maxAge } ;
197+
198+ jwt . verify ( token , key , options , function ( err , p ) {
199+ assert . equal ( err . name , 'JsonWebTokenError' ) ;
200+ assert . equal ( err . message , '"maxAge" should be a number of seconds or string representing a timespan eg: "1d", "20h", 60' ) ;
201+ assert . isUndefined ( p ) ;
202+ done ( ) ;
203+ } ) ;
204+ } ) ;
205+ } ) ;
206+
193207 it ( 'should error if maxAge is specified but there is no iat claim' , function ( done ) {
194208 var token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJmb28iOiJiYXIifQ.0MBPd4Bru9-fK_HY3xmuDAc6N_embknmNuhdb9bKL_U' ;
195209 var options = { algorithms : [ 'HS256' ] , maxAge : '1s' } ;
@@ -201,6 +215,7 @@ describe('verify', function() {
201215 done ( ) ;
202216 } ) ;
203217 } ) ;
218+
204219 } ) ;
205220
206221 describe ( 'option: clockTimestamp' , function ( ) {
0 commit comments