generated from bitwarden/template
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PM-11720 - TDE User Without MP Cannot Enable Autofill For Account (#908)
- Loading branch information
1 parent
c3f3a13
commit f37d588
Showing
5 changed files
with
141 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1035,6 +1035,7 @@ class AuthRepositoryTests: BitwardenTestCase { // swiftlint:disable:this type_bo | |
try await subject.unlockVaultWithNeverlockKey() | ||
} | ||
XCTAssertFalse(vaultTimeoutService.unlockVaultHadUserInteraction) | ||
XCTAssertFalse(biometricsRepository.didConfigureBiometricIntegrity) | ||
} | ||
|
||
/// `test_unlockVaultWithDeviceKey` attempts to unlock the vault using the device key from the keychain. | ||
|
@@ -1063,6 +1064,38 @@ class AuthRepositoryTests: BitwardenTestCase { // swiftlint:disable:this type_bo | |
XCTAssertTrue(vaultTimeoutService.unlockVaultHadUserInteraction) | ||
} | ||
|
||
/// `test_unlockVaultWithDeviceKey` attempts to unlock the vault using the device key from the keychain. | ||
func test_unlockVaultWithDeviceKey_successWithBiometricsEnabled() async throws { | ||
let active = Account.fixtureWithTDE() | ||
stateService.activeAccount = active | ||
keychainService.mockStorage = [ | ||
keychainService.formattedKey( | ||
for: KeychainItem.deviceKey( | ||
userId: active.profile.userId | ||
) | ||
): | ||
"pasta", | ||
] | ||
|
||
biometricsRepository.biometricUnlockStatus = .success( | ||
.available(.faceID, enabled: true, hasValidIntegrity: false) | ||
) | ||
|
||
stateService.accountEncryptionKeys = [ | ||
active.profile.userId: .init( | ||
encryptedPrivateKey: "secret", | ||
encryptedUserKey: "recipe" | ||
), | ||
] | ||
clientService.mockCrypto.getUserEncryptionKeyResult = .success("sauce") | ||
clientService.mockCrypto.initializeUserCryptoResult = .success(()) | ||
await assertAsyncDoesNotThrow { | ||
try await subject.unlockVaultWithDeviceKey() | ||
} | ||
XCTAssertTrue(vaultTimeoutService.unlockVaultHadUserInteraction) | ||
XCTAssertTrue(biometricsRepository.didConfigureBiometricIntegrity) | ||
} | ||
|
||
/// `test_unlockVaultWithDeviceKey` attempts to unlock the vault using the device key from the keychain. | ||
func test_unlockVaultWithDeviceKey_error() async throws { | ||
let active = Account.fixture() | ||
|
@@ -1457,6 +1490,43 @@ class AuthRepositoryTests: BitwardenTestCase { // swiftlint:disable:this type_bo | |
) | ||
XCTAssertFalse(keyConnectorService.convertNewUserToKeyConnectorCalled) | ||
XCTAssertTrue(vaultTimeoutService.unlockVaultHadUserInteraction) | ||
XCTAssertFalse(biometricsRepository.didConfigureBiometricIntegrity) | ||
} | ||
|
||
/// `unlockVaultWithKeyConnectorKey()` unlocks the user's vault with their key connector key. | ||
func test_unlockVaultWithKeyConnectorKeyWithBiometricsEnabled() async { | ||
clientService.mockCrypto.initializeUserCryptoResult = .success(()) | ||
keyConnectorService.getMasterKeyFromKeyConnectorResult = .success("key") | ||
stateService.accountEncryptionKeys = [ | ||
"1": AccountEncryptionKeys( | ||
encryptedPrivateKey: "private", | ||
encryptedUserKey: "user" | ||
), | ||
] | ||
stateService.activeAccount = .fixture() | ||
biometricsRepository.biometricUnlockStatus = .success( | ||
.available(.faceID, enabled: true, hasValidIntegrity: false) | ||
) | ||
|
||
await assertAsyncDoesNotThrow { | ||
try await subject.unlockVaultWithKeyConnectorKey( | ||
keyConnectorURL: URL(string: "https://example.com")!, | ||
orgIdentifier: "org-id" | ||
) | ||
} | ||
|
||
XCTAssertEqual( | ||
clientService.mockCrypto.initializeUserCryptoRequest, | ||
InitUserCryptoRequest( | ||
kdfParams: KdfConfig().sdkKdf, | ||
email: "[email protected]", | ||
privateKey: "private", | ||
method: .keyConnector(masterKey: "key", userKey: "user") | ||
) | ||
) | ||
XCTAssertFalse(keyConnectorService.convertNewUserToKeyConnectorCalled) | ||
XCTAssertTrue(vaultTimeoutService.unlockVaultHadUserInteraction) | ||
XCTAssertTrue(biometricsRepository.didConfigureBiometricIntegrity) | ||
} | ||
|
||
/// `unlockVaultWithKeyConnectorKey()` converts a new user to use key connector and unlocks the | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ final class AuthRouterTests: BitwardenTestCase { // swiftlint:disable:this type_ | |
// MARK: Properties | ||
|
||
var authRepository: MockAuthRepository! | ||
var biometricsRepository: MockBiometricsRepository! | ||
var configService: MockConfigService! | ||
var errorReporter: MockErrorReporter! | ||
var stateService: MockStateService! | ||
|
@@ -20,6 +21,7 @@ final class AuthRouterTests: BitwardenTestCase { // swiftlint:disable:this type_ | |
super.setUp() | ||
|
||
authRepository = MockAuthRepository() | ||
biometricsRepository = MockBiometricsRepository() | ||
configService = MockConfigService() | ||
errorReporter = MockErrorReporter() | ||
stateService = MockStateService() | ||
|
@@ -29,6 +31,7 @@ final class AuthRouterTests: BitwardenTestCase { // swiftlint:disable:this type_ | |
isInAppExtension: false, | ||
services: ServiceContainer.withMocks( | ||
authRepository: authRepository, | ||
biometricsRepository: biometricsRepository, | ||
configService: configService, | ||
errorReporter: errorReporter, | ||
stateService: stateService, | ||
|
@@ -41,6 +44,7 @@ final class AuthRouterTests: BitwardenTestCase { // swiftlint:disable:this type_ | |
super.tearDown() | ||
|
||
authRepository = nil | ||
biometricsRepository = nil | ||
configService = nil | ||
errorReporter = nil | ||
stateService = nil | ||
|
@@ -118,6 +122,39 @@ final class AuthRouterTests: BitwardenTestCase { // swiftlint:disable:this type_ | |
XCTAssertEqual(route, .complete) | ||
} | ||
|
||
/// `handleAndRoute(_ :)` redirects `.accountBecameActive()` to `.enterpriseSingleSignOn` | ||
/// when the account is unlocked. | ||
func test_handleAndRoute_accountBecameActive_noMpAndTDE_withBiometricsEnabled() async { | ||
let active = Account.fixture( | ||
profile: .fixture( | ||
userDecryptionOptions: UserDecryptionOptions( | ||
hasMasterPassword: false, | ||
keyConnectorOption: nil, | ||
trustedDeviceOption: nil | ||
) | ||
) | ||
) | ||
stateService.activeAccount = active | ||
|
||
biometricsRepository.biometricUnlockStatus = .success( | ||
.available(.faceID, enabled: true, hasValidIntegrity: false) | ||
) | ||
stateService.isAuthenticated = [ | ||
active.profile.userId: true, | ||
] | ||
|
||
authRepository.isLockedResult = .success(true) | ||
let route = await subject.handleAndRoute( | ||
.accountBecameActive( | ||
active, | ||
animated: true, | ||
attemptAutomaticBiometricUnlock: true, | ||
didSwitchAccountAutomatically: false | ||
) | ||
) | ||
XCTAssertEqual(route, .enterpriseSingleSignOn(email: "[email protected]")) | ||
} | ||
|
||
/// `handleAndRoute(_ :)` redirects `.accountBecameActive()` to `.vaultUnlock` when checking if | ||
/// an account is authenticated fails. | ||
func test_handleAndRoute_accountBecameActive_logout_isAuthenticatedError() async { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters