Skip to content

Commit 1fc52ab

Browse files
authored
[Release] Cherry-pick #13592 into release-11.2 (#13602)
1 parent 7993c8e commit 1fc52ab

File tree

4 files changed

+33
-16
lines changed

4 files changed

+33
-16
lines changed

FirebaseAuth/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
in methods and a `nil` error. In such cases, an empty array is instead
88
returned with the `nil` error. (#13550)
99
- [Fixed] Fixed user session persistence in multi tenant projects. Introduced in 11.0.0. (#13565)
10+
- [Fixed] Fixed encoding crash that occurs when using TOTP multi-factor
11+
authentication. Note that this fix will not be in the 11.2.0 zip and Carthage
12+
distributions, but will be included from 11.3.0 onwards. (#13591)
1013

1114
# 11.1.0
1215
- [fixed] Fixed `Swift.error` conformance for `AuthErrorCode`. (#13430)

FirebaseAuth/Sources/Swift/Backend/RPC/Proto/AuthProtoMFAEnrollment.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import Foundation
1616

1717
class AuthProtoMFAEnrollment: NSObject, AuthProto {
1818
let phoneInfo: String?
19+
// In practice, this will be an empty dictionary. The presence of which
20+
// indicates TOTP MFA enrollment rather than phone MFA enrollment.
1921
let totpInfo: NSObject?
2022
let mfaEnrollmentID: String?
2123
let displayName: String?

FirebaseAuth/Sources/Swift/MultiFactor/TOTP/TOTPMultiFactorInfo.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,18 @@ import Foundation
2222
///
2323
/// This class is available on iOS only.
2424
class TOTPMultiFactorInfo: MultiFactorInfo {
25-
/// This is the totp info for the second factor.
26-
let totpInfo: NSObject?
27-
2825
/// Initialize the AuthProtoMFAEnrollment instance with proto.
2926
/// - Parameter proto: AuthProtoMFAEnrollment proto object.
3027
init(proto: AuthProtoMFAEnrollment) {
31-
totpInfo = proto.totpInfo
3228
super.init(proto: proto, factorID: PhoneMultiFactorInfo.TOTPMultiFactorID)
3329
}
3430

35-
@available(*, unavailable)
3631
required init?(coder: NSCoder) {
37-
fatalError("init(coder:) has not been implemented")
32+
super.init(coder: coder)
33+
}
34+
35+
override class var supportsSecureCoding: Bool {
36+
super.supportsSecureCoding
3837
}
3938
}
4039
#endif

FirebaseAuth/Tests/Unit/UserTests.swift

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,21 @@ class UserTests: RPCBaseTests {
141141
"phoneNumber": kPhoneNumber,
142142
"createdAt": String(Int(kCreationDateTimeIntervalInSeconds) * 1000), // to nanoseconds
143143
"lastLoginAt": String(Int(kLastSignInDateTimeIntervalInSeconds) * 1000),
144-
"mfaInfo": [[
145-
"phoneInfo": kPhoneInfo,
146-
"mfaEnrollmentId": kEnrollmentID,
147-
"displayName": kDisplayName,
148-
"enrolledAt": kEnrolledAt,
149-
]],
144+
"mfaInfo": [
145+
[
146+
"phoneInfo": kPhoneInfo,
147+
"mfaEnrollmentId": kEnrollmentID,
148+
"displayName": kDisplayName,
149+
"enrolledAt": kEnrolledAt,
150+
],
151+
[
152+
// In practice, this will be an empty dictionary.
153+
"totpInfo": [AnyHashable: AnyHashable](),
154+
"mfaEnrollmentId": kEnrollmentID,
155+
"displayName": kDisplayName,
156+
"enrolledAt": kEnrolledAt,
157+
] as [AnyHashable: AnyHashable],
158+
],
150159
]]
151160

152161
let expectation = self.expectation(description: #function)
@@ -346,11 +355,15 @@ class UserTests: RPCBaseTests {
346355

347356
// Verify MultiFactorInfo properties.
348357
let enrolledFactors = try XCTUnwrap(user.multiFactor.enrolledFactors)
358+
XCTAssertEqual(enrolledFactors.count, 2)
349359
XCTAssertEqual(enrolledFactors[0].factorID, PhoneMultiFactorInfo.PhoneMultiFactorID)
350-
XCTAssertEqual(enrolledFactors[0].uid, kEnrollmentID)
351-
XCTAssertEqual(enrolledFactors[0].displayName, self.kDisplayName)
352-
let date = try XCTUnwrap(enrolledFactors[0].enrollmentDate)
353-
XCTAssertEqual("\(date)", kEnrolledAtMatch)
360+
XCTAssertEqual(enrolledFactors[1].factorID, PhoneMultiFactorInfo.TOTPMultiFactorID)
361+
for enrolledFactor in enrolledFactors {
362+
XCTAssertEqual(enrolledFactor.uid, kEnrollmentID)
363+
XCTAssertEqual(enrolledFactor.displayName, self.kDisplayName)
364+
let date = try XCTUnwrap(enrolledFactor.enrollmentDate)
365+
XCTAssertEqual("\(date)", kEnrolledAtMatch)
366+
}
354367
#endif
355368
} catch {
356369
XCTFail("Caught an error in \(#function): \(error)")

0 commit comments

Comments
 (0)