@@ -131,19 +131,19 @@ describe('AppCheckTokenGenerator', () => {
131131 } ) ;
132132 } ) ;
133133
134- const invalidTtls = [ null , NaN , '0' , 'abc' , '' , - 100 , - 1 , true , false , [ ] , { } , { a : 1 } , _ . noop ] ;
134+ const invalidTtls = [ null , NaN , '0' , 'abc' , '' , true , false , [ ] , { } , { a : 1 } , _ . noop ] ;
135135 invalidTtls . forEach ( ( invalidTtl ) => {
136136 it ( 'should throw given an options object with invalid ttl: ' + JSON . stringify ( invalidTtl ) , ( ) => {
137137 expect ( ( ) => {
138138 tokenGenerator . createCustomToken ( APP_ID , { ttlMillis : invalidTtl as any } ) ;
139139 } ) . to . throw ( FirebaseAppCheckError ) . with . property ( 'message' ,
140- 'ttlMillis must be a non-negative duration in milliseconds.' ) ;
140+ 'ttlMillis must be a duration in milliseconds.' ) ;
141141 } ) ;
142142 } ) ;
143143
144144 const THIRTY_MIN_IN_MS = 1800000 ;
145145 const SEVEN_DAYS_IN_MS = 604800000 ;
146- [ 0 , 10 , THIRTY_MIN_IN_MS - 1 , SEVEN_DAYS_IN_MS + 1 , SEVEN_DAYS_IN_MS * 2 ] . forEach ( ( ttlMillis ) => {
146+ [ - 100 , - 1 , 0 , 10 , THIRTY_MIN_IN_MS - 1 , SEVEN_DAYS_IN_MS + 1 , SEVEN_DAYS_IN_MS * 2 ] . forEach ( ( ttlMillis ) => {
147147 it ( 'should throw given options with ttl < 30 minutes or ttl > 7 days:' + JSON . stringify ( ttlMillis ) , ( ) => {
148148 expect ( ( ) => {
149149 tokenGenerator . createCustomToken ( APP_ID , { ttlMillis } ) ;
@@ -157,11 +157,16 @@ describe('AppCheckTokenGenerator', () => {
157157 . should . eventually . be . a ( 'string' ) . and . not . be . empty ;
158158 } ) ;
159159
160- [ THIRTY_MIN_IN_MS , THIRTY_MIN_IN_MS + 1 , SEVEN_DAYS_IN_MS / 2 , SEVEN_DAYS_IN_MS - 1 , SEVEN_DAYS_IN_MS ]
161- . forEach ( ( ttlMillis ) => {
162- it ( 'should be fulfilled with a Firebase Custom JWT with a valid custom ttl' + JSON . stringify ( ttlMillis ) , ( ) => {
163- return tokenGenerator . createCustomToken ( APP_ID , { ttlMillis } )
164- . should . eventually . be . a ( 'string' ) . and . not . be . empty ;
160+ [ [ THIRTY_MIN_IN_MS , '1800s' ] , [ THIRTY_MIN_IN_MS + 1 , '1800.001000000s' ] ,
161+ [ SEVEN_DAYS_IN_MS / 2 , '302400s' ] , [ SEVEN_DAYS_IN_MS - 1 , '604799.999000000s' ] , [ SEVEN_DAYS_IN_MS , '604800s' ] ]
162+ . forEach ( ( ttl ) => {
163+ it ( 'should be fulfilled with a Firebase Custom JWT with a valid custom ttl' + JSON . stringify ( ttl [ 0 ] ) , ( ) => {
164+ return tokenGenerator . createCustomToken ( APP_ID , { ttlMillis : ttl [ 0 ] as number } )
165+ . then ( ( token ) => {
166+ const decoded = jwt . decode ( token ) as { [ key : string ] : any } ;
167+
168+ expect ( decoded [ 'ttl' ] ) . to . equal ( ttl [ 1 ] ) ;
169+ } ) ;
165170 } ) ;
166171 } ) ;
167172
@@ -207,7 +212,7 @@ describe('AppCheckTokenGenerator', () => {
207212 } ) ;
208213 } ) ;
209214
210- [ [ 1800000.000001 , '1800.000000001s' ] , [ 1800000.001 , '1800.000001000s ' ] , [ 172800000 , '172800s' ] ,
215+ [ [ 1800000.000001 , '1800.000000001s' ] , [ 1800000.001 , '1800.000000999s ' ] , [ 172800000 , '172800s' ] ,
211216 [ 604799999 , '604799.999000000s' ] , [ 604800000 , '604800s' ]
212217 ] . forEach ( ( ttl ) => {
213218 it ( 'should be fulfilled with a JWT with custom ttl in decoded payload' , ( ) => {
0 commit comments