PM-10899: Fix user not being logged out properly on app restart (#3822)

This commit is contained in:
David Perez 2024-08-23 13:49:49 -05:00 committed by GitHub
parent 9db09c18cc
commit 666c165b6f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 16 additions and 9 deletions

View file

@ -476,10 +476,15 @@ class VaultLockManagerImpl(
}
else -> {
// Only perform action for users losing "fully active" status in some way.
when (checkTimeoutReason) {
// Don't perform delayed actions when first starting the app
CheckTimeoutReason.APP_RESTARTED -> Unit
// Always preform the timeout action on app restart to ensure the user is
// in the correct state.
CheckTimeoutReason.APP_RESTARTED -> {
handleTimeoutAction(
userId = userId,
vaultTimeoutAction = vaultTimeoutAction,
)
}
// User no longer active or engaging with the app.
CheckTimeoutReason.APP_BACKGROUNDED,

View file

@ -63,8 +63,7 @@ class RootNavViewModel @Inject constructor(
val specialCircumstance = action.specialCircumstance
val updatedRootNavState = when {
userState?.activeAccount?.trustedDevice?.isDeviceTrusted == false &&
!userState.activeAccount.isVaultUnlocked &&
!userState.activeAccount.hasManualUnlockMechanism -> RootNavState.TrustedDevice
!userState.activeAccount.isVaultUnlocked -> RootNavState.TrustedDevice
userState?.activeAccount?.needsMasterPassword == true -> RootNavState.SetPassword

View file

@ -275,7 +275,7 @@ class VaultLockManagerTest {
fakeAppForegroundManager.appForegroundState = AppForegroundState.FOREGROUNDED
assertTrue(vaultLockManager.isVaultUnlocked(USER_ID))
assertFalse(vaultLockManager.isVaultUnlocked(USER_ID))
}
@Suppress("MaxLineLength")
@ -330,6 +330,8 @@ class VaultLockManagerTest {
// Start in a foregrounded state
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.
fun resetTest(vaultTimeout: VaultTimeout) {

View file

@ -170,8 +170,9 @@ class RootNavViewModelTest : BaseViewModelTest() {
)
}
@Suppress("MaxLineLength")
@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(
UserState(
activeUserId = "activeUserId",
@ -207,7 +208,7 @@ class RootNavViewModelTest : BaseViewModelTest() {
@Suppress("MaxLineLength")
@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(
UserState(
activeUserId = "activeUserId",
@ -238,7 +239,7 @@ class RootNavViewModelTest : BaseViewModelTest() {
),
)
val viewModel = createViewModel()
assertEquals(RootNavState.VaultLocked, viewModel.stateFlow.value)
assertEquals(RootNavState.TrustedDevice, viewModel.stateFlow.value)
}
@Suppress("MaxLineLength")