5252static NSString *const kRedirectURI =
5353 @" com.googleusercontent.apps.223520599684-kg64hfn0h950oureqacja2fltg00msv3:/callback/path" ;
5454
55- static NSString *const kMigrationCheckPerformedKey = @" GID_MigrationCheckPerformed" ;
55+ static NSString *const kGTMAppAuthMigrationCheckPerformedKey = @" GID_MigrationCheckPerformed" ;
56+ static NSString *const kDataProtectedMigrationCheckPerformedKey =
57+ @" GID_DataProtectedMigrationCheckPerformed" ;
5658static NSString *const kFingerprintService = @" fingerprint" ;
5759
5860NS_ASSUME_NONNULL_BEGIN
@@ -132,39 +134,64 @@ - (void)tearDown {
132134
133135#pragma mark - Tests
134136
135- - (void )testMigrateIfNeeded_NoPreviousMigration {
137+ #if TARGET_OS_OSX || TARGET_OS_MACCATALYST
138+ - (void )testMigrateIfNeeded_NoPreviousMigration_DataProtectedMigration {
136139 [[[_mockUserDefaults stub ] andReturn: _mockUserDefaults] standardUserDefaults ];
137- [[[_mockUserDefaults expect ] andReturnValue: @NO ] boolForKey: kMigrationCheckPerformedKey ];
138- [[_mockUserDefaults expect ] setBool: YES forKey: kMigrationCheckPerformedKey ];
140+ [[[_mockUserDefaults expect ] andReturnValue: @NO ] boolForKey: kDataProtectedMigrationCheckPerformedKey ];
141+ [[_mockUserDefaults expect ] setBool: YES forKey: kDataProtectedMigrationCheckPerformedKey ];
139142
140143 [[_mockGTMKeychainStore expect ] saveAuthSession: OCMOCK_ANY error: OCMArg.anyObjectRef];
141-
142- #if TARGET_OS_OSX || TARGET_OS_MACCATALYST
143144 [[[_mockGTMKeychainStore expect ] andReturn: kKeychainName ] itemName ];
145+
146+ // set the auth session that will be migrated
144147 OIDAuthState *authState = [OIDAuthState testInstance ];
145148 GTMAuthSession *authSession = [[GTMAuthSession alloc ] initWithAuthState: authState];
146149 NSError *err;
147150 [_realLegacyGTMKeychainStore saveAuthSession: authSession error: &err];
148151 XCTAssertNil (err);
149- #else
150- [self setUpCommonExtractAuthorizationMocksWithFingerPrint: kSavedFingerprint ];
151- #endif
152152
153153 GIDAuthStateMigration *migration =
154154 [[GIDAuthStateMigration alloc ] initWithKeychainStore: _mockGTMKeychainStore];
155155 [migration migrateIfNeededWithTokenURL: [NSURL URLWithString: kTokenURL ]
156156 callbackPath: kCallbackPath
157157 keychainName: kKeychainName
158158 isFreshInstall: NO ];
159- #if TARGET_OS_OSX || TARGET_OS_MACCATALYST
159+
160+ // verify that the auth session was removed during migration
160161 XCTAssertNil ([_realLegacyGTMKeychainStore retrieveAuthSessionWithError: nil ]);
161- #endif
162162}
163163
164- - (void )testMigrateIfNeeded_HasPreviousMigration {
164+ - (void )testMigrateIfNeeded_KeychainFailure_DataProtectedMigration {
165+ [[[_mockUserDefaults stub ] andReturn: _mockUserDefaults] standardUserDefaults ];
166+ [[[_mockUserDefaults expect ] andReturnValue: @NO ] boolForKey: kDataProtectedMigrationCheckPerformedKey ];
167+
168+ NSError *keychainSaveError = [NSError new ];
169+ OCMStub ([_mockGTMKeychainStore saveAuthSession: OCMOCK_ANY error: [OCMArg setTo: keychainSaveError]]);
170+
171+ [[[_mockGTMKeychainStore expect ] andReturn: kKeychainName ] itemName ];
172+ OIDAuthState *authState = [OIDAuthState testInstance ];
173+ GTMAuthSession *authSession = [[GTMAuthSession alloc ] initWithAuthState: authState];
174+ NSError *err;
175+ [_realLegacyGTMKeychainStore saveAuthSession: authSession error: &err];
176+ XCTAssertNil (err);
177+
178+ GIDAuthStateMigration *migration =
179+ [[GIDAuthStateMigration alloc ] initWithKeychainStore: _mockGTMKeychainStore];
180+ [migration migrateIfNeededWithTokenURL: [NSURL URLWithString: kTokenURL ]
181+ callbackPath: kCallbackPath
182+ keychainName: kKeychainName
183+ isFreshInstall: NO ];
184+ XCTAssertNotNil ([_realLegacyGTMKeychainStore retrieveAuthSessionWithError: nil ]);
185+ }
186+
187+ #else
188+
189+ - (void )testMigrateIfNeeded_NoPreviousMigration_GTMAppAuthMigration {
165190 [[[_mockUserDefaults stub ] andReturn: _mockUserDefaults] standardUserDefaults ];
166- [[[_mockUserDefaults expect ] andReturnValue: @YES ] boolForKey: kMigrationCheckPerformedKey ];
167- [[_mockUserDefaults reject ] setBool: YES forKey: kMigrationCheckPerformedKey ];
191+ [[[_mockUserDefaults expect ] andReturnValue: @NO ] boolForKey: kMigrationCheckPerformedKey ];
192+ [[_mockUserDefaults expect ] setBool: YES forKey: kMigrationCheckPerformedKey ];
193+
194+ [[_mockGTMKeychainStore expect ] saveAuthSession: OCMOCK_ANY error: OCMArg.anyObjectRef];
168195
169196 GIDAuthStateMigration *migration =
170197 [[GIDAuthStateMigration alloc ] initWithKeychainStore: _mockGTMKeychainStore];
@@ -174,33 +201,43 @@ - (void)testMigrateIfNeeded_HasPreviousMigration {
174201 isFreshInstall: NO ];
175202}
176203
177- - (void )testMigrateIfNeeded_KeychainFailure {
204+ - (void )testMigrateIfNeeded_KeychainFailure_GTMAppAuthMigration {
178205 [[[_mockUserDefaults stub ] andReturn: _mockUserDefaults] standardUserDefaults ];
179206 [[[_mockUserDefaults expect ] andReturnValue: @NO ] boolForKey: kMigrationCheckPerformedKey ];
180207
181208 NSError *keychainSaveError = [NSError new ];
182209 OCMStub ([_mockGTMKeychainStore saveAuthSession: OCMOCK_ANY error: [OCMArg setTo: keychainSaveError]]);
183210
184- #if TARGET_OS_OSX || TARGET_OS_MACCATALYST
185- [[[_mockGTMKeychainStore expect ] andReturn: kKeychainName ] itemName ];
186- OIDAuthState *authState = [OIDAuthState testInstance ];
187- GTMAuthSession *authSession = [[GTMAuthSession alloc ] initWithAuthState: authState];
188- NSError *err;
189- [_realLegacyGTMKeychainStore saveAuthSession: authSession error: &err];
190- XCTAssertNil (err);
191- #else
192211 [self setUpCommonExtractAuthorizationMocksWithFingerPrint: kSavedFingerprint ];
193- #endif
194212
195213 GIDAuthStateMigration *migration =
196214 [[GIDAuthStateMigration alloc ] initWithKeychainStore: _mockGTMKeychainStore];
197215 [migration migrateIfNeededWithTokenURL: [NSURL URLWithString: kTokenURL ]
198216 callbackPath: kCallbackPath
199217 keychainName: kKeychainName
200218 isFreshInstall: NO ];
219+ }
220+
221+ #endif
222+
223+
224+
225+ - (void )testMigrateIfNeeded_HasPreviousMigration {
226+ [[[_mockUserDefaults stub ] andReturn: _mockUserDefaults] standardUserDefaults ];
201227#if TARGET_OS_OSX || TARGET_OS_MACCATALYST
202- XCTAssertNotNil ([_realLegacyGTMKeychainStore retrieveAuthSessionWithError: nil ]);
228+ [[[_mockUserDefaults expect ] andReturnValue: @YES ] boolForKey: kDataProtectedMigrationCheckPerformedKey ];
229+ [[_mockUserDefaults reject ] setBool: YES forKey: kDataProtectedMigrationCheckPerformedKey ];
230+ #else
231+ [[[_mockUserDefaults expect ] andReturnValue: @YES ] boolForKey: kGTMAppAuthMigrationCheckPerformedKey ];
232+ [[_mockUserDefaults reject ] setBool: YES forKey: kGTMAppAuthMigrationCheckPerformedKey ];
203233#endif
234+
235+ GIDAuthStateMigration *migration =
236+ [[GIDAuthStateMigration alloc ] initWithKeychainStore: _mockGTMKeychainStore];
237+ [migration migrateIfNeededWithTokenURL: [NSURL URLWithString: kTokenURL ]
238+ callbackPath: kCallbackPath
239+ keychainName: kKeychainName
240+ isFreshInstall: NO ];
204241}
205242
206243- (void )testMigrateIfNeeded_isFreshInstall {
0 commit comments