mirror of
https://github.com/bitwarden/android.git
synced 2024-11-24 10:25:57 +03:00
[PM-11982] On Passwordless flow switch activeAccount to match PasswordlessRequest userId (#4066)
This commit is contained in:
parent
4756040c4a
commit
9b5c88e990
2 changed files with 38 additions and 3 deletions
|
@ -224,7 +224,7 @@ class MainViewModel @Inject constructor(
|
|||
)
|
||||
}
|
||||
|
||||
@Suppress("LongMethod")
|
||||
@Suppress("LongMethod", "CyclomaticComplexMethod")
|
||||
private fun handleIntent(
|
||||
intent: Intent,
|
||||
isFirstIntent: Boolean,
|
||||
|
@ -242,6 +242,9 @@ class MainViewModel @Inject constructor(
|
|||
val fido2GetCredentialsRequest = intent.getFido2GetCredentialsRequestOrNull()
|
||||
when {
|
||||
passwordlessRequestData != null -> {
|
||||
if (authRepository.activeUserId != passwordlessRequestData.userId) {
|
||||
authRepository.switchAccount(passwordlessRequestData.userId)
|
||||
}
|
||||
specialCircumstanceManager.specialCircumstance =
|
||||
SpecialCircumstance.PasswordlessRequest(
|
||||
passwordlessRequestData = passwordlessRequestData,
|
||||
|
|
|
@ -608,7 +608,7 @@ class MainViewModelTest : BaseViewModelTest() {
|
|||
fun `on ReceiveFirstIntent with a passwordless request data should set the special circumstance to PasswordlessRequest`() {
|
||||
val viewModel = createViewModel()
|
||||
val mockIntent = mockk<Intent>()
|
||||
val passwordlessRequestData = mockk<PasswordlessRequestData>()
|
||||
val passwordlessRequestData = DEFAULT_PASSWORDLESS_REQUEST_DATA
|
||||
every {
|
||||
mockIntent.getPasswordlessRequestDataIntentOrNull()
|
||||
} returns passwordlessRequestData
|
||||
|
@ -917,7 +917,7 @@ class MainViewModelTest : BaseViewModelTest() {
|
|||
fun `on ReceiveNewIntent with a passwordless auth request data should set the special circumstance to PasswordlessRequest`() {
|
||||
val viewModel = createViewModel()
|
||||
val mockIntent = mockk<Intent>()
|
||||
val passwordlessRequestData = mockk<PasswordlessRequestData>()
|
||||
val passwordlessRequestData = DEFAULT_PASSWORDLESS_REQUEST_DATA
|
||||
every {
|
||||
mockIntent.getPasswordlessRequestDataIntentOrNull()
|
||||
} returns passwordlessRequestData
|
||||
|
@ -1054,6 +1054,33 @@ class MainViewModelTest : BaseViewModelTest() {
|
|||
}
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `on ReceiveNewIntent with a passwordless auth request data userId that doesn't match activeUserId should switchAccount`() {
|
||||
val viewModel = createViewModel()
|
||||
val mockIntent = mockk<Intent>()
|
||||
val passwordlessRequestData = mockk<PasswordlessRequestData>()
|
||||
every {
|
||||
mockIntent.getPasswordlessRequestDataIntentOrNull()
|
||||
} returns passwordlessRequestData
|
||||
every { mockIntent.getTotpDataOrNull() } returns null
|
||||
every { mockIntent.getAutofillSaveItemOrNull() } returns null
|
||||
every { mockIntent.getAutofillSelectionDataOrNull() } returns null
|
||||
every { mockIntent.getCompleteRegistrationDataIntentOrNull() } returns null
|
||||
every { intentManager.getShareDataFromIntent(mockIntent) } returns null
|
||||
every { mockIntent.isMyVaultShortcut } returns false
|
||||
every { mockIntent.isPasswordGeneratorShortcut } returns false
|
||||
every { passwordlessRequestData.userId } returns "userId"
|
||||
|
||||
viewModel.trySendAction(
|
||||
MainAction.ReceiveNewIntent(
|
||||
intent = mockIntent,
|
||||
),
|
||||
)
|
||||
|
||||
verify { authRepository.switchAccount("userId") }
|
||||
}
|
||||
|
||||
private fun createViewModel(
|
||||
initialSpecialCircumstance: SpecialCircumstance? = null,
|
||||
) = MainViewModel(
|
||||
|
@ -1109,6 +1136,11 @@ private val DEFAULT_USER_STATE = UserState(
|
|||
accounts = listOf(DEFAULT_ACCOUNT),
|
||||
)
|
||||
|
||||
private val DEFAULT_PASSWORDLESS_REQUEST_DATA = PasswordlessRequestData(
|
||||
userId = "activeUserId",
|
||||
loginRequestId = "",
|
||||
)
|
||||
|
||||
private fun createMockFido2RegistrationIntent(
|
||||
fido2CredentialRequest: Fido2CredentialRequest = createMockFido2CredentialRequest(number = 1),
|
||||
): Intent = mockk<Intent> {
|
||||
|
|
Loading…
Reference in a new issue