57 lines
1.6 KiB
TypeScript
57 lines
1.6 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test";
|
|
import { handleMcpRequest } from "../src/protocol/handler";
|
|
import { tools } from "../src/protocol/tools";
|
|
|
|
const originalFetch = global.fetch;
|
|
|
|
describe("MCP protocol cookie inputs", () => {
|
|
beforeEach(() => {
|
|
global.fetch = mock(() =>
|
|
Promise.resolve(new Response(JSON.stringify([]), { status: 200 })),
|
|
) as typeof fetch;
|
|
});
|
|
|
|
afterEach(() => {
|
|
global.fetch = originalFetch;
|
|
});
|
|
|
|
test("search tools should not expose Facebook or eBay cookie inputs", () => {
|
|
const searchFacebookTool = tools.find(
|
|
(tool) => tool.name === "search_facebook",
|
|
);
|
|
const searchEbayTool = tools.find((tool) => tool.name === "search_ebay");
|
|
|
|
expect(searchFacebookTool?.inputSchema.properties).not.toHaveProperty(
|
|
"cookiesSource",
|
|
);
|
|
expect(searchEbayTool?.inputSchema.properties).not.toHaveProperty(
|
|
"cookies",
|
|
);
|
|
});
|
|
|
|
test("search_facebook should not forward cookies query parameters", async () => {
|
|
await handleMcpRequest(
|
|
new Request("http://localhost", {
|
|
method: "POST",
|
|
body: JSON.stringify({
|
|
jsonrpc: "2.0",
|
|
id: 1,
|
|
method: "tools/call",
|
|
params: {
|
|
name: "search_facebook",
|
|
arguments: {
|
|
query: "laptop",
|
|
cookiesSource: "c_user=1",
|
|
},
|
|
},
|
|
}),
|
|
}),
|
|
);
|
|
|
|
const calledUrl = (global.fetch as ReturnType<typeof mock>).mock
|
|
.calls[0]?.[0];
|
|
expect(String(calledUrl)).toContain("/facebook?q=laptop");
|
|
expect(String(calledUrl)).not.toContain("cookies=");
|
|
});
|
|
});
|