Skip to content

Commit 6a329cb

Browse files
authored
Fix the restorePreviousSignIn when completion is nil (#301)
1 parent 20d4955 commit 6a329cb

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

GoogleSignIn/Sources/GIDSignIn.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ - (void)restorePreviousSignInWithCompletion:(nullable void (^)(GIDGoogleUser *_N
202202
NSError *_Nullable error))completion {
203203
[self signInWithOptions:[GIDSignInInternalOptions silentOptionsWithCompletion:
204204
^(GIDSignInResult *signInResult, NSError *error) {
205+
if (!completion) {
206+
return;
207+
}
205208
if (signInResult) {
206209
completion(signInResult.user, nil);
207210
} else {

GoogleSignIn/Tests/Unit/GIDSignInTest.m

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,39 @@ - (void)testRestorePreviousSignInWhenSignedOut {
503503
[_authState verify];
504504
}
505505

506+
- (void)testNotRestorePreviousSignInWhenSignedOutAndCompletionIsNil {
507+
[[[_authorization expect] andReturn:_authState] authState];
508+
[[[_authState expect] andReturnValue:[NSNumber numberWithBool:NO]] isAuthorized];
509+
510+
[_signIn restorePreviousSignInWithCompletion:nil];
511+
512+
XCTAssertNil(_signIn.currentUser);
513+
}
514+
515+
- (void)testRestorePreviousSignInWhenCompletionIsNil {
516+
[[[_authorization expect] andReturn:_authState] authState];
517+
[[[_authState expect] andReturnValue:[NSNumber numberWithBool:YES]] isAuthorized];
518+
519+
OIDTokenResponse *tokenResponse =
520+
[OIDTokenResponse testInstanceWithIDToken:[OIDTokenResponse fatIDToken]
521+
accessToken:kAccessToken
522+
expiresIn:nil
523+
refreshToken:kRefreshToken
524+
tokenRequest:nil];
525+
526+
[[[_authState stub] andReturn:tokenResponse] lastTokenResponse];
527+
528+
// TODO: Create a real GIDGoogleUser to verify the signed in user value(#306).
529+
[[[_user stub] andReturn:_user] alloc];
530+
(void)[[[_user expect] andReturn:_user] initWithAuthState:OCMOCK_ANY
531+
profileData:OCMOCK_ANY];
532+
XCTAssertNil(_signIn.currentUser);
533+
534+
[_signIn restorePreviousSignInWithCompletion:nil];
535+
536+
XCTAssertNotNil(_signIn.currentUser);
537+
}
538+
506539
- (void)testOAuthLogin {
507540
[self OAuthLoginWithAddScopesFlow:NO
508541
authError:nil
@@ -1239,7 +1272,7 @@ - (void)OAuthLoginWithAddScopesFlow:(BOOL)addScopesFlow
12391272
[[[_authState expect] andReturn:tokenResponse] lastTokenResponse];
12401273
if (oldAccessToken) {
12411274
#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
1242-
// Corresponds to EMM support
1275+
// Corresponds to EMM support
12431276
[[[_authState expect] andReturn:authResponse] lastAuthorizationResponse];
12441277
#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
12451278
[[[_authState expect] andReturn:tokenResponse] lastTokenResponse];

0 commit comments

Comments
 (0)