mirror of
https://github.com/bitwarden/android.git
synced 2026-11-19 17:40:12 -06:00
BIT-1205: Save login items (Encryption) (#295)
This commit is contained in:
committed by
Álison Fernandes
parent
9fcd2b1690
commit
b279633166
@@ -99,6 +99,29 @@ class VaultSdkSourceTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `decryptCipher should call SDK and return a Result with correct data`() = runBlocking {
|
||||
val mockCipher = mockk<CipherView>()
|
||||
val expectedResult = mockk<Cipher>()
|
||||
coEvery {
|
||||
clientVault.ciphers().encrypt(
|
||||
cipherView = mockCipher,
|
||||
)
|
||||
} returns expectedResult
|
||||
val result = vaultSdkSource.encryptCipher(
|
||||
cipherView = mockCipher,
|
||||
)
|
||||
assertEquals(
|
||||
expectedResult.asSuccess(),
|
||||
result,
|
||||
)
|
||||
coVerify {
|
||||
clientVault.ciphers().encrypt(
|
||||
cipherView = mockCipher,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Cipher decrypt should call SDK and return a Result with correct data`() = runBlocking {
|
||||
val mockCipher = mockk<Cipher>()
|
||||
|
||||
+1
-1
@@ -152,7 +152,7 @@ fun createMockPasswordHistoryView(number: Int): PasswordHistoryView =
|
||||
)
|
||||
|
||||
/**
|
||||
* Create a mock [SecureNoteView] with a given [number].
|
||||
* Create a mock [SecureNoteView].
|
||||
*/
|
||||
fun createMockSecureNoteView(): SecureNoteView =
|
||||
SecureNoteView(
|
||||
|
||||
@@ -16,7 +16,10 @@ import com.x8bit.bitwarden.data.platform.manager.dispatcher.DispatcherManager
|
||||
import com.x8bit.bitwarden.data.platform.repository.model.DataState
|
||||
import com.x8bit.bitwarden.data.platform.util.asFailure
|
||||
import com.x8bit.bitwarden.data.platform.util.asSuccess
|
||||
import com.x8bit.bitwarden.data.vault.datasource.network.model.createMockCipher
|
||||
import com.x8bit.bitwarden.data.vault.datasource.network.model.createMockCipherJsonRequest
|
||||
import com.x8bit.bitwarden.data.vault.datasource.network.model.createMockSyncResponse
|
||||
import com.x8bit.bitwarden.data.vault.datasource.network.service.CiphersService
|
||||
import com.x8bit.bitwarden.data.vault.datasource.network.service.SyncService
|
||||
import com.x8bit.bitwarden.data.vault.datasource.sdk.VaultSdkSource
|
||||
import com.x8bit.bitwarden.data.vault.datasource.sdk.model.InitializeCryptoResult
|
||||
@@ -26,6 +29,7 @@ import com.x8bit.bitwarden.data.vault.datasource.sdk.model.createMockSdkCipher
|
||||
import com.x8bit.bitwarden.data.vault.datasource.sdk.model.createMockSdkFolder
|
||||
import com.x8bit.bitwarden.data.vault.datasource.sdk.model.createMockSdkSend
|
||||
import com.x8bit.bitwarden.data.vault.datasource.sdk.model.createMockSendView
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.CreateCipherResult
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.SendData
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.VaultData
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.VaultState
|
||||
@@ -50,9 +54,11 @@ class VaultRepositoryTest {
|
||||
private val dispatcherManager: DispatcherManager = FakeDispatcherManager()
|
||||
private val fakeAuthDiskSource = FakeAuthDiskSource()
|
||||
private val syncService: SyncService = mockk()
|
||||
private val ciphersService: CiphersService = mockk()
|
||||
private val vaultSdkSource: VaultSdkSource = mockk()
|
||||
private val vaultRepository = VaultRepositoryImpl(
|
||||
syncService = syncService,
|
||||
ciphersService = ciphersService,
|
||||
vaultSdkSource = vaultSdkSource,
|
||||
authDiskSource = fakeAuthDiskSource,
|
||||
dispatcherManager = dispatcherManager,
|
||||
@@ -1381,6 +1387,76 @@ class VaultRepositoryTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `createCipher with encryptCipher failure should return CreateCipherResult failure`() =
|
||||
runTest {
|
||||
val mockCipherView = createMockCipherView(number = 1)
|
||||
coEvery {
|
||||
vaultSdkSource.encryptCipher(cipherView = mockCipherView)
|
||||
} returns IllegalStateException().asFailure()
|
||||
|
||||
val result = vaultRepository.createCipher(cipherView = mockCipherView)
|
||||
|
||||
assertEquals(
|
||||
CreateCipherResult.Error,
|
||||
result,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Suppress("MaxLineLength")
|
||||
fun `createCipher with ciphersService createCipher failure should return CreateCipherResult failure`() = runTest {
|
||||
val mockCipherView = createMockCipherView(number = 1)
|
||||
coEvery {
|
||||
vaultSdkSource.encryptCipher(cipherView = mockCipherView)
|
||||
} returns createMockSdkCipher(number = 1).asSuccess()
|
||||
coEvery {
|
||||
ciphersService.createCipher(
|
||||
body = createMockCipherJsonRequest(number = 1),
|
||||
)
|
||||
} returns IllegalStateException().asFailure()
|
||||
|
||||
val result = vaultRepository.createCipher(cipherView = mockCipherView)
|
||||
|
||||
assertEquals(
|
||||
CreateCipherResult.Error,
|
||||
result,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Suppress("MaxLineLength")
|
||||
fun `createCipher with ciphersService createCipher success should return CreateCipherResult success`() = runTest {
|
||||
val mockCipherView = createMockCipherView(number = 1)
|
||||
coEvery {
|
||||
vaultSdkSource.encryptCipher(cipherView = mockCipherView)
|
||||
} returns createMockSdkCipher(number = 1).asSuccess()
|
||||
coEvery {
|
||||
ciphersService.createCipher(
|
||||
body = createMockCipherJsonRequest(number = 1),
|
||||
)
|
||||
} returns createMockCipher(number = 1).asSuccess()
|
||||
coEvery {
|
||||
syncService.sync()
|
||||
} returns Result.success(createMockSyncResponse(1))
|
||||
coEvery {
|
||||
vaultSdkSource.decryptCipherList(listOf(createMockSdkCipher(1)))
|
||||
} returns listOf(createMockCipherView(1)).asSuccess()
|
||||
coEvery {
|
||||
vaultSdkSource.decryptFolderList(listOf(createMockSdkFolder(1)))
|
||||
} returns listOf(createMockFolderView(1)).asSuccess()
|
||||
coEvery {
|
||||
vaultSdkSource.decryptSendList(listOf(createMockSdkSend(1)))
|
||||
} returns listOf(createMockSendView(1)).asSuccess()
|
||||
|
||||
val result = vaultRepository.createCipher(cipherView = mockCipherView)
|
||||
|
||||
assertEquals(
|
||||
CreateCipherResult.Success,
|
||||
result,
|
||||
)
|
||||
}
|
||||
|
||||
//region Helper functions
|
||||
|
||||
/**
|
||||
|
||||
+11
@@ -11,6 +11,7 @@ import com.x8bit.bitwarden.data.vault.datasource.network.model.UriMatchTypeJson
|
||||
import com.x8bit.bitwarden.data.vault.datasource.network.model.createMockAttachment
|
||||
import com.x8bit.bitwarden.data.vault.datasource.network.model.createMockCard
|
||||
import com.x8bit.bitwarden.data.vault.datasource.network.model.createMockCipher
|
||||
import com.x8bit.bitwarden.data.vault.datasource.network.model.createMockCipherJsonRequest
|
||||
import com.x8bit.bitwarden.data.vault.datasource.network.model.createMockField
|
||||
import com.x8bit.bitwarden.data.vault.datasource.network.model.createMockIdentity
|
||||
import com.x8bit.bitwarden.data.vault.datasource.network.model.createMockLogin
|
||||
@@ -31,6 +32,16 @@ import org.junit.Test
|
||||
|
||||
class VaultSdkCipherExtensionsTest {
|
||||
|
||||
@Test
|
||||
fun `toEncryptedNetworkCipher should convert an Sdk Cipher to a Network Cipher`() {
|
||||
val sdkCipher = createMockSdkCipher(number = 1)
|
||||
val syncCipher = sdkCipher.toEncryptedNetworkCipher()
|
||||
assertEquals(
|
||||
createMockCipherJsonRequest(number = 1),
|
||||
syncCipher,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `toEncryptedSdkCipherList should convert list of Network Cipher to List of Sdk Cipher`() {
|
||||
val syncCiphers = listOf(
|
||||
|
||||
+49
-24
@@ -2,7 +2,11 @@ package com.x8bit.bitwarden.ui.vault.feature.additem
|
||||
|
||||
import androidx.lifecycle.SavedStateHandle
|
||||
import app.cash.turbine.test
|
||||
import com.x8bit.bitwarden.data.vault.repository.VaultRepository
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.CreateCipherResult
|
||||
import com.x8bit.bitwarden.ui.platform.base.BaseViewModelTest
|
||||
import io.mockk.coEvery
|
||||
import io.mockk.mockk
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
@@ -13,10 +17,11 @@ class VaultAddItemViewModelTest : BaseViewModelTest() {
|
||||
|
||||
private val initialState = createVaultAddLoginItemState()
|
||||
private val initialSavedStateHandle = createSavedStateHandleWithState(initialState)
|
||||
private val vaultRepository: VaultRepository = mockk()
|
||||
|
||||
@Test
|
||||
fun `initial state should be correct`() = runTest {
|
||||
val viewModel = VaultAddItemViewModel(initialSavedStateHandle)
|
||||
val viewModel = createAddVaultItemViewModel()
|
||||
viewModel.stateFlow.test {
|
||||
assertEquals(initialState, awaitItem())
|
||||
}
|
||||
@@ -24,7 +29,7 @@ class VaultAddItemViewModelTest : BaseViewModelTest() {
|
||||
|
||||
@Test
|
||||
fun `CloseClick should emit NavigateBack`() = runTest {
|
||||
val viewModel = VaultAddItemViewModel(initialSavedStateHandle)
|
||||
val viewModel = createAddVaultItemViewModel()
|
||||
viewModel.eventFlow.test {
|
||||
viewModel.actionChannel.trySend(VaultAddItemAction.CloseClick)
|
||||
assertEquals(VaultAddItemEvent.NavigateBack, awaitItem())
|
||||
@@ -32,17 +37,31 @@ class VaultAddItemViewModelTest : BaseViewModelTest() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `SaveClick should emit ShowToast`() = runTest {
|
||||
val viewModel = VaultAddItemViewModel(initialSavedStateHandle)
|
||||
fun `SaveClick createCipher success should emit NavigateBack`() = runTest {
|
||||
val viewModel = createAddVaultItemViewModel()
|
||||
coEvery {
|
||||
vaultRepository.createCipher(any())
|
||||
} returns CreateCipherResult.Success
|
||||
viewModel.eventFlow.test {
|
||||
viewModel.actionChannel.trySend(VaultAddItemAction.SaveClick)
|
||||
assertEquals(VaultAddItemEvent.ShowToast("Save Item"), awaitItem())
|
||||
assertEquals(VaultAddItemEvent.NavigateBack, awaitItem())
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `SaveClick createCipher error should emit ShowToast`() = runTest {
|
||||
val viewModel = createAddVaultItemViewModel()
|
||||
coEvery {
|
||||
vaultRepository.createCipher(any())
|
||||
} returns CreateCipherResult.Error
|
||||
viewModel.eventFlow.test {
|
||||
viewModel.actionChannel.trySend(VaultAddItemAction.SaveClick)
|
||||
assertEquals(VaultAddItemEvent.ShowToast("Save Item Failure"), awaitItem())
|
||||
}
|
||||
}
|
||||
@Test
|
||||
fun `TypeOptionSelect LOGIN should switch to LoginItem`() = runTest {
|
||||
val viewModel = VaultAddItemViewModel(initialSavedStateHandle)
|
||||
val viewModel = createAddVaultItemViewModel()
|
||||
val action = VaultAddItemAction.TypeOptionSelect(VaultAddItemState.ItemTypeOption.LOGIN)
|
||||
|
||||
viewModel.actionChannel.trySend(action)
|
||||
@@ -58,12 +77,12 @@ class VaultAddItemViewModelTest : BaseViewModelTest() {
|
||||
|
||||
@BeforeEach
|
||||
fun setup() {
|
||||
viewModel = VaultAddItemViewModel(initialSavedStateHandle)
|
||||
viewModel = createAddVaultItemViewModel()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `NameTextChange should update name in LoginItem`() = runTest {
|
||||
val viewModel = VaultAddItemViewModel(initialSavedStateHandle)
|
||||
val viewModel = createAddVaultItemViewModel()
|
||||
val action = VaultAddItemAction.ItemType.LoginType.NameTextChange("newName")
|
||||
|
||||
viewModel.actionChannel.trySend(action)
|
||||
@@ -80,7 +99,7 @@ class VaultAddItemViewModelTest : BaseViewModelTest() {
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `UsernameTextChange should update username in LoginItem`() = runTest {
|
||||
val viewModel = VaultAddItemViewModel(initialSavedStateHandle)
|
||||
val viewModel = createAddVaultItemViewModel()
|
||||
val action = VaultAddItemAction.ItemType.LoginType.UsernameTextChange("newUsername")
|
||||
|
||||
viewModel.actionChannel.trySend(action)
|
||||
@@ -97,7 +116,7 @@ class VaultAddItemViewModelTest : BaseViewModelTest() {
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `PasswordTextChange should update password in LoginItem`() = runTest {
|
||||
val viewModel = VaultAddItemViewModel(initialSavedStateHandle)
|
||||
val viewModel = createAddVaultItemViewModel()
|
||||
val action = VaultAddItemAction.ItemType.LoginType.PasswordTextChange("newPassword")
|
||||
|
||||
viewModel.actionChannel.trySend(action)
|
||||
@@ -113,7 +132,7 @@ class VaultAddItemViewModelTest : BaseViewModelTest() {
|
||||
|
||||
@Test
|
||||
fun `UriTextChange should update uri in LoginItem`() = runTest {
|
||||
val viewModel = VaultAddItemViewModel(initialSavedStateHandle)
|
||||
val viewModel = createAddVaultItemViewModel()
|
||||
val action = VaultAddItemAction.ItemType.LoginType.UriTextChange("newUri")
|
||||
|
||||
viewModel.actionChannel.trySend(action)
|
||||
@@ -129,7 +148,7 @@ class VaultAddItemViewModelTest : BaseViewModelTest() {
|
||||
|
||||
@Test
|
||||
fun `FolderChange should update folder in LoginItem`() = runTest {
|
||||
val viewModel = VaultAddItemViewModel(initialSavedStateHandle)
|
||||
val viewModel = createAddVaultItemViewModel()
|
||||
val action = VaultAddItemAction.ItemType.LoginType.FolderChange("newFolder")
|
||||
|
||||
viewModel.actionChannel.trySend(action)
|
||||
@@ -145,7 +164,7 @@ class VaultAddItemViewModelTest : BaseViewModelTest() {
|
||||
|
||||
@Test
|
||||
fun `ToggleFavorite should update favorite in LoginItem`() = runTest {
|
||||
val viewModel = VaultAddItemViewModel(initialSavedStateHandle)
|
||||
val viewModel = createAddVaultItemViewModel()
|
||||
val action = VaultAddItemAction.ItemType.LoginType.ToggleFavorite(true)
|
||||
|
||||
viewModel.actionChannel.trySend(action)
|
||||
@@ -163,7 +182,7 @@ class VaultAddItemViewModelTest : BaseViewModelTest() {
|
||||
@Test
|
||||
fun `ToggleMasterPasswordReprompt should update masterPasswordReprompt in LoginItem`() =
|
||||
runTest {
|
||||
val viewModel = VaultAddItemViewModel(initialSavedStateHandle)
|
||||
val viewModel = createAddVaultItemViewModel()
|
||||
val action = VaultAddItemAction.ItemType.LoginType.ToggleMasterPasswordReprompt(
|
||||
isMasterPasswordReprompt = true,
|
||||
)
|
||||
@@ -181,7 +200,7 @@ class VaultAddItemViewModelTest : BaseViewModelTest() {
|
||||
|
||||
@Test
|
||||
fun `NotesTextChange should update notes in LoginItem`() = runTest {
|
||||
val viewModel = VaultAddItemViewModel(initialSavedStateHandle)
|
||||
val viewModel = createAddVaultItemViewModel()
|
||||
val action = VaultAddItemAction.ItemType.LoginType.NotesTextChange(notes = "newNotes")
|
||||
|
||||
viewModel.actionChannel.trySend(action)
|
||||
@@ -198,7 +217,7 @@ class VaultAddItemViewModelTest : BaseViewModelTest() {
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `OwnershipChange should update ownership in LoginItem`() = runTest {
|
||||
val viewModel = VaultAddItemViewModel(initialSavedStateHandle)
|
||||
val viewModel = createAddVaultItemViewModel()
|
||||
val action =
|
||||
VaultAddItemAction.ItemType.LoginType.OwnershipChange(ownership = "newOwner")
|
||||
|
||||
@@ -217,7 +236,7 @@ class VaultAddItemViewModelTest : BaseViewModelTest() {
|
||||
@Test
|
||||
fun `OpenUsernameGeneratorClick should emit ShowToast with 'Open Username Generator' message`() =
|
||||
runTest {
|
||||
val viewModel = VaultAddItemViewModel(initialSavedStateHandle)
|
||||
val viewModel = createAddVaultItemViewModel()
|
||||
|
||||
viewModel.eventFlow.test {
|
||||
viewModel.actionChannel.trySend(
|
||||
@@ -233,7 +252,7 @@ class VaultAddItemViewModelTest : BaseViewModelTest() {
|
||||
@Test
|
||||
fun `PasswordCheckerClick should emit ShowToast with 'Password Checker' message`() =
|
||||
runTest {
|
||||
val viewModel = VaultAddItemViewModel(initialSavedStateHandle)
|
||||
val viewModel = createAddVaultItemViewModel()
|
||||
|
||||
viewModel.eventFlow.test {
|
||||
viewModel
|
||||
@@ -248,7 +267,7 @@ class VaultAddItemViewModelTest : BaseViewModelTest() {
|
||||
@Test
|
||||
fun `OpenPasswordGeneratorClick should emit ShowToast with 'Open Password Generator' message`() =
|
||||
runTest {
|
||||
val viewModel = VaultAddItemViewModel(initialSavedStateHandle)
|
||||
val viewModel = createAddVaultItemViewModel()
|
||||
|
||||
viewModel.eventFlow.test {
|
||||
viewModel
|
||||
@@ -265,7 +284,7 @@ class VaultAddItemViewModelTest : BaseViewModelTest() {
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `SetupTotpClick should emit ShowToast with 'Setup TOTP' message`() = runTest {
|
||||
val viewModel = VaultAddItemViewModel(initialSavedStateHandle)
|
||||
val viewModel = createAddVaultItemViewModel()
|
||||
|
||||
viewModel.eventFlow.test {
|
||||
viewModel.actionChannel.trySend(VaultAddItemAction.ItemType.LoginType.SetupTotpClick)
|
||||
@@ -276,7 +295,7 @@ class VaultAddItemViewModelTest : BaseViewModelTest() {
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `UriSettingsClick should emit ShowToast with 'URI Settings' message`() = runTest {
|
||||
val viewModel = VaultAddItemViewModel(initialSavedStateHandle)
|
||||
val viewModel = createAddVaultItemViewModel()
|
||||
|
||||
viewModel.eventFlow.test {
|
||||
viewModel.actionChannel.trySend(VaultAddItemAction.ItemType.LoginType.UriSettingsClick)
|
||||
@@ -286,7 +305,7 @@ class VaultAddItemViewModelTest : BaseViewModelTest() {
|
||||
|
||||
@Test
|
||||
fun `AddNewUriClick should emit ShowToast with 'Add New URI' message`() = runTest {
|
||||
val viewModel = VaultAddItemViewModel(initialSavedStateHandle)
|
||||
val viewModel = createAddVaultItemViewModel()
|
||||
|
||||
viewModel.eventFlow.test {
|
||||
viewModel
|
||||
@@ -301,7 +320,7 @@ class VaultAddItemViewModelTest : BaseViewModelTest() {
|
||||
|
||||
@Test
|
||||
fun `TooltipClick should emit ShowToast with 'Tooltip' message`() = runTest {
|
||||
val viewModel = VaultAddItemViewModel(initialSavedStateHandle)
|
||||
val viewModel = createAddVaultItemViewModel()
|
||||
|
||||
viewModel.eventFlow.test {
|
||||
viewModel
|
||||
@@ -316,7 +335,7 @@ class VaultAddItemViewModelTest : BaseViewModelTest() {
|
||||
@Test
|
||||
fun `AddNewCustomFieldClick should emit ShowToast with 'Add New Custom Field' message`() =
|
||||
runTest {
|
||||
val viewModel = VaultAddItemViewModel(initialSavedStateHandle)
|
||||
val viewModel = createAddVaultItemViewModel()
|
||||
|
||||
viewModel.eventFlow.test {
|
||||
viewModel
|
||||
@@ -359,4 +378,10 @@ class VaultAddItemViewModelTest : BaseViewModelTest() {
|
||||
SavedStateHandle().apply {
|
||||
set("state", state)
|
||||
}
|
||||
|
||||
private fun createAddVaultItemViewModel(): VaultAddItemViewModel =
|
||||
VaultAddItemViewModel(
|
||||
savedStateHandle = initialSavedStateHandle,
|
||||
vaultRepository = vaultRepository,
|
||||
)
|
||||
}
|
||||
|
||||
+79
@@ -1,15 +1,33 @@
|
||||
package com.x8bit.bitwarden.ui.vault.feature.vault.util
|
||||
|
||||
import com.bitwarden.core.CipherRepromptType
|
||||
import com.bitwarden.core.CipherType
|
||||
import com.bitwarden.core.CipherView
|
||||
import com.bitwarden.core.LoginUriView
|
||||
import com.bitwarden.core.LoginView
|
||||
import com.bitwarden.core.UriMatchType
|
||||
import com.x8bit.bitwarden.data.vault.datasource.sdk.model.createMockCipherView
|
||||
import com.x8bit.bitwarden.data.vault.datasource.sdk.model.createMockFolderView
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.VaultData
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.asText
|
||||
import com.x8bit.bitwarden.ui.vault.feature.additem.VaultAddItemState
|
||||
import com.x8bit.bitwarden.ui.vault.feature.vault.VaultState
|
||||
import io.mockk.every
|
||||
import io.mockk.mockkStatic
|
||||
import io.mockk.unmockkStatic
|
||||
import org.junit.jupiter.api.AfterEach
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.time.Instant
|
||||
|
||||
class VaultDataExtensionsTest {
|
||||
|
||||
@AfterEach
|
||||
fun tearDown() {
|
||||
// Some individual tests call mockkStatic so we will make sure this is always undone.
|
||||
unmockkStatic(Instant::class)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `toViewState should transform full VaultData into ViewState Content`() {
|
||||
val vaultData = VaultData(
|
||||
@@ -84,4 +102,65 @@ class VaultDataExtensionsTest {
|
||||
actual,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `toCipherView should transform Login ItemType to CipherView`() {
|
||||
mockkStatic(Instant::class)
|
||||
every { Instant.now() } returns Instant.MIN
|
||||
val loginItemType = VaultAddItemState.ItemType.Login(
|
||||
name = "mockName-1",
|
||||
username = "mockUsername-1",
|
||||
password = "mockPassword-1",
|
||||
uri = "mockUri-1",
|
||||
folder = "mockFolder-1",
|
||||
favorite = false,
|
||||
masterPasswordReprompt = false,
|
||||
notes = "mockNotes-1",
|
||||
ownership = "mockOwnership-1",
|
||||
)
|
||||
|
||||
val result = loginItemType.toCipherView()
|
||||
|
||||
assertEquals(
|
||||
CipherView(
|
||||
id = null,
|
||||
organizationId = null,
|
||||
folderId = null,
|
||||
collectionIds = emptyList(),
|
||||
key = null,
|
||||
name = "mockName-1",
|
||||
notes = "mockNotes-1",
|
||||
type = CipherType.LOGIN,
|
||||
login = LoginView(
|
||||
username = "mockUsername-1",
|
||||
password = "mockPassword-1",
|
||||
passwordRevisionDate = null,
|
||||
uris = listOf(
|
||||
LoginUriView(
|
||||
uri = "mockUri-1",
|
||||
match = UriMatchType.DOMAIN,
|
||||
),
|
||||
),
|
||||
totp = null,
|
||||
autofillOnPageLoad = false,
|
||||
),
|
||||
identity = null,
|
||||
card = null,
|
||||
secureNote = null,
|
||||
favorite = false,
|
||||
reprompt = CipherRepromptType.NONE,
|
||||
organizationUseTotp = false,
|
||||
edit = true,
|
||||
viewPassword = true,
|
||||
localData = null,
|
||||
attachments = null,
|
||||
fields = null,
|
||||
passwordHistory = null,
|
||||
creationDate = Instant.MIN,
|
||||
deletedDate = null,
|
||||
revisionDate = Instant.MIN,
|
||||
),
|
||||
result,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user