diff --git a/apps/browser/src/autofill/background/overlay.background.spec.ts b/apps/browser/src/autofill/background/overlay.background.spec.ts index 8a4954c63f..5e00b97243 100644 --- a/apps/browser/src/autofill/background/overlay.background.spec.ts +++ b/apps/browser/src/autofill/background/overlay.background.spec.ts @@ -36,7 +36,6 @@ import { VaultSettingsService } from "@bitwarden/common/vault/abstractions/vault import { CipherRepromptType, CipherType } from "@bitwarden/common/vault/enums"; import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view"; import { Fido2CredentialView } from "@bitwarden/common/vault/models/view/fido2-credential.view"; -import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy"; import { BrowserApi } from "../../platform/browser/browser-api"; import { BrowserPlatformUtilsService } from "../../platform/services/platform-utils/browser-platform-utils.service"; @@ -76,6 +75,7 @@ import { import { OverlayBackground } from "./overlay.background"; describe("OverlayBackground", () => { + const generatedPassword = "generated-password"; const mockUserId = Utils.newGuid() as UserId; const sendResponse = jest.fn(); let accountService: FakeAccountService; @@ -98,7 +98,6 @@ describe("OverlayBackground", () => { let vaultSettingsServiceMock: MockProxy; let fido2ActiveRequestManager: Fido2ActiveRequestManager; let selectedThemeMock$: BehaviorSubject; - let passwordGenerationService: MockProxy; let inlineMenuFieldQualificationService: MockProxy; let themeStateService: MockProxy; let overlayBackground: OverlayBackground; @@ -176,9 +175,6 @@ describe("OverlayBackground", () => { selectedThemeMock$ = new BehaviorSubject(ThemeType.Light); inlineMenuFieldQualificationService = mock(); themeStateService = mock(); - passwordGenerationService = mock({ - getOptions: jest.fn().mockResolvedValue([null, null]), - }); themeStateService.selectedTheme$ = selectedThemeMock$; overlayBackground = new OverlayBackground( logService, @@ -192,9 +188,9 @@ describe("OverlayBackground", () => { platformUtilsService, vaultSettingsServiceMock, fido2ActiveRequestManager, - passwordGenerationService, inlineMenuFieldQualificationService, themeStateService, + () => Promise.resolve(generatedPassword), ); portKeyForTabSpy = overlayBackground["portKeyForTab"]; pageDetailsForTabSpy = overlayBackground["pageDetailsForTab"]; diff --git a/apps/browser/src/autofill/background/overlay.background.ts b/apps/browser/src/autofill/background/overlay.background.ts index ba568dd35f..41a33a3a94 100644 --- a/apps/browser/src/autofill/background/overlay.background.ts +++ b/apps/browser/src/autofill/background/overlay.background.ts @@ -42,7 +42,6 @@ import { Fido2CredentialView } from "@bitwarden/common/vault/models/view/fido2-c import { IdentityView } from "@bitwarden/common/vault/models/view/identity.view"; import { LoginUriView } from "@bitwarden/common/vault/models/view/login-uri.view"; import { LoginView } from "@bitwarden/common/vault/models/view/login.view"; -import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy"; import { openUnlockPopout } from "../../auth/popup/utils/auth-popout-window"; import { BrowserApi } from "../../platform/browser/browser-api"; @@ -206,9 +205,9 @@ export class OverlayBackground implements OverlayBackgroundInterface { private platformUtilsService: PlatformUtilsService, private vaultSettingsService: VaultSettingsService, private fido2ActiveRequestManager: Fido2ActiveRequestManager, - private passwordGenerationService: PasswordGenerationServiceAbstraction, private inlineMenuFieldQualificationService: InlineMenuFieldQualificationService, private themeStateService: ThemeStateService, + private generatePasswordCallback: () => Promise, ) { this.initOverlayEventObservables(); } @@ -1511,10 +1510,7 @@ export class OverlayBackground implements OverlayBackgroundInterface { * Generates a password based on the user defined password generation options. */ private async generatePassword(): Promise { - const options = (await this.passwordGenerationService.getOptions())?.[0] ?? {}; - const password = await this.passwordGenerationService.generatePassword(options); - await this.passwordGenerationService.addHistory(password); - this.generatedPassword = password; + this.generatedPassword = await this.generatePasswordCallback(); } /** diff --git a/apps/browser/src/background/main.background.ts b/apps/browser/src/background/main.background.ts index d4dd79c8ca..5ee736a661 100644 --- a/apps/browser/src/background/main.background.ts +++ b/apps/browser/src/background/main.background.ts @@ -1168,12 +1168,7 @@ export default class MainBackground { const contextMenuClickedHandler = new ContextMenuClickedHandler( (options) => this.platformUtilsService.copyToClipboard(options.text), async (_tab) => { - const options = (await this.passwordGenerationService.getOptions())?.[0] ?? {}; - const password = await this.passwordGenerationService.generatePassword(options); - this.platformUtilsService.copyToClipboard(password); - // FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling. - // eslint-disable-next-line @typescript-eslint/no-floating-promises - this.passwordGenerationService.addHistory(password); + this.platformUtilsService.copyToClipboard(await this.generatePassword()); }, async (tab, cipher) => { this.loginToAutoFill = cipher; @@ -1625,9 +1620,9 @@ export default class MainBackground { this.platformUtilsService, this.vaultSettingsService, this.fido2ActiveRequestManager, - this.passwordGenerationService, inlineMenuFieldQualificationService, this.themeStateService, + () => this.generatePassword(), ); } @@ -1640,4 +1635,12 @@ export default class MainBackground { await this.overlayBackground.init(); await this.tabsBackground.init(); } + + generatePassword = async (): Promise => { + const options = (await this.passwordGenerationService.getOptions())?.[0] ?? {}; + const password = await this.passwordGenerationService.generatePassword(options); + await this.passwordGenerationService.addHistory(password); + + return password; + }; }