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

Fix the restorePreviousSignIn when completion is nil #301

Merged
merged 6 commits into from
May 4, 2023
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
3 changes: 3 additions & 0 deletions GoogleSignIn/Sources/GIDSignIn.m
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ - (void)restorePreviousSignInWithCompletion:(nullable void (^)(GIDGoogleUser *_N
NSError *_Nullable error))completion {
[self signInWithOptions:[GIDSignInInternalOptions silentOptionsWithCompletion:
^(GIDSignInResult *signInResult, NSError *error) {
if (!completion) {
return;
}
if (signInResult) {
completion(signInResult.user, nil);
} else {
Expand Down
35 changes: 34 additions & 1 deletion GoogleSignIn/Tests/Unit/GIDSignInTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,39 @@ - (void)testRestorePreviousSignInWhenSignedOut {
[_authState verify];
}

- (void)testNotRestorePreviousSignInWhenSignedOutAndCompletionIsNil {
[[[_authorization expect] andReturn:_authState] authState];
[[[_authState expect] andReturnValue:[NSNumber numberWithBool:NO]] isAuthorized];

[_signIn restorePreviousSignInWithCompletion:nil];

XCTAssertNil(_signIn.currentUser);
}

- (void)testRestorePreviousSignInWhenCompletionIsNil {
[[[_authorization expect] andReturn:_authState] authState];
[[[_authState expect] andReturnValue:[NSNumber numberWithBool:YES]] isAuthorized];

OIDTokenResponse *tokenResponse =
[OIDTokenResponse testInstanceWithIDToken:[OIDTokenResponse fatIDToken]
accessToken:kAccessToken
expiresIn:nil
refreshToken:kRefreshToken
tokenRequest:nil];

[[[_authState stub] andReturn:tokenResponse] lastTokenResponse];

// TODO: Create a real GIDGoogleUser to verify the signed in user value(#306).
[[[_user stub] andReturn:_user] alloc];
(void)[[[_user expect] andReturn:_user] initWithAuthState:OCMOCK_ANY
mdmathias marked this conversation as resolved.
Show resolved Hide resolved
profileData:OCMOCK_ANY];
XCTAssertNil(_signIn.currentUser);

[_signIn restorePreviousSignInWithCompletion:nil];

XCTAssertNotNil(_signIn.currentUser);
}

- (void)testOAuthLogin {
[self OAuthLoginWithAddScopesFlow:NO
authError:nil
Expand Down Expand Up @@ -1239,7 +1272,7 @@ - (void)OAuthLoginWithAddScopesFlow:(BOOL)addScopesFlow
[[[_authState expect] andReturn:tokenResponse] lastTokenResponse];
if (oldAccessToken) {
#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
// Corresponds to EMM support
// Corresponds to EMM support
[[[_authState expect] andReturn:authResponse] lastAuthorizationResponse];
#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
[[[_authState expect] andReturn:tokenResponse] lastTokenResponse];
Expand Down