mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 07:40:44 +00:00
test: share browser security mock
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import { vi } from "vitest";
|
||||
|
||||
vi.mock("openclaw/plugin-sdk/browser-security-runtime", async () => {
|
||||
const actual = await vi.importActual<
|
||||
typeof import("openclaw/plugin-sdk/browser-security-runtime")
|
||||
>("openclaw/plugin-sdk/browser-security-runtime");
|
||||
const lookupFn = async (_hostname: string, options?: { all?: boolean }) => {
|
||||
const result = { address: "93.184.216.34", family: 4 };
|
||||
return options?.all === true ? [result] : result;
|
||||
};
|
||||
return {
|
||||
...actual,
|
||||
resolvePinnedHostnameWithPolicy: (hostname: string, params: object = {}) =>
|
||||
actual.resolvePinnedHostnameWithPolicy(hostname, { ...params, lookupFn: lookupFn as never }),
|
||||
};
|
||||
});
|
||||
@@ -3,27 +3,13 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { type WebSocket, WebSocketServer } from "ws";
|
||||
import { SsrFBlockedError } from "../infra/net/ssrf.js";
|
||||
import { rawDataToString } from "../infra/ws.js";
|
||||
import "./browser-security-runtime.test-helper.js";
|
||||
import { isDirectCdpWebSocketEndpoint, isWebSocketUrl } from "./cdp.helpers.js";
|
||||
import { createTargetViaCdp, evaluateJavaScript, normalizeCdpWsUrl, snapshotAria } from "./cdp.js";
|
||||
import { parseHttpUrl } from "./config.js";
|
||||
import { BrowserCdpEndpointBlockedError } from "./errors.js";
|
||||
import { InvalidBrowserNavigationUrlError } from "./navigation-guard.js";
|
||||
|
||||
vi.mock("openclaw/plugin-sdk/browser-security-runtime", async () => {
|
||||
const actual = await vi.importActual<
|
||||
typeof import("openclaw/plugin-sdk/browser-security-runtime")
|
||||
>("openclaw/plugin-sdk/browser-security-runtime");
|
||||
const lookupFn = async (_hostname: string, options?: { all?: boolean }) => {
|
||||
const result = { address: "93.184.216.34", family: 4 };
|
||||
return options?.all === true ? [result] : result;
|
||||
};
|
||||
return {
|
||||
...actual,
|
||||
resolvePinnedHostnameWithPolicy: (hostname: string, params: object = {}) =>
|
||||
actual.resolvePinnedHostnameWithPolicy(hostname, { ...params, lookupFn: lookupFn as never }),
|
||||
};
|
||||
});
|
||||
|
||||
describe("cdp", () => {
|
||||
let httpServer: ReturnType<typeof createServer> | null = null;
|
||||
let wsServer: WebSocketServer | null = null;
|
||||
|
||||
@@ -1,21 +1,7 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import "./browser-security-runtime.test-helper.js";
|
||||
import type { BrowserDispatchResponse } from "./routes/dispatcher.js";
|
||||
|
||||
vi.mock("openclaw/plugin-sdk/browser-security-runtime", async () => {
|
||||
const actual = await vi.importActual<
|
||||
typeof import("openclaw/plugin-sdk/browser-security-runtime")
|
||||
>("openclaw/plugin-sdk/browser-security-runtime");
|
||||
const lookupFn = async (_hostname: string, options?: { all?: boolean }) => {
|
||||
const result = { address: "93.184.216.34", family: 4 };
|
||||
return options?.all === true ? [result] : result;
|
||||
};
|
||||
return {
|
||||
...actual,
|
||||
resolvePinnedHostnameWithPolicy: (hostname: string, params: object = {}) =>
|
||||
actual.resolvePinnedHostnameWithPolicy(hostname, { ...params, lookupFn: lookupFn as never }),
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("openclaw/plugin-sdk/ssrf-runtime", async () => {
|
||||
const actual = await vi.importActual<typeof import("openclaw/plugin-sdk/ssrf-runtime")>(
|
||||
"openclaw/plugin-sdk/ssrf-runtime",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { chromium } from "playwright-core";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { SsrFBlockedError } from "../infra/net/ssrf.js";
|
||||
import "./browser-security-runtime.test-helper.js";
|
||||
import * as chromeModule from "./chrome.js";
|
||||
import { BrowserTabNotFoundError } from "./errors.js";
|
||||
import { InvalidBrowserNavigationUrlError } from "./navigation-guard.js";
|
||||
@@ -15,21 +16,6 @@ import {
|
||||
listPagesViaPlaywright,
|
||||
} from "./pw-session.js";
|
||||
|
||||
vi.mock("openclaw/plugin-sdk/browser-security-runtime", async () => {
|
||||
const actual = await vi.importActual<
|
||||
typeof import("openclaw/plugin-sdk/browser-security-runtime")
|
||||
>("openclaw/plugin-sdk/browser-security-runtime");
|
||||
const lookupFn = async (_hostname: string, options?: { all?: boolean }) => {
|
||||
const result = { address: "93.184.216.34", family: 4 };
|
||||
return options?.all === true ? [result] : result;
|
||||
};
|
||||
return {
|
||||
...actual,
|
||||
resolvePinnedHostnameWithPolicy: (hostname: string, params: object = {}) =>
|
||||
actual.resolvePinnedHostnameWithPolicy(hostname, { ...params, lookupFn: lookupFn as never }),
|
||||
};
|
||||
});
|
||||
|
||||
const connectOverCdpSpy = vi.spyOn(chromium, "connectOverCDP");
|
||||
const getChromeWebSocketUrlSpy = vi.spyOn(chromeModule, "getChromeWebSocketUrl");
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { SsrFBlockedError } from "../infra/net/ssrf.js";
|
||||
import "./browser-security-runtime.test-helper.js";
|
||||
import { InvalidBrowserNavigationUrlError } from "./navigation-guard.js";
|
||||
import {
|
||||
getPwToolsCoreSessionMocks,
|
||||
@@ -7,21 +8,6 @@ import {
|
||||
setPwToolsCoreCurrentPage,
|
||||
} from "./pw-tools-core.test-harness.js";
|
||||
|
||||
vi.mock("openclaw/plugin-sdk/browser-security-runtime", async () => {
|
||||
const actual = await vi.importActual<
|
||||
typeof import("openclaw/plugin-sdk/browser-security-runtime")
|
||||
>("openclaw/plugin-sdk/browser-security-runtime");
|
||||
const lookupFn = async (_hostname: string, options?: { all?: boolean }) => {
|
||||
const result = { address: "93.184.216.34", family: 4 };
|
||||
return options?.all === true ? [result] : result;
|
||||
};
|
||||
return {
|
||||
...actual,
|
||||
resolvePinnedHostnameWithPolicy: (hostname: string, params: object = {}) =>
|
||||
actual.resolvePinnedHostnameWithPolicy(hostname, { ...params, lookupFn: lookupFn as never }),
|
||||
};
|
||||
});
|
||||
|
||||
installPwToolsCoreTestHooks();
|
||||
const mod = await import("./pw-tools-core.snapshot.js");
|
||||
|
||||
|
||||
@@ -1,22 +1,8 @@
|
||||
import fs from "node:fs";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import "./browser-security-runtime.test-helper.js";
|
||||
import type { BrowserServerState } from "./server-context.js";
|
||||
|
||||
vi.mock("openclaw/plugin-sdk/browser-security-runtime", async () => {
|
||||
const actual = await vi.importActual<
|
||||
typeof import("openclaw/plugin-sdk/browser-security-runtime")
|
||||
>("openclaw/plugin-sdk/browser-security-runtime");
|
||||
const lookupFn = async (_hostname: string, options?: { all?: boolean }) => {
|
||||
const result = { address: "93.184.216.34", family: 4 };
|
||||
return options?.all === true ? [result] : result;
|
||||
};
|
||||
return {
|
||||
...actual,
|
||||
resolvePinnedHostnameWithPolicy: (hostname: string, params: object = {}) =>
|
||||
actual.resolvePinnedHostnameWithPolicy(hostname, { ...params, lookupFn: lookupFn as never }),
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("./chrome-mcp.js", () => ({
|
||||
closeChromeMcpSession: vi.fn(async () => true),
|
||||
ensureChromeMcpAvailable: vi.fn(async () => {}),
|
||||
|
||||
Reference in New Issue
Block a user