Переглянути джерело

[Auth] Remove unreachable code (#11091)

* [Auth] Remove unreachable code

* Rename '-[FIRAuthStoredUserManager getStoredUserAccessGroupWithError:]'

* Favor 'NULL' over 'nil' for a **

* Rename '-[FIRAuthStoredUserManager setStoredUserAccessGroup:error:]'
Nick Cooke 3 роки тому
батько
коміт
963cc2d6bd

+ 29 - 42
FirebaseAuth/Sources/Auth/FIRAuth.m

@@ -526,54 +526,41 @@ static NSMutableDictionary *gKeychainServiceNameForAppName;
           [[FIRAuthStoredUserManager alloc] initWithServiceName:keychainServiceName];
     }
 
-    NSError *error;
-    NSString *storedUserAccessGroup =
-        [strongSelf.storedUserManager getStoredUserAccessGroupWithError:&error];
-    if (!error) {
-      if (!storedUserAccessGroup) {
-        FIRUser *user;
-        if ([strongSelf getUser:&user error:&error]) {
-          strongSelf.tenantID = user.tenantID;
-          [strongSelf updateCurrentUser:user byForce:NO savingToDisk:NO error:&error];
-          self->_lastNotifiedUserToken = user.rawAccessToken;
-        } else {
-#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_MACCATALYST
-          if (error.code == FIRAuthErrorCodeKeychainError) {
-            // If there's a keychain error, assume it is due to the keychain being accessed
-            // before the device is unlocked as a result of prewarming, and listen for the
-            // UIApplicationProtectedDataDidBecomeAvailable notification.
-            [strongSelf addProtectedDataDidBecomeAvailableObserver];
-          }
-#endif  // TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_MACCATALYST
-          FIRLogError(kFIRLoggerAuth, @"I-AUT000001",
-                      @"Error loading saved user when starting up: %@", error);
-        }
+    NSString *storedUserAccessGroup = [strongSelf.storedUserManager getStoredUserAccessGroup];
+    if (!storedUserAccessGroup) {
+      FIRUser *user;
+      NSError *error;
+      if ([strongSelf getUser:&user error:&error]) {
+        strongSelf.tenantID = user.tenantID;
+        [strongSelf updateCurrentUser:user byForce:NO savingToDisk:NO error:&error];
+        self->_lastNotifiedUserToken = user.rawAccessToken;
       } else {
-        [strongSelf internalUseUserAccessGroup:storedUserAccessGroup error:&error];
-        if (error) {
 #if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_MACCATALYST
-          if (error.code == FIRAuthErrorCodeKeychainError) {
-            // If there's a keychain error, assume it is due to the keychain being accessed
-            // before the device is unlocked as a result of prewarming, and listen for the
-            // UIApplicationProtectedDataDidBecomeAvailable notification.
-            [strongSelf addProtectedDataDidBecomeAvailableObserver];
-          }
-#endif  // TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_MACCATALYST
-          FIRLogError(kFIRLoggerAuth, @"I-AUT000001",
-                      @"Error loading saved user when starting up: %@", error);
+        if (error.code == FIRAuthErrorCodeKeychainError) {
+          // If there's a keychain error, assume it is due to the keychain being accessed
+          // before the device is unlocked as a result of prewarming, and listen for the
+          // UIApplicationProtectedDataDidBecomeAvailable notification.
+          [strongSelf addProtectedDataDidBecomeAvailableObserver];
         }
+#endif  // TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_MACCATALYST
+        FIRLogError(kFIRLoggerAuth, @"I-AUT000001",
+                    @"Error loading saved user when starting up: %@", error);
       }
     } else {
+      NSError *error;
+      [strongSelf internalUseUserAccessGroup:storedUserAccessGroup error:&error];
+      if (error) {
 #if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_MACCATALYST
-      if (error.code == FIRAuthErrorCodeKeychainError) {
-        // If there's a keychain error, assume it is due to the keychain being accessed
-        // before the device is unlocked as a result of prewarming, and listen for the
-        // UIApplicationProtectedDataDidBecomeAvailable notification.
-        [strongSelf addProtectedDataDidBecomeAvailableObserver];
-      }
+        if (error.code == FIRAuthErrorCodeKeychainError) {
+          // If there's a keychain error, assume it is due to the keychain being accessed
+          // before the device is unlocked as a result of prewarming, and listen for the
+          // UIApplicationProtectedDataDidBecomeAvailable notification.
+          [strongSelf addProtectedDataDidBecomeAvailableObserver];
+        }
 #endif  // TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_MACCATALYST
-      FIRLogError(kFIRLoggerAuth, @"I-AUT000001", @"Error loading saved user when starting up: %@",
-                  error);
+        FIRLogError(kFIRLoggerAuth, @"I-AUT000001",
+                    @"Error loading saved user when starting up: %@", error);
+      }
     }
 
 #if TARGET_OS_IOS
@@ -2307,7 +2294,7 @@ static NSMutableDictionary *gKeychainServiceNameForAppName;
 - (BOOL)internalUseUserAccessGroup:(NSString *_Nullable)accessGroup
                              error:(NSError *_Nullable *_Nullable)outError {
   BOOL success;
-  success = [self.storedUserManager setStoredUserAccessGroup:accessGroup error:outError];
+  success = [self.storedUserManager setStoredUserAccessGroup:accessGroup];
   if (!success) {
     return NO;
   }

+ 2 - 5
FirebaseAuth/Sources/SystemService/FIRAuthStoredUserManager.h

@@ -47,17 +47,14 @@ NS_ASSUME_NONNULL_BEGIN
 
 /** @fn getStoredUserAccessGroupWithError:
     @brief Get the user access group stored locally.
-    @param outError Return value for any error which occurs.
  */
-- (nullable NSString *)getStoredUserAccessGroupWithError:(NSError *_Nullable *_Nullable)outError;
+- (nullable NSString *)getStoredUserAccessGroup;
 
 /** @fn setStoredUserAccessGroup:error:
     @brief The setter of the user access group stored locally.
     @param accessGroup The access group to be set.
-    @param outError Return value for any error which occurs.
  */
-- (BOOL)setStoredUserAccessGroup:(NSString *_Nullable)accessGroup
-                           error:(NSError *_Nullable *_Nullable)outError;
+- (BOOL)setStoredUserAccessGroup:(NSString *_Nullable)accessGroup;
 
 /** @fn getStoredUserForAccessGroup:projectID:error:
     @brief The getter of the user stored locally.

+ 5 - 6
FirebaseAuth/Sources/SystemService/FIRAuthStoredUserManager.m

@@ -49,8 +49,8 @@ static NSString *kStoredUserCoderKey = @"firebase_auth_stored_user_coder_key";
 
 #pragma mark - User Access Group
 
-- (NSString *_Nullable)getStoredUserAccessGroupWithError:(NSError *_Nullable *_Nullable)outError {
-  NSData *data = [self.userDefaults dataForKey:kStoredUserAccessGroupKey error:outError];
+- (NSString *_Nullable)getStoredUserAccessGroup {
+  NSData *data = [self.userDefaults dataForKey:kStoredUserAccessGroupKey error:NULL];
   if (data) {
     NSString *userAccessGroup = [NSString stringWithUTF8String:data.bytes];
     return userAccessGroup;
@@ -59,13 +59,12 @@ static NSString *kStoredUserCoderKey = @"firebase_auth_stored_user_coder_key";
   }
 }
 
-- (BOOL)setStoredUserAccessGroup:(NSString *_Nullable)accessGroup
-                           error:(NSError *_Nullable *_Nullable)outError {
+- (BOOL)setStoredUserAccessGroup:(NSString *_Nullable)accessGroup {
   NSData *data = [accessGroup dataUsingEncoding:NSUTF8StringEncoding];
   if (!data) {
-    return [self.userDefaults removeDataForKey:kStoredUserAccessGroupKey error:outError];
+    return [self.userDefaults removeDataForKey:kStoredUserAccessGroupKey error:NULL];
   } else {
-    return [self.userDefaults setData:data forKey:kStoredUserAccessGroupKey error:outError];
+    return [self.userDefaults setData:data forKey:kStoredUserAccessGroupKey error:NULL];
   }
 }
 

+ 2 - 2
FirebaseAuth/Tests/Unit/FIRAuthUseUserAccessGroupTests.m

@@ -42,14 +42,14 @@
   OCMStub([classMock keychainServiceNameForAppName:OCMOCK_ANY]).andReturn(nil);
   FIRAuthStoredUserManager *myManager =
       [[FIRAuthStoredUserManager alloc] initWithServiceName:@"MyService"];
-  [myManager setStoredUserAccessGroup:@"MyGroup" error:nil];
+  [myManager setStoredUserAccessGroup:@"MyGroup"];
 
   FIRAuth *auth = [FIRAuth auth];
   XCTAssertNotNil(auth);
   id partialMock = OCMPartialMock(auth);
   OCMStub([partialMock storedUserManager]).andReturn(myManager);
 
-  XCTAssertNotNil([auth.storedUserManager getStoredUserAccessGroupWithError:nil]);
+  XCTAssertNotNil([auth.storedUserManager getStoredUserAccessGroup]);
   XCTAssertTrue([auth useUserAccessGroup:@"id.com.example.group1" error:nil]);
   XCTAssertTrue([auth useUserAccessGroup:@"id.com.example.group2" error:nil]);
   XCTAssertTrue([auth useUserAccessGroup:nil error:nil]);