Expose the HaveIBeenPwned service via auth repo (#306)

This commit is contained in:
David Perez
2023-11-30 15:19:47 -06:00
committed by GitHub
parent 193ecd1495
commit 2e2d4de0d7
4 changed files with 63 additions and 0 deletions

View File

@@ -25,6 +25,7 @@ import com.x8bit.bitwarden.data.auth.datasource.sdk.model.PasswordStrength.LEVEL
import com.x8bit.bitwarden.data.auth.datasource.sdk.model.PasswordStrength.LEVEL_3
import com.x8bit.bitwarden.data.auth.datasource.sdk.model.PasswordStrength.LEVEL_4
import com.x8bit.bitwarden.data.auth.repository.model.AuthState
import com.x8bit.bitwarden.data.auth.repository.model.BreachCountResult
import com.x8bit.bitwarden.data.auth.repository.model.DeleteAccountResult
import com.x8bit.bitwarden.data.auth.repository.model.LoginResult
import com.x8bit.bitwarden.data.auth.repository.model.PasswordStrengthResult
@@ -1078,6 +1079,37 @@ class AuthRepositoryTest {
}
}
@Test
fun `getPasswordBreachCount should return failure when service returns failure`() = runTest {
val password = "password"
coEvery {
haveIBeenPwnedService.getPasswordBreachCount(password)
} returns Throwable("Fail").asFailure()
val result = repository.getPasswordBreachCount(password)
coVerify(exactly = 1) {
haveIBeenPwnedService.getPasswordBreachCount(password)
}
assertEquals(BreachCountResult.Error, result)
}
@Test
fun `getPasswordBreachCount should return success when service returns success`() = runTest {
val password = "password"
val breachCount = 5
coEvery {
haveIBeenPwnedService.getPasswordBreachCount(password)
} returns breachCount.asSuccess()
val result = repository.getPasswordBreachCount(password)
coVerify(exactly = 1) {
haveIBeenPwnedService.getPasswordBreachCount(password)
}
assertEquals(BreachCountResult.Success(breachCount), result)
}
@Test
fun `getPasswordStrength should be based on password length`() = runTest {
// TODO: Replace with SDK call (BIT-964)