mirror of
https://github.com/bitwarden/android.git
synced 2025-02-16 11:59:57 +03:00
PM-10899: Fix user not being logged out properly on app restart (#3822)
This commit is contained in:
parent
9db09c18cc
commit
666c165b6f
4 changed files with 16 additions and 9 deletions
|
@ -476,10 +476,15 @@ class VaultLockManagerImpl(
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
// Only perform action for users losing "fully active" status in some way.
|
|
||||||
when (checkTimeoutReason) {
|
when (checkTimeoutReason) {
|
||||||
// Don't perform delayed actions when first starting the app
|
// Always preform the timeout action on app restart to ensure the user is
|
||||||
CheckTimeoutReason.APP_RESTARTED -> Unit
|
// in the correct state.
|
||||||
|
CheckTimeoutReason.APP_RESTARTED -> {
|
||||||
|
handleTimeoutAction(
|
||||||
|
userId = userId,
|
||||||
|
vaultTimeoutAction = vaultTimeoutAction,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// User no longer active or engaging with the app.
|
// User no longer active or engaging with the app.
|
||||||
CheckTimeoutReason.APP_BACKGROUNDED,
|
CheckTimeoutReason.APP_BACKGROUNDED,
|
||||||
|
|
|
@ -63,8 +63,7 @@ class RootNavViewModel @Inject constructor(
|
||||||
val specialCircumstance = action.specialCircumstance
|
val specialCircumstance = action.specialCircumstance
|
||||||
val updatedRootNavState = when {
|
val updatedRootNavState = when {
|
||||||
userState?.activeAccount?.trustedDevice?.isDeviceTrusted == false &&
|
userState?.activeAccount?.trustedDevice?.isDeviceTrusted == false &&
|
||||||
!userState.activeAccount.isVaultUnlocked &&
|
!userState.activeAccount.isVaultUnlocked -> RootNavState.TrustedDevice
|
||||||
!userState.activeAccount.hasManualUnlockMechanism -> RootNavState.TrustedDevice
|
|
||||||
|
|
||||||
userState?.activeAccount?.needsMasterPassword == true -> RootNavState.SetPassword
|
userState?.activeAccount?.needsMasterPassword == true -> RootNavState.SetPassword
|
||||||
|
|
||||||
|
|
|
@ -275,7 +275,7 @@ class VaultLockManagerTest {
|
||||||
|
|
||||||
fakeAppForegroundManager.appForegroundState = AppForegroundState.FOREGROUNDED
|
fakeAppForegroundManager.appForegroundState = AppForegroundState.FOREGROUNDED
|
||||||
|
|
||||||
assertTrue(vaultLockManager.isVaultUnlocked(USER_ID))
|
assertFalse(vaultLockManager.isVaultUnlocked(USER_ID))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("MaxLineLength")
|
@Suppress("MaxLineLength")
|
||||||
|
@ -330,6 +330,8 @@ class VaultLockManagerTest {
|
||||||
|
|
||||||
// Start in a foregrounded state
|
// Start in a foregrounded state
|
||||||
fakeAppForegroundManager.appForegroundState = AppForegroundState.BACKGROUNDED
|
fakeAppForegroundManager.appForegroundState = AppForegroundState.BACKGROUNDED
|
||||||
|
// We want to skip the first time since that is different from subsequent foregrounds
|
||||||
|
fakeAppForegroundManager.appForegroundState = AppForegroundState.FOREGROUNDED
|
||||||
|
|
||||||
// Will be used within each loop to reset the test to a suitable initial state.
|
// Will be used within each loop to reset the test to a suitable initial state.
|
||||||
fun resetTest(vaultTimeout: VaultTimeout) {
|
fun resetTest(vaultTimeout: VaultTimeout) {
|
||||||
|
|
|
@ -170,8 +170,9 @@ class RootNavViewModelTest : BaseViewModelTest() {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("MaxLineLength")
|
||||||
@Test
|
@Test
|
||||||
fun `when the active user has an untrusted device the nav state should be TrustedDevice`() {
|
fun `when the active user has an untrusted device without password the nav state should be TrustedDevice`() {
|
||||||
mutableUserStateFlow.tryEmit(
|
mutableUserStateFlow.tryEmit(
|
||||||
UserState(
|
UserState(
|
||||||
activeUserId = "activeUserId",
|
activeUserId = "activeUserId",
|
||||||
|
@ -207,7 +208,7 @@ class RootNavViewModelTest : BaseViewModelTest() {
|
||||||
|
|
||||||
@Suppress("MaxLineLength")
|
@Suppress("MaxLineLength")
|
||||||
@Test
|
@Test
|
||||||
fun `when the active user has an untrusted device with password the nav state should be VaultLocked`() {
|
fun `when the active user has an untrusted device with password the nav state should be TrustedDevice`() {
|
||||||
mutableUserStateFlow.tryEmit(
|
mutableUserStateFlow.tryEmit(
|
||||||
UserState(
|
UserState(
|
||||||
activeUserId = "activeUserId",
|
activeUserId = "activeUserId",
|
||||||
|
@ -238,7 +239,7 @@ class RootNavViewModelTest : BaseViewModelTest() {
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
val viewModel = createViewModel()
|
val viewModel = createViewModel()
|
||||||
assertEquals(RootNavState.VaultLocked, viewModel.stateFlow.value)
|
assertEquals(RootNavState.TrustedDevice, viewModel.stateFlow.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("MaxLineLength")
|
@Suppress("MaxLineLength")
|
||||||
|
|
Loading…
Add table
Reference in a new issue