User settings repo to get biometrics enabled info (#824)

This commit is contained in:
David Perez
2024-06-20 17:08:07 +01:00
committed by Álison Fernandes
parent 9fcc326df3
commit aacb955720
5 changed files with 31 additions and 69 deletions
@@ -412,6 +412,24 @@ class SettingsRepositoryTest {
}
}
@Suppress("MaxLineLength")
@Test
fun `isUnlockWithBiometricsEnabled should return a value that tracks the existence of a biometrics key for the current user`() {
val userId = "userId"
fakeAuthDiskSource.userState = MOCK_USER_STATE
fakeAuthDiskSource.storeUserBiometricUnlockKey(
userId = userId,
biometricsKey = null,
)
assertFalse(settingsRepository.isUnlockWithBiometricsEnabled)
fakeAuthDiskSource.storeUserBiometricUnlockKey(
userId = userId,
biometricsKey = "biometricsKey",
)
assertTrue(settingsRepository.isUnlockWithBiometricsEnabled)
}
@Suppress("MaxLineLength")
@Test
fun `isUnlockWithPinEnabled should return a value that tracks the existence of an encrypted PIN for the current user`() {
@@ -4,7 +4,6 @@ import androidx.lifecycle.SavedStateHandle
import app.cash.turbine.test
import com.x8bit.bitwarden.data.auth.repository.AuthRepository
import com.x8bit.bitwarden.data.auth.repository.model.UserFingerprintResult
import com.x8bit.bitwarden.data.auth.repository.model.UserState
import com.x8bit.bitwarden.data.platform.repository.EnvironmentRepository
import com.x8bit.bitwarden.data.platform.repository.SettingsRepository
import com.x8bit.bitwarden.data.platform.repository.model.Environment
@@ -21,7 +20,6 @@ import io.mockk.just
import io.mockk.mockk
import io.mockk.runs
import io.mockk.verify
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertFalse
@@ -31,12 +29,10 @@ import org.junit.jupiter.api.Test
class AccountSecurityViewModelTest : BaseViewModelTest() {
private val fakeEnvironmentRepository = FakeEnvironmentRepository()
private val mutableUserStateFlow = MutableStateFlow<UserState?>(DEFAULT_USER_STATE)
private val authRepository: AuthRepository = mockk(relaxed = true) {
every { userStateFlow } returns mutableUserStateFlow
}
private val authRepository: AuthRepository = mockk(relaxed = true)
private val vaultRepository: VaultRepository = mockk(relaxed = true)
private val settingsRepository: SettingsRepository = mockk {
every { isUnlockWithBiometricsEnabled } returns false
every { isApprovePasswordlessLoginsEnabled } returns false
every { isUnlockWithPinEnabled } returns false
every { vaultTimeout } returns VaultTimeout.ThirtyMinutes
@@ -62,18 +58,6 @@ class AccountSecurityViewModelTest : BaseViewModelTest() {
coVerify { settingsRepository.getUserFingerprint() }
}
@Test
fun `userState with biometrics should update state`() {
mutableUserStateFlow.value = DEFAULT_USER_STATE.copy(
accounts = listOf(DEFAULT_USER_ACCOUNT.copy(isBiometricsEnabled = true)),
)
val viewModel = createViewModel(initialState = null)
assertEquals(
DEFAULT_STATE.copy(isUnlockWithBiometricsEnabled = true),
viewModel.stateFlow.value,
)
}
@Test
fun `on FingerprintResultReceive should update the fingerprint phrase`() = runTest {
val fingerprint = "fingerprint"
@@ -466,21 +450,3 @@ private val DEFAULT_STATE: AccountSecurityState = AccountSecurityState(
vaultTimeout = VaultTimeout.ThirtyMinutes,
vaultTimeoutAction = VaultTimeoutAction.LOCK,
)
private val DEFAULT_USER_ACCOUNT: UserState.Account = UserState.Account(
userId = "activeUserId",
name = "Active User",
email = "active@bitwarden.com",
avatarColorHex = "#aa00aa",
environment = Environment.Us,
isPremium = true,
isLoggedIn = true,
isVaultUnlocked = true,
isBiometricsEnabled = false,
organizations = emptyList(),
)
private val DEFAULT_USER_STATE: UserState = UserState(
activeUserId = "activeUserId",
accounts = listOf(DEFAULT_USER_ACCOUNT),
)