Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PM-8222] Cherrypick - New device verification page fixes (#1381) #1384

Merged
merged 1 commit into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ final class TwoFactorAuthProcessor: StateProcessor<TwoFactorAuthState, TwoFactor
state.toast = newValue
case let .verificationCodeChanged(newValue):
state.verificationCode = newValue
state.continueEnabled = (newValue.count >= 6)
state.continueEnabled = newValue.count >= (state.deviceVerificationRequired ? 8 : 6)
}
}

Expand Down Expand Up @@ -179,6 +179,8 @@ final class TwoFactorAuthProcessor: StateProcessor<TwoFactorAuthState, TwoFactor
coordinator.showAlert(Alert.inputValidationAlert(error: error))
} catch let IdentityTokenRequestError.captchaRequired(hCaptchaSiteCode) {
launchCaptchaFlow(with: hCaptchaSiteCode)
} catch IdentityTokenRequestError.newDeviceNotVerified {
coordinator.showAlert(.defaultAlert(title: Localizations.invalidVerificationCode))
} catch let authError as AuthError {
if authError == .requireSetPassword,
let orgId = state.orgIdentifier {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,24 @@ class TwoFactorAuthProcessorTests: BitwardenTestCase { // swiftlint:disable:this
XCTAssertEqual(errorReporter.errors.last as? BitwardenTestError, .example)
}

/// `perform(_:)` with `.continueTapped` handles identity device verification code error correctly.
@MainActor
func test_perform_continueTapped_deviceVerificationCode_error() async {
subject.state.authMethod = .email
subject.state.deviceVerificationRequired = true
subject.state.verificationCode = "123123123 "
authService.loginWithTwoFactorCodeResult = .failure(
IdentityTokenRequestError.newDeviceNotVerified
)

await subject.perform(.continueTapped)

XCTAssertFalse(coordinator.isLoadingOverlayShowing)
XCTAssertEqual(coordinator.loadingOverlaysShown, [.init(title: Localizations.verifying)])
XCTAssertEqual(authService.loginWithTwoFactorCodeCode, "123123123")
XCTAssertEqual(coordinator.alertShown.last, .defaultAlert(title: Localizations.invalidVerificationCode))
}

/// `perform(_:)` with `.continueTapped` shows an alert for empty verification code text.
@MainActor
func test_perform_continueTapped_invalidInput() async throws {
Expand Down Expand Up @@ -729,6 +747,20 @@ class TwoFactorAuthProcessorTests: BitwardenTestCase { // swiftlint:disable:this
XCTAssertEqual(subject.state.verificationCode, "123456")
XCTAssertTrue(subject.state.continueEnabled)
}

/// `receive(_:)` with `.verificationCodeChanged` updates the value in the state and enables the button if
/// applicable if device needs verification and code length is at least 8 characters.
@MainActor
func test_receive_verificationCodeChanged_deviceNeedsVerification() {
subject.state.deviceVerificationRequired = true
subject.receive(.verificationCodeChanged("123456"))
XCTAssertEqual(subject.state.verificationCode, "123456")
XCTAssertFalse(subject.state.continueEnabled)

subject.receive(.verificationCodeChanged("12345678"))
XCTAssertEqual(subject.state.verificationCode, "12345678")
XCTAssertTrue(subject.state.continueEnabled)
}
}

// MARK: - MockWebAuthnFlowDelegate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ struct TwoFactorAuthState: Equatable, Sendable {
/// User organization idenfier if came from SSO flow
var orgIdentifier: String?

/// The text to display in the detailed instructions.
var titleText: String {
if deviceVerificationRequired {
return Localizations.verifyYourIdentity
}
return authMethod.title
}

/// A toast message to show in the view.
var toast: Toast?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct TwoFactorAuthView: View {
get: \.toast,
send: TwoFactorAuthAction.toastShown
))
.navigationBar(title: store.state.authMethod.title, titleDisplayMode: .inline)
.navigationBar(title: store.state.titleText, titleDisplayMode: .inline)
.task(id: store.state.authMethod) {
guard store.state.authMethod == .yubiKey else { return }
await store.perform(.listenForNFC)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1147,3 +1147,4 @@
"ContactInfo" = "Contact info";
"Identification" = "Identification";
"Owner" = "Owner";
"VerifyYourIdentity"="Verify your identity";