
























@@ -1,4 +1,6 @@
11import fs from "node:fs/promises";
2+import os from "node:os";
3+import path from "node:path";
24import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
35import {
46clickChromeMcpElement,
@@ -119,6 +121,7 @@ describe("chrome MCP page parsing", () => {
119121120122afterEach(() => {
121123vi.useRealTimers();
124+vi.unstubAllEnvs();
122125});
123126124127it("parses list_pages text responses when structuredContent is missing", async () => {
@@ -232,25 +235,56 @@ describe("chrome MCP page parsing", () => {
232235233236it("redacts remote CDP URL secrets from attach failures", async () => {
234237const secretToken = "browserless-secret-token-1234567890"; // pragma: allowlist secret
235-const cdpUrl = `wss://browserless.example/chrome?token=${secretToken}`;
238+const user = "browser-user";
239+const password = "browser-password-1234567890"; // pragma: allowlist secret
240+const cdpUrl = `wss://${user}:${password}@browserless.example/chrome?token=${secretToken}`;
241+const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-chrome-mcp-test-"));
242+const configPath = path.join(tempDir, "openclaw.json");
243+await fs.writeFile(configPath, JSON.stringify({ logging: { redactSensitive: "off" } }));
244+vi.stubEnv("OPENCLAW_CONFIG_PATH", configPath);
245+const fakeMcpCommand = path.join(tempDir, "fake-mcp.mjs");
246+await fs.writeFile(
247+fakeMcpCommand,
248+`#!/usr/bin/env node
249+ const cdpUrl = process.argv.find((arg) => arg.includes("browserless.example")) ?? "";
250+ let input = "";
251+ process.stdin.on("data", (chunk) => {
252+ input += chunk;
253+ const match = input.match(/"id"\\s*:\\s*(\\d+)/);
254+ if (!match) return;
255+ const body = JSON.stringify({
256+ jsonrpc: "2.0",
257+ id: Number(match[1]),
258+ error: { code: -32000, message: "attach failed for " + cdpUrl },
259+ });
260+ process.stdout.write(body + "\\n");
261+ });
262+ `,
263+);
264+await fs.chmod(fakeMcpCommand, 0o755);
236265237266let message = "";
238267try {
239268await ensureChromeMcpAvailable(
240269"remote-profile",
241270{
242271 cdpUrl,
243-mcpCommand: process.execPath,
244-mcpArgs: ["-e", "process.exit(1)"],
272+mcpCommand: fakeMcpCommand,
245273},
246274{ ephemeral: true },
247275);
248276} catch (err) {
249277message = err instanceof Error ? err.message : String(err);
278+} finally {
279+await fs.rm(tempDir, { recursive: true, force: true });
250280}
251281252282expect(message).toContain("Chrome MCP existing-session attach failed");
283+expect(message).toContain("attach failed");
253284expect(message).toContain("browserless.example");
285+expect(message).not.toContain(cdpUrl);
286+expect(message).not.toContain(user);
287+expect(message).not.toContain(password);
254288expect(message).not.toContain(secretToken);
255289});
256290此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。