Fixed login bug (#882)

This commit is contained in:
Shannon Draeker 2024-01-30 17:24:00 -07:00 committed by Álison Fernandes
parent 95b4aaf605
commit cf8f2ff7fa
27 changed files with 8 additions and 116 deletions

View file

@ -256,18 +256,13 @@ class AuthRepositoryImpl(
authDiskSource.currentUserPoliciesListFlow
.onEach { policies ->
val userId = activeUserId ?: return@onEach
if (passwordPassesPolicies(policies)) {
vaultRepository.completeUnlock(userId = userId)
storeUserResetPasswordReason(
userId = userId,
reason = null,
reason = ForcePasswordResetReason.WEAK_MASTER_PASSWORD_ON_LOGIN
.takeIf {
!passwordPassesPolicies(policies)
},
)
} else {
storeUserResetPasswordReason(
userId = userId,
reason = ForcePasswordResetReason.WEAK_MASTER_PASSWORD_ON_LOGIN,
)
}
}
.launchIn(unconfinedScope)
}
@ -711,9 +706,6 @@ class AuthRepositoryImpl(
)
}
// Complete the login flow.
vaultRepository.completeUnlock(userId = activeAccount.profile.userId)
// Return the success.
ResetPasswordResult.Success
},

View file

@ -40,8 +40,6 @@ data class UserState(
* @property isLoggedIn `true` if the account is logged in, or `false` if it requires additional
* authentication to view their vault.
* @property isVaultUnlocked Whether or not the user's vault is currently unlocked.
* @property isVaultPendingUnlock Whether or not the user's vault is currently pending being
* unlocked, such as when the password policy has not completed verification yet.
* @property needsPasswordReset If the user needs to reset their password.
* @property organizations List of [Organization]s the user is associated with, if any.
* @property isBiometricsEnabled Indicates that the biometrics mechanism for unlocking the
@ -57,7 +55,6 @@ data class UserState(
val isPremium: Boolean,
val isLoggedIn: Boolean,
val isVaultUnlocked: Boolean,
val isVaultPendingUnlock: Boolean,
val needsPasswordReset: Boolean,
val organizations: List<Organization>,
val isBiometricsEnabled: Boolean,

View file

@ -72,8 +72,6 @@ fun UserStateJson.toUserState(
isLoggedIn = accountJson.isLoggedIn,
isVaultUnlocked = vaultState.statusFor(userId) ==
VaultUnlockData.Status.UNLOCKED,
isVaultPendingUnlock = vaultState.statusFor(userId) ==
VaultUnlockData.Status.PENDING,
needsPasswordReset = accountJson.profile.forcePasswordResetReason != null,
organizations = userOrganizationsList
.find { it.userId == userId }

View file

@ -30,12 +30,6 @@ interface VaultLockManager {
*/
fun lockVault(userId: String)
/**
* Complete the unlock flow for a given [userId], moving their pendingUnlock status
* to a full unlock.
*/
fun completeUnlock(userId: String)
/**
* Locks the vault for the current user if currently unlocked.
*/

View file

@ -92,10 +92,6 @@ class VaultLockManagerImpl(
setVaultToLocked(userId = userId)
}
override fun completeUnlock(userId: String) {
setVaultToUnlocked(userId = userId)
}
override fun lockVaultForCurrentUser() {
activeUserId?.let {
lockVault(it)
@ -168,7 +164,7 @@ class VaultLockManagerImpl(
.also {
if (it is VaultUnlockResult.Success) {
clearInvalidUnlockCount(userId = userId)
setVaultToPendingUnlocked(userId = userId)
setVaultToUnlocked(userId = userId)
} else {
incrementInvalidUnlockCount(userId = userId)
}
@ -214,12 +210,6 @@ class VaultLockManagerImpl(
storeUserAutoUnlockKeyIfNecessary(userId = userId)
}
private fun setVaultToPendingUnlocked(userId: String) {
mutableVaultUnlockDataStateFlow.update {
it.update(userId, VaultUnlockData.Status.PENDING)
}
}
private fun setVaultToLocked(userId: String) {
vaultSdkSource.clearCrypto(userId = userId)
mutableVaultUnlockDataStateFlow.update {

View file

@ -14,7 +14,6 @@ data class VaultUnlockData(
* The lock status of a user's vault.
*/
enum class Status {
PENDING,
UNLOCKED,
UNLOCKING,
}

View file

@ -63,7 +63,6 @@ class RootNavViewModel @Inject constructor(
userState == null ||
!userState.activeAccount.isLoggedIn ||
userState.activeAccount.isVaultPendingUnlock ||
userState.hasPendingAccountAddition -> RootNavState.Auth
userState.activeAccount.isVaultUnlocked -> {

View file

@ -262,7 +262,6 @@ class MainViewModelTest : BaseViewModelTest() {
isPremium = true,
isLoggedIn = true,
isVaultUnlocked = true,
isVaultPendingUnlock = false,
needsPasswordReset = false,
isBiometricsEnabled = false,
organizations = emptyList(),

View file

@ -119,7 +119,6 @@ class AuthRepositoryTest {
private val mutableVaultUnlockDataStateFlow = MutableStateFlow(VAULT_UNLOCK_DATA)
private val vaultRepository: VaultRepository = mockk {
every { vaultUnlockDataStateFlow } returns mutableVaultUnlockDataStateFlow
every { completeUnlock(any()) } just runs
every { deleteVaultData(any()) } just runs
every { clearUnlockedData() } just runs
}
@ -857,7 +856,6 @@ class AuthRepositoryTest {
)
verify { settingsRepository.setDefaultsIfNecessary(userId = USER_ID_1) }
verify { vaultRepository.clearUnlockedData() }
verify { vaultRepository.completeUnlock(userId = USER_ID_1) }
}
@Suppress("MaxLineLength")
@ -2039,9 +2037,6 @@ class AuthRepositoryTest {
),
)
}
verify {
vaultRepository.completeUnlock(userId = USER_ID_1)
}
fakeAuthDiskSource.assertMasterPasswordHash(
userId = USER_ID_1,
passwordHash = PASSWORD_HASH,

View file

@ -107,7 +107,6 @@ class UserStateJsonExtensionsTest {
isPremium = false,
isLoggedIn = true,
isVaultUnlocked = true,
isVaultPendingUnlock = false,
needsPasswordReset = false,
organizations = listOf(
Organization(
@ -183,7 +182,6 @@ class UserStateJsonExtensionsTest {
isPremium = true,
isLoggedIn = false,
isVaultUnlocked = false,
isVaultPendingUnlock = false,
needsPasswordReset = false,
organizations = listOf(
Organization(

View file

@ -723,7 +723,6 @@ class VaultLockManagerTest {
privateKey = privateKey,
organizationKeys = organizationKeys,
)
vaultLockManager.completeUnlock(userId = USER_ID)
assertEquals(VaultUnlockResult.Success, result)
assertEquals(
@ -827,7 +826,6 @@ class VaultLockManagerTest {
privateKey = privateKey,
organizationKeys = organizationKeys,
)
vaultLockManager.completeUnlock(userId = USER_ID)
assertEquals(VaultUnlockResult.Success, result)
assertEquals(
@ -1362,7 +1360,6 @@ class VaultLockManagerTest {
),
organizationKeys = organizationKeys,
)
vaultLockManager.completeUnlock(userId = userId)
assertEquals(VaultUnlockResult.Success, result)
coVerify(exactly = 1) {

View file

@ -71,7 +71,6 @@ class LandingViewModelTest : BaseViewModelTest() {
isPremium = true,
isLoggedIn = true,
isVaultUnlocked = true,
isVaultPendingUnlock = false,
needsPasswordReset = false,
isBiometricsEnabled = false,
organizations = emptyList(),
@ -204,7 +203,6 @@ class LandingViewModelTest : BaseViewModelTest() {
isPremium = true,
isLoggedIn = true,
isVaultUnlocked = true,
isVaultPendingUnlock = false,
needsPasswordReset = false,
isBiometricsEnabled = false,
organizations = emptyList(),
@ -256,7 +254,6 @@ class LandingViewModelTest : BaseViewModelTest() {
isPremium = true,
isLoggedIn = false,
isVaultUnlocked = true,
isVaultPendingUnlock = false,
needsPasswordReset = false,
isBiometricsEnabled = false,
organizations = emptyList(),

View file

@ -127,7 +127,6 @@ class LoginViewModelTest : BaseViewModelTest() {
isPremium = true,
isLoggedIn = true,
isVaultUnlocked = true,
isVaultPendingUnlock = false,
needsPasswordReset = false,
isBiometricsEnabled = false,
organizations = emptyList(),

View file

@ -116,7 +116,6 @@ class VaultUnlockViewModelTest : BaseViewModelTest() {
isPremium = true,
isLoggedIn = true,
isVaultUnlocked = true,
isVaultPendingUnlock = false,
needsPasswordReset = false,
isBiometricsEnabled = false,
organizations = emptyList(),
@ -151,7 +150,6 @@ class VaultUnlockViewModelTest : BaseViewModelTest() {
isPremium = true,
isLoggedIn = true,
isVaultUnlocked = false,
isVaultPendingUnlock = false,
needsPasswordReset = false,
isBiometricsEnabled = true,
organizations = emptyList(),
@ -729,7 +727,6 @@ private val DEFAULT_ACCOUNT = UserState.Account(
isPremium = true,
isLoggedIn = true,
isVaultUnlocked = true,
isVaultPendingUnlock = false,
needsPasswordReset = false,
isBiometricsEnabled = false,
organizations = emptyList(),

View file

@ -46,7 +46,6 @@ class RootNavViewModelTest : BaseViewModelTest() {
isPremium = true,
isLoggedIn = false,
isVaultUnlocked = true,
isVaultPendingUnlock = false,
needsPasswordReset = false,
isBiometricsEnabled = false,
organizations = emptyList(),
@ -73,7 +72,6 @@ class RootNavViewModelTest : BaseViewModelTest() {
isPremium = true,
isLoggedIn = false,
isVaultUnlocked = false,
isVaultPendingUnlock = true,
needsPasswordReset = true,
isBiometricsEnabled = false,
organizations = emptyList(),
@ -101,7 +99,6 @@ class RootNavViewModelTest : BaseViewModelTest() {
isPremium = true,
isLoggedIn = true,
isVaultUnlocked = true,
isVaultPendingUnlock = false,
needsPasswordReset = false,
isBiometricsEnabled = false,
organizations = emptyList(),
@ -114,36 +111,6 @@ class RootNavViewModelTest : BaseViewModelTest() {
assertEquals(RootNavState.Auth, viewModel.stateFlow.value)
}
@Test
fun `when the active user has a pending unlocked vault the nav state should be Auth`() {
mutableUserStateFlow.tryEmit(
UserState(
activeUserId = "activeUserId",
accounts = listOf(
UserState.Account(
userId = "activeUserId",
name = "name",
email = "email",
avatarColorHex = "avatarColorHex",
environment = Environment.Us,
isPremium = true,
isLoggedIn = true,
isVaultUnlocked = false,
isVaultPendingUnlock = true,
needsPasswordReset = false,
isBiometricsEnabled = false,
organizations = emptyList(),
),
),
),
)
val viewModel = createViewModel()
assertEquals(
RootNavState.Auth,
viewModel.stateFlow.value,
)
}
@Test
fun `when the active user has an unlocked vault the nav state should be VaultUnlocked`() {
mutableUserStateFlow.tryEmit(
@ -159,7 +126,6 @@ class RootNavViewModelTest : BaseViewModelTest() {
isPremium = true,
isLoggedIn = true,
isVaultUnlocked = true,
isVaultPendingUnlock = false,
needsPasswordReset = false,
isBiometricsEnabled = false,
organizations = emptyList(),
@ -195,7 +161,6 @@ class RootNavViewModelTest : BaseViewModelTest() {
isPremium = true,
isLoggedIn = true,
isVaultUnlocked = true,
isVaultPendingUnlock = false,
needsPasswordReset = false,
isBiometricsEnabled = false,
organizations = emptyList(),
@ -235,7 +200,6 @@ class RootNavViewModelTest : BaseViewModelTest() {
isPremium = true,
isLoggedIn = true,
isVaultUnlocked = true,
isVaultPendingUnlock = false,
needsPasswordReset = false,
isBiometricsEnabled = false,
organizations = emptyList(),
@ -268,7 +232,6 @@ class RootNavViewModelTest : BaseViewModelTest() {
isPremium = true,
isLoggedIn = true,
isVaultUnlocked = false,
isVaultPendingUnlock = false,
needsPasswordReset = false,
isBiometricsEnabled = false,
organizations = emptyList(),

View file

@ -974,7 +974,6 @@ private val DEFAULT_USER_STATE = UserState(
isPremium = true,
isLoggedIn = true,
isVaultUnlocked = true,
isVaultPendingUnlock = false,
needsPasswordReset = false,
isBiometricsEnabled = false,
organizations = emptyList(),

View file

@ -192,7 +192,6 @@ private val DEFAULT_USER_STATE = UserState(
isPremium = true,
isLoggedIn = true,
isVaultUnlocked = true,
isVaultPendingUnlock = false,
needsPasswordReset = false,
organizations = emptyList(),
),

View file

@ -1798,7 +1798,6 @@ private val DEFAULT_USER_STATE = UserState(
isPremium = true,
isLoggedIn = true,
isVaultUnlocked = true,
isVaultPendingUnlock = false,
needsPasswordReset = false,
isBiometricsEnabled = false,
organizations = emptyList(),

View file

@ -1002,7 +1002,6 @@ class AddSendViewModelTest : BaseViewModelTest() {
isPremium = false,
isLoggedIn = true,
isVaultUnlocked = true,
isVaultPendingUnlock = false,
needsPasswordReset = false,
isBiometricsEnabled = false,
organizations = emptyList(),

View file

@ -2174,7 +2174,6 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
isPremium = true,
isLoggedIn = false,
isVaultUnlocked = false,
isVaultPendingUnlock = false,
needsPasswordReset = false,
organizations = listOf(
Organization(

View file

@ -553,7 +553,6 @@ private val DEFAULT_USER_STATE = UserState(
isPremium = true,
isLoggedIn = true,
isVaultUnlocked = true,
isVaultPendingUnlock = false,
needsPasswordReset = false,
isBiometricsEnabled = false,
organizations = emptyList(),

View file

@ -1497,7 +1497,6 @@ class VaultItemViewModelTest : BaseViewModelTest() {
isPremium = true,
isLoggedIn = true,
isVaultUnlocked = true,
isVaultPendingUnlock = false,
needsPasswordReset = false,
isBiometricsEnabled = false,
organizations = emptyList(),

View file

@ -1372,7 +1372,6 @@ private val DEFAULT_ACCOUNT = UserState.Account(
isPremium = true,
isLoggedIn = true,
isVaultUnlocked = true,
isVaultPendingUnlock = false,
needsPasswordReset = false,
isBiometricsEnabled = false,
organizations = emptyList(),

View file

@ -425,7 +425,6 @@ private val DEFAULT_USER_STATE = UserState(
isPremium = true,
isLoggedIn = true,
isVaultUnlocked = true,
isVaultPendingUnlock = false,
needsPasswordReset = false,
isBiometricsEnabled = false,
organizations = listOf(

View file

@ -94,7 +94,6 @@ private fun createMockUserState(hasOrganizations: Boolean = true): UserState =
isPremium = true,
isLoggedIn = true,
isVaultUnlocked = true,
isVaultPendingUnlock = false,
needsPasswordReset = false,
isBiometricsEnabled = false,
organizations = if (hasOrganizations) {

View file

@ -162,7 +162,6 @@ class VaultViewModelTest : BaseViewModelTest() {
isPremium = true,
isLoggedIn = true,
isVaultUnlocked = true,
isVaultPendingUnlock = false,
needsPasswordReset = false,
isBiometricsEnabled = false,
organizations = listOf(
@ -1281,7 +1280,6 @@ private val DEFAULT_USER_STATE = UserState(
isPremium = true,
isLoggedIn = true,
isVaultUnlocked = true,
isVaultPendingUnlock = false,
needsPasswordReset = false,
isBiometricsEnabled = false,
organizations = emptyList(),
@ -1295,7 +1293,6 @@ private val DEFAULT_USER_STATE = UserState(
isPremium = false,
isLoggedIn = true,
isVaultUnlocked = false,
isVaultPendingUnlock = false,
needsPasswordReset = false,
isBiometricsEnabled = false,
organizations = emptyList(),

View file

@ -69,7 +69,6 @@ class UserStateExtensionsTest {
isPremium = true,
isLoggedIn = true,
isVaultUnlocked = true,
isVaultPendingUnlock = false,
needsPasswordReset = false,
isBiometricsEnabled = false,
organizations = listOf(
@ -88,7 +87,6 @@ class UserStateExtensionsTest {
isPremium = false,
isLoggedIn = true,
isVaultUnlocked = false,
isVaultPendingUnlock = false,
needsPasswordReset = false,
isBiometricsEnabled = false,
organizations = listOf(
@ -111,7 +109,6 @@ class UserStateExtensionsTest {
isPremium = true,
isLoggedIn = true,
isVaultUnlocked = true,
isVaultPendingUnlock = false,
needsPasswordReset = false,
isBiometricsEnabled = false,
organizations = listOf(
@ -134,7 +131,6 @@ class UserStateExtensionsTest {
isPremium = true,
isLoggedIn = false,
isVaultUnlocked = false,
isVaultPendingUnlock = false,
needsPasswordReset = false,
isBiometricsEnabled = false,
organizations = listOf(
@ -172,7 +168,6 @@ class UserStateExtensionsTest {
isPremium = true,
isLoggedIn = true,
isVaultUnlocked = true,
isVaultPendingUnlock = false,
needsPasswordReset = false,
isBiometricsEnabled = false,
organizations = listOf(
@ -208,7 +203,6 @@ class UserStateExtensionsTest {
isPremium = false,
isLoggedIn = true,
isVaultUnlocked = false,
isVaultPendingUnlock = false,
needsPasswordReset = false,
isBiometricsEnabled = false,
organizations = listOf(
@ -248,7 +242,6 @@ class UserStateExtensionsTest {
isPremium = true,
isLoggedIn = true,
isVaultUnlocked = true,
isVaultPendingUnlock = false,
needsPasswordReset = false,
isBiometricsEnabled = false,
organizations = listOf(
@ -276,7 +269,6 @@ class UserStateExtensionsTest {
isPremium = true,
isLoggedIn = true,
isVaultUnlocked = true,
isVaultPendingUnlock = false,
needsPasswordReset = false,
isBiometricsEnabled = false,
organizations = emptyList(),
@ -313,7 +305,6 @@ class UserStateExtensionsTest {
isPremium = true,
isLoggedIn = true,
isVaultUnlocked = true,
isVaultPendingUnlock = false,
needsPasswordReset = false,
isBiometricsEnabled = false,
organizations = listOf(