@@ -32,6 +32,12 @@ class ContextProviderTests: XCTestCase {
32
32
code: - 1 ,
33
33
userInfo: nil
34
34
) )
35
+ let appCheckLimitedUseTokenError = FIRAppCheckTokenResultFake ( token: " limited use token " ,
36
+ error: NSError (
37
+ domain: " testAppCheckError " ,
38
+ code: - 1 ,
39
+ userInfo: nil
40
+ ) )
35
41
let appCheckTokenSuccess = FIRAppCheckTokenResultFake ( token: " valid_token " , error: nil )
36
42
let messagingFake = FIRMessagingInteropFake ( )
37
43
@@ -143,8 +149,20 @@ class ContextProviderTests: XCTestCase {
143
149
144
150
XCTAssertNil ( context. authToken)
145
151
XCTAssertNil ( context. fcmToken)
146
- // Don't expect any token in the case of App Check error.
147
- XCTAssertNil ( context. appCheckToken)
152
+ // Expect placeholder token in the case of App Check error.
153
+ XCTAssertEqual ( context. appCheckToken, appCheckFake. tokenResult. token)
154
+ }
155
+
156
+ func testAsyncContextWithAppCheckOnlyError_LimitedUseToken( ) async throws {
157
+ appCheckFake. limitedUseTokenResult = appCheckLimitedUseTokenError
158
+ let provider = FunctionsContextProvider ( auth: nil , messaging: nil , appCheck: appCheckFake)
159
+
160
+ let context = try await provider. context ( options: . init( requireLimitedUseAppCheckTokens: true ) )
161
+
162
+ XCTAssertNil ( context. authToken)
163
+ XCTAssertNil ( context. fcmToken)
164
+ // Expect placeholder token in the case of App Check error.
165
+ XCTAssertEqual ( context. limitedUseAppCheckToken, appCheckFake. limitedUseTokenResult. token)
148
166
}
149
167
150
168
func testContextWithAppCheckOnlyError( ) {
@@ -156,8 +174,24 @@ class ContextProviderTests: XCTestCase {
156
174
XCTAssertNil ( error)
157
175
XCTAssertNil ( context. authToken)
158
176
XCTAssertNil ( context. fcmToken)
159
- // Don't expect any token in the case of App Check error.
160
- XCTAssertNil ( context. appCheckToken)
177
+ // Expect placeholder token in the case of App Check error.
178
+ XCTAssertEqual ( context. appCheckToken, self . appCheckFake. tokenResult. token)
179
+ expectation. fulfill ( )
180
+ }
181
+ waitForExpectations ( timeout: 0.1 )
182
+ }
183
+
184
+ func testContextWithAppCheckOnlyError_LimitedUseToken( ) {
185
+ appCheckFake. limitedUseTokenResult = appCheckLimitedUseTokenError
186
+ let provider = FunctionsContextProvider ( auth: nil , messaging: nil , appCheck: appCheckFake)
187
+ let expectation = expectation ( description: " Verify bad app check token " )
188
+ provider. getContext ( options: . init( requireLimitedUseAppCheckTokens: true ) ) { context, error in
189
+ XCTAssertNotNil ( context)
190
+ XCTAssertNil ( error)
191
+ XCTAssertNil ( context. authToken)
192
+ XCTAssertNil ( context. fcmToken)
193
+ // Expect placeholder token in the case of App Check error.
194
+ XCTAssertEqual ( context. limitedUseAppCheckToken, self . appCheckFake. limitedUseTokenResult. token)
161
195
expectation. fulfill ( )
162
196
}
163
197
waitForExpectations ( timeout: 0.1 )
@@ -264,8 +298,30 @@ class ContextProviderTests: XCTestCase {
264
298
XCTAssertEqual ( error as NSError ? , authError)
265
299
XCTAssertNil ( context. authToken)
266
300
XCTAssertEqual ( context. fcmToken, self . messagingFake. fcmToken)
267
- // Don't expect any token in the case of App Check error.
268
- XCTAssertNil ( context. appCheckToken)
301
+ // Expect placeholder token in the case of App Check error.
302
+ XCTAssertEqual ( context. appCheckToken, self . appCheckFake. tokenResult. token)
303
+ expectation. fulfill ( )
304
+ }
305
+ waitForExpectations ( timeout: 0.1 )
306
+ }
307
+
308
+ func testAllContextsAuthAndAppCheckError_LimitedUseToken( ) {
309
+ appCheckFake. limitedUseTokenResult = appCheckLimitedUseTokenError
310
+ let authError = NSError ( domain: " com.functions.tests " , code: 4 , userInfo: nil )
311
+ let auth = FIRAuthInteropFake ( token: nil , userID: " userID " , error: authError)
312
+ let provider = FunctionsContextProvider (
313
+ auth: auth,
314
+ messaging: messagingFake,
315
+ appCheck: appCheckFake
316
+ )
317
+ let expectation = expectation ( description: " All contexts with errors " )
318
+ provider. getContext ( options: . init( requireLimitedUseAppCheckTokens: true ) ) { context, error in
319
+ XCTAssertNotNil ( context)
320
+ XCTAssertEqual ( error as NSError ? , authError)
321
+ XCTAssertNil ( context. authToken)
322
+ XCTAssertEqual ( context. fcmToken, self . messagingFake. fcmToken)
323
+ // Expect placeholder token in the case of App Check error.
324
+ XCTAssertEqual ( context. limitedUseAppCheckToken, self . appCheckFake. limitedUseTokenResult. token)
269
325
expectation. fulfill ( )
270
326
}
271
327
waitForExpectations ( timeout: 0.1 )
0 commit comments