@@ -32,6 +32,10 @@ import {
32
32
FirebaseAuthInternal ,
33
33
FirebaseAuthInternalName
34
34
} from '@firebase/auth-interop-types' ;
35
+ import {
36
+ FirebaseAppCheckInternal ,
37
+ AppCheckInternalComponentName
38
+ } from '@firebase/app-check-interop-types' ;
35
39
import { makeFakeApp , createTestService } from '../test/utils' ;
36
40
import { httpsCallable } from './service' ;
37
41
import { FUNCTIONS_TYPE } from './constants' ;
@@ -108,7 +112,7 @@ describe('Firebase Functions > Call', () => {
108
112
expect ( result . data ) . to . equal ( 76 ) ;
109
113
} ) ;
110
114
111
- it ( 'token' , async ( ) => {
115
+ it ( 'auth token' , async ( ) => {
112
116
// mock auth-internal service
113
117
const authMock : FirebaseAuthInternal = {
114
118
getToken : async ( ) => ( { accessToken : 'token' } )
@@ -133,6 +137,74 @@ describe('Firebase Functions > Call', () => {
133
137
stub . restore ( ) ;
134
138
} ) ;
135
139
140
+ it ( 'app check token' , async ( ) => {
141
+ const appCheckMock : FirebaseAppCheckInternal = {
142
+ getToken : async ( ) => ( { token : 'app-check-token' } )
143
+ } as unknown as FirebaseAppCheckInternal ;
144
+ const appCheckProvider = new Provider < AppCheckInternalComponentName > (
145
+ 'app-check-internal' ,
146
+ new ComponentContainer ( 'test' )
147
+ ) ;
148
+ appCheckProvider . setComponent (
149
+ new Component (
150
+ 'app-check-internal' ,
151
+ ( ) => appCheckMock ,
152
+ ComponentType . PRIVATE
153
+ )
154
+ ) ;
155
+ const functions = createTestService (
156
+ app ,
157
+ region ,
158
+ undefined ,
159
+ undefined ,
160
+ appCheckProvider
161
+ ) ;
162
+
163
+ // Stub out the internals to get an app check token.
164
+ const stub = sinon . stub ( appCheckMock , 'getToken' ) . callThrough ( ) ;
165
+ const func = httpsCallable ( functions , 'appCheckTest' ) ;
166
+ const result = await func ( { } ) ;
167
+ expect ( result . data ) . to . deep . equal ( { token : 'app-check-token' } ) ;
168
+
169
+ expect ( stub . callCount ) . to . equal ( 1 ) ;
170
+ stub . restore ( ) ;
171
+ } ) ;
172
+
173
+ it ( 'app check limited use token' , async ( ) => {
174
+ const appCheckMock : FirebaseAppCheckInternal = {
175
+ getLimitedUseToken : async ( ) => ( { token : 'app-check-single-use-token' } )
176
+ } as unknown as FirebaseAppCheckInternal ;
177
+ const appCheckProvider = new Provider < AppCheckInternalComponentName > (
178
+ 'app-check-internal' ,
179
+ new ComponentContainer ( 'test' )
180
+ ) ;
181
+ appCheckProvider . setComponent (
182
+ new Component (
183
+ 'app-check-internal' ,
184
+ ( ) => appCheckMock ,
185
+ ComponentType . PRIVATE
186
+ )
187
+ ) ;
188
+ const functions = createTestService (
189
+ app ,
190
+ region ,
191
+ undefined ,
192
+ undefined ,
193
+ appCheckProvider
194
+ ) ;
195
+
196
+ // Stub out the internals to get an app check token.
197
+ const stub = sinon . stub ( appCheckMock , 'getLimitedUseToken' ) . callThrough ( ) ;
198
+ const func = httpsCallable ( functions , 'appCheckTest' , {
199
+ limitedUseAppCheckTokens : true
200
+ } ) ;
201
+ const result = await func ( { } ) ;
202
+ expect ( result . data ) . to . deep . equal ( { token : 'app-check-single-use-token' } ) ;
203
+
204
+ expect ( stub . callCount ) . to . equal ( 1 ) ;
205
+ stub . restore ( ) ;
206
+ } ) ;
207
+
136
208
it ( 'instance id' , async ( ) => {
137
209
// Should effectively skip this test in environments where messaging doesn't work.
138
210
// (Node, IE)
0 commit comments