Skip to content

Commit 55b88cc

Browse files
committed
update tests
1 parent 7a7483c commit 55b88cc

2 files changed

Lines changed: 39 additions & 36 deletions

File tree

GoogleSignIn/Sources/GIDAuthStateMigration.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ - (void)migrateIfNeededWithTokenURL:(NSURL *)tokenURL
7676
[defaults setBool:YES forKey:kDataProtectedMigrationCheckPerformedKey];
7777
#elif TARGET_OS_IOS
7878
[defaults setBool:YES forKey:kGTMAppAuthMigrationCheckPerformedKey];
79-
#endif
79+
#endif // TARGET_OS_OSX || TARGET_OS_MACCATALYST
8080
return;
8181
}
8282

@@ -85,8 +85,8 @@ - (void)migrateIfNeededWithTokenURL:(NSURL *)tokenURL
8585
#elif TARGET_OS_IOS
8686
[self performGIDMigrationIfNeededWithTokenURL:tokenURL
8787
callbackPath:callbackPath
88-
keychainName:keychainName]
89-
#endif
88+
keychainName:keychainName];
89+
#endif // TARGET_OS_OSX || TARGET_OS_MACCATALYST
9090
}
9191

9292
#if TARGET_OS_OSX || TARGET_OS_MACCATALYST
@@ -116,7 +116,7 @@ - (void)performDataProtectedMigrationIfNeeded {
116116
}
117117

118118
// Mark the migration check as having been performed.
119-
[defaults setBool:YES forKey:kDataProtectgedMigrationCheckPerformedKey];
119+
[defaults setBool:YES forKey:kDataProtectedMigrationCheckPerformedKey];
120120
}
121121

122122
#elif TARGET_OS_IOS
@@ -247,7 +247,7 @@ + (nullable NSString *)passwordForService:(NSString *)service {
247247
NSString *password = [[NSString alloc] initWithData:passwordData encoding:NSUTF8StringEncoding];
248248
return password;
249249
}
250-
#endif
250+
#endif // TARGET_OS_OSX || TARGET_OS_MACCATALYST
251251

252252
@end
253253

GoogleSignIn/Tests/Unit/GIDAuthStateMigrationTest.m

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ - (void)setUp {
105105
NSSet *attributes = [NSSet setWithArray:@[fileBasedKeychain]];
106106
_realLegacyGTMKeychainStore = [[GTMKeychainStore alloc] initWithItemName:kKeychainName
107107
keychainAttributes:attributes];
108-
#endif
108+
#endif // TARGET_OS_OSX || TARGET_OS_MACCATALYST
109109
}
110110

111111
- (void)tearDown {
@@ -127,7 +127,7 @@ - (void)tearDown {
127127
[_mockGTMOAuth2Compatibility stopMocking];
128128
#if TARGET_OS_OSX || TARGET_OS_MACCATALYST
129129
[_realLegacyGTMKeychainStore removeAuthSessionWithError:nil];
130-
#endif
130+
#endif // TARGET_OS_OSX || TARGET_OS_MACCATALYST
131131

132132
[super tearDown];
133133
}
@@ -188,11 +188,13 @@ - (void)testMigrateIfNeeded_KeychainFailure_DataProtectedMigration {
188188

189189
- (void)testMigrateIfNeeded_NoPreviousMigration_GTMAppAuthMigration {
190190
[[[_mockUserDefaults stub] andReturn:_mockUserDefaults] standardUserDefaults];
191-
[[[_mockUserDefaults expect] andReturnValue:@NO] boolForKey:kMigrationCheckPerformedKey];
192-
[[_mockUserDefaults expect] setBool:YES forKey:kMigrationCheckPerformedKey];
191+
[[[_mockUserDefaults expect] andReturnValue:@NO] boolForKey:kGTMAppAuthMigrationCheckPerformedKey];
192+
[[_mockUserDefaults expect] setBool:YES forKey:kGTMAppAuthMigrationCheckPerformedKey];
193193

194194
[[_mockGTMKeychainStore expect] saveAuthSession:OCMOCK_ANY error:OCMArg.anyObjectRef];
195195

196+
[self setUpCommonExtractAuthorizationMocksWithFingerPrint:kSavedFingerprint];
197+
196198
GIDAuthStateMigration *migration =
197199
[[GIDAuthStateMigration alloc] initWithKeychainStore:_mockGTMKeychainStore];
198200
[migration migrateIfNeededWithTokenURL:[NSURL URLWithString:kTokenURL]
@@ -203,7 +205,7 @@ - (void)testMigrateIfNeeded_NoPreviousMigration_GTMAppAuthMigration {
203205

204206
- (void)testMigrateIfNeeded_KeychainFailure_GTMAppAuthMigration {
205207
[[[_mockUserDefaults stub] andReturn:_mockUserDefaults] standardUserDefaults];
206-
[[[_mockUserDefaults expect] andReturnValue:@NO] boolForKey:kMigrationCheckPerformedKey];
208+
[[[_mockUserDefaults expect] andReturnValue:@NO] boolForKey:kGTMAppAuthMigrationCheckPerformedKey];
207209

208210
NSError *keychainSaveError = [NSError new];
209211
OCMStub([_mockGTMKeychainStore saveAuthSession:OCMOCK_ANY error:[OCMArg setTo:keychainSaveError]]);
@@ -218,9 +220,30 @@ - (void)testMigrateIfNeeded_KeychainFailure_GTMAppAuthMigration {
218220
isFreshInstall:NO];
219221
}
220222

221-
#endif
223+
- (void)testExtractAuthorization {
224+
[self setUpCommonExtractAuthorizationMocksWithFingerPrint:kSavedFingerprint];
225+
226+
GIDAuthStateMigration *migration =
227+
[[GIDAuthStateMigration alloc] initWithKeychainStore:_mockGTMKeychainStore];
228+
GTMAuthSession *authorization =
229+
[migration extractAuthSessionWithTokenURL:[NSURL URLWithString:kTokenURL]
230+
callbackPath:kCallbackPath];
222231

232+
XCTAssertNotNil(authorization);
233+
}
223234

235+
- (void)testExtractAuthorization_HostedDomain {
236+
[self setUpCommonExtractAuthorizationMocksWithFingerPrint:kSavedFingerprint_HostedDomain];
237+
238+
GIDAuthStateMigration *migration =
239+
[[GIDAuthStateMigration alloc] initWithKeychainStore:_mockGTMKeychainStore];
240+
GTMAuthSession *authorization =
241+
[migration extractAuthSessionWithTokenURL:[NSURL URLWithString:kTokenURL]
242+
callbackPath:kCallbackPath];
243+
244+
XCTAssertNotNil(authorization);
245+
}
246+
#endif
224247

225248
- (void)testMigrateIfNeeded_HasPreviousMigration {
226249
[[[_mockUserDefaults stub] andReturn:_mockUserDefaults] standardUserDefaults];
@@ -242,9 +265,11 @@ - (void)testMigrateIfNeeded_HasPreviousMigration {
242265

243266
- (void)testMigrateIfNeeded_isFreshInstall {
244267
[[[_mockUserDefaults stub] andReturn:_mockUserDefaults] standardUserDefaults];
245-
[[[_mockUserDefaults expect] andReturnValue:@NO]
246-
boolForKey:kMigrationCheckPerformedKey];
247-
[[_mockUserDefaults expect] setBool:YES forKey:kMigrationCheckPerformedKey];
268+
#if TARGET_OS_OSX || TARGET_OS_MACCATALYST
269+
[[_mockUserDefaults expect] setBool:YES forKey:kDataProtectedMigrationCheckPerformedKey];
270+
#else
271+
[[_mockUserDefaults expect] setBool:YES forKey:kGTMAppAuthMigrationCheckPerformedKey];
272+
#endif // TARGET_OS_OSX || TARGET_OS_MACCATALYST
248273

249274
GIDAuthStateMigration *migration =
250275
[[GIDAuthStateMigration alloc] initWithKeychainStore:_mockGTMKeychainStore];
@@ -254,29 +279,7 @@ - (void)testMigrateIfNeeded_isFreshInstall {
254279
isFreshInstall:YES];
255280
}
256281

257-
- (void)testExtractAuthorization {
258-
[self setUpCommonExtractAuthorizationMocksWithFingerPrint:kSavedFingerprint];
259-
260-
GIDAuthStateMigration *migration =
261-
[[GIDAuthStateMigration alloc] initWithKeychainStore:_mockGTMKeychainStore];
262-
GTMAuthSession *authorization =
263-
[migration extractAuthSessionWithTokenURL:[NSURL URLWithString:kTokenURL]
264-
callbackPath:kCallbackPath];
265-
266-
XCTAssertNotNil(authorization);
267-
}
268-
269-
- (void)testExtractAuthorization_HostedDomain {
270-
[self setUpCommonExtractAuthorizationMocksWithFingerPrint:kSavedFingerprint_HostedDomain];
271282

272-
GIDAuthStateMigration *migration =
273-
[[GIDAuthStateMigration alloc] initWithKeychainStore:_mockGTMKeychainStore];
274-
GTMAuthSession *authorization =
275-
[migration extractAuthSessionWithTokenURL:[NSURL URLWithString:kTokenURL]
276-
callbackPath:kCallbackPath];
277-
278-
XCTAssertNotNil(authorization);
279-
}
280283

281284
#pragma mark - Helpers
282285

0 commit comments

Comments
 (0)