Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Auth] Address possible race condition #13772

Merged
merged 6 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions FirebaseAuth/Sources/Swift/Backend/AuthBackend.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,19 @@ class AuthBackend {
return "FirebaseAuth.iOS/\(FirebaseVersion()) \(GTMFetcherStandardUserAgentString(nil))"
}

private static var gBackendImplementation: AuthBackendImplementation?
private static var realRPCBackend = AuthBackendRPCImplementation()
private static var gBackendImplementation = realRPCBackend

class func setDefaultBackendImplementationWithRPCIssuer(issuer: AuthBackendRPCIssuer?) {
let defaultImplementation = AuthBackendRPCImplementation()
if let issuer = issuer {
defaultImplementation.rpcIssuer = issuer
}
gBackendImplementation = defaultImplementation
class func setTestRPCIssuer(issuer: AuthBackendRPCIssuer) {
gBackendImplementation.rpcIssuer = issuer
}

class func resetRPCIssuer() {
gBackendImplementation.rpcIssuer = realRPCBackend.rpcIssuer
}

class func implementation() -> AuthBackendImplementation {
if gBackendImplementation == nil {
gBackendImplementation = AuthBackendRPCImplementation()
}
return gBackendImplementation!
return gBackendImplementation
}

class func call<T: AuthRPCRequest>(with request: T) async throws -> T.Response {
Expand Down
31 changes: 0 additions & 31 deletions FirebaseAuth/Tests/Unit/FIROAuthProviderTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@
@import FirebaseAuth;
@import FirebaseCore;

/** @var kExpectationTimeout
@brief The maximum time waiting for expectations to fulfill.
*/
static const NSTimeInterval kExpectationTimeout = 1;

/** @var kFakeAuthorizedDomain
@brief A fake authorized domain for the app.
*/
Expand Down Expand Up @@ -162,32 +157,6 @@ - (void)testObtainingOAuthCredentialWithIDToken {
XCTAssertEqualObjects(OAuthCredential.IDToken, kFakeIDToken);
}

/** @fn testGetCredentialWithUIDelegateWithClientIDOnMainThread
@brief Verifies @c getCredentialWithUIDelegate:completion: calls its completion handler on the
main thread. Regression test for firebase/FirebaseUI-iOS#1199.
*/
- (void)testGetCredentialWithUIDelegateWithClientIDOnMainThread {
XCTestExpectation *expectation = [self expectationWithDescription:@"callback"];

FIROptions *options =
[[FIROptions alloc] initWithGoogleAppID:@"0:0000000000000:ios:0000000000000000"
GCMSenderID:@"00000000000000000-00000000000-000000000"];
options.APIKey = kFakeAPIKey;
options.projectID = @"myProjectID";
options.clientID = kFakeClientID;
[FIRApp configureWithName:@"objAppName" options:options];
FIRAuth *auth = [FIRAuth authWithApp:[FIRApp appNamed:@"objAppName"]];
[auth setMainBundleUrlTypes:@[ @{@"CFBundleURLSchemes" : @[ kFakeReverseClientID ]} ]];

FIROAuthProvider *provider = [FIROAuthProvider providerWithProviderID:kFakeProviderID auth:auth];
[provider getCredentialWithUIDelegate:nil
completion:^(FIRAuthCredential *_Nullable credential,
NSError *_Nullable error) {
XCTAssertTrue([NSThread isMainThread]);
[expectation fulfill];
}];
[self waitForExpectationsWithTimeout:kExpectationTimeout handler:nil];
}
@end

#endif // TARGET_OS_IOS
4 changes: 2 additions & 2 deletions FirebaseAuth/Tests/Unit/RPCBaseTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ class RPCBaseTests: XCTestCase {

override func setUp() {
rpcIssuer = FakeBackendRPCIssuer()
AuthBackend.setDefaultBackendImplementationWithRPCIssuer(issuer: rpcIssuer)
AuthBackend.setTestRPCIssuer(issuer: rpcIssuer)
rpcImplementation = AuthBackend.implementation()
}

override func tearDown() {
rpcIssuer = nil
AuthBackend.setDefaultBackendImplementationWithRPCIssuer(issuer: nil)
AuthBackend.resetRPCIssuer()
}

/** @fn checkRequest
Expand Down
Loading