1
0
mirror of https://github.com/bitwarden/browser.git synced 2025-02-03 23:21:29 +01:00

[PM-8027] Fixing issue with username fields not qualifyng as a valid login field if a viewable password field is not present

This commit is contained in:
Cesar Gonzalez 2024-06-13 11:24:55 -05:00
parent 90098168b6
commit f2289f2b21
No known key found for this signature in database
GPG Key ID: 3381A5457F8CCECF
2 changed files with 95 additions and 3 deletions

View File

@ -446,6 +446,63 @@ describe("InlineMenuFieldQualificationService", () => {
inlineMenuFieldQualificationService.isFieldForLoginForm(field, pageDetails),
).toBe(false);
});
it("is structured on a page with multiple viewable password field", () => {
const field = mock<AutofillField>({
type: "text",
autoCompleteType: "",
htmlID: "user-username",
htmlName: "user-username",
placeholder: "user-username",
form: "validFormId",
});
const passwordField = mock<AutofillField>({
type: "password",
autoCompleteType: "current-password",
htmlID: "user-password",
htmlName: "user-password",
placeholder: "user-password",
form: "validFormId",
});
const secondPasswordField = mock<AutofillField>({
type: "password",
autoCompleteType: "current-password",
htmlID: "some-other-password",
htmlName: "some-other-password",
placeholder: "some-other-password",
form: "validFormId",
});
pageDetails.fields = [field, passwordField, secondPasswordField];
expect(
inlineMenuFieldQualificationService.isFieldForLoginForm(field, pageDetails),
).toBe(false);
});
it("is structured on a page with a with no visible password fields and but contains a disabled autocomplete type", () => {
const field = mock<AutofillField>({
type: "text",
autoCompleteType: "off",
htmlID: "user-username",
htmlName: "user-username",
placeholder: "user-username",
form: "validFormId",
});
const passwordField = mock<AutofillField>({
type: "password",
autoCompleteType: "current-password",
htmlID: "user-password",
htmlName: "user-password",
placeholder: "user-password",
form: "validFormId",
viewable: false,
});
pageDetails.fields = [field, passwordField];
expect(
inlineMenuFieldQualificationService.isFieldForLoginForm(field, pageDetails),
).toBe(false);
});
});
});
@ -549,6 +606,31 @@ describe("InlineMenuFieldQualificationService", () => {
inlineMenuFieldQualificationService.isFieldForLoginForm(field, pageDetails),
).toBe(true);
});
it("is structured on a page with a with no visible password fields and a non-disabled autocomplete type", () => {
const field = mock<AutofillField>({
type: "text",
autoCompleteType: "",
htmlID: "user-username",
htmlName: "user-username",
placeholder: "user-username",
form: "validFormId",
});
const passwordField = mock<AutofillField>({
type: "password",
autoCompleteType: "current-password",
htmlID: "user-password",
htmlName: "user-password",
placeholder: "user-password",
form: "validFormId",
viewable: false,
});
pageDetails.fields = [field, passwordField];
expect(
inlineMenuFieldQualificationService.isFieldForLoginForm(field, pageDetails),
).toBe(true);
});
});
});
});

View File

@ -192,12 +192,22 @@ export class InlineMenuFieldQualificationService
// If a single password field exists within the page details, and that password field is part of
// the same form as the provided field, we should assume that the field is part of a login form.
// If multiple visible password fields exist within the page details, we need to assume that the
// provided field is part of an account creation form.
const visiblePasswordFieldsInPageDetails = passwordFieldsInPageDetails.filter(
(passwordField) => passwordField.form === field.form && passwordField.viewable,
);
return visiblePasswordFieldsInPageDetails.length === 1;
if (visiblePasswordFieldsInPageDetails.length === 1) {
return true;
}
// If multiple visible password fields exist within the page details, we need to assume that the
// provided field is part of an account creation form.
if (visiblePasswordFieldsInPageDetails.length > 1) {
return false;
}
// If no visible password fields are found, this field might be part of a multipart form.
// Check for an invalid autocompleteType to determine if the field is part of a login form.
return !this.autocompleteDisabledValues.has(field.autoCompleteType);
}
/**