@@ -19,7 +19,19 @@ import { expect } from 'chai';
19
19
import '../test/setup' ;
20
20
import { ComponentContainer } from '@firebase/component' ;
21
21
import { FirebaseServerAppImpl } from './firebaseServerApp' ;
22
- import { FirebaseServerAppSettings } from './public-types' ;
22
+ import { FirebaseApp , FirebaseServerAppSettings } from './public-types' ;
23
+
24
+ const VALID_INSTATLLATIONS_AUTH_TOKEN_SECONDPART : string =
25
+ 'foo.eyJhcHBJZCI6IjE6MDAwMDAwMDAwMDAwOndlYjowMDAwMDAwMDAwMDAwMDAwMDAwMDAwIiwiZXhwIjoiMDAwMDAwMD' +
26
+ 'AwMCIsImZpZCI6IjAwMDAwMDAwMDAwMDAwMDAwMDAwMDAiLCJwcm9qZWN0TnVtYmVyIjoiMDAwMDAwMDAwMDAwIn0.foo' ;
27
+
28
+ const INVALID_INSTATLLATIONS_AUTH_TOKEN : string =
29
+ 'foo.eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9eyJhcHBJZCI6IjE6MDAwMDAwMDAwMDAwOndlYjowMDAwMDAwMDAwMD' +
30
+ 'AwMDAwMDAwMDAwIiwiZXhwIjowMDAwMDAwMDAwLCJwcm9qZWN0TnVtYmVyIjowMDAwMDAwMDAwMDB9.foo' ;
31
+
32
+ const INVALID_INSTATLLATIONS_AUTH_TOKEN_ONE_PART : string =
33
+ 'eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9eyJhcHBJZCI6IjE6MDAwMDAwMDAwMDAwOndlYjowMDAwMDAwMDAwMD' +
34
+ 'AwMDAwMDAwMDAwIiwiZXhwIjowMDAwMDAwMDAwLCJwcm9qZWN0TnVtYmVyIjowMDAwMDAwMDAwMDB9' ;
23
35
24
36
describe ( 'FirebaseServerApp' , ( ) => {
25
37
it ( 'has various accessors' , ( ) => {
@@ -155,4 +167,74 @@ describe('FirebaseServerApp', () => {
155
167
156
168
expect ( JSON . stringify ( app ) ) . to . eql ( undefined ) ;
157
169
} ) ;
170
+
171
+ it ( 'parses valid installationsAuthToken' , ( ) => {
172
+ const options = {
173
+ apiKey : 'APIKEY'
174
+ } ;
175
+
176
+ const serverAppSettings : FirebaseServerAppSettings = {
177
+ automaticDataCollectionEnabled : false ,
178
+ installationsAuthToken : VALID_INSTATLLATIONS_AUTH_TOKEN_SECONDPART
179
+ } ;
180
+
181
+ let app : FirebaseApp | null = null ;
182
+ try {
183
+ app = new FirebaseServerAppImpl (
184
+ options ,
185
+ serverAppSettings ,
186
+ 'testName' ,
187
+ new ComponentContainer ( 'test' )
188
+ ) ;
189
+ } catch ( e ) { }
190
+ expect ( app ) . to . not . be . null ;
191
+ } ) ;
192
+
193
+ it ( 'invalid installationsAuthToken throws' , ( ) => {
194
+ const options = {
195
+ apiKey : 'APIKEY'
196
+ } ;
197
+
198
+ const serverAppSettings : FirebaseServerAppSettings = {
199
+ automaticDataCollectionEnabled : false ,
200
+ installationsAuthToken : INVALID_INSTATLLATIONS_AUTH_TOKEN
201
+ } ;
202
+
203
+ let failed = false ;
204
+ try {
205
+ new FirebaseServerAppImpl (
206
+ options ,
207
+ serverAppSettings ,
208
+ 'testName' ,
209
+ new ComponentContainer ( 'test' )
210
+ ) ;
211
+ } catch ( e ) {
212
+ failed = true ;
213
+ }
214
+ expect ( failed ) . to . be . true ;
215
+ } ) ;
216
+
217
+ it ( 'invalid single part installationsAuthToken throws' , ( ) => {
218
+ const options = {
219
+ apiKey : 'APIKEY'
220
+ } ;
221
+
222
+ const serverAppSettings : FirebaseServerAppSettings = {
223
+ automaticDataCollectionEnabled : false ,
224
+ installationsAuthToken : INVALID_INSTATLLATIONS_AUTH_TOKEN_ONE_PART
225
+ } ;
226
+
227
+ let failed = false ;
228
+ try {
229
+ new FirebaseServerAppImpl (
230
+ options ,
231
+ serverAppSettings ,
232
+ 'testName' ,
233
+ new ComponentContainer ( 'test' )
234
+ ) ;
235
+ } catch ( e ) {
236
+ failed = true ;
237
+ }
238
+ expect ( failed ) . to . be . true ;
239
+ } ) ;
158
240
} ) ;
0 commit comments