mirror of
https://github.com/bitwarden/android.git
synced 2026-11-19 17:40:12 -06:00
BIT-783: Enforce Send restriction policy (#915)
This commit is contained in:
committed by
Álison Fernandes
parent
d538e37606
commit
05a171e71c
@@ -186,6 +186,26 @@ class SendScreenTest : BaseComposeTest() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `policy warning should update according to state`() {
|
||||
val policyText = "Due to an enterprise policy, you are only " +
|
||||
"able to delete an existing Send."
|
||||
composeTestRule
|
||||
.onNodeWithText(policyText)
|
||||
.assertDoesNotExist()
|
||||
|
||||
mutableStateFlow.update {
|
||||
it.copy(
|
||||
viewState = SendState.ViewState.Empty,
|
||||
policyDisablesSend = true,
|
||||
)
|
||||
}
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithText(policyText)
|
||||
.assertIsDisplayed()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `fab should be displayed according to state`() {
|
||||
mutableStateFlow.update {
|
||||
@@ -379,6 +399,32 @@ class SendScreenTest : BaseComposeTest() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `send item overflow button should update according to state`() {
|
||||
mutableStateFlow.update {
|
||||
it.copy(
|
||||
viewState = SendState.ViewState.Content(
|
||||
textTypeCount = 0,
|
||||
fileTypeCount = 1,
|
||||
sendItems = listOf(DEFAULT_SEND_ITEM),
|
||||
),
|
||||
)
|
||||
}
|
||||
composeTestRule
|
||||
.onNodeWithContentDescription("Options")
|
||||
.assertIsDisplayed()
|
||||
|
||||
mutableStateFlow.update {
|
||||
it.copy(
|
||||
policyDisablesSend = true,
|
||||
)
|
||||
}
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithContentDescription("Options")
|
||||
.assertDoesNotExist()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `on send item overflow click should display dialog`() {
|
||||
mutableStateFlow.update {
|
||||
@@ -664,6 +710,7 @@ private val DEFAULT_STATE: SendState = SendState(
|
||||
viewState = SendState.ViewState.Loading,
|
||||
dialogState = null,
|
||||
isPullToRefreshSettingEnabled = false,
|
||||
policyDisablesSend = false,
|
||||
)
|
||||
|
||||
private val DEFAULT_SEND_ITEM: SendState.ViewState.Content.SendItem =
|
||||
|
||||
@@ -3,12 +3,14 @@ package com.x8bit.bitwarden.ui.tools.feature.send
|
||||
import androidx.lifecycle.SavedStateHandle
|
||||
import app.cash.turbine.test
|
||||
import com.x8bit.bitwarden.R
|
||||
import com.x8bit.bitwarden.data.platform.manager.PolicyManager
|
||||
import com.x8bit.bitwarden.data.platform.manager.clipboard.BitwardenClipboardManager
|
||||
import com.x8bit.bitwarden.data.platform.repository.EnvironmentRepository
|
||||
import com.x8bit.bitwarden.data.platform.repository.SettingsRepository
|
||||
import com.x8bit.bitwarden.data.platform.repository.model.DataState
|
||||
import com.x8bit.bitwarden.data.platform.repository.model.Environment
|
||||
import com.x8bit.bitwarden.data.platform.repository.util.baseWebSendUrl
|
||||
import com.x8bit.bitwarden.data.vault.datasource.network.model.PolicyTypeJson
|
||||
import com.x8bit.bitwarden.data.vault.repository.VaultRepository
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.DeleteSendResult
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.RemovePasswordSendResult
|
||||
@@ -26,6 +28,7 @@ import io.mockk.runs
|
||||
import io.mockk.unmockkStatic
|
||||
import io.mockk.verify
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.emptyFlow
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.jupiter.api.AfterEach
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
@@ -48,6 +51,10 @@ class SendViewModelTest : BaseViewModelTest() {
|
||||
private val vaultRepo: VaultRepository = mockk {
|
||||
every { sendDataStateFlow } returns mutableSendDataFlow
|
||||
}
|
||||
private val policyManager: PolicyManager = mockk {
|
||||
every { getActivePolicies(type = PolicyTypeJson.DISABLE_SEND) } returns emptyList()
|
||||
every { getActivePoliciesFlow(type = PolicyTypeJson.DISABLE_SEND) } returns emptyFlow()
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
fun setup() {
|
||||
@@ -435,12 +442,14 @@ class SendViewModelTest : BaseViewModelTest() {
|
||||
)
|
||||
}
|
||||
|
||||
@Suppress("LongParameterList")
|
||||
private fun createViewModel(
|
||||
state: SendState? = null,
|
||||
bitwardenClipboardManager: BitwardenClipboardManager = clipboardManager,
|
||||
environmentRepository: EnvironmentRepository = environmentRepo,
|
||||
settingsRepository: SettingsRepository = settingsRepo,
|
||||
vaultRepository: VaultRepository = vaultRepo,
|
||||
policyManager: PolicyManager = this.policyManager,
|
||||
): SendViewModel = SendViewModel(
|
||||
savedStateHandle = SavedStateHandle().apply {
|
||||
set("state", state)
|
||||
@@ -449,6 +458,7 @@ class SendViewModelTest : BaseViewModelTest() {
|
||||
environmentRepo = environmentRepository,
|
||||
settingsRepo = settingsRepository,
|
||||
vaultRepo = vaultRepository,
|
||||
policyManager = policyManager,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -456,4 +466,5 @@ private val DEFAULT_STATE: SendState = SendState(
|
||||
viewState = SendState.ViewState.Loading,
|
||||
dialogState = null,
|
||||
isPullToRefreshSettingEnabled = false,
|
||||
policyDisablesSend = false,
|
||||
)
|
||||
|
||||
+46
@@ -148,6 +148,32 @@ class AddSendScreenTest : BaseComposeTest() {
|
||||
.isDisplayed()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `on overflow button click should only display delete when policy disables send`() {
|
||||
mutableStateFlow.value = DEFAULT_STATE.copy(
|
||||
addSendType = AddSendType.EditItem(sendItemId = "sendId"),
|
||||
policyDisablesSend = true,
|
||||
)
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithContentDescription("More")
|
||||
.performClick()
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithText("Remove password")
|
||||
.assertDoesNotExist()
|
||||
composeTestRule
|
||||
.onNodeWithText("Copy link")
|
||||
.assertDoesNotExist()
|
||||
composeTestRule
|
||||
.onNodeWithText("Share link")
|
||||
.assertDoesNotExist()
|
||||
composeTestRule
|
||||
.onNodeWithText("Delete")
|
||||
.assert(hasAnyAncestor(isPopup()))
|
||||
.isDisplayed()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `overflow remove password button should be hidden when hasPassword is false`() {
|
||||
mutableStateFlow.value = DEFAULT_STATE.copy(
|
||||
@@ -267,6 +293,25 @@ class AddSendScreenTest : BaseComposeTest() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `policy warning should update according to state`() {
|
||||
val policyText = "Due to an enterprise policy, you are only " +
|
||||
"able to delete an existing Send."
|
||||
composeTestRule
|
||||
.onNodeWithText(policyText)
|
||||
.assertDoesNotExist()
|
||||
|
||||
mutableStateFlow.update {
|
||||
it.copy(
|
||||
policyDisablesSend = true,
|
||||
)
|
||||
}
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithText(policyText)
|
||||
.assertIsDisplayed()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `on name input change should send NameChange`() {
|
||||
composeTestRule
|
||||
@@ -932,6 +977,7 @@ class AddSendScreenTest : BaseComposeTest() {
|
||||
isShared = false,
|
||||
isPremiumUser = false,
|
||||
baseWebSendUrl = "https://vault.bitwarden.com/#/send/",
|
||||
policyDisablesSend = false,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+29
@@ -7,11 +7,14 @@ import com.bitwarden.core.SendView
|
||||
import com.x8bit.bitwarden.R
|
||||
import com.x8bit.bitwarden.data.auth.repository.AuthRepository
|
||||
import com.x8bit.bitwarden.data.auth.repository.model.UserState
|
||||
import com.x8bit.bitwarden.data.platform.manager.PolicyManager
|
||||
import com.x8bit.bitwarden.data.platform.manager.SpecialCircumstanceManager
|
||||
import com.x8bit.bitwarden.data.platform.manager.clipboard.BitwardenClipboardManager
|
||||
import com.x8bit.bitwarden.data.platform.repository.EnvironmentRepository
|
||||
import com.x8bit.bitwarden.data.platform.repository.model.DataState
|
||||
import com.x8bit.bitwarden.data.platform.repository.model.Environment
|
||||
import com.x8bit.bitwarden.data.vault.datasource.network.model.PolicyTypeJson
|
||||
import com.x8bit.bitwarden.data.vault.datasource.network.model.createMockPolicy
|
||||
import com.x8bit.bitwarden.data.vault.datasource.sdk.model.createMockSendView
|
||||
import com.x8bit.bitwarden.data.vault.repository.VaultRepository
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.CreateSendResult
|
||||
@@ -70,6 +73,9 @@ class AddSendViewModelTest : BaseViewModelTest() {
|
||||
private val vaultRepository: VaultRepository = mockk {
|
||||
every { getSendStateFlow(any()) } returns mutableSendDataStateFlow
|
||||
}
|
||||
private val policyManager: PolicyManager = mockk {
|
||||
every { getActivePolicies(type = PolicyTypeJson.DISABLE_SEND) } returns emptyList()
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
fun setup() {
|
||||
@@ -811,6 +817,27 @@ class AddSendViewModelTest : BaseViewModelTest() {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `FileTypeClick should display error dialog when policy disables send`() {
|
||||
every {
|
||||
policyManager.getActivePolicies(type = PolicyTypeJson.DISABLE_SEND)
|
||||
} returns listOf(createMockPolicy())
|
||||
val viewModel = createViewModel()
|
||||
|
||||
viewModel.trySendAction(AddSendAction.FileTypeClick)
|
||||
|
||||
assertEquals(
|
||||
DEFAULT_STATE.copy(
|
||||
dialogState = AddSendState.DialogState.Error(
|
||||
title = null,
|
||||
message = R.string.send_disabled_warning.asText(),
|
||||
),
|
||||
policyDisablesSend = true,
|
||||
),
|
||||
viewModel.stateFlow.value,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `NameChange should update name input`() = runTest {
|
||||
val viewModel = createViewModel()
|
||||
@@ -954,6 +981,7 @@ class AddSendViewModelTest : BaseViewModelTest() {
|
||||
clock = clock,
|
||||
clipboardManager = clipboardManager,
|
||||
vaultRepo = vaultRepository,
|
||||
policyManager = policyManager,
|
||||
)
|
||||
|
||||
companion object {
|
||||
@@ -991,6 +1019,7 @@ class AddSendViewModelTest : BaseViewModelTest() {
|
||||
isShared = false,
|
||||
isPremiumUser = false,
|
||||
baseWebSendUrl = DEFAULT_ENVIRONMENT_URL,
|
||||
policyDisablesSend = false,
|
||||
)
|
||||
|
||||
private val DEFAULT_USER_ACCOUNT_STATE = UserState.Account(
|
||||
|
||||
+54
@@ -291,6 +291,34 @@ class VaultItemListingScreenTest : BaseComposeTest() {
|
||||
verify { viewModel.trySendAction(VaultItemListingsAction.SearchIconClick) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `policy warning should update according to state`() {
|
||||
mutableStateFlow.update {
|
||||
it.copy(
|
||||
itemListingType = VaultItemListingState.ItemListingType.Send.SendFile,
|
||||
viewState = VaultItemListingState.ViewState.NoItems(
|
||||
message = "There are no Sends in your account.".asText(),
|
||||
shouldShowAddButton = true,
|
||||
),
|
||||
)
|
||||
}
|
||||
val policyText = "Due to an enterprise policy, you are only " +
|
||||
"able to delete an existing Send."
|
||||
composeTestRule
|
||||
.onNodeWithText(policyText)
|
||||
.assertDoesNotExist()
|
||||
|
||||
mutableStateFlow.update {
|
||||
it.copy(
|
||||
policyDisablesSend = true,
|
||||
)
|
||||
}
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithText(policyText)
|
||||
.assertIsDisplayed()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `floating action button click should send AddItemClick action`() {
|
||||
composeTestRule
|
||||
@@ -833,6 +861,31 @@ class VaultItemListingScreenTest : BaseComposeTest() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `send item overflow item button should update according to state`() {
|
||||
mutableStateFlow.update {
|
||||
it.copy(
|
||||
itemListingType = VaultItemListingState.ItemListingType.Send.SendFile,
|
||||
viewState = VaultItemListingState.ViewState.Content(
|
||||
displayItemList = listOf(createDisplayItem(number = 1)),
|
||||
),
|
||||
)
|
||||
}
|
||||
composeTestRule
|
||||
.onNodeWithContentDescription("Options")
|
||||
.assertIsDisplayed()
|
||||
|
||||
mutableStateFlow.update {
|
||||
it.copy(
|
||||
policyDisablesSend = true,
|
||||
)
|
||||
}
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithContentDescription("Options")
|
||||
.assertDoesNotExist()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `on send item overflow click should display dialog`() {
|
||||
val number = 1
|
||||
@@ -1071,6 +1124,7 @@ private val DEFAULT_STATE = VaultItemListingState(
|
||||
baseIconUrl = Environment.Us.environmentUrlData.baseIconUrl,
|
||||
isPullToRefreshSettingEnabled = false,
|
||||
dialogState = null,
|
||||
policyDisablesSend = false,
|
||||
)
|
||||
|
||||
private val STATE_FOR_AUTOFILL = DEFAULT_STATE.copy(
|
||||
|
||||
+10
@@ -12,6 +12,7 @@ import com.x8bit.bitwarden.data.auth.repository.model.ValidatePasswordResult
|
||||
import com.x8bit.bitwarden.data.autofill.manager.AutofillSelectionManager
|
||||
import com.x8bit.bitwarden.data.autofill.manager.AutofillSelectionManagerImpl
|
||||
import com.x8bit.bitwarden.data.autofill.model.AutofillSelectionData
|
||||
import com.x8bit.bitwarden.data.platform.manager.PolicyManager
|
||||
import com.x8bit.bitwarden.data.platform.manager.SpecialCircumstanceManagerImpl
|
||||
import com.x8bit.bitwarden.data.platform.manager.ciphermatching.CipherMatchingManager
|
||||
import com.x8bit.bitwarden.data.platform.manager.clipboard.BitwardenClipboardManager
|
||||
@@ -22,6 +23,7 @@ import com.x8bit.bitwarden.data.platform.repository.model.DataState
|
||||
import com.x8bit.bitwarden.data.platform.repository.model.Environment
|
||||
import com.x8bit.bitwarden.data.platform.repository.util.baseIconUrl
|
||||
import com.x8bit.bitwarden.data.platform.repository.util.baseWebSendUrl
|
||||
import com.x8bit.bitwarden.data.vault.datasource.network.model.PolicyTypeJson
|
||||
import com.x8bit.bitwarden.data.vault.datasource.sdk.model.createMockCipherView
|
||||
import com.x8bit.bitwarden.data.vault.datasource.sdk.model.createMockCollectionView
|
||||
import com.x8bit.bitwarden.data.vault.datasource.sdk.model.createMockFolderView
|
||||
@@ -51,6 +53,7 @@ import io.mockk.runs
|
||||
import io.mockk.unmockkStatic
|
||||
import io.mockk.verify
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.emptyFlow
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertFalse
|
||||
@@ -112,6 +115,11 @@ class VaultItemListingViewModelTest : BaseViewModelTest() {
|
||||
every { getPullToRefreshEnabledFlow() } returns mutablePullToRefreshEnabledFlow
|
||||
}
|
||||
private val specialCircumstanceManager = SpecialCircumstanceManagerImpl()
|
||||
private val policyManager: PolicyManager = mockk {
|
||||
every { getActivePolicies(type = PolicyTypeJson.DISABLE_SEND) } returns emptyList()
|
||||
every { getActivePoliciesFlow(type = PolicyTypeJson.DISABLE_SEND) } returns emptyFlow()
|
||||
}
|
||||
|
||||
private val initialState = createVaultItemListingState()
|
||||
private val initialSavedStateHandle = createSavedStateHandleWithVaultItemListingType(
|
||||
vaultItemListingType = VaultItemListingType.Login,
|
||||
@@ -1340,6 +1348,7 @@ class VaultItemListingViewModelTest : BaseViewModelTest() {
|
||||
autofillSelectionManager = autofillSelectionManager,
|
||||
cipherMatchingManager = cipherMatchingManager,
|
||||
specialCircumstanceManager = specialCircumstanceManager,
|
||||
policyManager = policyManager,
|
||||
)
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@@ -1360,6 +1369,7 @@ class VaultItemListingViewModelTest : BaseViewModelTest() {
|
||||
dialogState = null,
|
||||
autofillSelectionData = null,
|
||||
shouldFinishOnComplete = false,
|
||||
policyDisablesSend = false,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user