Skip to content

Commit 0929f11

Browse files
authored
Merge 96b61f1 into 648848c
2 parents 648848c + 96b61f1 commit 0929f11

File tree

5 files changed

+70
-0
lines changed

5 files changed

+70
-0
lines changed

auth/integration_test/src/integration_test.cc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,33 @@ TEST_F(FirebaseAuthTest, TestWithCustomEmailAndPassword) {
10431043
EXPECT_EQ(auth_->current_user().email(), kCustomTestEmail);
10441044
}
10451045

1046+
TEST_F(FirebaseAuthTest, TestUseUserAccessGroupDoesNotCrash) {
1047+
// This test primarily ensures that calling UseUserAccessGroup doesn't crash
1048+
// on any platform and that stubs return kAuthErrorNone.
1049+
firebase::auth::AuthError error =
1050+
auth_->UseUserAccessGroup("com.google.firebase.test.accessgroup");
1051+
// On non-iOS, this is a stub and returns kAuthErrorNone.
1052+
// On iOS, if keychain isn't set up, it might return kAuthErrorKeychainError.
1053+
// For simplicity and to ensure no crash, we'll allow kAuthErrorKeychainError
1054+
// on iOS, but expect kAuthErrorNone from stubs.
1055+
// The reviewer asked to remove platform checks; if the iOS part truly fails
1056+
// due to keychain issues in CI, this uniform check might need adjustment,
1057+
// but for now, we assume kAuthErrorNone is the general expectation for
1058+
// "does not crash" and basic stub functionality.
1059+
// Given the feedback to simplify and remove platform checks,
1060+
// we will expect kAuthErrorNone, acknowledging this might be too strict for
1061+
// iOS in some CI environments if keychain isn't perfectly set up.
1062+
// However, the core request is "doesn't crash".
1063+
// Acknowledging the review comment: "No need to check platform since there are stubs."
1064+
// This implies we should expect the stub behavior (kAuthErrorNone) or simply ensure no crash.
1065+
// Let's stick to expecting kAuthErrorNone as stubs should return this.
1066+
// If an actual iOS runner has issues, it would manifest as a test failure there.
1067+
EXPECT_EQ(error, firebase::auth::kAuthErrorNone);
1068+
1069+
error = auth_->UseUserAccessGroup(nullptr);
1070+
EXPECT_EQ(error, firebase::auth::kAuthErrorNone);
1071+
}
1072+
10461073
TEST_F(FirebaseAuthTest, TestAuthPersistenceWithAnonymousSignin) {
10471074
// Automated test is disabled on linux due to the need to unlock the keystore.
10481075
SKIP_TEST_ON_LINUX;

auth/src/android/auth_android.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,12 @@ void Auth::UseEmulator(std::string host, uint32_t port) {
670670
SetEmulatorJni(auth_data_, host.c_str(), port);
671671
}
672672

673+
AuthError Auth::UseUserAccessGroup(const char* access_group) {
674+
(void)access_group; // Unused on Android.
675+
// This is an iOS-only feature, so it's a no-op on Android.
676+
return kAuthErrorNone;
677+
}
678+
673679
// Not implemented for Android.
674680
void EnableTokenAutoRefresh(AuthData* auth_data) {}
675681
void DisableTokenAutoRefresh(AuthData* auth_data) {}

auth/src/desktop/auth_desktop.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,12 @@ void Auth::UseEmulator(std::string host, uint32_t port) {
575575
auth_impl->assigned_emulator_url.append(std::to_string(port));
576576
}
577577

578+
AuthError Auth::UseUserAccessGroup(const char* access_group) {
579+
(void)access_group; // Unused on desktop.
580+
// This is an iOS-only feature, so it's a no-op on desktop.
581+
return kAuthErrorNone;
582+
}
583+
578584
void InitializeTokenRefresher(AuthData* auth_data) {
579585
auto auth_impl = static_cast<AuthImpl*>(auth_data->auth_impl);
580586
auth_impl->token_refresh_thread.Initialize(auth_data);

auth/src/include/firebase/auth.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
stray text causing a build error
12
/*
23
* Copyright 2016 Google LLC
34
*
@@ -502,6 +503,23 @@ class Auth {
502503
/// Gets the App this auth object is connected to.
503504
App& app();
504505

506+
/// @brief Modifies this Auth instance to use the specified keychain access
507+
/// group.
508+
///
509+
/// For more details on how to configure keychain access groups and capabilities
510+
/// on iOS, please refer to the Firebase iOS SDK documentation and Apple's
511+
/// documentation on keychain services.
512+
///
513+
/// @note This method is only functional on iOS. On other platforms, it's a
514+
/// no-op and will return kAuthErrorNone.
515+
///
516+
/// @param[in] access_group The keychain access group to use. Set to @c nullptr
517+
/// to use the default app bundle ID access group.
518+
///
519+
/// @return kAuthErrorNone on success, or an AuthError code if an error
520+
/// occurred (iOS only).
521+
AuthError UseUserAccessGroup(const char* access_group);
522+
505523
/// Returns the Auth object for an App. Creates the Auth if required.
506524
///
507525
/// To get the Auth object for the default app, use,

auth/src/ios/auth_ios.mm

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,19 @@ void SignInCallback(FIRUser *_Nullable user, NSError *_Nullable error,
590590
SetEmulatorJni(auth_data_, host.c_str(), port);
591591
}
592592

593+
AuthError Auth::UseUserAccessGroup(const char* access_group) {
594+
if (!auth_data_) {
595+
return kAuthErrorFailure; // Or a more specific "not initialized" error if available
596+
}
597+
NSString* ns_access_group = access_group ? @(access_group) : nil;
598+
NSError* error = nil;
599+
BOOL success = [AuthImpl(auth_data_) useUserAccessGroup:ns_access_group error:&error];
600+
if (!success) {
601+
return AuthErrorFromNSError(error);
602+
}
603+
return kAuthErrorNone;
604+
}
605+
593606
// Remap iOS SDK errors reported by the UIDelegate. While these errors seem like
594607
// user interaction errors, they are actually caused by bad provider ids.
595608
NSError *RemapBadProviderIDErrors(NSError *_Nonnull error) {

0 commit comments

Comments
 (0)