PM-12631: Handle password re-prompt for accessibility autofill (#3965)

This commit is contained in:
David Perez 2024-09-25 13:16:22 -05:00 committed by GitHub
parent 6908111377
commit caa0c613a5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 64 additions and 1 deletions

View file

@ -1122,8 +1122,19 @@ class VaultItemListingViewModel @Inject constructor(
when (data) {
is MasterPasswordRepromptData.Autofill -> {
// Complete the autofill selection flow
val autofillSelectionData = state.autofillSelectionData ?: return
val cipherView = getCipherViewOrNull(cipherId = data.cipherId) ?: return
autofillSelectionManager.emitAutofillSelection(cipherView = cipherView)
when (autofillSelectionData.framework) {
AutofillSelectionData.Framework.ACCESSIBILITY -> {
accessibilitySelectionManager.emitAccessibilitySelection(
cipherView = cipherView,
)
}
AutofillSelectionData.Framework.AUTOFILL -> {
autofillSelectionManager.emitAutofillSelection(cipherView = cipherView)
}
}
}
is MasterPasswordRepromptData.OverflowItem -> {

View file

@ -794,6 +794,15 @@ class VaultItemListingViewModelTest : BaseViewModelTest() {
sendViewList = emptyList(),
),
)
specialCircumstanceManager.specialCircumstance =
SpecialCircumstance.AutofillSelection(
autofillSelectionData = AutofillSelectionData(
type = AutofillSelectionData.Type.LOGIN,
framework = AutofillSelectionData.Framework.AUTOFILL,
uri = "https://www.test.com",
),
shouldFinishWhenComplete = true,
)
val viewModel = createVaultItemListingViewModel()
coEvery {
authRepository.validatePassword(password = password)
@ -815,6 +824,49 @@ class VaultItemListingViewModelTest : BaseViewModelTest() {
}
}
@Suppress("MaxLineLength")
@Test
fun `MasterPasswordRepromptSubmit for a request Success with a valid password for accessibility autofill should post to the AccessibilitySelectionManager`() =
runTest {
setupMockUri()
val cipherView = createMockCipherView(number = 1)
val cipherId = "mockId-1"
val password = "password"
mutableVaultDataStateFlow.value = DataState.Loaded(
data = VaultData(
cipherViewList = listOf(cipherView),
folderViewList = emptyList(),
collectionViewList = emptyList(),
sendViewList = emptyList(),
),
)
specialCircumstanceManager.specialCircumstance =
SpecialCircumstance.AutofillSelection(
autofillSelectionData = AutofillSelectionData(
type = AutofillSelectionData.Type.LOGIN,
framework = AutofillSelectionData.Framework.ACCESSIBILITY,
uri = "https://www.test.com",
),
shouldFinishWhenComplete = true,
)
val viewModel = createVaultItemListingViewModel()
coEvery {
authRepository.validatePassword(password = password)
} returns ValidatePasswordResult.Success(isValid = true)
accessibilitySelectionManager.accessibilitySelectionFlow.test {
viewModel.trySendAction(
VaultItemListingsAction.MasterPasswordRepromptSubmit(
password = password,
masterPasswordRepromptData = MasterPasswordRepromptData.Autofill(
cipherId = cipherId,
),
),
)
assertEquals(cipherView, awaitItem())
}
}
@Suppress("MaxLineLength")
@Test
fun `MasterPasswordRepromptSubmit for a request Success with a valid password for overflow actions should process the action`() =