mirror of
https://github.com/bitwarden/android.git
synced 2026-11-19 17:40:12 -06:00
Handle null or blank auth urls for Duo 2FA (#1044)
This commit is contained in:
committed by
Álison Fernandes
parent
8eafb8e180
commit
2e2b80470c
+3
-2
@@ -6,6 +6,7 @@ import kotlinx.serialization.json.JsonNull
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import kotlinx.serialization.json.JsonPrimitive
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertNull
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class TwoFactorRequiredExtensionTest {
|
||||
@@ -62,7 +63,7 @@ class TwoFactorRequiredExtensionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `twoFactorDuoAuthUrl returns empty string when no DUO AuthUrl is present`() {
|
||||
fun `twoFactorDuoAuthUrl returns null when no DUO AuthUrl is present`() {
|
||||
val subject = GetTokenResponseJson.TwoFactorRequired(
|
||||
authMethodsData = mapOf(
|
||||
TwoFactorAuthMethod.AUTHENTICATOR_APP to JsonObject(mapOf("AuthUrl" to JsonNull)),
|
||||
@@ -70,7 +71,7 @@ class TwoFactorRequiredExtensionTest {
|
||||
captchaToken = null,
|
||||
ssoToken = null,
|
||||
)
|
||||
assertEquals("", subject.twoFactorDuoAuthUrl)
|
||||
assertNull(subject.twoFactorDuoAuthUrl)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+31
-1
@@ -249,8 +249,9 @@ class TwoFactorLoginViewModelTest : BaseViewModelTest() {
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `ContinueButtonClick login should emit NavigateToDuo when auth method is Duo`() = runTest {
|
||||
fun `ContinueButtonClick login should emit NavigateToDuo when auth method is Duo and authUrl is non-null`() = runTest {
|
||||
val authMethodsData = mapOf(
|
||||
TwoFactorAuthMethod.DUO to JsonObject(
|
||||
mapOf("AuthUrl" to JsonPrimitive("bitwarden.com")),
|
||||
@@ -281,6 +282,35 @@ class TwoFactorLoginViewModelTest : BaseViewModelTest() {
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `ContinueButtonClick login should emit ShowToast when auth method is Duo and authUrl is null`() = runTest {
|
||||
val authMethodsData = mapOf(
|
||||
TwoFactorAuthMethod.DUO to JsonObject(
|
||||
mapOf("Nothing" to JsonPrimitive("Nothing")),
|
||||
),
|
||||
)
|
||||
val response = GetTokenResponseJson.TwoFactorRequired(
|
||||
authMethodsData = authMethodsData,
|
||||
captchaToken = null,
|
||||
ssoToken = null,
|
||||
)
|
||||
every { authRepository.twoFactorResponse } returns response
|
||||
val mockkUri = mockk<Uri>()
|
||||
val viewModel = createViewModel(
|
||||
state = DEFAULT_STATE.copy(
|
||||
authMethod = TwoFactorAuthMethod.DUO,
|
||||
),
|
||||
)
|
||||
viewModel.eventFlow.test {
|
||||
viewModel.actionChannel.trySend(TwoFactorLoginAction.ContinueButtonClick)
|
||||
assertEquals(
|
||||
TwoFactorLoginEvent.ShowToast("Duo not yet supported".asText()),
|
||||
awaitItem(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ContinueButtonClick login returns CaptchaRequired should emit NavigateToCaptcha`() =
|
||||
runTest {
|
||||
|
||||
Reference in New Issue
Block a user