@@ -107,6 +107,25 @@ class ContextProviderTests: XCTestCase {
107
107
waitForExpectations ( timeout: 0.1 )
108
108
}
109
109
110
+ func testContextWithAppCheckWithoutOptionalMethods( ) {
111
+ let appCheck = AppCheckFakeWithoutOptionalMethods ( tokenResult: appCheckTokenSuccess)
112
+ let provider = FunctionsContextProvider ( auth: nil , messaging: nil , appCheck: appCheck)
113
+ let expectation =
114
+ expectation ( description: " Verify non-implemented method for limited-use tokens " )
115
+ provider. getContext ( options: . init( requireLimitedUseAppCheckTokens: true ) ) { context, error in
116
+ XCTAssertNotNil ( context)
117
+ XCTAssertNil ( error)
118
+ XCTAssertNil ( context. authToken)
119
+ XCTAssertNil ( context. fcmToken)
120
+ XCTAssertNil ( context. appCheckToken)
121
+ // If the method for limited-use tokens is not implemented, the value should be `nil`:
122
+ XCTAssertNil ( context. limitedUseAppCheckToken)
123
+ expectation. fulfill ( )
124
+ }
125
+ // Importantly, `getContext(options:_:)` must still finish in a timely manner:
126
+ waitForExpectations ( timeout: 0.1 )
127
+ }
128
+
110
129
func testAllContextsAvailableSuccess( ) {
111
130
appCheckFake. tokenResult = appCheckTokenSuccess
112
131
let auth = FIRAuthInteropFake ( token: " token " , userID: " userID " , error: nil )
@@ -149,3 +168,21 @@ class ContextProviderTests: XCTestCase {
149
168
waitForExpectations ( timeout: 0.1 )
150
169
}
151
170
}
171
+
172
+ // MARK: - Utilities
173
+
174
+ private class AppCheckFakeWithoutOptionalMethods : NSObject , AppCheckInterop {
175
+ let tokenResult : FIRAppCheckTokenResultInterop
176
+
177
+ init ( tokenResult: FIRAppCheckTokenResultInterop ) {
178
+ self . tokenResult = tokenResult
179
+ }
180
+
181
+ func getToken( forcingRefresh: Bool , completion handler: @escaping AppCheckTokenHandlerInterop ) {
182
+ handler ( tokenResult)
183
+ }
184
+
185
+ func tokenDidChangeNotificationName( ) -> String { " AppCheckFakeTokenDidChangeNotification " }
186
+ func notificationTokenKey( ) -> String { " AppCheckFakeTokenNotificationKey " }
187
+ func notificationAppNameKey( ) -> String { " AppCheckFakeAppNameNotificationKey " }
188
+ }
0 commit comments