@@ -303,6 +303,36 @@ component extends="coldbox.system.testing.BaseTestCase" appMapping="/root" {
303
303
} );
304
304
} );
305
305
306
+ given ( " a valid jwt token put in to storage" , function (){
307
+ then ( " it should use the exp on the token for the storage timeout" , function (){
308
+ var originalTokenStorage = duplicate ( variables .jwtService .getTokenStorage () );
309
+ try {
310
+ variables .jwtService .getTokenStorage ().clearAll ();
311
+ var tokenStorageMock = prepareMock ( variables .jwtService .getTokenStorage () );
312
+ tokenStorageMock .$( " set" , tokenStorageMock );
313
+ var expirationSeconds = 100 ;
314
+ var expirationTime = variables .jwtService .toEpoch (
315
+ dateAdd ( " n" , expirationSeconds , now () )
316
+ );
317
+ var thisToken = variables .jwtService .attempt (
318
+ " test" ,
319
+ " test" ,
320
+ { " exp" : expirationTime }
321
+ );
322
+ var tokenStorageSetCallLog = tokenStorageMock .$callLog ().set ;
323
+ expect ( tokenStorageSetCallLog ).toBeArray ();
324
+ expect ( tokenStorageSetCallLog ).toHaveLength ( 1 );
325
+ expect ( tokenStorageSetCallLog [ 1 ] ).toHaveKey ( " expiration" );
326
+ expect ( tokenStorageSetCallLog [ 1 ].expiration ).toBeCloseTo (
327
+ expirationSeconds ,
328
+ 1
329
+ );
330
+ } finally {
331
+ variables .jwtService .setTokenStorage ( originalTokenStorage );
332
+ }
333
+ } );
334
+ } );
335
+
306
336
given ( " a valid jwt token but it is not in the storage" , function (){
307
337
then ( " it should block with no authorization" , function (){
308
338
var thisToken = variables .jwtService .attempt ( " test" , " test" );
0 commit comments