From 40d9f497a61bd86695c8ad5445f6a848eae69b76 Mon Sep 17 00:00:00 2001 From: Andrew Heard Date: Mon, 24 Jul 2023 10:50:55 -0400 Subject: [PATCH 1/2] Make tokenDelegate nullable in GACAppCheck --- AppCheckCore/Sources/Core/GACAppCheck.m | 10 ++++++---- .../AppCheckCore/{AppCheck.h => AppCheckCore.h} | 0 .../Sources/Public/AppCheckCore/GACAppCheck.h | 12 +++++++++--- AppCheckCore/Tests/Unit/Core/GACAppCheckTests.m | 2 +- 4 files changed, 16 insertions(+), 8 deletions(-) rename AppCheckCore/Sources/Public/AppCheckCore/{AppCheck.h => AppCheckCore.h} (100%) diff --git a/AppCheckCore/Sources/Core/GACAppCheck.m b/AppCheckCore/Sources/Core/GACAppCheck.m index 2437f13bf35..bb8380c9b1b 100644 --- a/AppCheckCore/Sources/Core/GACAppCheck.m +++ b/AppCheckCore/Sources/Core/GACAppCheck.m @@ -48,7 +48,7 @@ @interface GACAppCheck () @property(nonatomic, readonly) id appCheckProvider; @property(nonatomic, readonly) id storage; @property(nonatomic, readonly) id settings; -@property(nonatomic, readonly, weak) id tokenDelegate; +@property(nonatomic, readonly, nullable, weak) id tokenDelegate; @property(nonatomic, readonly, nullable) id tokenRefresher; @@ -65,7 +65,7 @@ - (instancetype)initWithInstanceName:(NSString *)instanceName storage:(id)storage tokenRefresher:(id)tokenRefresher settings:(id)settings - tokenDelegate:(id)tokenDelegate { + tokenDelegate:(nullable id)tokenDelegate { self = [super init]; if (self) { _instanceName = instanceName; @@ -89,7 +89,7 @@ - (instancetype)initWithInstanceName:(NSString *)instanceName - (instancetype)initWithInstanceName:(NSString *)instanceName appCheckProvider:(id)appCheckProvider settings:(id)settings - tokenDelegate:(id)tokenDelegate + tokenDelegate:(nullable id)tokenDelegate resourceName:(NSString *)resourceName keychainAccessGroup:(nullable NSString *)accessGroup { GACAppCheckTokenRefreshResult *refreshResult = @@ -204,7 +204,9 @@ - (void)getLimitedUseTokenWithCompletion:(GACAppCheckTokenHandlerInterop)handler initWithStatusSuccessAndExpirationDate:token.expirationDate receivedAtDate:token.receivedAtDate]; [self.tokenRefresher updateWithRefreshResult:refreshResult]; - [self.tokenDelegate tokenDidUpdate:token instanceName:self.instanceName]; + if (self.tokenDelegate) { + [self.tokenDelegate tokenDidUpdate:token instanceName:self.instanceName]; + } return token; }); } diff --git a/AppCheckCore/Sources/Public/AppCheckCore/AppCheck.h b/AppCheckCore/Sources/Public/AppCheckCore/AppCheckCore.h similarity index 100% rename from AppCheckCore/Sources/Public/AppCheckCore/AppCheck.h rename to AppCheckCore/Sources/Public/AppCheckCore/AppCheckCore.h diff --git a/AppCheckCore/Sources/Public/AppCheckCore/GACAppCheck.h b/AppCheckCore/Sources/Public/AppCheckCore/GACAppCheck.h index db644d16c2b..65833be83f7 100644 --- a/AppCheckCore/Sources/Public/AppCheckCore/GACAppCheck.h +++ b/AppCheckCore/Sources/Public/AppCheckCore/GACAppCheck.h @@ -32,12 +32,18 @@ NS_SWIFT_NAME(AppCheckCore) - (instancetype)init NS_UNAVAILABLE; /// Returns an instance of `AppCheck` for an application. -/// @param appCheckProvider An `AppCheckCoreProvider` instance that provides App Check tokens. -/// @return An instance of `AppCheckCore` corresponding to the provided `app`. +/// @param appCheckProvider An object that provides App Check tokens. +/// @param settings An object that provides App Check settings. +/// @param tokenDelegate A delegate that receives token update notifications. +/// @param resourceName The name of the resource protected by App Check; for a Firebase App this is +/// "projects/{project_id}/apps/{app_id}". +/// @param accessGroup The identifier for a keychain group that the app shares items with; if +/// provided, requires the Keychain Access Groups Entitlement. +/// @return An instance of `AppCheckCore` with the specified token provider. - (instancetype)initWithInstanceName:(NSString *)instanceName appCheckProvider:(id)appCheckProvider settings:(id)settings - tokenDelegate:(id)tokenDelegate + tokenDelegate:(nullable id)tokenDelegate resourceName:(NSString *)resourceName keychainAccessGroup:(nullable NSString *)accessGroup; diff --git a/AppCheckCore/Tests/Unit/Core/GACAppCheckTests.m b/AppCheckCore/Tests/Unit/Core/GACAppCheckTests.m index 1d92a80a4fc..ff22bd0a617 100644 --- a/AppCheckCore/Tests/Unit/Core/GACAppCheckTests.m +++ b/AppCheckCore/Tests/Unit/Core/GACAppCheckTests.m @@ -48,7 +48,7 @@ - (instancetype)initWithInstanceName:(NSString *)instanceName storage:(id)storage tokenRefresher:(id)tokenRefresher settings:(id)settings - tokenDelegate:(id)tokenDelegate; + tokenDelegate:(nullable id)tokenDelegate; @end From bdc821aa24ce6364ea39045b0223345e7a50cc3f Mon Sep 17 00:00:00 2001 From: Andrew Heard Date: Mon, 24 Jul 2023 11:04:29 -0400 Subject: [PATCH 2/2] Group `tokenDelegate` with other nullable params --- AppCheckCore/Sources/Core/GACAppCheck.m | 2 +- AppCheckCore/Sources/Public/AppCheckCore/GACAppCheck.h | 4 ++-- AppCheckCore/Tests/Unit/Core/GACAppCheckTests.m | 2 +- AppCheckCore/Tests/Unit/Swift/AppCheckAPITests.swift | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/AppCheckCore/Sources/Core/GACAppCheck.m b/AppCheckCore/Sources/Core/GACAppCheck.m index bb8380c9b1b..15b1ca78658 100644 --- a/AppCheckCore/Sources/Core/GACAppCheck.m +++ b/AppCheckCore/Sources/Core/GACAppCheck.m @@ -89,8 +89,8 @@ - (instancetype)initWithInstanceName:(NSString *)instanceName - (instancetype)initWithInstanceName:(NSString *)instanceName appCheckProvider:(id)appCheckProvider settings:(id)settings - tokenDelegate:(nullable id)tokenDelegate resourceName:(NSString *)resourceName + tokenDelegate:(nullable id)tokenDelegate keychainAccessGroup:(nullable NSString *)accessGroup { GACAppCheckTokenRefreshResult *refreshResult = [[GACAppCheckTokenRefreshResult alloc] initWithStatusNever]; diff --git a/AppCheckCore/Sources/Public/AppCheckCore/GACAppCheck.h b/AppCheckCore/Sources/Public/AppCheckCore/GACAppCheck.h index 65833be83f7..cf93da0d039 100644 --- a/AppCheckCore/Sources/Public/AppCheckCore/GACAppCheck.h +++ b/AppCheckCore/Sources/Public/AppCheckCore/GACAppCheck.h @@ -34,17 +34,17 @@ NS_SWIFT_NAME(AppCheckCore) /// Returns an instance of `AppCheck` for an application. /// @param appCheckProvider An object that provides App Check tokens. /// @param settings An object that provides App Check settings. -/// @param tokenDelegate A delegate that receives token update notifications. /// @param resourceName The name of the resource protected by App Check; for a Firebase App this is /// "projects/{project_id}/apps/{app_id}". +/// @param tokenDelegate A delegate that receives token update notifications. /// @param accessGroup The identifier for a keychain group that the app shares items with; if /// provided, requires the Keychain Access Groups Entitlement. /// @return An instance of `AppCheckCore` with the specified token provider. - (instancetype)initWithInstanceName:(NSString *)instanceName appCheckProvider:(id)appCheckProvider settings:(id)settings - tokenDelegate:(nullable id)tokenDelegate resourceName:(NSString *)resourceName + tokenDelegate:(nullable id)tokenDelegate keychainAccessGroup:(nullable NSString *)accessGroup; @end diff --git a/AppCheckCore/Tests/Unit/Core/GACAppCheckTests.m b/AppCheckCore/Tests/Unit/Core/GACAppCheckTests.m index ff22bd0a617..e5a5657ed90 100644 --- a/AppCheckCore/Tests/Unit/Core/GACAppCheckTests.m +++ b/AppCheckCore/Tests/Unit/Core/GACAppCheckTests.m @@ -147,8 +147,8 @@ - (void)testAppCheckInit { GACAppCheck *appCheck = [[GACAppCheck alloc] initWithInstanceName:kAppName appCheckProvider:mockProvider settings:mockSettings - tokenDelegate:mockTokenDelegate resourceName:kResourceName + tokenDelegate:mockTokenDelegate keychainAccessGroup:kAppGroupID]; XCTAssert([appCheck isKindOfClass:[GACAppCheck class]]); diff --git a/AppCheckCore/Tests/Unit/Swift/AppCheckAPITests.swift b/AppCheckCore/Tests/Unit/Swift/AppCheckAPITests.swift index 486d54a7870..0a421fcb877 100644 --- a/AppCheckCore/Tests/Unit/Swift/AppCheckAPITests.swift +++ b/AppCheckCore/Tests/Unit/Swift/AppCheckAPITests.swift @@ -55,8 +55,8 @@ final class AppCheckAPITests { instanceName: app.name, appCheckProvider: DummyAppCheckProvider(), settings: DummyAppCheckSettings(), - tokenDelegate: DummyAppCheckTokenDelegate(), resourceName: resourceName, + tokenDelegate: DummyAppCheckTokenDelegate(), keychainAccessGroup: app.options.appGroupID )