@@ -19,6 +19,7 @@ import * as chai from 'chai';
19
19
import * as chaiAsPromised from 'chai-as-promised' ;
20
20
import * as firebase from '../src/api' ;
21
21
import { base64 } from '@firebase/util' ;
22
+ import { _FirebaseApp } from '@firebase/app-types/private' ;
22
23
23
24
const expect = chai . expect ;
24
25
@@ -60,8 +61,12 @@ describe('Testing Module Tests', function() {
60
61
projectId : 'foo' ,
61
62
auth : undefined
62
63
} ) ;
63
- const token = await ( app as any ) . INTERNAL . getToken ( ) ;
64
- expect ( token ) . to . be . null ;
64
+
65
+ const authInternal = ( ( app as unknown ) as _FirebaseApp ) . container
66
+ . getProvider ( 'auth-internal' )
67
+ . getImmediate ( { optional : true } ) ;
68
+ // Auth instance will not be available because no API Key is provided
69
+ expect ( authInternal ) . to . be . null ;
65
70
} ) ;
66
71
67
72
it ( 'initializeTestApp() with auth sets the correct access token' , async function ( ) {
@@ -70,20 +75,28 @@ describe('Testing Module Tests', function() {
70
75
projectId : 'foo' ,
71
76
auth : auth
72
77
} ) ;
73
- const token = await ( app as any ) . INTERNAL . getToken ( ) ;
78
+ const authInternal = ( ( app as unknown ) as _FirebaseApp ) . container
79
+ . getProvider ( 'auth-internal' )
80
+ . getImmediate ( ) ;
81
+
82
+ const token = await authInternal . getToken ( ) ;
74
83
expect ( token ) . to . have . keys ( 'accessToken' ) ;
75
84
const claims = JSON . parse (
76
- base64 . decodeString ( token . accessToken . split ( '.' ) [ 1 ] , /*webSafe=*/ false )
85
+ base64 . decodeString ( token ! . accessToken . split ( '.' ) [ 1 ] , /*webSafe=*/ false )
77
86
) ;
78
87
// We add an 'iat' field.
79
88
expect ( claims ) . to . deep . equal ( { uid : auth . uid , iat : 0 , sub : auth . uid } ) ;
80
89
} ) ;
81
90
82
91
it ( 'initializeAdminApp() sets the access token to "owner"' , async function ( ) {
83
92
const app = firebase . initializeAdminApp ( { projectId : 'foo' } ) ;
84
- const token = await ( app as any ) . INTERNAL . getToken ( ) ;
93
+ const authInternal = ( ( app as unknown ) as _FirebaseApp ) . container
94
+ . getProvider ( 'auth-internal' )
95
+ . getImmediate ( ) ;
96
+
97
+ const token = await authInternal . getToken ( ) ;
85
98
expect ( token ) . to . have . keys ( 'accessToken' ) ;
86
- expect ( token . accessToken ) . to . be . string ( 'owner' ) ;
99
+ expect ( token ! . accessToken ) . to . be . string ( 'owner' ) ;
87
100
} ) ;
88
101
89
102
it ( 'loadDatabaseRules() throws if no databaseName or rules' , async function ( ) {
0 commit comments