1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 07:43:35 +00: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
2 changed files with 95 additions and 3 deletions

View File

@@ -446,6 +446,63 @@ describe("InlineMenuFieldQualificationService", () => {
inlineMenuFieldQualificationService.isFieldForLoginForm(field, pageDetails), inlineMenuFieldQualificationService.isFieldForLoginForm(field, pageDetails),
).toBe(false); ).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), inlineMenuFieldQualificationService.isFieldForLoginForm(field, pageDetails),
).toBe(true); ).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 // 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. // 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( const visiblePasswordFieldsInPageDetails = passwordFieldsInPageDetails.filter(
(passwordField) => passwordField.form === field.form && passwordField.viewable, (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);
} }
/** /**