From e69ef60f530c868ada24f90bba026ca23b3d9460 Mon Sep 17 00:00:00 2001 From: David Perez Date: Wed, 17 Apr 2024 16:25:00 -0500 Subject: [PATCH] BIT-2255: When admin-approval is denied, do not update the UI (#1283) --- .../LoginWithDeviceViewModel.kt | 34 ++++++++++++------- .../LoginWithDeviceViewModelTest.kt | 17 +++++++++- 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/loginwithdevice/LoginWithDeviceViewModel.kt b/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/loginwithdevice/LoginWithDeviceViewModel.kt index ca712b76c..040d7a115 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/loginwithdevice/LoginWithDeviceViewModel.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/loginwithdevice/LoginWithDeviceViewModel.kt @@ -158,18 +158,28 @@ class LoginWithDeviceViewModel @Inject constructor( } CreateAuthRequestResult.Declined -> { - mutableStateFlow.update { - it.copy( - viewState = LoginWithDeviceState.ViewState.Content( - loginWithDeviceType = it.loginWithDeviceType, - fingerprintPhrase = "", - isResendNotificationLoading = false, - ), - dialogState = LoginWithDeviceState.DialogState.Error( - title = null, - message = R.string.this_request_is_no_longer_valid.asText(), - ), - ) + when (state.loginWithDeviceType) { + LoginWithDeviceType.OTHER_DEVICE, + LoginWithDeviceType.SSO_OTHER_DEVICE, + -> { + mutableStateFlow.update { + it.copy( + viewState = LoginWithDeviceState.ViewState.Content( + loginWithDeviceType = it.loginWithDeviceType, + fingerprintPhrase = "", + isResendNotificationLoading = false, + ), + dialogState = LoginWithDeviceState.DialogState.Error( + title = null, + message = R.string.this_request_is_no_longer_valid.asText(), + ), + ) + } + } + + LoginWithDeviceType.SSO_ADMIN_APPROVAL -> { + // Do nothing, the user should not be informed of this state + } } } diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/loginwithdevice/LoginWithDeviceViewModelTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/loginwithdevice/LoginWithDeviceViewModelTest.kt index d77582402..51e6f4cde 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/loginwithdevice/LoginWithDeviceViewModelTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/loginwithdevice/LoginWithDeviceViewModelTest.kt @@ -442,7 +442,7 @@ class LoginWithDeviceViewModelTest : BaseViewModelTest() { @Suppress("MaxLineLength") @Test - fun `on createAuthRequestWithUpdates Declined received should show content with error dialog`() { + fun `on createAuthRequestWithUpdates with OTHER_DEVICE, Declined received should show error dialog`() { val viewModel = createViewModel() assertEquals(DEFAULT_STATE, viewModel.stateFlow.value) mutableCreateAuthRequestWithUpdatesFlow.tryEmit(CreateAuthRequestResult.Declined) @@ -461,6 +461,21 @@ class LoginWithDeviceViewModelTest : BaseViewModelTest() { ) } + @Suppress("MaxLineLength") + @Test + fun `on createAuthRequestWithUpdates with SSO_ADMIN_APPROVAL, Declined received should show unchanged content`() { + val initialState = DEFAULT_STATE.copy( + loginWithDeviceType = LoginWithDeviceType.SSO_ADMIN_APPROVAL, + viewState = DEFAULT_CONTENT_VIEW_STATE.copy( + loginWithDeviceType = LoginWithDeviceType.SSO_ADMIN_APPROVAL, + ), + ) + val viewModel = createViewModel(initialState) + assertEquals(initialState, viewModel.stateFlow.value) + mutableCreateAuthRequestWithUpdatesFlow.tryEmit(CreateAuthRequestResult.Declined) + assertEquals(initialState, viewModel.stateFlow.value) + } + @Test fun `on createAuthRequestWithUpdates Expired received should show content with error dialog`() { val viewModel = createViewModel()