From 2dbd46ac4d7b4e3e69f6ccdfc1300b6b6e6816c7 Mon Sep 17 00:00:00 2001 From: Camden King Date: Thu, 5 Jun 2025 13:18:16 -0700 Subject: [PATCH 1/2] update GIDAuthStateMMigration to treat catalyst apps as iOS apps --- GoogleSignIn/Sources/GIDAuthStateMigration.m | 12 ++++---- .../Tests/Unit/GIDAuthStateMigrationTest.m | 28 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/GoogleSignIn/Sources/GIDAuthStateMigration.m b/GoogleSignIn/Sources/GIDAuthStateMigration.m index 4df01d11..97a9cb08 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 [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 [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. @@ -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..d42f3e7a 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]; @@ -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 [[[_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 [[_mockUserDefaults expect] setBool:YES forKey:kGTMAppAuthMigrationCheckPerformedKey]; -#endif // TARGET_OS_OSX || TARGET_OS_MACCATALYST +#endif // TARGET_OS_OSX GIDAuthStateMigration *migration = [[GIDAuthStateMigration alloc] initWithKeychainStore:_mockGTMKeychainStore]; From 09676789f3d9e312ed19e04a4fe0bf08b2b690e9 Mon Sep 17 00:00:00 2001 From: Camden King Date: Mon, 9 Jun 2025 10:27:16 -0700 Subject: [PATCH 2/2] don't perform GTMAppAuth migration on catalyst --- GoogleSignIn/Sources/GIDAuthStateMigration.m | 6 +++--- GoogleSignIn/Tests/Unit/GIDAuthStateMigrationTest.m | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/GoogleSignIn/Sources/GIDAuthStateMigration.m b/GoogleSignIn/Sources/GIDAuthStateMigration.m index 97a9cb08..3085fa76 100644 --- a/GoogleSignIn/Sources/GIDAuthStateMigration.m +++ b/GoogleSignIn/Sources/GIDAuthStateMigration.m @@ -73,7 +73,7 @@ - (void)migrateIfNeededWithTokenURL:(NSURL *)tokenURL NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; #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 return; @@ -81,7 +81,7 @@ - (void)migrateIfNeededWithTokenURL:(NSURL *)tokenURL #if TARGET_OS_OSX [self performDataProtectedMigrationIfNeeded]; -#elif TARGET_OS_IOS +#elif TARGET_OS_IOS && !TARGET_OS_MACCATALYST [self performGIDMigrationIfNeededWithTokenURL:tokenURL callbackPath:callbackPath keychainName:keychainName]; @@ -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 diff --git a/GoogleSignIn/Tests/Unit/GIDAuthStateMigrationTest.m b/GoogleSignIn/Tests/Unit/GIDAuthStateMigrationTest.m index d42f3e7a..a26acc9e 100644 --- a/GoogleSignIn/Tests/Unit/GIDAuthStateMigrationTest.m +++ b/GoogleSignIn/Tests/Unit/GIDAuthStateMigrationTest.m @@ -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]; @@ -249,7 +249,7 @@ - (void)testMigrateIfNeeded_HasPreviousMigration { #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 @@ -266,7 +266,7 @@ - (void)testMigrateIfNeeded_isFreshInstall { [[[_mockUserDefaults stub] andReturn:_mockUserDefaults] standardUserDefaults]; #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