File tree Expand file tree Collapse file tree 3 files changed +21
-4
lines changed
Expand file tree Collapse file tree 3 files changed +21
-4
lines changed Original file line number Diff line number Diff line change 119119// Error string for user cancelations.
120120static NSString *const kUserCanceledError = @" The user canceled the sign-in flow." ;
121121
122- // User preference key to detect fresh install of the app.
123- static NSString *const kAppHasRunBeforeKey = @" GID_AppHasRunBefore" ;
122+ NSString *const kAppHasRunBeforeKey = @" GID_AppHasRunBefore" ;
124123
125124// Maximum retry interval in seconds for the fetcher.
126125static const NSTimeInterval kFetcherMaxRetryInterval = 15.0 ;
@@ -553,6 +552,11 @@ - (instancetype)initWithKeychainStore:(GTMKeychainStore *)keychainStore
553552
554553 // Check to see if the 3P app is being run for the first time after a fresh install.
555554 BOOL isFreshInstall = [self isFreshInstall ];
555+
556+ // If this is a fresh install, ensure that any pre-existing keychain data is purged.
557+ if (isFreshInstall) {
558+ [self removeAllKeychainEntries ];
559+ }
556560
557561 NSString *authorizationEnpointURL = [NSString stringWithFormat: kAuthorizationURLTemplate ,
558562 [GIDSignInPreferences googleAuthorizationServer ]];
Original file line number Diff line number Diff line change @@ -32,6 +32,9 @@ NS_ASSUME_NONNULL_BEGIN
3232@class GIDAppCheck;
3333@class GIDAuthStateMigration;
3434
35+ // / User preference key to detect fresh install of the app.
36+ extern NSString *const kAppHasRunBeforeKey ;
37+
3538// / Represents a completion block that takes a `GIDSignInResult` on success or an error if the
3639// / operation was unsuccessful.
3740typedef void (^GIDSignInCompletion)(GIDSignInResult *_Nullable signInResult,
Original file line number Diff line number Diff line change 119119 @" com.google.UnitTests:///emmcallback?action=unrecognized" ;
120120static NSString * const kDevicePolicyAppBundleID = @" com.google.DevicePolicy" ;
121121
122- static NSString * const kAppHasRunBeforeKey = @" GPP_AppHasRunBefore" ;
123-
124122static NSString * const kFingerprintKeychainName = @" fingerprint" ;
125123static NSString * const kVerifierKeychainName = @" verifier" ;
126124static NSString * const kVerifierKey = @" verifier" ;
@@ -993,6 +991,18 @@ - (void)testNotHandleWrongPath {
993991 XCTAssertFalse (_completionCalled, @" should not call delegate" );
994992}
995993
994+ #pragma mark - Test Fresh Install
995+
996+ - (void )testFreshInstall_removesKeychainEntries {
997+ // Simulate that the app has been deleted and user defaults removed.
998+ [NSUserDefaults .standardUserDefaults removeObjectForKey: kAppHasRunBeforeKey ];
999+ // Initialization should check `isFreshInstall`.
1000+ GIDSignIn *signIn = [[GIDSignIn alloc ] initWithKeychainStore: _keychainStore
1001+ authStateMigrationService: _authStateMigrationService];
1002+ // If `isFreshInstall`, keychain entries should be removed.
1003+ XCTAssertTrue (self->_keychainRemoved );
1004+ }
1005+
9961006#pragma mark - Tests - disconnectWithCallback:
9971007
9981008// Verifies disconnect calls callback with no errors if access token is present.
You can’t perform that action at this time.
0 commit comments