diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/login/LoginViewModel.kt b/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/login/LoginViewModel.kt index cc10a74d8..36ea5ca02 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/login/LoginViewModel.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/login/LoginViewModel.kt @@ -24,6 +24,7 @@ import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch +import kotlinx.parcelize.IgnoredOnParcel import kotlinx.parcelize.Parcelize import javax.inject.Inject @@ -39,6 +40,7 @@ class LoginViewModel @Inject constructor( private val vaultRepository: VaultRepository, savedStateHandle: SavedStateHandle, ) : BaseViewModel( + // We load the state from the savedStateHandle for testing purposes. initialState = savedStateHandle[KEY_STATE] ?: LoginState( emailAddress = LoginArgs(savedStateHandle).emailAddress, @@ -53,10 +55,6 @@ class LoginViewModel @Inject constructor( ) { init { - // As state updates, write to saved state handle: - stateFlow - .onEach { savedStateHandle[KEY_STATE] = it } - .launchIn(viewModelScope) authRepository.captchaTokenResultFlow .onEach { sendAction( @@ -273,7 +271,8 @@ class LoginViewModel @Inject constructor( */ @Parcelize data class LoginState( - val passwordInput: String, + // We never want this saved since the input is sensitive data. + @IgnoredOnParcel val passwordInput: String = "", val emailAddress: String, val captchaToken: String?, val environmentLabel: String, diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/login/LoginViewModelTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/login/LoginViewModelTest.kt index 3df71e670..df143122e 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/login/LoginViewModelTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/login/LoginViewModelTest.kt @@ -37,9 +37,6 @@ import org.junit.jupiter.api.Test class LoginViewModelTest : BaseViewModelTest() { - private val savedStateHandle = SavedStateHandle().also { - it["email_address"] = EMAIL - } private val mutableCaptchaTokenResultFlow = bufferedMutableSharedFlow() private val mutableUserStateFlow = MutableStateFlow(null) @@ -149,8 +146,7 @@ class LoginViewModelTest : BaseViewModelTest() { passwordInput = "input", isLoginButtonEnabled = true, ) - savedStateHandle["state"] = expectedState - val viewModel = createViewModel() + val viewModel = createViewModel(expectedState) viewModel.stateFlow.test { assertEquals(expectedState, awaitItem()) } @@ -447,12 +443,15 @@ class LoginViewModelTest : BaseViewModelTest() { } } - private fun createViewModel(): LoginViewModel = + private fun createViewModel(state: LoginState? = null): LoginViewModel = LoginViewModel( authRepository = authRepository, environmentRepository = fakeEnvironmentRepository, vaultRepository = vaultRepository, - savedStateHandle = savedStateHandle, + savedStateHandle = SavedStateHandle().also { + it["email_address"] = EMAIL + it["state"] = state + } ) companion object {