Skip to content

Commit 76980bf

Browse files
[Messaging] macOS keychain auth prompt fix (#10166)
* macOS keychain auth prompt fix * Fix unit test failures on macOS * group all tests under single #if
1 parent ef68626 commit 76980bf

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

FirebaseMessaging/Sources/Token/FIRMessagingAuthKeychain.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ + (NSMutableDictionary *)keychainQueryForService:(NSString *)service
6565
if ([service length] && ![kFIRMessagingKeychainWildcardIdentifier isEqualToString:service]) {
6666
finalQuery[(__bridge NSString *)kSecAttrService] = service;
6767
}
68+
69+
if (@available(iOS 13.0, macOS 10.15, macCatalyst 13.0, tvOS 13.0, watchOS 6.0, *)) {
70+
// Ensures that the keychain query behaves the same across all platforms.
71+
// See go/firebase-macos-keychain-popups for details.
72+
finalQuery[(__bridge id)kSecUseDataProtectionKeychain] = (__bridge id)kCFBooleanTrue;
73+
}
74+
6875
return finalQuery;
6976
}
7077

FirebaseMessaging/Tests/UnitTests/FIRMessagingAuthKeychainTest.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,11 @@ - (void)testKeyChainNoCorruptionWithUniqueService {
214214
#endif
215215
}
216216

217+
// Skip keychain tests on Catalyst and macOS. Tests are skipped because they
218+
// involve interactions with the keychain that require a provisioning profile.
219+
// See go/firebase-macos-keychain-popups for more details.
220+
#if !TARGET_OS_MACCATALYST && !TARGET_OS_OSX
221+
217222
- (void)testQueryCachedKeychainItems {
218223
XCTestExpectation *addItemToKeychainExpectation =
219224
[self expectationWithDescription:@"Test added item should be cached properly"];
@@ -396,6 +401,8 @@ - (void)testQueryAndAddEntry {
396401
XCTAssertNotNil(keychain.cachedKeychainData[service][account2]);
397402
}
398403

404+
#endif
405+
399406
#pragma mark - helper function
400407
- (NSData *)tokenDataWithAuthorizedEntity:(NSString *)authorizedEntity
401408
scope:(NSString *)scope

0 commit comments

Comments
 (0)