PM-15022 Auto login when user completes a YubiKey login trigger. (#4368)

This commit is contained in:
Dave Severns 2024-11-22 13:01:49 -05:00 committed by GitHub
parent c1be5be188
commit 2e1845887c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 22 additions and 3 deletions

View file

@ -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(),

View file

@ -367,6 +367,7 @@ class TwoFactorLoginViewModel @Inject constructor(
isContinueButtonEnabled = true,
)
}
initiateLogin()
}
/**

View file

@ -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