Skip to content

Commit 121a26d

Browse files
PM-11979: Allow PIN unlock to configure biometric integrity if needed (#918)
1 parent 261bb86 commit 121a26d

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

BitwardenShared/Core/Auth/Repositories/AuthRepository.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -959,8 +959,7 @@ extension DefaultAuthRepository: AuthRepository {
959959

960960
try await configureBiometricUnlockIfRequired()
961961
case .pin:
962-
// No-op: nothing extra to do for pin unlock.
963-
break
962+
try await configureBiometricUnlockIfRequired()
964963
}
965964

966965
_ = try await trustDeviceService.trustDeviceIfNeeded()

BitwardenShared/Core/Auth/Repositories/AuthRepositoryTests.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,6 +1742,37 @@ class AuthRepositoryTests: BitwardenTestCase { // swiftlint:disable:this type_bo
17421742
)
17431743
XCTAssertFalse(vaultTimeoutService.isLocked(userId: "1"))
17441744
XCTAssertTrue(vaultTimeoutService.unlockVaultHadUserInteraction)
1745+
XCTAssertFalse(biometricsRepository.didConfigureBiometricIntegrity)
1746+
}
1747+
1748+
/// `unlockVaultWithPIN(_:)` unlocks the vault with the user's PIN and configures biometric
1749+
/// integrity if needed.
1750+
func test_unlockVaultWithPIN_configuresBiometrics() async throws {
1751+
let account = Account.fixture()
1752+
stateService.activeAccount = account
1753+
stateService.accountEncryptionKeys = [
1754+
"1": AccountEncryptionKeys(encryptedPrivateKey: "PRIVATE_KEY", encryptedUserKey: "USER_KEY"),
1755+
]
1756+
stateService.encryptedPinByUserId[account.profile.userId] = "123"
1757+
stateService.pinProtectedUserKeyValue[account.profile.userId] = "123"
1758+
biometricsRepository.biometricUnlockStatus = .success(
1759+
.available(.faceID, enabled: true, hasValidIntegrity: false)
1760+
)
1761+
1762+
try await subject.unlockVaultWithPIN(pin: "123")
1763+
1764+
XCTAssertEqual(
1765+
clientService.mockCrypto.initializeUserCryptoRequest,
1766+
InitUserCryptoRequest(
1767+
kdfParams: .pbkdf2(iterations: UInt32(Constants.pbkdf2Iterations)),
1768+
1769+
privateKey: "PRIVATE_KEY",
1770+
method: .pin(pin: "123", pinProtectedUserKey: "123")
1771+
)
1772+
)
1773+
XCTAssertFalse(vaultTimeoutService.isLocked(userId: "1"))
1774+
XCTAssertTrue(vaultTimeoutService.unlockVaultHadUserInteraction)
1775+
XCTAssertTrue(biometricsRepository.didConfigureBiometricIntegrity)
17451776
}
17461777

17471778
/// `unlockVaultWithPIN(_:)` throws an error if there's no pin.

0 commit comments

Comments
 (0)