@strixgov/mcp-proxy 0.2.5 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +76 -8
- package/README.md +209 -20
- package/bin/strix-mcp-proxy.mjs +100 -5
- package/package.json +4 -4
- package/src/config.mjs +152 -2
- package/src/content-guard.mjs +432 -0
- package/src/http-upstream.mjs +431 -0
- package/src/index.mjs +11 -2
- package/src/proxy.mjs +241 -33
- package/src/tool-guard.mjs +183 -0
- package/src/types.d.ts +83 -1
- package/test/content-guard-hardening.test.mjs +159 -0
- package/test/content-guard.test.mjs +387 -0
- package/test/http-upstream-config.test.mjs +115 -0
- package/test/http-upstream-e2e.test.mjs +279 -0
- package/test/http-upstream.test.mjs +304 -0
- package/test/tool-guard.test.mjs +243 -0
- package/test/validate-cli.test.mjs +171 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config-file and CLI handling of an HTTP upstream. A bad HTTP config must
|
|
3
|
+
* fail at load time, before anything connects.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import test from "node:test";
|
|
7
|
+
import assert from "node:assert/strict";
|
|
8
|
+
import { mkdtempSync, writeFileSync, rmSync } from "node:fs";
|
|
9
|
+
import { tmpdir } from "node:os";
|
|
10
|
+
import path from "node:path";
|
|
11
|
+
import url from "node:url";
|
|
12
|
+
import { spawnSync } from "node:child_process";
|
|
13
|
+
|
|
14
|
+
import { loadConfig } from "../src/config.mjs";
|
|
15
|
+
|
|
16
|
+
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
|
|
17
|
+
const BIN = path.resolve(__dirname, "..", "bin", "strix-mcp-proxy.mjs");
|
|
18
|
+
|
|
19
|
+
async function withTempConfig(contents, fn) {
|
|
20
|
+
const dir = mkdtempSync(path.join(tmpdir(), "strix-proxy-http-config-"));
|
|
21
|
+
const file = path.join(dir, "proxy.json");
|
|
22
|
+
writeFileSync(file, JSON.stringify(contents));
|
|
23
|
+
try { return await fn(file); } finally { rmSync(dir, { recursive: true, force: true }); }
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
test("loadConfig: accepts an https upstream.url with an env-sourced credential header", async () => {
|
|
27
|
+
await withTempConfig(
|
|
28
|
+
{ upstream: { url: "https://mcp.example.com/mcp", headers: { Authorization: { fromEnv: "TOK", prefix: "Bearer " } } } },
|
|
29
|
+
async (file) => {
|
|
30
|
+
const cfg = await loadConfig(file);
|
|
31
|
+
assert.equal(cfg.upstream.url, "https://mcp.example.com/mcp");
|
|
32
|
+
},
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test("loadConfig: refuses both command and url", async () => {
|
|
37
|
+
await withTempConfig({ upstream: { command: "npx", url: "https://mcp.example.com/mcp" } }, async (file) => {
|
|
38
|
+
await assert.rejects(loadConfig(file), /exactly one of 'upstream\.command'.*'upstream\.url'/);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("loadConfig: refuses an http URL to a remote host", async () => {
|
|
43
|
+
await withTempConfig({ upstream: { url: "http://mcp.example.com/mcp" } }, async (file) => {
|
|
44
|
+
await assert.rejects(loadConfig(file), /must be https/);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test("loadConfig: refuses a literal credential in a header", async () => {
|
|
49
|
+
await withTempConfig(
|
|
50
|
+
{ upstream: { url: "https://mcp.example.com/mcp", headers: { Authorization: "Bearer abc123" } } },
|
|
51
|
+
async (file) => {
|
|
52
|
+
await assert.rejects(loadConfig(file), /looks like a credential/);
|
|
53
|
+
},
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test("loadConfig: refuses args/env on a url upstream", async () => {
|
|
58
|
+
await withTempConfig({ upstream: { url: "https://mcp.example.com/mcp", args: ["x"] } }, async (file) => {
|
|
59
|
+
await assert.rejects(loadConfig(file), /apply only to a 'command' upstream/);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test("CLI: --upstream-command and --upstream-url together are refused", () => {
|
|
64
|
+
const out = spawnSync("node", [BIN, "--upstream-command", "npx", "--upstream-url", "https://mcp.example.com/mcp"], {
|
|
65
|
+
encoding: "utf8",
|
|
66
|
+
timeout: 10_000,
|
|
67
|
+
input: "",
|
|
68
|
+
});
|
|
69
|
+
assert.notEqual(out.status, 0);
|
|
70
|
+
assert.match(out.stderr, /mutually exclusive/);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test("CLI: --upstream-header-env must be NAME=VAR", () => {
|
|
74
|
+
const out = spawnSync("node", [BIN, "--upstream-url", "https://mcp.example.com/mcp", "--upstream-header-env", "Authorization"], {
|
|
75
|
+
encoding: "utf8",
|
|
76
|
+
timeout: 10_000,
|
|
77
|
+
input: "",
|
|
78
|
+
});
|
|
79
|
+
assert.notEqual(out.status, 0);
|
|
80
|
+
assert.match(out.stderr, /expects NAME=ENV_VAR/);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test("CLI: --help documents the HTTP upstream flags", () => {
|
|
84
|
+
const out = spawnSync("node", [BIN, "--help"], { encoding: "utf8", timeout: 10_000 });
|
|
85
|
+
assert.equal(out.status, 0);
|
|
86
|
+
assert.match(out.stdout, /--upstream-url/);
|
|
87
|
+
assert.match(out.stdout, /--upstream-header-env/);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test("loadConfig: toolPinning, hideDeniedTools and rateLimits are validated", async () => {
|
|
91
|
+
const base = { upstream: { command: "node" } };
|
|
92
|
+
await withTempConfig({ ...base, toolPinning: "loose" }, async (file) => {
|
|
93
|
+
await assert.rejects(loadConfig(file), /'toolPinning' must be/);
|
|
94
|
+
});
|
|
95
|
+
await withTempConfig({ ...base, hideDeniedTools: "yes" }, async (file) => {
|
|
96
|
+
await assert.rejects(loadConfig(file), /'hideDeniedTools' must be a boolean/);
|
|
97
|
+
});
|
|
98
|
+
await withTempConfig({ ...base, rateLimits: { "mcp.x.*": { windowMs: 0, max: 1 } } }, async (file) => {
|
|
99
|
+
await assert.rejects(loadConfig(file), /positive integer windowMs and max/);
|
|
100
|
+
});
|
|
101
|
+
await withTempConfig(
|
|
102
|
+
{ ...base, toolPinning: "warn", hideDeniedTools: true, rateLimits: { "mcp.x.*": { windowMs: 1000, max: 5 } } },
|
|
103
|
+
async (file) => {
|
|
104
|
+
const cfg = await loadConfig(file);
|
|
105
|
+
assert.equal(cfg.toolPinning, "warn");
|
|
106
|
+
},
|
|
107
|
+
);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test("CLI: --help documents pinning, repin and hiding", () => {
|
|
111
|
+
const out = spawnSync("node", [BIN, "--help"], { encoding: "utf8", timeout: 10_000 });
|
|
112
|
+
assert.match(out.stdout, /--tool-pinning/);
|
|
113
|
+
assert.match(out.stdout, /--repin-tools/);
|
|
114
|
+
assert.match(out.stdout, /--hide-denied-tools/);
|
|
115
|
+
});
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* End-to-end: the proxy governing a REAL Streamable HTTP MCP server.
|
|
3
|
+
*
|
|
4
|
+
* [Test Client] ─in-memory─▶ [Strix Proxy] ─HTTP (loopback)─▶ [SDK MCP server on node:http]
|
|
5
|
+
*
|
|
6
|
+
* Nothing on the upstream leg is mocked: the upstream is the MCP SDK's own
|
|
7
|
+
* StreamableHTTPServerTransport behind a node:http listener on 127.0.0.1,
|
|
8
|
+
* and the proxy reaches it through the production HTTP transport. Every
|
|
9
|
+
* claim here is checked against what the upstream server actually saw.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import test from "node:test";
|
|
13
|
+
import assert from "node:assert/strict";
|
|
14
|
+
import http from "node:http";
|
|
15
|
+
import { randomUUID } from "node:crypto";
|
|
16
|
+
|
|
17
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
18
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
19
|
+
import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";
|
|
20
|
+
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
21
|
+
import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
22
|
+
import { verifyReceipt, verifyExecutionOutcome } from "@strixgov/tool-gateway";
|
|
23
|
+
|
|
24
|
+
import { startProxy } from "../src/index.mjs";
|
|
25
|
+
|
|
26
|
+
const TOKEN = "e2e-secret-token-9f3a";
|
|
27
|
+
|
|
28
|
+
const CAPS = [
|
|
29
|
+
{ id: "mcp.remote.read_thing", name: "read_thing", risk: "LOW", mode: "READ" },
|
|
30
|
+
{ id: "mcp.remote.delete_thing", name: "delete_thing", risk: "CRITICAL", mode: "WRITE" },
|
|
31
|
+
{ id: "mcp.remote.slow_thing", name: "slow_thing", risk: "LOW", mode: "WRITE" },
|
|
32
|
+
{ id: "mcp.remote.leaky_thing", name: "leaky_thing", risk: "LOW", mode: "READ" },
|
|
33
|
+
{ id: "mcp.remote.huge_thing", name: "huge_thing", risk: "LOW", mode: "READ" },
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Start a real MCP server over Streamable HTTP. Records every tool call
|
|
38
|
+
* and every Authorization header it received.
|
|
39
|
+
*/
|
|
40
|
+
async function startHttpUpstream({ slowMs = 0, redirectTo = null } = {}) {
|
|
41
|
+
const seen = { calls: [], authHeaders: [], requests: 0 };
|
|
42
|
+
const server = new Server({ name: "remote-upstream", version: "0.0.1" }, { capabilities: { tools: {} } });
|
|
43
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
44
|
+
tools: CAPS.map((c) => ({ name: c.name, description: c.name, inputSchema: { type: "object" } })),
|
|
45
|
+
}));
|
|
46
|
+
server.setRequestHandler(CallToolRequestSchema, async (req, extra) => {
|
|
47
|
+
seen.calls.push(req.params.name);
|
|
48
|
+
if (req.params.name === "leaky_thing") {
|
|
49
|
+
// A careless upstream that echoes the credential it received in an error.
|
|
50
|
+
throw new Error(`backend refused request with header ${extra?.requestInfo?.headers?.authorization}`);
|
|
51
|
+
}
|
|
52
|
+
if (req.params.name === "huge_thing") {
|
|
53
|
+
return { content: [{ type: "text", text: "x".repeat(200_000) }] };
|
|
54
|
+
}
|
|
55
|
+
if (req.params.name === "slow_thing") await new Promise((r) => setTimeout(r, slowMs));
|
|
56
|
+
return { content: [{ type: "text", text: `remote executed ${req.params.name}` }] };
|
|
57
|
+
});
|
|
58
|
+
const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: () => randomUUID() });
|
|
59
|
+
await server.connect(transport);
|
|
60
|
+
|
|
61
|
+
const listener = http.createServer(async (req, res) => {
|
|
62
|
+
seen.requests += 1;
|
|
63
|
+
seen.authHeaders.push(req.headers.authorization ?? null);
|
|
64
|
+
if (redirectTo) {
|
|
65
|
+
res.writeHead(307, { location: redirectTo });
|
|
66
|
+
res.end();
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (req.headers.authorization !== `Bearer ${TOKEN}`) {
|
|
70
|
+
res.writeHead(401, { "content-type": "application/json" });
|
|
71
|
+
res.end(JSON.stringify({ error: "unauthorized" }));
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
let body;
|
|
75
|
+
if (req.method === "POST") {
|
|
76
|
+
const chunks = [];
|
|
77
|
+
for await (const c of req) chunks.push(c);
|
|
78
|
+
body = JSON.parse(Buffer.concat(chunks).toString("utf-8"));
|
|
79
|
+
}
|
|
80
|
+
await transport.handleRequest(req, res, body);
|
|
81
|
+
});
|
|
82
|
+
await new Promise((r) => listener.listen(0, "127.0.0.1", r));
|
|
83
|
+
const { port } = listener.address();
|
|
84
|
+
return {
|
|
85
|
+
url: `http://127.0.0.1:${port}/mcp`,
|
|
86
|
+
seen,
|
|
87
|
+
async close() {
|
|
88
|
+
await transport.close().catch(() => {});
|
|
89
|
+
listener.closeAllConnections?.();
|
|
90
|
+
await new Promise((r) => listener.close(r));
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async function startGovernedProxy(upstreamUrl, extra = {}) {
|
|
96
|
+
const [clientSide, serverSide] = InMemoryTransport.createLinkedPair();
|
|
97
|
+
const receipts = [];
|
|
98
|
+
const audits = [];
|
|
99
|
+
const proxy = await startProxy({
|
|
100
|
+
serverId: "remote",
|
|
101
|
+
upstream: {
|
|
102
|
+
url: upstreamUrl,
|
|
103
|
+
headers: { Authorization: { fromEnv: "E2E_UPSTREAM_TOKEN", prefix: "Bearer " } },
|
|
104
|
+
...extra.upstream,
|
|
105
|
+
},
|
|
106
|
+
capabilities: CAPS,
|
|
107
|
+
policy: { riskOverrides: { LOW: "ALLOW", CRITICAL: "DENY" }, default: "DENY" },
|
|
108
|
+
storagePath: null,
|
|
109
|
+
shadowDiscovery: false,
|
|
110
|
+
onReceipt: (r) => receipts.push(r),
|
|
111
|
+
onAudit: (e) => audits.push(e),
|
|
112
|
+
transport: { kind: "test", serverTransport: serverSide },
|
|
113
|
+
});
|
|
114
|
+
const client = new Client({ name: "e2e-consumer", version: "0.0.1" }, { capabilities: {} });
|
|
115
|
+
await client.connect(clientSide);
|
|
116
|
+
return { proxy, client, receipts, audits };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
process.env.E2E_UPSTREAM_TOKEN = TOKEN;
|
|
120
|
+
|
|
121
|
+
test("http e2e: list + allowed call reach the remote server and yield a verifiable receipt and outcome", async () => {
|
|
122
|
+
const upstream = await startHttpUpstream();
|
|
123
|
+
const outcomes = [];
|
|
124
|
+
const { proxy, client, receipts, audits } = await startGovernedProxy(upstream.url);
|
|
125
|
+
proxy.gateway.on("outcome", (o) => outcomes.push(o));
|
|
126
|
+
try {
|
|
127
|
+
const listed = await client.listTools();
|
|
128
|
+
assert.deepEqual(listed.tools.map((t) => t.name).sort(), ["delete_thing", "huge_thing", "leaky_thing", "read_thing", "slow_thing"]);
|
|
129
|
+
|
|
130
|
+
const result = await client.callTool({ name: "read_thing", arguments: { id: 1 } });
|
|
131
|
+
assert.equal(result.content[0].text, "remote executed read_thing");
|
|
132
|
+
assert.deepEqual(upstream.seen.calls, ["read_thing"]);
|
|
133
|
+
|
|
134
|
+
// The credential reached the upstream on every request, from the env.
|
|
135
|
+
assert.ok(upstream.seen.authHeaders.every((h) => h === `Bearer ${TOKEN}`));
|
|
136
|
+
|
|
137
|
+
// Signed receipt + outcome verify with the proxy's own public key.
|
|
138
|
+
assert.equal(receipts.length, 1);
|
|
139
|
+
const pub = proxy.signingKey.publicKey;
|
|
140
|
+
const rv = verifyReceipt(receipts[0], pub);
|
|
141
|
+
assert.equal(rv.signatureValid, true);
|
|
142
|
+
assert.equal(rv.hashValid, true);
|
|
143
|
+
assert.equal(outcomes.length, 1);
|
|
144
|
+
const ov = verifyExecutionOutcome(outcomes[0], pub, receipts[0]);
|
|
145
|
+
assert.equal(ov.signatureValid, true);
|
|
146
|
+
assert.equal(outcomes[0].executionStatus, "SUCCEEDED");
|
|
147
|
+
|
|
148
|
+
// The credential appears nowhere in signed artifacts or the audit stream.
|
|
149
|
+
const everything = JSON.stringify({ receipts, outcomes, audits });
|
|
150
|
+
assert.ok(!everything.includes(TOKEN), "token leaked into receipts/outcomes/audits");
|
|
151
|
+
|
|
152
|
+
// Transport + origin are recorded in the unsigned audit stream.
|
|
153
|
+
const connected = audits.find((a) => a.kind === "upstream.connected");
|
|
154
|
+
assert.equal(connected.detail.transport, "http");
|
|
155
|
+
assert.match(connected.detail.origin, /^http:\/\/127\.0\.0\.1:\d+$/);
|
|
156
|
+
} finally {
|
|
157
|
+
await proxy.stop();
|
|
158
|
+
await upstream.close();
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
test("http e2e: a denied call never reaches the remote server and still yields a signed DENY", async () => {
|
|
163
|
+
const upstream = await startHttpUpstream();
|
|
164
|
+
const { proxy, client, receipts } = await startGovernedProxy(upstream.url);
|
|
165
|
+
try {
|
|
166
|
+
await assert.rejects(client.callTool({ name: "delete_thing", arguments: {} }));
|
|
167
|
+
assert.deepEqual(upstream.seen.calls, [], "the remote server must not see a denied call");
|
|
168
|
+
assert.equal(receipts.length, 1);
|
|
169
|
+
assert.equal(receipts[0].decision, "DENY");
|
|
170
|
+
assert.equal(verifyReceipt(receipts[0], proxy.signingKey.publicKey).signatureValid, true);
|
|
171
|
+
} finally {
|
|
172
|
+
await proxy.stop();
|
|
173
|
+
await upstream.close();
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test("http e2e: an unanswered call is reported as UPSTREAM_OUTCOME_UNKNOWN, signed FAILED, and not retried", async () => {
|
|
178
|
+
const upstream = await startHttpUpstream({ slowMs: 1500 });
|
|
179
|
+
const outcomes = [];
|
|
180
|
+
const { proxy, client, audits } = await startGovernedProxy(upstream.url, { upstream: { timeoutMs: 300 } });
|
|
181
|
+
proxy.gateway.on("outcome", (o) => outcomes.push(o));
|
|
182
|
+
try {
|
|
183
|
+
const before = upstream.seen.calls.length;
|
|
184
|
+
await assert.rejects(client.callTool({ name: "slow_thing", arguments: {} }), /UPSTREAM_OUTCOME_UNKNOWN|did not answer/);
|
|
185
|
+
await new Promise((r) => setTimeout(r, 1700));
|
|
186
|
+
assert.equal(upstream.seen.calls.length - before, 1, "the call reached the server exactly once — no retry");
|
|
187
|
+
assert.equal(outcomes.length, 1);
|
|
188
|
+
assert.equal(outcomes[0].executionStatus, "FAILED");
|
|
189
|
+
assert.ok(audits.some((a) => a.kind === "upstream.outcome_unknown"));
|
|
190
|
+
} finally {
|
|
191
|
+
await proxy.stop();
|
|
192
|
+
await upstream.close();
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
test("http e2e: a redirecting upstream is refused at connect and nothing follows the redirect", async () => {
|
|
197
|
+
const target = await startHttpUpstream();
|
|
198
|
+
const redirector = await startHttpUpstream({ redirectTo: target.url });
|
|
199
|
+
try {
|
|
200
|
+
await assert.rejects(startGovernedProxy(redirector.url), /redirect/i);
|
|
201
|
+
assert.equal(target.seen.requests, 0, "the redirect target must never be contacted");
|
|
202
|
+
} finally {
|
|
203
|
+
await redirector.close();
|
|
204
|
+
await target.close();
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
test("http e2e: a missing credential env var fails startup before any request", async () => {
|
|
209
|
+
const upstream = await startHttpUpstream();
|
|
210
|
+
try {
|
|
211
|
+
await assert.rejects(
|
|
212
|
+
startGovernedProxy(upstream.url, {
|
|
213
|
+
upstream: { headers: { Authorization: { fromEnv: "E2E_DEFINITELY_UNSET_VAR" } } },
|
|
214
|
+
}),
|
|
215
|
+
/E2E_DEFINITELY_UNSET_VAR/,
|
|
216
|
+
);
|
|
217
|
+
assert.equal(upstream.seen.requests, 0);
|
|
218
|
+
} finally {
|
|
219
|
+
await upstream.close();
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
test("http e2e: a rejected credential surfaces without echoing the token", async () => {
|
|
224
|
+
const upstream = await startHttpUpstream();
|
|
225
|
+
process.env.E2E_WRONG_TOKEN = "wrong-token-value-77";
|
|
226
|
+
try {
|
|
227
|
+
await assert.rejects(
|
|
228
|
+
startGovernedProxy(upstream.url, {
|
|
229
|
+
upstream: { headers: { Authorization: { fromEnv: "E2E_WRONG_TOKEN", prefix: "Bearer " } } },
|
|
230
|
+
}),
|
|
231
|
+
(err) => {
|
|
232
|
+
assert.ok(!String(err.message).includes("wrong-token-value-77"), err.message);
|
|
233
|
+
return true;
|
|
234
|
+
},
|
|
235
|
+
);
|
|
236
|
+
} finally {
|
|
237
|
+
delete process.env.E2E_WRONG_TOKEN;
|
|
238
|
+
await upstream.close();
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
test("http e2e: an upstream error that echoes the credential is scrubbed before it reaches the client", async () => {
|
|
243
|
+
const upstream = await startHttpUpstream();
|
|
244
|
+
const errors = [];
|
|
245
|
+
const { proxy, client } = await startGovernedProxy(upstream.url);
|
|
246
|
+
proxy.gateway.on("error", (e) => errors.push(String(e?.err?.message)));
|
|
247
|
+
try {
|
|
248
|
+
const outcome = await client.callTool({ name: "leaky_thing", arguments: {} }).then(
|
|
249
|
+
(r) => JSON.stringify(r),
|
|
250
|
+
(err) => String(err?.message),
|
|
251
|
+
);
|
|
252
|
+
assert.deepEqual(upstream.seen.calls, ["leaky_thing"]);
|
|
253
|
+
assert.ok(!outcome.includes(TOKEN), `token reached the client: ${outcome}`);
|
|
254
|
+
assert.ok(errors.every((m) => !m.includes(TOKEN)), "token reached the gateway error event");
|
|
255
|
+
} finally {
|
|
256
|
+
await proxy.stop();
|
|
257
|
+
await upstream.close();
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
test("http e2e: a response over maxResponseBytes is discarded and the call fails (signed FAILED), without hanging", async () => {
|
|
262
|
+
const upstream = await startHttpUpstream();
|
|
263
|
+
const outcomes = [];
|
|
264
|
+
const { proxy, client } = await startGovernedProxy(upstream.url, {
|
|
265
|
+
upstream: { maxResponseBytes: 50_000, timeoutMs: 5_000 },
|
|
266
|
+
});
|
|
267
|
+
proxy.gateway.on("outcome", (o) => outcomes.push(o));
|
|
268
|
+
try {
|
|
269
|
+
const started = Date.now();
|
|
270
|
+
await assert.rejects(client.callTool({ name: "huge_thing", arguments: {} }));
|
|
271
|
+
assert.ok(Date.now() - started < 4_000, "must fail on the cap, not wait for the timeout");
|
|
272
|
+
assert.deepEqual(upstream.seen.calls, ["huge_thing"]);
|
|
273
|
+
assert.equal(outcomes.length, 1);
|
|
274
|
+
assert.equal(outcomes[0].executionStatus, "FAILED");
|
|
275
|
+
} finally {
|
|
276
|
+
await proxy.stop();
|
|
277
|
+
await upstream.close();
|
|
278
|
+
}
|
|
279
|
+
});
|