Explorar o código

[Auth] Restore MFA request setup to Firebase 10 behavior (#13858)

Nick Cooke hai 1 ano
pai
achega
0e3e20d23a

+ 4 - 0
FirebaseAuth/CHANGELOG.md

@@ -1,3 +1,7 @@
+# Unreleased
+- [Fixed] Restore Firebase 10 behavior by ignoring `nil` display names used
+  during multi factor enrollment. (#13856)
+
 # 11.3.0
 - [Fixed] Restore Firebase 10 behavior by querying with the
   `kSecAttrSynchronizable` key when auth state is set to be shared across

+ 5 - 5
FirebaseAuth/Sources/Swift/Backend/RPC/MultiFactor/Enroll/FinalizeMFAEnrollmentRequest.swift

@@ -64,11 +64,11 @@ class FinalizeMFAEnrollmentRequest: IdentityToolkitRequest, AuthRPCRequest {
     }
     if let displayName = displayName {
       body["displayName"] = displayName
-      if let phoneVerificationInfo {
-        body["phoneVerificationInfo"] = phoneVerificationInfo.dictionary
-      } else if let totpVerificationInfo {
-        body["totpVerificationInfo"] = totpVerificationInfo.dictionary
-      }
+    }
+    if let phoneVerificationInfo {
+      body["phoneVerificationInfo"] = phoneVerificationInfo.dictionary
+    } else if let totpVerificationInfo {
+      body["totpVerificationInfo"] = totpVerificationInfo.dictionary
     }
 
     if let tenantID = tenantID {

+ 10 - 2
FirebaseAuth/Tests/Unit/FinalizeMFAEnrollmentRequestTests.swift

@@ -29,6 +29,14 @@ class FinalizeMFAEnrollmentRequestTests: RPCBaseTests {
    @brief Tests the Finalize MFA Enrollment using TOTP request.
    */
   func testTOTPStartMFAEnrollmentRequest() async throws {
+    try await assertTOTPStartMFAEnrollmentRequest(displayName: "sparky")
+  }
+
+  func testTOTPStartMFAEnrollmentRequest_WhenDisplayNameIsNil() async throws {
+    try await assertTOTPStartMFAEnrollmentRequest(displayName: nil)
+  }
+
+  func assertTOTPStartMFAEnrollmentRequest(displayName: String?) async throws {
     let kIDToken = "idToken"
     let kDisplayName = "displayName"
     let kSessionInfo = "sessionInfo"
@@ -40,7 +48,7 @@ class FinalizeMFAEnrollmentRequestTests: RPCBaseTests {
     let requestInfo = AuthProtoFinalizeMFATOTPEnrollmentRequestInfo(sessionInfo: kSessionInfo,
                                                                     verificationCode: kVerificationCode)
     let request = FinalizeMFAEnrollmentRequest(idToken: kIDToken,
-                                               displayName: kDisplayName,
+                                               displayName: displayName,
                                                totpVerificationInfo: requestInfo,
                                                requestConfiguration: requestConfiguration)
 
@@ -55,7 +63,7 @@ class FinalizeMFAEnrollmentRequestTests: RPCBaseTests {
       value: kIDToken
     )
     let requestDictionary = try XCTUnwrap(rpcIssuer.decodedRequest as? [String: AnyHashable])
-    XCTAssertEqual(requestDictionary[kDisplayName], kDisplayName)
+    XCTAssertEqual(requestDictionary[kDisplayName], displayName)
     let totpInfo = try XCTUnwrap(requestDictionary[kTOTPVerificationInfo] as? [String: String])
     XCTAssertEqual(totpInfo["verificationCode"], kVerificationCode)
     XCTAssertNil(requestDictionary[kPhoneVerificationInfo])