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 120120// Error string for user cancelations.
121121static NSString *const kUserCanceledError = @" The user canceled the sign-in flow." ;
122122
123- // User preference key to detect fresh install of the app.
124- static NSString *const kAppHasRunBeforeKey = @" GID_AppHasRunBefore" ;
123+ NSString *const kAppHasRunBeforeKey = @" GID_AppHasRunBefore" ;
125124
126125// Maximum retry interval in seconds for the fetcher.
127126static const NSTimeInterval kFetcherMaxRetryInterval = 15.0 ;
@@ -672,6 +671,11 @@ - (instancetype)initWithKeychainStore:(GTMKeychainStore *)keychainStore
672671
673672 // Check to see if the 3P app is being run for the first time after a fresh install.
674673 BOOL isFreshInstall = [self isFreshInstall ];
674+
675+ // If this is a fresh install, ensure that any pre-existing keychain data is purged.
676+ if (isFreshInstall) {
677+ [self removeAllKeychainEntries ];
678+ }
675679
676680 NSString *authorizationEnpointURL = [NSString stringWithFormat: kAuthorizationURLTemplate ,
677681 [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 120120 @" com.google.UnitTests:///emmcallback?action=unrecognized" ;
121121static NSString * const kDevicePolicyAppBundleID = @" com.google.DevicePolicy" ;
122122
123- static NSString * const kAppHasRunBeforeKey = @" GPP_AppHasRunBefore" ;
124-
125123static NSString * const kFingerprintKeychainName = @" fingerprint" ;
126124static NSString * const kVerifierKeychainName = @" verifier" ;
127125static NSString * const kVerifierKey = @" verifier" ;
@@ -1212,6 +1210,18 @@ - (void)testNotHandleWrongPath {
12121210 XCTAssertFalse (_completionCalled, @" should not call delegate" );
12131211}
12141212
1213+ #pragma mark - Test Fresh Install
1214+
1215+ - (void )testFreshInstall_removesKeychainEntries {
1216+ // Simulate that the app has been deleted and user defaults removed.
1217+ [NSUserDefaults .standardUserDefaults removeObjectForKey: kAppHasRunBeforeKey ];
1218+ // Initialization should check `isFreshInstall`.
1219+ GIDSignIn *signIn = [[GIDSignIn alloc ] initWithKeychainStore: _keychainStore
1220+ authStateMigrationService: _authStateMigrationService];
1221+ // If `isFreshInstall`, keychain entries should be removed.
1222+ XCTAssertTrue (self->_keychainRemoved );
1223+ }
1224+
12151225#pragma mark - Tests - disconnectWithCallback:
12161226
12171227// Verifies disconnect calls callback with no errors if access token is present.
You can’t perform that action at this time.
0 commit comments