BIT-945 Continue with registration if HIBP call fails (#158)

This commit is contained in:
Andrew Haisting 2023-10-24 16:23:16 -05:00 committed by Álison Fernandes
parent bb2b0e8cd1
commit 8295a47e3d
2 changed files with 24 additions and 10 deletions

View file

@ -157,14 +157,11 @@ class AuthRepositoryImpl @Inject constructor(
if (shouldCheckDataBreaches) {
haveIBeenPwnedService
.hasPasswordBeenBreached(password = masterPassword)
.fold(
onFailure = { return RegisterResult.Error(null) },
onSuccess = { foundDataBreaches ->
if (foundDataBreaches) {
return RegisterResult.DataBreachFound
}
},
)
.onSuccess { foundDataBreaches ->
if (foundDataBreaches) {
return RegisterResult.DataBreachFound
}
}
}
val kdf = Kdf.Pbkdf2(DEFAULT_KDF_ITERATIONS.toUInt())
return authSdkSource

View file

@ -235,10 +235,27 @@ class AuthRepositoryTest {
}
@Test
fun `register check data breaches error should return Error`() = runTest {
fun `register check data breaches error should still return register success`() = runTest {
coEvery {
haveIBeenPwnedService.hasPasswordBeenBreached(PASSWORD)
} returns Result.failure(Throwable())
coEvery {
accountsService.register(
body = RegisterRequestJson(
email = EMAIL,
masterPasswordHash = PASSWORD_HASH,
masterPasswordHint = null,
captchaResponse = null,
key = ENCRYPTED_USER_KEY,
keys = RegisterRequestJson.Keys(
publicKey = PUBLIC_KEY,
encryptedPrivateKey = PRIVATE_KEY,
),
kdfType = PBKDF2_SHA256,
kdfIterations = DEFAULT_KDF_ITERATIONS.toUInt(),
),
)
} returns Result.success(RegisterResponseJson.Success(captchaBypassToken = CAPTCHA_KEY))
val result = repository.register(
email = EMAIL,
@ -247,7 +264,7 @@ class AuthRepositoryTest {
captchaToken = null,
shouldCheckDataBreaches = true,
)
assertEquals(RegisterResult.Error(null), result)
assertEquals(RegisterResult.Success(CAPTCHA_KEY), result)
}
@Test