1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-22 16:29:09 +01:00

[PM-8498] Moving content script-specific FIDO2 code from Vault to Autofill ownership (#9431)

* [PM-8498] Moving content script-specific FIDO2 code from Vault to Autofill ownership

* [PM-8498] Adjusting jest test reference for webauth-utils
This commit is contained in:
Cesar Gonzalez 2024-06-07 08:47:38 -05:00 committed by GitHub
parent 28e8f8f364
commit d30b947dd7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
21 changed files with 36 additions and 36 deletions

View File

@ -18,7 +18,7 @@ import {
} from "../../../autofill/spec/testing-utils";
import { BrowserApi } from "../../../platform/browser/browser-api";
import { BrowserScriptInjectorService } from "../../../platform/services/browser-script-injector.service";
import { AbortManager } from "../../background/abort-manager";
import { AbortManager } from "../../../vault/background/abort-manager";
import { Fido2ContentScript, Fido2ContentScriptId } from "../enums/fido2-content-script.enum";
import { Fido2PortName } from "../enums/fido2-port-name.enum";

View File

@ -13,7 +13,7 @@ import { VaultSettingsService } from "@bitwarden/common/vault/abstractions/vault
import { BrowserApi } from "../../../platform/browser/browser-api";
import { ScriptInjectorService } from "../../../platform/services/abstractions/script-injector.service";
import { AbortManager } from "../../background/abort-manager";
import { AbortManager } from "../../../vault/background/abort-manager";
import { Fido2ContentScript, Fido2ContentScriptId } from "../enums/fido2-content-script.enum";
import { Fido2PortName } from "../enums/fido2-port-name.enum";

View File

@ -60,7 +60,7 @@ describe("Fido2 Content Script", () => {
chrome.runtime.connect = jest.fn(() => portSpy);
it("destroys the messenger when the port is disconnected", () => {
require("./content-script");
require("./fido2-content-script");
triggerPortOnDisconnectEvent(portSpy);
@ -75,7 +75,7 @@ describe("Fido2 Content Script", () => {
const mockResult = { credentialId: "mock" } as CreateCredentialResult;
jest.spyOn(chrome.runtime, "sendMessage").mockResolvedValue(mockResult);
require("./content-script");
require("./fido2-content-script");
const response = await messenger.handler!(message, new AbortController());
@ -99,7 +99,7 @@ describe("Fido2 Content Script", () => {
data: mock<InsecureCreateCredentialParams>(),
});
require("./content-script");
require("./fido2-content-script");
await messenger.handler!(message, new AbortController());
@ -121,7 +121,7 @@ describe("Fido2 Content Script", () => {
const abortController = new AbortController();
const abortSpy = jest.spyOn(abortController.signal, "removeEventListener");
require("./content-script");
require("./fido2-content-script");
await messenger.handler!(message, abortController);
@ -141,7 +141,7 @@ describe("Fido2 Content Script", () => {
abortController.abort();
});
require("./content-script");
require("./fido2-content-script");
await messenger.handler!(message, abortController);
@ -161,7 +161,7 @@ describe("Fido2 Content Script", () => {
const abortController = new AbortController();
jest.spyOn(chrome.runtime, "sendMessage").mockResolvedValue({ error: errorMessage });
require("./content-script");
require("./fido2-content-script");
const result = messenger.handler!(message, abortController);
await expect(result).rejects.toEqual(errorMessage);
@ -175,7 +175,7 @@ describe("Fido2 Content Script", () => {
contentType: "application/json",
}));
require("./content-script");
require("./fido2-content-script");
expect(messengerForDOMCommunicationSpy).not.toHaveBeenCalled();
});
@ -193,7 +193,7 @@ describe("Fido2 Content Script", () => {
},
}));
require("./content-script");
require("./fido2-content-script");
expect(messengerForDOMCommunicationSpy).not.toHaveBeenCalled();
});

View File

@ -13,7 +13,7 @@ describe("FIDO2 page-script for manifest v2", () => {
it("skips appending the `page-script.js` file if the document contentType is not `text/html`", () => {
Object.defineProperty(window.document, "contentType", { value: "text/plain", writable: true });
require("./page-script-append.mv2");
require("./fido2-page-script-append.mv2");
expect(window.document.createElement).not.toHaveBeenCalled();
});
@ -24,7 +24,7 @@ describe("FIDO2 page-script for manifest v2", () => {
return node;
});
require("./page-script-append.mv2");
require("./fido2-page-script-append.mv2");
expect(window.document.createElement).toHaveBeenCalledWith("script");
expect(chrome.runtime.getURL).toHaveBeenCalledWith(Fido2ContentScript.PageScript);
@ -42,7 +42,7 @@ describe("FIDO2 page-script for manifest v2", () => {
return node;
});
require("./page-script-append.mv2");
require("./fido2-page-script-append.mv2");
expect(window.document.createElement).toHaveBeenCalledWith("script");
expect(chrome.runtime.getURL).toHaveBeenCalledWith(Fido2ContentScript.PageScript);
@ -59,7 +59,7 @@ describe("FIDO2 page-script for manifest v2", () => {
return createdScriptElement;
});
require("./page-script-append.mv2");
require("./fido2-page-script-append.mv2");
jest.spyOn(createdScriptElement, "remove");
createdScriptElement.dispatchEvent(new Event("load"));

View File

@ -1,6 +1,6 @@
import { FallbackRequestedError } from "@bitwarden/common/platform/abstractions/fido2/fido2-client.service.abstraction";
import { WebauthnUtils } from "../webauthn-utils";
import { WebauthnUtils } from "../../../vault/fido2/webauthn-utils";
import { MessageType } from "./messaging/message";
import { Messenger } from "./messaging/messenger";

View File

@ -5,7 +5,7 @@ import {
createCredentialRequestOptionsMock,
setupMockedWebAuthnSupport,
} from "../../../autofill/spec/fido2-testing-utils";
import { WebauthnUtils } from "../webauthn-utils";
import { WebauthnUtils } from "../../../vault/fido2/webauthn-utils";
import { MessageType } from "./messaging/message";
import { Messenger } from "./messaging/messenger";
@ -40,7 +40,7 @@ jest.mock("./messaging/messenger", () => {
},
};
});
jest.mock("../webauthn-utils");
jest.mock("../../../vault/fido2/webauthn-utils");
describe("Fido2 page script with native WebAuthn support", () => {
(jest.spyOn(globalThis, "document", "get") as jest.Mock).mockImplementation(
@ -54,7 +54,7 @@ describe("Fido2 page script with native WebAuthn support", () => {
setupMockedWebAuthnSupport();
beforeAll(() => {
require("./page-script");
require("./fido2-page-script");
});
afterEach(() => {
@ -154,7 +154,7 @@ describe("Fido2 page script with native WebAuthn support", () => {
contentType: "json/application",
}));
require("./content-script");
require("./fido2-content-script");
expect(Messenger.forDOMCommunication).not.toHaveBeenCalled();
});
@ -172,7 +172,7 @@ describe("Fido2 page script with native WebAuthn support", () => {
},
}));
require("./content-script");
require("./fido2-content-script");
expect(Messenger.forDOMCommunication).not.toHaveBeenCalled();
});

View File

@ -4,7 +4,7 @@ import {
createCredentialCreationOptionsMock,
createCredentialRequestOptionsMock,
} from "../../../autofill/spec/fido2-testing-utils";
import { WebauthnUtils } from "../webauthn-utils";
import { WebauthnUtils } from "../../../vault/fido2/webauthn-utils";
import { MessageType } from "./messaging/message";
import { Messenger } from "./messaging/messenger";
@ -39,7 +39,7 @@ jest.mock("./messaging/messenger", () => {
},
};
});
jest.mock("../webauthn-utils");
jest.mock("../../../vault/fido2/webauthn-utils");
describe("Fido2 page script without native WebAuthn support", () => {
(jest.spyOn(globalThis, "document", "get") as jest.Mock).mockImplementation(
@ -50,7 +50,7 @@ describe("Fido2 page script without native WebAuthn support", () => {
const mockCreateCredentialsResult = createCreateCredentialResultMock();
const mockCredentialRequestOptions = createCredentialRequestOptionsMock();
const mockCredentialAssertResult = createAssertCredentialResultMock();
require("./page-script");
require("./fido2-page-script");
afterEach(() => {
jest.resetModules();

View File

@ -1,7 +1,7 @@
export const Fido2ContentScript = {
PageScript: "content/fido2/page-script.js",
PageScriptAppend: "content/fido2/page-script-append-mv2.js",
ContentScript: "content/fido2/content-script.js",
PageScript: "content/fido2-page-script.js",
PageScriptAppend: "content/fido2-page-script-append-mv2.js",
ContentScript: "content/fido2-content-script.js",
} as const;
export const Fido2ContentScriptId = {

View File

@ -202,6 +202,8 @@ import WebRequestBackground from "../autofill/background/web-request.background"
import { CipherContextMenuHandler } from "../autofill/browser/cipher-context-menu-handler";
import { ContextMenuClickedHandler } from "../autofill/browser/context-menu-clicked-handler";
import { MainContextMenuHandler } from "../autofill/browser/main-context-menu-handler";
import { Fido2Background as Fido2BackgroundAbstraction } from "../autofill/fido2/background/abstractions/fido2.background";
import { Fido2Background } from "../autofill/fido2/background/fido2.background";
import { AutofillService as AutofillServiceAbstraction } from "../autofill/services/abstractions/autofill.service";
import AutofillService from "../autofill/services/autofill.service";
import { SafariApp } from "../browser/safariApp";
@ -233,8 +235,6 @@ import { SyncServiceListener } from "../platform/sync/sync-service.listener";
import { fromChromeRuntimeMessaging } from "../platform/utils/from-chrome-runtime-messaging";
import VaultTimeoutService from "../services/vault-timeout/vault-timeout.service";
import FilelessImporterBackground from "../tools/background/fileless-importer.background";
import { Fido2Background as Fido2BackgroundAbstraction } from "../vault/fido2/background/abstractions/fido2.background";
import { Fido2Background } from "../vault/fido2/background/fido2.background";
import { BrowserFido2UserInterfaceService } from "../vault/fido2/browser-fido2-user-interface.service";
import { VaultFilterService } from "../vault/services/vault-filter.service";

View File

@ -20,11 +20,11 @@ import {
openTwoFactorAuthPopout,
} from "../auth/popup/utils/auth-popout-window";
import { LockedVaultPendingNotificationsData } from "../autofill/background/abstractions/notification.background";
import { Fido2Background } from "../autofill/fido2/background/abstractions/fido2.background";
import { AutofillService } from "../autofill/services/abstractions/autofill.service";
import { BrowserApi } from "../platform/browser/browser-api";
import { BrowserEnvironmentService } from "../platform/services/browser-environment.service";
import { BrowserPlatformUtilsService } from "../platform/services/platform-utils/browser-platform-utils.service";
import { Fido2Background } from "../vault/fido2/background/abstractions/fido2.background";
import MainBackground from "./main.background";

View File

@ -101,7 +101,7 @@
}
},
"web_accessible_resources": [
"content/fido2/page-script.js",
"content/fido2-page-script.js",
"content/lp-suppress-import-download.js",
"notification/bar.html",
"images/icon38.png",

View File

@ -107,7 +107,7 @@
"web_accessible_resources": [
{
"resources": [
"content/fido2/page-script.js",
"content/fido2-page-script.js",
"notification/bar.html",
"images/icon38.png",
"images/icon38_locked.png",

View File

@ -7,7 +7,7 @@ import { Fido2Utils } from "@bitwarden/common/platform/services/fido2/fido2-util
import {
InsecureAssertCredentialParams,
InsecureCreateCredentialParams,
} from "./content/messaging/message";
} from "../../autofill/fido2/content/messaging/message";
export class WebauthnUtils {
static mapCredentialCreationOptions(

View File

@ -165,8 +165,8 @@ const mainConfig = {
"content/notificationBar": "./src/autofill/content/notification-bar.ts",
"content/contextMenuHandler": "./src/autofill/content/context-menu-handler.ts",
"content/content-message-handler": "./src/autofill/content/content-message-handler.ts",
"content/fido2/content-script": "./src/vault/fido2/content/content-script.ts",
"content/fido2/page-script": "./src/vault/fido2/content/page-script.ts",
"content/fido2-content-script": "./src/autofill/fido2/content/fido2-content-script.ts",
"content/fido2-page-script": "./src/autofill/fido2/content/fido2-page-script.ts",
"notification/bar": "./src/autofill/notification/bar.ts",
"overlay/button": "./src/autofill/overlay/pages/button/bootstrap-autofill-overlay-button.ts",
"overlay/list": "./src/autofill/overlay/pages/list/bootstrap-autofill-overlay-list.ts",
@ -274,8 +274,8 @@ if (manifestVersion == 2) {
mainConfig.entry.background = "./src/platform/background.ts";
mainConfig.entry["content/lp-suppress-import-download-script-append-mv2"] =
"./src/tools/content/lp-suppress-import-download-script-append.mv2.ts";
mainConfig.entry["content/fido2/page-script-append-mv2"] =
"./src/vault/fido2/content/page-script-append.mv2.ts";
mainConfig.entry["content/fido2-page-script-append-mv2"] =
"./src/autofill/fido2/content/fido2-page-script-append.mv2.ts";
configs.push(mainConfig);
} else {