Skip to content
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
18 changes: 9 additions & 9 deletions GoogleSignIn/Sources/GIDAuthStateMigration.m
Original file line numberDiff line numberDiff line change
Expand Up@@ -71,24 +71,24 @@ - (void)migrateIfNeededWithTokenURL:(NSURL *)tokenURL
// performed.
if (isFreshInstall) {
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
#if TARGET_OS_OSX || TARGET_OS_MACCATALYST
#if TARGET_OS_OSX
[defaults setBool:YES forKey:kDataProtectedMigrationCheckPerformedKey];
#elif TARGET_OS_IOS
#elif TARGET_OS_IOS && !TARGET_OS_MACCATALYST
[defaults setBool:YES forKey:kGTMAppAuthMigrationCheckPerformedKey];
#endif // TARGET_OS_OSX || TARGET_OS_MACCATALYST
#endif // TARGET_OS_OSX
return;
}

#if TARGET_OS_OSX || TARGET_OS_MACCATALYST
#if TARGET_OS_OSX
[self performDataProtectedMigrationIfNeeded];
#elif TARGET_OS_IOS
#elif TARGET_OS_IOS && !TARGET_OS_MACCATALYST
[self performGIDMigrationIfNeededWithTokenURL:tokenURL
callbackPath:callbackPath
keychainName:keychainName];
#endif // TARGET_OS_OSX || TARGET_OS_MACCATALYST
#endif // TARGET_OS_OSX
}

#if TARGET_OS_OSX || TARGET_OS_MACCATALYST
#if TARGET_OS_OSX
// Migrate from the fileBasedKeychain to dataProtectedKeychain with GTMAppAuth 5.0.
- (void)performDataProtectedMigrationIfNeeded {
// See if we've performed the migration check previously.
Expand DownExpand Up@@ -118,7 +118,7 @@ - (void)performDataProtectedMigrationIfNeeded {
[defaults setBool:YES forKey:kDataProtectedMigrationCheckPerformedKey];
}

#elif TARGET_OS_IOS
#elif TARGET_OS_IOS && !TARGET_OS_MACCATALYST
// Migrate from GPPSignIn 1.x or GIDSignIn 1.0 - 4.x to the GTMAppAuth storage introduced in
// GIDSignIn 5.0.
- (void)performGIDMigrationIfNeededWithTokenURL:(NSURL *)tokenURL
Expand DownExpand Up@@ -246,7 +246,7 @@ + (nullable NSString *)passwordForService:(NSString *)service {
NSString *password = [[NSString alloc] initWithData:passwordData encoding:NSUTF8StringEncoding];
return password;
}
#endif // TARGET_OS_OSX || TARGET_OS_MACCATALYST
#endif // TARGET_OS_OSX

@end

Expand Down
34 changes: 17 additions & 17 deletions GoogleSignIn/Tests/Unit/GIDAuthStateMigrationTest.m
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,9 +16,9 @@

#import "GoogleSignIn/Sources/GIDAuthStateMigration.h"
#import "GoogleSignIn/Sources/GIDSignInCallbackSchemes.h"
#if TARGET_OS_OSX || TARGET_OS_MACCATALYST
#if TARGET_OS_OSX
#import "GoogleSignIn/Tests/Unit/OIDAuthState+Testing.h"
#endif // TARGET_OS_OSX || TARGET_OS_MACCATALYST
#endif // TARGET_OS_OSX

@import GTMAppAuth;

Expand DownExpand Up@@ -84,9 +84,9 @@ @implementation GIDAuthStateMigrationTest {
id _mockNSBundle;
id _mockGIDSignInCallbackSchemes;
id _mockGTMOAuth2Compatibility;
#if TARGET_OS_OSX || TARGET_OS_MACCATALYST
#if TARGET_OS_OSX
id _realLegacyGTMKeychainStore;
#endif // TARGET_OS_OSX || TARGET_OS_MACCATALYST
#endif // TARGET_OS_OSX
}

- (void)setUp {
Expand All@@ -100,12 +100,12 @@ - (void)setUp {
_mockNSBundle = OCMStrictClassMock([NSBundle class]);
_mockGIDSignInCallbackSchemes = OCMStrictClassMock([GIDSignInCallbackSchemes class]);
_mockGTMOAuth2Compatibility = OCMStrictClassMock([GTMOAuth2Compatibility class]);
#if TARGET_OS_OSX || TARGET_OS_MACCATALYST
#if TARGET_OS_OSX
GTMKeychainAttribute *fileBasedKeychain = [GTMKeychainAttribute useFileBasedKeychain];
NSSet *attributes = [NSSet setWithArray:@[fileBasedKeychain]];
_realLegacyGTMKeychainStore = [[GTMKeychainStore alloc] initWithItemName:kKeychainName
keychainAttributes:attributes];
#endif // TARGET_OS_OSX || TARGET_OS_MACCATALYST
#endif // TARGET_OS_OSX
}

- (void)tearDown {
Expand All@@ -125,16 +125,16 @@ - (void)tearDown {
[_mockGIDSignInCallbackSchemes stopMocking];
[_mockGTMOAuth2Compatibility verify];
[_mockGTMOAuth2Compatibility stopMocking];
#if TARGET_OS_OSX || TARGET_OS_MACCATALYST
#if TARGET_OS_OSX
[_realLegacyGTMKeychainStore removeAuthSessionWithError:nil];
#endif // TARGET_OS_OSX || TARGET_OS_MACCATALYST
#endif // TARGET_OS_OSX

[super tearDown];
}

#pragma mark - Tests

#if TARGET_OS_OSX || TARGET_OS_MACCATALYST
#if TARGET_OS_OSX
- (void)testMigrateIfNeeded_NoPreviousMigration_DataProtectedMigration {
[[[_mockUserDefaults stub] andReturn:_mockUserDefaults] standardUserDefaults];
[[[_mockUserDefaults expect] andReturnValue:@NO] boolForKey:kDataProtectedMigrationCheckPerformedKey];
Expand DownExpand Up@@ -184,7 +184,7 @@ - (void)testMigrateIfNeeded_KeychainFailure_DataProtectedMigration {
XCTAssertNotNil([_realLegacyGTMKeychainStore retrieveAuthSessionWithError:nil]);
}

#else
#elif TARGET_OS_IOS && !TARGET_OS_MACCATALYST
- (void)testMigrateIfNeeded_NoPreviousMigration_GTMAppAuthMigration {
[[[_mockUserDefaults stub] andReturn:_mockUserDefaults] standardUserDefaults];
[[[_mockUserDefaults expect] andReturnValue:@NO] boolForKey:kGTMAppAuthMigrationCheckPerformedKey];
Expand DownExpand Up@@ -242,17 +242,17 @@ - (void)testExtractAuthorization_HostedDomain {

XCTAssertNotNil(authorization);
}
#endif // TARGET_OS_OSX || TARGET_OS_MACCATALYST
#endif // TARGET_OS_OSX

- (void)testMigrateIfNeeded_HasPreviousMigration {
[[[_mockUserDefaults stub] andReturn:_mockUserDefaults] standardUserDefaults];
#if TARGET_OS_OSX || TARGET_OS_MACCATALYST
#if TARGET_OS_OSX
[[[_mockUserDefaults expect] andReturnValue:@YES] boolForKey:kDataProtectedMigrationCheckPerformedKey];
[[_mockUserDefaults reject] setBool:YES forKey:kDataProtectedMigrationCheckPerformedKey];
#else
#elif TARGET_OS_IOS && !TARGET_OS_MACCATALYST
[[[_mockUserDefaults expect] andReturnValue:@YES] boolForKey:kGTMAppAuthMigrationCheckPerformedKey];
[[_mockUserDefaults reject] setBool:YES forKey:kGTMAppAuthMigrationCheckPerformedKey];
#endif // TARGET_OS_OSX || TARGET_OS_MACCATALYST
#endif // TARGET_OS_OSX

GIDAuthStateMigration *migration =
[[GIDAuthStateMigration alloc] initWithKeychainStore:_mockGTMKeychainStore];
Expand All@@ -264,11 +264,11 @@ - (void)testMigrateIfNeeded_HasPreviousMigration {

- (void)testMigrateIfNeeded_isFreshInstall {
[[[_mockUserDefaults stub] andReturn:_mockUserDefaults] standardUserDefaults];
#if TARGET_OS_OSX || TARGET_OS_MACCATALYST
#if TARGET_OS_OSX
[[_mockUserDefaults expect] setBool:YES forKey:kDataProtectedMigrationCheckPerformedKey];
#else
#elif TARGET_OS_IOS && !TARGET_OS_MACCATALYST
[[_mockUserDefaults expect] setBool:YES forKey:kGTMAppAuthMigrationCheckPerformedKey];
#endif // TARGET_OS_OSX || TARGET_OS_MACCATALYST
#endif // TARGET_OS_OSX

GIDAuthStateMigration *migration =
[[GIDAuthStateMigration alloc] initWithKeychainStore:_mockGTMKeychainStore];
Expand Down