@@ -297,14 +297,42 @@ describe('verifyJWT()', () => {
297297 } )
298298 } )
299299
300- it ( 'accepts a valid nbf' , ( ) => {
301- return createJWT ( { nbf : NOW + NBF_SKEW } , { issuer : did , signer } ) . then (
302- jwt =>
303- verifyJWT ( jwt ) . then (
304- ( { payload } ) => expect ( payload ) . toMatchSnapshot ( ) ,
305- error => expect ( error ) . toBeNull ( )
306- )
307- )
300+ describe ( 'validFrom timestamp' , ( ) => {
301+ it ( 'passes when nbf is in the past' , async ( ) => {
302+ // tslint:disable-next-line: max-line-length
303+ const jwt = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NksifQ.eyJpYXQiOjE0ODUzMjExMzMsIm5iZiI6MTQ4NTI2MTEzMywiaXNzIjoiZGlkOnVwb3J0OjJuUXRpUUc2Q2dtMUdZVEJhYUtBZ3I3NnVZN2lTZXhVa3FYIn0.btzVz7fZsoSEDa7JyWo3cYWL63pkWTKTz8OUzepIesfSFeBozUjX2oq1xOJ2OyzuinnLGwtSqY303VoyALrafA'
304+ expect ( verifyJWT ( jwt ) ) . resolves . not . toThrow ( )
305+ } )
306+ it ( 'passes when nbf is in the past and iat is in the future' , async ( ) => {
307+ // tslint:disable-next-line: max-line-length
308+ const jwt = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NksifQ.eyJpYXQiOjE0ODUzODExMzMsIm5iZiI6MTQ4NTI2MTEzMywiaXNzIjoiZGlkOnVwb3J0OjJuUXRpUUc2Q2dtMUdZVEJhYUtBZ3I3NnVZN2lTZXhVa3FYIn0.ELsPnDC_YTTkT5hxw09UCLSjWVje9mDs1n_mpvlo2Wk5VJONSy-FDAzm5TunzzCeLixU04m6dD4w6Uk3-OVkww'
309+ expect ( verifyJWT ( jwt ) ) . resolves . not . toThrow ( )
310+ } )
311+ it ( 'fails when nbf is in the future' , async ( ) => {
312+ // tslint:disable-next-line: max-line-length
313+ const jwt = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NksifQ.eyJpYXQiOjE0ODUzMjExMzMsIm5iZiI6MTQ4NTM4MTEzMywiaXNzIjoiZGlkOnVwb3J0OjJuUXRpUUc2Q2dtMUdZVEJhYUtBZ3I3NnVZN2lTZXhVa3FYIn0.rcFuhVHtie3Y09pWxBSf1dnjaVh6FFQLHh-83N-uLty3M5ADJ-jVFFkyt_Eupl8Kr735-oPGn_D1Nj9rl4s_Kw'
314+ expect ( verifyJWT ( jwt ) ) . rejects . toThrow ( )
315+ } )
316+ it ( 'fails when nbf is in the future and iat is in the past' , async ( ) => {
317+ // tslint:disable-next-line: max-line-length
318+ const jwt = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NksifQ.eyJpYXQiOjE0ODUyNjExMzMsIm5iZiI6MTQ4NTM4MTEzMywiaXNzIjoiZGlkOnVwb3J0OjJuUXRpUUc2Q2dtMUdZVEJhYUtBZ3I3NnVZN2lTZXhVa3FYIn0.jiVI11IcKNOvnDrJBzojKtNAGaZbEcafcqW-wfP78g6-6RucjYPBi5qvKje35IOvITWvvpXpK48IW-17Srh02w'
319+ expect ( verifyJWT ( jwt ) ) . rejects . toThrow ( )
320+ } )
321+ it ( 'passes when nbf is missing and iat is in the past' , async ( ) => {
322+ // tslint:disable-next-line: max-line-length
323+ const jwt = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NksifQ.eyJpYXQiOjE0ODUyNjExMzMsImlzcyI6ImRpZDp1cG9ydDoyblF0aVFHNkNnbTFHWVRCYWFLQWdyNzZ1WTdpU2V4VWtxWCJ9.1VwGHDm7f9V-1Fa545uAwF9NfU3RI8yqRFW6XAHOg0FBeM7krC_rEf0PwqbKFO8MiIBELBwUhW_fT4oZsuggUA'
324+ expect ( verifyJWT ( jwt ) ) . resolves . not . toThrow ( )
325+ } )
326+ it ( 'fails when nbf is missing and iat is in the future' , async ( ) => {
327+ // tslint:disable-next-line: max-line-length
328+ const jwt = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NksifQ.eyJpYXQiOjE0ODUzODExMzMsImlzcyI6ImRpZDp1cG9ydDoyblF0aVFHNkNnbTFHWVRCYWFLQWdyNzZ1WTdpU2V4VWtxWCJ9.jU0R8qP3aUX_3DiFt9tIONiq_P5OooFc-ypUwpqK4plGyw6WiI0FTGfZvq7pOarKrjmSojE9Sm_3ETfMpdQckg'
329+ expect ( verifyJWT ( jwt ) ) . rejects . toThrow ( )
330+ } )
331+ it ( 'passes when nbf and iat are both missing' , async ( ) => {
332+ // tslint:disable-next-line: max-line-length
333+ const jwt = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NksifQ.eyJpc3MiOiJkaWQ6dXBvcnQ6Mm5RdGlRRzZDZ20xR1lUQmFhS0Fncjc2dVk3aVNleFVrcVgifQ.5kGKU9ljebhTqvfVDu9MH7vGAqRH0GDTbZNGH45YmhUySgBTyI7u-MkkRit72eFvQAqBfzw6wNUbGf9FPC5AtQ'
334+ expect ( verifyJWT ( jwt ) ) . resolves . not . toThrow ( )
335+ } )
308336 } )
309337
310338 it ( 'handles ES256K-R algorithm' , ( ) => {
@@ -331,25 +359,12 @@ describe('verifyJWT()', () => {
331359 )
332360 } )
333361
334- it ( 'rejects an nbf in the future' , ( ) => {
335- return createJWT ( { nbf : NOW + NBF_SKEW + 1 } , { issuer : did , signer } ) . then (
336- jwt =>
337- verifyJWT ( jwt )
338- . catch ( error =>
339- expect ( error . message ) . toEqual (
340- 'JWT not valid yet (issued in the future): nbf: 1485321434 > now: 1485321133'
341- )
342- )
343- . then ( p => expect ( p ) . toBeFalsy ( ) )
344- )
345- } )
346-
347362 it ( 'accepts a valid exp' , ( ) => {
348363 return createJWT (
349- { exp : NOW - NBF_SKEW + 1 } ,
350- { issuer : did , signer, expiresIn : 1 }
364+ { exp : NOW } ,
365+ { issuer : did , signer }
351366 ) . then ( jwt =>
352- verifyJWT ( jwt ) . then ( ( { payload } ) => expect ( payload ) . toMatchSnapshot ( ) )
367+ verifyJWT ( jwt ) . then ( ( { payload } ) => expect ( payload ) . toBeDefined ( ) )
353368 )
354369 } )
355370
0 commit comments