Skip to content

Commit 058e411

Browse files
Add test to verify notifications from other sources are ignored (#8903)
1 parent 0e15427 commit 058e411

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

Firestore/core/test/unit/credentials/firebase_app_check_credentials_provider_test.mm

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ - (nonnull NSString*)tokenDidChangeNotificationName {
159159
credentials_provider.SetCredentialChangeListener(
160160
[token_promise](const std::string& result) {
161161
if (result != "") {
162-
EXPECT_EQ("updated_app_check_token", result);
163162
token_promise->set_value(result);
164163
}
165164
});
@@ -176,6 +175,49 @@ - (nonnull NSString*)tokenDidChangeNotificationName {
176175
auto kTimeout = std::chrono::seconds(5);
177176
auto token_future = token_promise->get_future();
178177
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());
179221
}
180222

181223
} // namespace credentials

0 commit comments

Comments
 (0)