[PM-8833] Reworking how we handle generating the password to pull the usage of the service out of the OverlayBackground
This commit is contained in:
parent
5e6b2ea830
commit
4281685cc0
|
@ -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<VaultSettingsService>;
|
||||
let fido2ActiveRequestManager: Fido2ActiveRequestManager;
|
||||
let selectedThemeMock$: BehaviorSubject<ThemeType>;
|
||||
let passwordGenerationService: MockProxy<PasswordGenerationServiceAbstraction>;
|
||||
let inlineMenuFieldQualificationService: MockProxy<InlineMenuFieldQualificationService>;
|
||||
let themeStateService: MockProxy<ThemeStateService>;
|
||||
let overlayBackground: OverlayBackground;
|
||||
|
@ -176,9 +175,6 @@ describe("OverlayBackground", () => {
|
|||
selectedThemeMock$ = new BehaviorSubject(ThemeType.Light);
|
||||
inlineMenuFieldQualificationService = mock<InlineMenuFieldQualificationService>();
|
||||
themeStateService = mock<ThemeStateService>();
|
||||
passwordGenerationService = mock<PasswordGenerationServiceAbstraction>({
|
||||
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"];
|
||||
|
|
|
@ -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<string>,
|
||||
) {
|
||||
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<void> {
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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<string> => {
|
||||
const options = (await this.passwordGenerationService.getOptions())?.[0] ?? {};
|
||||
const password = await this.passwordGenerationService.generatePassword(options);
|
||||
await this.passwordGenerationService.addHistory(password);
|
||||
|
||||
return password;
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue