@@ -159,7 +159,6 @@ - (nonnull NSString*)tokenDidChangeNotificationName {
159
159
credentials_provider.SetCredentialChangeListener (
160
160
[token_promise](const std::string& result) {
161
161
if (result != " " ) {
162
- EXPECT_EQ (" updated_app_check_token" , result);
163
162
token_promise->set_value (result);
164
163
}
165
164
});
@@ -176,6 +175,49 @@ - (nonnull NSString*)tokenDidChangeNotificationName {
176
175
auto kTimeout = std::chrono::seconds (5 );
177
176
auto token_future = token_promise->get_future ();
178
177
ASSERT_EQ (std::future_status::ready, token_future.wait_for (kTimeout ));
178
+
179
+ EXPECT_EQ (" updated_app_check_token" , token_future.get ());
180
+ }
181
+
182
+ // Regression test for https://github.com/firebase/firebase-ios-sdk/issues/8895
183
+ TEST (FirebaseAppCheckCredentialsProviderTest,
184
+ ListenForTokenChangesIgnoresUnrelatedNotifcations) {
185
+ auto token_promise = std::make_shared<std::promise<std::string>>();
186
+
187
+ FIRApp* app = testutil::AppForUnitTesting ();
188
+ FSTAppCheckFake* app_check = [[FSTAppCheckFake alloc ] initWithToken: @" " ];
189
+ FirebaseAppCheckCredentialsProvider credentials_provider (app, app_check);
190
+
191
+ credentials_provider.SetCredentialChangeListener (
192
+ [token_promise](const std::string& result) {
193
+ if (result != " " ) {
194
+ token_promise->set_value (result);
195
+ }
196
+ });
197
+
198
+ [[NSNotificationCenter defaultCenter ]
199
+ postNotificationName: @" unrelated"
200
+ object: app_check
201
+ userInfo: @{
202
+ [app_check notificationTokenKey ] : @" token1" ,
203
+ [app_check notificationAppNameKey ] : [app name ],
204
+ }];
205
+
206
+ [[NSNotificationCenter defaultCenter ]
207
+ postNotificationName: [app_check tokenDidChangeNotificationName ]
208
+ object: app_check
209
+ userInfo: @{
210
+ [app_check notificationTokenKey ] : @" token2" ,
211
+ [app_check notificationAppNameKey ] : [app name ],
212
+ }];
213
+
214
+ auto kTimeout = std::chrono::seconds (5 );
215
+ auto token_future = token_promise->get_future ();
216
+ ASSERT_EQ (std::future_status::ready, token_future.wait_for (kTimeout ));
217
+
218
+ // Verify that we get 'token2`, which is the second notification but the
219
+ // only one that uses the AppCheck topic.
220
+ EXPECT_EQ (" token2" , token_future.get ());
179
221
}
180
222
181
223
} // namespace credentials
0 commit comments