1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-25 12:15:18 +01:00

[PM-3704] Autofill Command Should Not Attempt to Fill If Fields Are Not Found in Page Details (#6318)

* [PM-3704] Autofil Command Should Not Attempt to Fill If Fields Are Not Found in Page Details

* [PM-2319] Adding jest test to ensure workflow is captured in future refactors
This commit is contained in:
Cesar Gonzalez 2023-09-30 13:25:01 -05:00 committed by GitHub
parent a42cea8570
commit 20564f2f54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View File

@ -780,6 +780,18 @@ describe("AutofillService", () => {
];
});
it("returns a null vault without doing autofill if the page details does not contain fields ", async () => {
pageDetails[0].details.fields = [];
jest.spyOn(autofillService as any, "getActiveTab");
jest.spyOn(autofillService, "doAutoFill");
const result = await autofillService.doAutoFillActiveTab(pageDetails, false);
expect(autofillService["getActiveTab"]).not.toHaveBeenCalled();
expect(autofillService.doAutoFill).not.toHaveBeenCalled();
expect(result).toBeNull();
});
it("returns a null value without doing autofill if the active tab cannot be found", async () => {
jest.spyOn(autofillService as any, "getActiveTab").mockResolvedValueOnce(undefined);
jest.spyOn(autofillService, "doAutoFill");

View File

@ -314,6 +314,10 @@ export default class AutofillService implements AutofillServiceInterface {
fromCommand: boolean,
cipherType?: CipherType
): Promise<string | null> {
if (!pageDetails[0]?.details?.fields?.length) {
return null;
}
const tab = await this.getActiveTab();
if (!tab || !tab.url) {