From d85485e5cbd2936f5e9dfe75b594178f3384bb2f Mon Sep 17 00:00:00 2001 From: Cesar Gonzalez Date: Fri, 19 Jan 2024 11:20:21 -0600 Subject: [PATCH] [PM-5488] Master password re-prompt not triggering correctly from autofill action (#7590) * [PM-5488] Master Password Re-prompt Not Triggering Correctly When Autofilling From Command * [PM-5488] Master Password Re-prompt Not Triggering Correctly When Autofilling From Command * [PM-5488] Adjusting how we handle debouncing the password reprompt window --- .../services/autofill.service.spec.ts | 22 +++++++++++++++++++ .../src/autofill/services/autofill.service.ts | 15 ++++++------- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/apps/browser/src/autofill/services/autofill.service.spec.ts b/apps/browser/src/autofill/services/autofill.service.spec.ts index cd02e8fcbd..437a99e0f3 100644 --- a/apps/browser/src/autofill/services/autofill.service.spec.ts +++ b/apps/browser/src/autofill/services/autofill.service.spec.ts @@ -909,6 +909,28 @@ describe("AutofillService", () => { expect(autofillService.doAutoFill).not.toHaveBeenCalled(); expect(result).toBeNull(); }); + + it("skips autofill and does not launch the password reprompt window if the password reprompt is currently debouncing", async () => { + cipher.reprompt = CipherRepromptType.Password; + jest.spyOn(autofillService, "doAutoFill"); + jest.spyOn(cipherService, "getNextCipherForUrl").mockResolvedValueOnce(cipher); + jest + .spyOn(userVerificationService, "hasMasterPasswordAndMasterKeyHash") + .mockResolvedValueOnce(true); + jest + .spyOn(autofillService as any, "openVaultItemPasswordRepromptPopout") + .mockImplementation(); + jest + .spyOn(autofillService as any, "isDebouncingPasswordRepromptPopout") + .mockReturnValueOnce(true); + + const result = await autofillService.doAutoFillOnTab(pageDetails, tab, true); + + expect(cipherService.getNextCipherForUrl).toHaveBeenCalledWith(tab.url); + expect(autofillService["openVaultItemPasswordRepromptPopout"]).not.toHaveBeenCalled(); + expect(autofillService.doAutoFill).not.toHaveBeenCalled(); + expect(result).toBeNull(); + }); }); }); diff --git a/apps/browser/src/autofill/services/autofill.service.ts b/apps/browser/src/autofill/services/autofill.service.ts index f14dd0c14c..38515ed61c 100644 --- a/apps/browser/src/autofill/services/autofill.service.ts +++ b/apps/browser/src/autofill/services/autofill.service.ts @@ -332,10 +332,7 @@ export default class AutofillService implements AutofillServiceInterface { return null; } - if ( - (await this.isPasswordRepromptRequired(cipher, tab)) && - !this.isDebouncingPasswordRepromptPopout() - ) { + if (await this.isPasswordRepromptRequired(cipher, tab)) { if (fromCommand) { this.cipherService.updateLastUsedIndexForUrl(tab.url); } @@ -368,10 +365,12 @@ export default class AutofillService implements AutofillServiceInterface { const userHasMasterPasswordAndKeyHash = await this.userVerificationService.hasMasterPasswordAndMasterKeyHash(); if (cipher.reprompt === CipherRepromptType.Password && userHasMasterPasswordAndKeyHash) { - await this.openVaultItemPasswordRepromptPopout(tab, { - cipherId: cipher.id, - action: "autofill", - }); + if (!this.isDebouncingPasswordRepromptPopout()) { + await this.openVaultItemPasswordRepromptPopout(tab, { + cipherId: cipher.id, + action: "autofill", + }); + } return true; }