comfyui-mcp
Version:
Local-first, agent-native control plane for ComfyUI — MCP server + autonomous sidebar agent that drives your live graph in natural language on ANY LLM: Claude/ChatGPT/Gemini on your subscription (no API key), free local models via Ollama (fully offline),
83 lines • 4.52 kB
JavaScript
// Pre-merge fix (final whole-branch review, orchestrator side): the refresh
// functions in code-provider-auth.ts used to embed the raw provider HTTP
// error body in the thrown message unredacted. The refresh request body
// contains `refresh_token`, and IdPs can echo request params back in error
// bodies, so an error line could leak a live token. These tests pin that a
// leaked-looking refresh_token in the error body never survives into the
// thrown message, for all three refresh paths (Grok, Codex/OpenAI, Kimi),
// plus the adjacent "2xx but malformed JSON" path.
import { describe, expect, it, vi } from "vitest";
import { __testing } from "./code-provider-auth.js";
const { refreshGrokTokens, refreshOpenAICodexTokens, refreshKimiCodeTokens } = __testing;
describe("refresh error paths redact token-shaped material", () => {
it("refreshGrokTokens: a leaked refresh_token in the error body never reaches the thrown message", async () => {
const fetchMock = vi.fn(async () => new Response(JSON.stringify({ error: "bad", refresh_token: "LEAKED_RT_123" }), {
status: 400,
}));
const err = await refreshGrokTokens("some-refresh-token", {
fetch: fetchMock,
}).catch((e) => e);
expect(err).toBeInstanceOf(Error);
const message = err.message;
expect(message).toContain("bad");
expect(message).not.toContain("LEAKED_RT_123");
expect(message).toContain("<redacted>");
});
it("refreshGrokTokens: a 2xx-but-malformed body throws a generic error, not the raw text", async () => {
const fetchMock = vi.fn(async () => new Response("not json at all refresh_token=LEAKED_RT_999", { status: 200 }));
const err = await refreshGrokTokens("some-refresh-token", {
fetch: fetchMock,
}).catch((e) => e);
expect(err).toBeInstanceOf(Error);
const message = err.message;
expect(message).not.toContain("LEAKED_RT_999");
expect(message).toMatch(/malformed/i);
});
it("refreshOpenAICodexTokens: a leaked refresh_token in the error body never reaches the thrown message", async () => {
const fetchMock = vi.fn(async () => new Response(JSON.stringify({ error: "bad", refresh_token: "LEAKED_RT_123" }), {
status: 400,
}));
const err = await refreshOpenAICodexTokens("some-refresh-token", {
fetch: fetchMock,
}).catch((e) => e);
expect(err).toBeInstanceOf(Error);
const message = err.message;
expect(message).toContain("bad");
expect(message).not.toContain("LEAKED_RT_123");
expect(message).toContain("<redacted>");
});
it("refreshOpenAICodexTokens: a 2xx-but-malformed body throws a generic error, not the raw text", async () => {
const fetchMock = vi.fn(async () => new Response("not json at all refresh_token=LEAKED_RT_999", { status: 200 }));
const err = await refreshOpenAICodexTokens("some-refresh-token", {
fetch: fetchMock,
}).catch((e) => e);
expect(err).toBeInstanceOf(Error);
const message = err.message;
expect(message).not.toContain("LEAKED_RT_999");
expect(message).toMatch(/malformed/i);
});
it("refreshKimiCodeTokens: a leaked refresh_token in the error body never reaches the thrown message", async () => {
const fetchMock = vi.fn(async () => new Response(JSON.stringify({ error: "bad", refresh_token: "LEAKED_RT_123" }), {
status: 400,
}));
const err = await refreshKimiCodeTokens("some-refresh-token", {
fetch: fetchMock,
}).catch((e) => e);
expect(err).toBeInstanceOf(Error);
const message = err.message;
expect(message).toContain("bad");
expect(message).not.toContain("LEAKED_RT_123");
expect(message).toContain("<redacted>");
});
it("refreshKimiCodeTokens: a 2xx-but-malformed body throws a generic error, not the raw text", async () => {
const fetchMock = vi.fn(async () => new Response("not json at all refresh_token=LEAKED_RT_999", { status: 200 }));
const err = await refreshKimiCodeTokens("some-refresh-token", {
fetch: fetchMock,
}).catch((e) => e);
expect(err).toBeInstanceOf(Error);
const message = err.message;
expect(message).not.toContain("LEAKED_RT_999");
expect(message).toMatch(/malformed/i);
});
});
//# sourceMappingURL=code-provider-auth-redact.test.js.map