mirror of
https://github.com/bitwarden/android.git
synced 2024-10-31 15:15:34 +03:00
Minor cleanup of Vault Repo tests (#1030)
This commit is contained in:
parent
fe68cb6039
commit
2c8c28b257
1 changed files with 44 additions and 58 deletions
|
@ -150,7 +150,7 @@ class VaultRepositoryTest {
|
||||||
ZoneOffset.UTC,
|
ZoneOffset.UTC,
|
||||||
)
|
)
|
||||||
private val dispatcherManager: DispatcherManager = FakeDispatcherManager()
|
private val dispatcherManager: DispatcherManager = FakeDispatcherManager()
|
||||||
private val userLogoutManager: UserLogoutManager = mockk() {
|
private val userLogoutManager: UserLogoutManager = mockk {
|
||||||
every { logout(any(), any()) } just runs
|
every { logout(any(), any()) } just runs
|
||||||
}
|
}
|
||||||
private val fileManager: FileManager = mockk()
|
private val fileManager: FileManager = mockk()
|
||||||
|
@ -932,14 +932,12 @@ class VaultRepositoryTest {
|
||||||
coVerify(exactly = 0) { syncService.sync() }
|
coVerify(exactly = 0) { syncService.sync() }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("MaxLineLength")
|
|
||||||
@Test
|
@Test
|
||||||
fun `lockVaultForCurrentUser should delegate to the VaultLockManager`() {
|
fun `lockVaultForCurrentUser should delegate to the VaultLockManager`() {
|
||||||
vaultRepository.lockVaultForCurrentUser()
|
vaultRepository.lockVaultForCurrentUser()
|
||||||
verify { vaultLockManager.lockVaultForCurrentUser() }
|
verify { vaultLockManager.lockVaultForCurrentUser() }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("MaxLineLength")
|
|
||||||
@Test
|
@Test
|
||||||
fun `unlockVaultWithBiometrics with missing user state should return InvalidStateError`() =
|
fun `unlockVaultWithBiometrics with missing user state should return InvalidStateError`() =
|
||||||
runTest {
|
runTest {
|
||||||
|
@ -958,7 +956,6 @@ class VaultRepositoryTest {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("MaxLineLength")
|
|
||||||
@Test
|
@Test
|
||||||
fun `unlockVaultWithBiometrics with missing biometrics key should return InvalidStateError`() =
|
fun `unlockVaultWithBiometrics with missing biometrics key should return InvalidStateError`() =
|
||||||
runTest {
|
runTest {
|
||||||
|
@ -1091,7 +1088,6 @@ class VaultRepositoryTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("MaxLineLength")
|
|
||||||
@Test
|
@Test
|
||||||
fun `unlockVaultWithMasterPassword with missing user state should return InvalidStateError`() =
|
fun `unlockVaultWithMasterPassword with missing user state should return InvalidStateError`() =
|
||||||
runTest {
|
runTest {
|
||||||
|
@ -1113,7 +1109,6 @@ class VaultRepositoryTest {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("MaxLineLength")
|
|
||||||
@Test
|
@Test
|
||||||
fun `unlockVaultWithMasterPassword with missing user key should return InvalidStateError`() =
|
fun `unlockVaultWithMasterPassword with missing user key should return InvalidStateError`() =
|
||||||
runTest {
|
runTest {
|
||||||
|
@ -1311,27 +1306,25 @@ class VaultRepositoryTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("MaxLineLength")
|
|
||||||
@Test
|
@Test
|
||||||
fun `unlockVaultWithPin with missing user state should return InvalidStateError`() =
|
fun `unlockVaultWithPin with missing user state should return InvalidStateError`() = runTest {
|
||||||
runTest {
|
fakeAuthDiskSource.userState = null
|
||||||
fakeAuthDiskSource.userState = null
|
assertEquals(
|
||||||
assertEquals(
|
emptyList<VaultUnlockData>(),
|
||||||
emptyList<VaultUnlockData>(),
|
vaultRepository.vaultUnlockDataStateFlow.value,
|
||||||
vaultRepository.vaultUnlockDataStateFlow.value,
|
)
|
||||||
)
|
|
||||||
|
|
||||||
val result = vaultRepository.unlockVaultWithPin(pin = "1234")
|
val result = vaultRepository.unlockVaultWithPin(pin = "1234")
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
VaultUnlockResult.InvalidStateError,
|
VaultUnlockResult.InvalidStateError,
|
||||||
result,
|
result,
|
||||||
)
|
)
|
||||||
assertEquals(
|
assertEquals(
|
||||||
emptyList<VaultUnlockData>(),
|
emptyList<VaultUnlockData>(),
|
||||||
vaultRepository.vaultUnlockDataStateFlow.value,
|
vaultRepository.vaultUnlockDataStateFlow.value,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("MaxLineLength")
|
@Suppress("MaxLineLength")
|
||||||
@Test
|
@Test
|
||||||
|
@ -1362,33 +1355,31 @@ class VaultRepositoryTest {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("MaxLineLength")
|
|
||||||
@Test
|
@Test
|
||||||
fun `unlockVaultWithPin with missing private key should return InvalidStateError`() =
|
fun `unlockVaultWithPin with missing private key should return InvalidStateError`() = runTest {
|
||||||
runTest {
|
assertEquals(
|
||||||
assertEquals(
|
emptyList<VaultUnlockData>(),
|
||||||
emptyList<VaultUnlockData>(),
|
vaultRepository.vaultUnlockDataStateFlow.value,
|
||||||
vaultRepository.vaultUnlockDataStateFlow.value,
|
)
|
||||||
)
|
val result = vaultRepository.unlockVaultWithPin(pin = "1234")
|
||||||
val result = vaultRepository.unlockVaultWithPin(pin = "1234")
|
fakeAuthDiskSource.storePinProtectedUserKey(
|
||||||
fakeAuthDiskSource.storePinProtectedUserKey(
|
userId = "mockId-1",
|
||||||
userId = "mockId-1",
|
pinProtectedUserKey = "mockKey-1",
|
||||||
pinProtectedUserKey = "mockKey-1",
|
)
|
||||||
)
|
fakeAuthDiskSource.storePrivateKey(
|
||||||
fakeAuthDiskSource.storePrivateKey(
|
userId = "mockId-1",
|
||||||
userId = "mockId-1",
|
privateKey = null,
|
||||||
privateKey = null,
|
)
|
||||||
)
|
fakeAuthDiskSource.userState = MOCK_USER_STATE
|
||||||
fakeAuthDiskSource.userState = MOCK_USER_STATE
|
assertEquals(
|
||||||
assertEquals(
|
VaultUnlockResult.InvalidStateError,
|
||||||
VaultUnlockResult.InvalidStateError,
|
result,
|
||||||
result,
|
)
|
||||||
)
|
assertEquals(
|
||||||
assertEquals(
|
emptyList<VaultUnlockData>(),
|
||||||
emptyList<VaultUnlockData>(),
|
vaultRepository.vaultUnlockDataStateFlow.value,
|
||||||
vaultRepository.vaultUnlockDataStateFlow.value,
|
)
|
||||||
)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Suppress("MaxLineLength")
|
@Suppress("MaxLineLength")
|
||||||
@Test
|
@Test
|
||||||
|
@ -3518,7 +3509,6 @@ class VaultRepositoryTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("MaxLineLength")
|
|
||||||
@Test
|
@Test
|
||||||
fun `downloadAttachment with failed decryption should delete file and return Failure`() =
|
fun `downloadAttachment with failed decryption should delete file and return Failure`() =
|
||||||
runTest {
|
runTest {
|
||||||
|
@ -3590,7 +3580,6 @@ class VaultRepositoryTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("MaxLineLength")
|
|
||||||
@Test
|
@Test
|
||||||
fun `downloadAttachment with successful decryption should delete file and return Success`() =
|
fun `downloadAttachment with successful decryption should delete file and return Success`() =
|
||||||
runTest {
|
runTest {
|
||||||
|
@ -3683,9 +3672,9 @@ class VaultRepositoryTest {
|
||||||
@Test
|
@Test
|
||||||
fun `generateTotp should return a success result on getting a code`() = runTest {
|
fun `generateTotp should return a success result on getting a code`() = runTest {
|
||||||
val totpResponse = TotpResponse("Testcode", 30u)
|
val totpResponse = TotpResponse("Testcode", 30u)
|
||||||
coEvery { vaultSdkSource.generateTotp(any(), any(), any()) } returns Result.success(
|
coEvery {
|
||||||
totpResponse,
|
vaultSdkSource.generateTotp(any(), any(), any())
|
||||||
)
|
} returns totpResponse.asSuccess()
|
||||||
fakeAuthDiskSource.userState = MOCK_USER_STATE
|
fakeAuthDiskSource.userState = MOCK_USER_STATE
|
||||||
|
|
||||||
val result = vaultRepository.generateTotp(
|
val result = vaultRepository.generateTotp(
|
||||||
|
@ -4071,14 +4060,12 @@ class VaultRepositoryTest {
|
||||||
assertEquals(UpdateFolderResult.Success(folderView), result)
|
assertEquals(UpdateFolderResult.Success(folderView), result)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("MaxLineLength")
|
|
||||||
@Test
|
@Test
|
||||||
fun `getAuthCodeFlow with no active user should emit an error`() = runTest {
|
fun `getAuthCodeFlow with no active user should emit an error`() = runTest {
|
||||||
fakeAuthDiskSource.userState = null
|
fakeAuthDiskSource.userState = null
|
||||||
assertTrue(vaultRepository.getAuthCodeFlow(cipherId = "cipherId").value is DataState.Error)
|
assertTrue(vaultRepository.getAuthCodeFlow(cipherId = "cipherId").value is DataState.Error)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("MaxLineLength")
|
|
||||||
@Test
|
@Test
|
||||||
fun `getAuthCodeFlow for a single cipher should update data state when state changes`() =
|
fun `getAuthCodeFlow for a single cipher should update data state when state changes`() =
|
||||||
runTest {
|
runTest {
|
||||||
|
@ -4142,7 +4129,6 @@ class VaultRepositoryTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("MaxLineLength")
|
|
||||||
@Test
|
@Test
|
||||||
fun `getAuthCodesFlow with no active user should emit an error`() = runTest {
|
fun `getAuthCodesFlow with no active user should emit an error`() = runTest {
|
||||||
fakeAuthDiskSource.userState = null
|
fakeAuthDiskSource.userState = null
|
||||||
|
|
Loading…
Reference in a new issue