@@ -131,19 +131,19 @@ describe('AppCheckTokenGenerator', () => {
131
131
} ) ;
132
132
} ) ;
133
133
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 ] ;
135
135
invalidTtls . forEach ( ( invalidTtl ) => {
136
136
it ( 'should throw given an options object with invalid ttl: ' + JSON . stringify ( invalidTtl ) , ( ) => {
137
137
expect ( ( ) => {
138
138
tokenGenerator . createCustomToken ( APP_ID , { ttlMillis : invalidTtl as any } ) ;
139
139
} ) . to . throw ( FirebaseAppCheckError ) . with . property ( 'message' ,
140
- 'ttlMillis must be a non-negative duration in milliseconds.' ) ;
140
+ 'ttlMillis must be a duration in milliseconds.' ) ;
141
141
} ) ;
142
142
} ) ;
143
143
144
144
const THIRTY_MIN_IN_MS = 1800000 ;
145
145
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 ) => {
147
147
it ( 'should throw given options with ttl < 30 minutes or ttl > 7 days:' + JSON . stringify ( ttlMillis ) , ( ) => {
148
148
expect ( ( ) => {
149
149
tokenGenerator . createCustomToken ( APP_ID , { ttlMillis } ) ;
@@ -157,11 +157,16 @@ describe('AppCheckTokenGenerator', () => {
157
157
. should . eventually . be . a ( 'string' ) . and . not . be . empty ;
158
158
} ) ;
159
159
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
+ } ) ;
165
170
} ) ;
166
171
} ) ;
167
172
@@ -207,7 +212,7 @@ describe('AppCheckTokenGenerator', () => {
207
212
} ) ;
208
213
} ) ;
209
214
210
- [ [ 1800000.000001 , '1800.000000001s' ] , [ 1800000.001 , '1800.000001000s ' ] , [ 172800000 , '172800s' ] ,
215
+ [ [ 1800000.000001 , '1800.000000001s' ] , [ 1800000.001 , '1800.000000999s ' ] , [ 172800000 , '172800s' ] ,
211
216
[ 604799999 , '604799.999000000s' ] , [ 604800000 , '604800s' ]
212
217
] . forEach ( ( ttl ) => {
213
218
it ( 'should be fulfilled with a JWT with custom ttl in decoded payload' , ( ) => {
0 commit comments