mirror of
https://github.com/bitwarden/android.git
synced 2025-03-15 10:48:47 +03:00
PM-15022 Auto login when user completes a YubiKey login trigger. (#4368)
This commit is contained in:
parent
c1be5be188
commit
2e1845887c
3 changed files with 22 additions and 3 deletions
|
@ -11,6 +11,7 @@ import androidx.compose.foundation.layout.imePadding
|
|||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.text.KeyboardActions
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Text
|
||||
|
@ -251,6 +252,9 @@ private fun TwoFactorLoginScreenContent(
|
|||
keyboardType = KeyboardType.Number,
|
||||
imeAction = ImeAction.Done,
|
||||
autoFocus = true,
|
||||
keyboardActions = KeyboardActions(
|
||||
onDone = { onContinueButtonClick() },
|
||||
),
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 16.dp)
|
||||
.fillMaxWidth(),
|
||||
|
|
|
@ -367,6 +367,7 @@ class TwoFactorLoginViewModel @Inject constructor(
|
|||
isContinueButtonEnabled = true,
|
||||
)
|
||||
}
|
||||
initiateLogin()
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -48,12 +48,13 @@ class TwoFactorLoginViewModelTest : BaseViewModelTest() {
|
|||
private val mutableDuoTokenResultFlow = bufferedMutableSharedFlow<DuoCallbackTokenResult>()
|
||||
private val mutableYubiKeyResultFlow = bufferedMutableSharedFlow<YubiKeyResult>()
|
||||
private val mutableWebAuthResultFlow = bufferedMutableSharedFlow<WebAuthResult>()
|
||||
private val authRepository: AuthRepository = mockk(relaxed = true) {
|
||||
private val authRepository: AuthRepository = mockk {
|
||||
every { twoFactorResponse } returns TWO_FACTOR_RESPONSE
|
||||
every { captchaTokenResultFlow } returns mutableCaptchaTokenResultFlow
|
||||
every { duoTokenResultFlow } returns mutableDuoTokenResultFlow
|
||||
every { yubiKeyResultFlow } returns mutableYubiKeyResultFlow
|
||||
every { webAuthResultFlow } returns mutableWebAuthResultFlow
|
||||
coEvery { login(any(), any(), any(), any(), any()) } returns LoginResult.Success
|
||||
}
|
||||
private val environmentRepository: EnvironmentRepository = mockk {
|
||||
every { environment } returns Environment.Us
|
||||
|
@ -98,8 +99,8 @@ class TwoFactorLoginViewModelTest : BaseViewModelTest() {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun `yubiKeyResultFlow update should populate the input field`() {
|
||||
val initialState = DEFAULT_STATE
|
||||
fun `yubiKeyResultFlow update should populate the input field and attempt login`() {
|
||||
val initialState = DEFAULT_STATE.copy(authMethod = TwoFactorAuthMethod.YUBI_KEY)
|
||||
val token = "token"
|
||||
val viewModel = createViewModel(initialState)
|
||||
mutableYubiKeyResultFlow.tryEmit(YubiKeyResult(token))
|
||||
|
@ -110,6 +111,19 @@ class TwoFactorLoginViewModelTest : BaseViewModelTest() {
|
|||
),
|
||||
viewModel.stateFlow.value,
|
||||
)
|
||||
coVerify(exactly = 1) {
|
||||
authRepository.login(
|
||||
email = DEFAULT_STATE.email,
|
||||
password = DEFAULT_STATE.password,
|
||||
twoFactorData = TwoFactorDataModel(
|
||||
code = token,
|
||||
method = TwoFactorAuthMethod.YUBI_KEY.value.toString(),
|
||||
remember = DEFAULT_STATE.isRememberMeEnabled,
|
||||
),
|
||||
captchaToken = DEFAULT_STATE.captchaToken,
|
||||
orgIdentifier = DEFAULT_STATE.orgIdentifier,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Add table
Reference in a new issue