diff --git a/GoogleSignIn/Sources/GIDAuthStateMigration.m b/GoogleSignIn/Sources/GIDAuthStateMigration.m index 4df01d11..3085fa76 100644 --- a/GoogleSignIn/Sources/GIDAuthStateMigration.m +++ b/GoogleSignIn/Sources/GIDAuthStateMigration.m @@ -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. @@ -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 @@ -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 diff --git a/GoogleSignIn/Tests/Unit/GIDAuthStateMigrationTest.m b/GoogleSignIn/Tests/Unit/GIDAuthStateMigrationTest.m index 6379fb4f..a26acc9e 100644 --- a/GoogleSignIn/Tests/Unit/GIDAuthStateMigrationTest.m +++ b/GoogleSignIn/Tests/Unit/GIDAuthStateMigrationTest.m @@ -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; @@ -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 { @@ -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 { @@ -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]; @@ -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]; @@ -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]; @@ -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];