Skip to content

Commit 143c169

Browse files
authored
[Auth] Address possible race condition (#13772)
1 parent 995c933 commit 143c169

File tree

3 files changed

+11
-44
lines changed

3 files changed

+11
-44
lines changed

FirebaseAuth/Sources/Swift/Backend/AuthBackend.swift

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,19 @@ class AuthBackend {
7676
return "FirebaseAuth.iOS/\(FirebaseVersion()) \(GTMFetcherStandardUserAgentString(nil))"
7777
}
7878

79-
private static var gBackendImplementation: AuthBackendImplementation?
79+
private static var realRPCBackend = AuthBackendRPCImplementation()
80+
private static var gBackendImplementation = realRPCBackend
8081

81-
class func setDefaultBackendImplementationWithRPCIssuer(issuer: AuthBackendRPCIssuer?) {
82-
let defaultImplementation = AuthBackendRPCImplementation()
83-
if let issuer = issuer {
84-
defaultImplementation.rpcIssuer = issuer
85-
}
86-
gBackendImplementation = defaultImplementation
82+
class func setTestRPCIssuer(issuer: AuthBackendRPCIssuer) {
83+
gBackendImplementation.rpcIssuer = issuer
84+
}
85+
86+
class func resetRPCIssuer() {
87+
gBackendImplementation.rpcIssuer = realRPCBackend.rpcIssuer
8788
}
8889

8990
class func implementation() -> AuthBackendImplementation {
90-
if gBackendImplementation == nil {
91-
gBackendImplementation = AuthBackendRPCImplementation()
92-
}
93-
return gBackendImplementation!
91+
return gBackendImplementation
9492
}
9593

9694
class func call<T: AuthRPCRequest>(with request: T) async throws -> T.Response {

FirebaseAuth/Tests/Unit/FIROAuthProviderTests.m

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@
2222
@import FirebaseAuth;
2323
@import FirebaseCore;
2424

25-
/** @var kExpectationTimeout
26-
@brief The maximum time waiting for expectations to fulfill.
27-
*/
28-
static const NSTimeInterval kExpectationTimeout = 1;
29-
3025
/** @var kFakeAuthorizedDomain
3126
@brief A fake authorized domain for the app.
3227
*/
@@ -162,32 +157,6 @@ - (void)testObtainingOAuthCredentialWithIDToken {
162157
XCTAssertEqualObjects(OAuthCredential.IDToken, kFakeIDToken);
163158
}
164159

165-
/** @fn testGetCredentialWithUIDelegateWithClientIDOnMainThread
166-
@brief Verifies @c getCredentialWithUIDelegate:completion: calls its completion handler on the
167-
main thread. Regression test for firebase/FirebaseUI-iOS#1199.
168-
*/
169-
- (void)testGetCredentialWithUIDelegateWithClientIDOnMainThread {
170-
XCTestExpectation *expectation = [self expectationWithDescription:@"callback"];
171-
172-
FIROptions *options =
173-
[[FIROptions alloc] initWithGoogleAppID:@"0:0000000000000:ios:0000000000000000"
174-
GCMSenderID:@"00000000000000000-00000000000-000000000"];
175-
options.APIKey = kFakeAPIKey;
176-
options.projectID = @"myProjectID";
177-
options.clientID = kFakeClientID;
178-
[FIRApp configureWithName:@"objAppName" options:options];
179-
FIRAuth *auth = [FIRAuth authWithApp:[FIRApp appNamed:@"objAppName"]];
180-
[auth setMainBundleUrlTypes:@[ @{@"CFBundleURLSchemes" : @[ kFakeReverseClientID ]} ]];
181-
182-
FIROAuthProvider *provider = [FIROAuthProvider providerWithProviderID:kFakeProviderID auth:auth];
183-
[provider getCredentialWithUIDelegate:nil
184-
completion:^(FIRAuthCredential *_Nullable credential,
185-
NSError *_Nullable error) {
186-
XCTAssertTrue([NSThread isMainThread]);
187-
[expectation fulfill];
188-
}];
189-
[self waitForExpectationsWithTimeout:kExpectationTimeout handler:nil];
190-
}
191160
@end
192161

193162
#endif // TARGET_OS_IOS

FirebaseAuth/Tests/Unit/RPCBaseTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ class RPCBaseTests: XCTestCase {
7272

7373
override func setUp() {
7474
rpcIssuer = FakeBackendRPCIssuer()
75-
AuthBackend.setDefaultBackendImplementationWithRPCIssuer(issuer: rpcIssuer)
75+
AuthBackend.setTestRPCIssuer(issuer: rpcIssuer)
7676
rpcImplementation = AuthBackend.implementation()
7777
}
7878

7979
override func tearDown() {
8080
rpcIssuer = nil
81-
AuthBackend.setDefaultBackendImplementationWithRPCIssuer(issuer: nil)
81+
AuthBackend.resetRPCIssuer()
8282
}
8383

8484
/** @fn checkRequest

0 commit comments

Comments
 (0)