Skip to content

Commit

Permalink
PM-9000 - User can save empty PIN (whitespaces) (#779)
Browse files Browse the repository at this point in the history
  • Loading branch information
phil-livefront authored Jul 31, 2024
1 parent b0a55c4 commit 5c84cbc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ final class AccountSecurityProcessor: StateProcessor<
private func toggleUnlockWithPIN(_ isOn: Bool) {
if isOn {
coordinator.showAlert(.enterPINCode { pin in
guard !pin.isEmpty else { return }
guard !pin.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else { return }

do {
let userHasMasterPassword = try await self.services.stateService.getUserHasMasterPassword()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,19 @@ class AccountSecurityProcessorTests: BitwardenTestCase { // swiftlint:disable:th

let alert = try XCTUnwrap(coordinator.alertShown.last)
try await alert.tapAction(title: Localizations.submit)
XCTAssertFalse(subject.state.isUnlockWithPINCodeOn)
}

/// `receive(_:)` with `.toggleUnlockWithPINCode` displays an alert and updates the state when submit has been
/// pressed but an empty pin was passed.
func test_receive_toggleUnlockWithPINCode_toggleOn_withWhitespacePIN() async throws {
stateService.activeAccount = .fixture()
subject.state.isUnlockWithPINCodeOn = false
subject.receive(.toggleUnlockWithPINCode(true))

let alert = try XCTUnwrap(coordinator.alertShown.last)
try alert.setText(" ", forTextFieldWithId: "pin")
try await alert.tapAction(title: Localizations.submit)
XCTAssertFalse(subject.state.isUnlockWithPINCodeOn)
}

Expand Down

0 comments on commit 5c84cbc

Please sign in to comment.