@zereight/mcp-gitlab 2.1.70 → 2.2.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/README.ko.md +3 -1
- package/README.md +6 -2
- package/README.pt-BR.md +1 -1
- package/README.zh-CN.md +3 -1
- package/build/config.js +12 -4
- package/build/deprecated-env.js +47 -0
- package/build/index.js +369 -184
- package/build/oauth-device-flow.js +80 -0
- package/build/oauth.js +135 -18
- package/build/schemas.js +1 -1
- package/build/server/remote-http-stack.js +39 -0
- package/build/tools/discover-activation.js +38 -0
- package/build/tools/exposed-tools.js +35 -0
- package/build/tools/listed-tools.js +76 -0
- package/build/tools/registry.js +226 -57
- package/build/tools/tool-profile.js +66 -0
- package/build/utils/compact-tool-allowlist.js +14 -0
- package/build/utils/logger.js +34 -12
- package/package.json +3 -3
- package/build/scripts/check-skill-sync.js +0 -143
- package/build/scripts/generate-server-card.js +0 -39
- package/build/scripts/generate-tool-coverage.js +0 -58
- package/build/scripts/generate-tool-docs.js +0 -430
- package/build/scripts/tool-coverage/coverage.js +0 -341
- package/build/scripts/tool-coverage/coverage.test.js +0 -142
- package/build/test/callback-proxy-tests.js +0 -321
- package/build/test/cli/args.test.js +0 -175
- package/build/test/cli/boolean-flags.test.js +0 -106
- package/build/test/cli/compact-mcp-result.test.js +0 -93
- package/build/test/cli/credentials.test.js +0 -153
- package/build/test/cli/exposure.test.js +0 -104
- package/build/test/cli/load-config-snapshot.js +0 -5
- package/build/test/cli/output.test.js +0 -74
- package/build/test/cli/replay-command.test.js +0 -37
- package/build/test/cli/router.test.js +0 -183
- package/build/test/client-pool-test.js +0 -109
- package/build/test/clients/client.js +0 -34
- package/build/test/clients/custom-header-client.js +0 -122
- package/build/test/clients/sse-client.js +0 -95
- package/build/test/clients/stdio-client.js +0 -113
- package/build/test/clients/streamable-http-client.js +0 -95
- package/build/test/config-allowed-groups.test.js +0 -97
- package/build/test/create-commit-actions.test.js +0 -102
- package/build/test/draft-note-schema.test.js +0 -44
- package/build/test/dynamic-api-url-allowlist.test.js +0 -121
- package/build/test/dynamic-api-url-test.js +0 -304
- package/build/test/dynamic-routing-tests.js +0 -495
- package/build/test/get-merge-request-discussion-schema.test.js +0 -30
- package/build/test/gitlab-api-tool-errors.test.js +0 -112
- package/build/test/gitlab-artifact-entry-schema.test.js +0 -44
- package/build/test/gitlab-diff-schema.test.js +0 -36
- package/build/test/gitlab-pipeline-schedule-schema.test.js +0 -32
- package/build/test/gitlab-tag-schema.test.js +0 -51
- package/build/test/group-milestone-schema.test.js +0 -45
- package/build/test/mcp-oauth-tests.js +0 -905
- package/build/test/mcp-server-name.test.js +0 -87
- package/build/test/merge-merge-request-schema.test.js +0 -75
- package/build/test/multi-server-test.js +0 -190
- package/build/test/no-proxy-integration-test.js +0 -183
- package/build/test/no-proxy-test.js +0 -149
- package/build/test/nullable-gitlab-response-fields.test.js +0 -37
- package/build/test/nullish-tool-arguments-schema.test.js +0 -118
- package/build/test/oauth-device-flow-tests.js +0 -450
- package/build/test/oauth-download-url.test.js +0 -157
- package/build/test/oauth-startup.test.js +0 -204
- package/build/test/oauth-tests.js +0 -428
- package/build/test/path-segment-encoding.test.js +0 -98
- package/build/test/remote-auth-simple-test.js +0 -277
- package/build/test/remote-auth-tests.js +0 -314
- package/build/test/response-masking.test.js +0 -445
- package/build/test/schema-tests.js +0 -1679
- package/build/test/server/metrics.test.js +0 -47
- package/build/test/server/request-helpers.test.js +0 -48
- package/build/test/server/version.test.js +0 -13
- package/build/test/sse-auth-guard.test.js +0 -96
- package/build/test/sse-session-limits.test.js +0 -273
- package/build/test/stateless/callback-proxy.test.js +0 -510
- package/build/test/stateless/client-id.test.js +0 -177
- package/build/test/stateless/codec.test.js +0 -328
- package/build/test/stateless/config-ttl.test.js +0 -149
- package/build/test/stateless/consumed-proxy-code-cache.test.js +0 -150
- package/build/test/stateless/session-id-integration.test.js +0 -675
- package/build/test/stateless/session-id.test.js +0 -157
- package/build/test/streamable-http-concurrent-session.test.js +0 -171
- package/build/test/streamable-http-dns-rebinding.test.js +0 -185
- package/build/test/streamable-http-sse-stream.test.js +0 -350
- package/build/test/streamable-http-static-token-auth.test.js +0 -157
- package/build/test/streamable-http-unauthenticated-discovery.test.js +0 -207
- package/build/test/test-all-transport-server.js +0 -255
- package/build/test/test-auth-retry.js +0 -195
- package/build/test/test-blank-filters.js +0 -156
- package/build/test/test-ci-catalog.js +0 -177
- package/build/test/test-ci-lint.js +0 -191
- package/build/test/test-ci-variables.js +0 -309
- package/build/test/test-create-repository.js +0 -120
- package/build/test/test-dependency-proxy.js +0 -195
- package/build/test/test-deployment-tools.js +0 -463
- package/build/test/test-download-attachment.js +0 -190
- package/build/test/test-dynamic-project-scope.js +0 -524
- package/build/test/test-empty-toolsets.js +0 -535
- package/build/test/test-get-file-blame.js +0 -145
- package/build/test/test-get-file-contents.js +0 -128
- package/build/test/test-geteffectiveprojectid.js +0 -804
- package/build/test/test-health-check.js +0 -115
- package/build/test/test-issue-description-patch.js +0 -256
- package/build/test/test-job-artifacts.js +0 -275
- package/build/test/test-json-schema.js +0 -166
- package/build/test/test-list-group-members.js +0 -150
- package/build/test/test-list-group-merge-requests.js +0 -165
- package/build/test/test-list-issues.js +0 -170
- package/build/test/test-list-merge-requests.js +0 -201
- package/build/test/test-list-milestones.js +0 -145
- package/build/test/test-list-project-members.js +0 -132
- package/build/test/test-merge-request-approval-state-tools.js +0 -213
- package/build/test/test-merge-request-approvals.js +0 -187
- package/build/test/test-merge-request-pipelines.js +0 -106
- package/build/test/test-mr-diffs-filter.js +0 -132
- package/build/test/test-mr-file-diffs.js +0 -251
- package/build/test/test-oauth-proxy-rate-limit.js +0 -133
- package/build/test/test-orbit.js +0 -155
- package/build/test/test-permission-mode.js +0 -424
- package/build/test/test-pipeline-schedules.js +0 -484
- package/build/test/test-protected-branches.js +0 -174
- package/build/test/test-remote-downloads.js +0 -510
- package/build/test/test-search-code.js +0 -275
- package/build/test/test-snippets.js +0 -735
- package/build/test/test-tags.js +0 -220
- package/build/test/test-todos.js +0 -195
- package/build/test/test-token-optimizations.js +0 -691
- package/build/test/test-toolset-filtering.js +0 -499
- package/build/test/test-update-issue-slim.js +0 -141
- package/build/test/test-update-project.js +0 -112
- package/build/test/test-upload-markdown.js +0 -206
- package/build/test/test-vulnerabilities.js +0 -399
- package/build/test/test-webhooks.js +0 -218
- package/build/test/tool-description-quality.test.js +0 -50
- package/build/test/utils/bulk-publish-options.test.js +0 -32
- package/build/test/utils/download-token.test.js +0 -35
- package/build/test/utils/forwarded-public-base-url.test.js +0 -46
- package/build/test/utils/gitlab-instance-version.test.js +0 -32
- package/build/test/utils/gitlab-version-gate.test.js +0 -74
- package/build/test/utils/graphql-query.test.js +0 -168
- package/build/test/utils/helpers-path.test.js +0 -104
- package/build/test/utils/jmespath-tool-result.test.js +0 -91
- package/build/test/utils/masking.test.js +0 -384
- package/build/test/utils/merge-request-position.test.js +0 -57
- package/build/test/utils/mock-gitlab-server.js +0 -614
- package/build/test/utils/proxy-client-ip.test.js +0 -28
- package/build/test/utils/redact-sensitive.test.js +0 -32
- package/build/test/utils/safe-redirect-fetch.test.js +0 -463
- package/build/test/utils/server-launcher.js +0 -231
- package/build/test/utils/tool-args.test.js +0 -210
- package/build/test/utils/url.test.js +0 -141
- package/build/test/utils/version-check.test.js +0 -239
- package/build/test/utils/wiki-title.test.js +0 -21
- package/build/test-note.js +0 -54
- package/build/test-resolve-issue-note.js +0 -127
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Unit tests for the sealed Mcp-Session-Id helpers.
|
|
3
|
-
*/
|
|
4
|
-
import assert from "node:assert/strict";
|
|
5
|
-
import { randomBytes } from "node:crypto";
|
|
6
|
-
import { describe, test } from "node:test";
|
|
7
|
-
import { loadKeyMaterialFromEnv, looksLikeStatelessSessionId, mintSessionId, openSessionId, } from "../../stateless/index.js";
|
|
8
|
-
function secret() {
|
|
9
|
-
return randomBytes(32).toString("base64url");
|
|
10
|
-
}
|
|
11
|
-
function load(current, previous) {
|
|
12
|
-
const env = {
|
|
13
|
-
OAUTH_STATELESS_SECRET: current,
|
|
14
|
-
};
|
|
15
|
-
if (previous)
|
|
16
|
-
env.OAUTH_STATELESS_SECRET_PREVIOUS = previous;
|
|
17
|
-
const m = loadKeyMaterialFromEnv(true, env);
|
|
18
|
-
assert.ok(m);
|
|
19
|
-
return m;
|
|
20
|
-
}
|
|
21
|
-
describe("mintSessionId / openSessionId", () => {
|
|
22
|
-
test("seals and restores a narrowed project scope", () => {
|
|
23
|
-
const s = secret();
|
|
24
|
-
const a = load(s);
|
|
25
|
-
const b = load(s);
|
|
26
|
-
const sid = mintSessionId(a, {
|
|
27
|
-
header: "Private-Token",
|
|
28
|
-
token: "glpat-ABCDEFG123456789-abcdef",
|
|
29
|
-
apiUrl: "https://gitlab.example.com/api/v4",
|
|
30
|
-
allowedProjectIds: ["42", "org/theorg"],
|
|
31
|
-
});
|
|
32
|
-
const opened = openSessionId(b, sid, 3600);
|
|
33
|
-
assert.ok(opened);
|
|
34
|
-
assert.deepEqual(opened.p, ["42", "org/theorg"]);
|
|
35
|
-
});
|
|
36
|
-
test("omits the scope field when no scope was narrowed", () => {
|
|
37
|
-
const s = secret();
|
|
38
|
-
const m = load(s);
|
|
39
|
-
const sid = mintSessionId(m, {
|
|
40
|
-
header: "Private-Token",
|
|
41
|
-
token: "glpat-ABCDEFG123456789-abcdef",
|
|
42
|
-
apiUrl: "https://gitlab.example.com/api/v4",
|
|
43
|
-
});
|
|
44
|
-
const opened = openSessionId(m, sid, 3600);
|
|
45
|
-
assert.ok(opened);
|
|
46
|
-
assert.equal(opened.p, undefined);
|
|
47
|
-
});
|
|
48
|
-
test("roundtrips across pods", () => {
|
|
49
|
-
const s = secret();
|
|
50
|
-
const a = load(s);
|
|
51
|
-
const b = load(s);
|
|
52
|
-
const sid = mintSessionId(a, {
|
|
53
|
-
header: "Authorization",
|
|
54
|
-
token: "glpat-ABCDEFG123456789-abcdef",
|
|
55
|
-
apiUrl: "https://gitlab.example.com/api/v4",
|
|
56
|
-
});
|
|
57
|
-
assert.ok(looksLikeStatelessSessionId(sid));
|
|
58
|
-
const opened = openSessionId(b, sid, 3600);
|
|
59
|
-
assert.ok(opened);
|
|
60
|
-
assert.equal(opened.h, "Authorization");
|
|
61
|
-
assert.equal(opened.t, "glpat-ABCDEFG123456789-abcdef");
|
|
62
|
-
assert.equal(opened.u, "https://gitlab.example.com/api/v4");
|
|
63
|
-
});
|
|
64
|
-
test("preserves Private-Token / JOB-TOKEN headers", () => {
|
|
65
|
-
const m = load(secret());
|
|
66
|
-
for (const h of ["Private-Token", "JOB-TOKEN"]) {
|
|
67
|
-
const sid = mintSessionId(m, {
|
|
68
|
-
header: h,
|
|
69
|
-
token: "some-token-value-at-least-20-chars",
|
|
70
|
-
apiUrl: "https://gitlab.example.com/api/v4",
|
|
71
|
-
});
|
|
72
|
-
const opened = openSessionId(m, sid, 3600);
|
|
73
|
-
assert.ok(opened);
|
|
74
|
-
assert.equal(opened.h, h);
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
test("rejects unknown header values", () => {
|
|
78
|
-
// Hand-craft a payload with a bogus header value. We do this by minting a
|
|
79
|
-
// legitimate token then mutating the decoded payload via a second mint
|
|
80
|
-
// won't work (AEAD). Instead, assert the helper rejects garbage input
|
|
81
|
-
// by tampering with an unrelated value and checking it still fails safely.
|
|
82
|
-
const m = load(secret());
|
|
83
|
-
const sid = mintSessionId(m, {
|
|
84
|
-
header: "Authorization",
|
|
85
|
-
token: "t".repeat(25),
|
|
86
|
-
apiUrl: "u",
|
|
87
|
-
});
|
|
88
|
-
// Truncate to force bad ciphertext on open.
|
|
89
|
-
const broken = sid.slice(0, -3);
|
|
90
|
-
assert.equal(openSessionId(m, broken, 3600), null);
|
|
91
|
-
});
|
|
92
|
-
test("expired sid rejected", () => {
|
|
93
|
-
const m = load(secret());
|
|
94
|
-
const past = Math.floor(Date.now() / 1000) - 10_000;
|
|
95
|
-
const sid = mintSessionId(m, {
|
|
96
|
-
header: "Authorization",
|
|
97
|
-
token: "t".repeat(25),
|
|
98
|
-
apiUrl: "u",
|
|
99
|
-
now: () => past,
|
|
100
|
-
});
|
|
101
|
-
assert.equal(openSessionId(m, sid, 60), null);
|
|
102
|
-
});
|
|
103
|
-
test("different secret rejects", () => {
|
|
104
|
-
const a = load(secret());
|
|
105
|
-
const b = load(secret());
|
|
106
|
-
const sid = mintSessionId(a, {
|
|
107
|
-
header: "Authorization",
|
|
108
|
-
token: "t".repeat(25),
|
|
109
|
-
apiUrl: "u",
|
|
110
|
-
});
|
|
111
|
-
assert.equal(openSessionId(b, sid, 3600), null);
|
|
112
|
-
});
|
|
113
|
-
test("rotation: sid minted under previous secret opens on rotated pod", () => {
|
|
114
|
-
const s1 = secret();
|
|
115
|
-
const s2 = secret();
|
|
116
|
-
const old = load(s1);
|
|
117
|
-
const rotated = load(s2, s1);
|
|
118
|
-
const sid = mintSessionId(old, {
|
|
119
|
-
header: "Authorization",
|
|
120
|
-
token: "t".repeat(25),
|
|
121
|
-
apiUrl: "u",
|
|
122
|
-
});
|
|
123
|
-
const opened = openSessionId(rotated, sid, 3600);
|
|
124
|
-
assert.ok(opened);
|
|
125
|
-
});
|
|
126
|
-
test("looksLikeStatelessSessionId distinguishes legacy UUIDs", () => {
|
|
127
|
-
const m = load(secret());
|
|
128
|
-
const sid = mintSessionId(m, {
|
|
129
|
-
header: "Authorization",
|
|
130
|
-
token: "t".repeat(25),
|
|
131
|
-
apiUrl: "u",
|
|
132
|
-
});
|
|
133
|
-
assert.ok(looksLikeStatelessSessionId(sid));
|
|
134
|
-
assert.ok(!looksLikeStatelessSessionId("a4f1c2b8-f2c4-4ee6-bc14-2b7ab0e6ab11"));
|
|
135
|
-
assert.ok(!looksLikeStatelessSessionId(""));
|
|
136
|
-
});
|
|
137
|
-
test("fresh sid has different iat each time (rotation on every refresh)", () => {
|
|
138
|
-
const m = load(secret());
|
|
139
|
-
const sid1 = mintSessionId(m, {
|
|
140
|
-
header: "Authorization",
|
|
141
|
-
token: "t".repeat(25),
|
|
142
|
-
apiUrl: "u",
|
|
143
|
-
now: () => 1000,
|
|
144
|
-
});
|
|
145
|
-
const sid2 = mintSessionId(m, {
|
|
146
|
-
header: "Authorization",
|
|
147
|
-
token: "t".repeat(25),
|
|
148
|
-
apiUrl: "u",
|
|
149
|
-
now: () => 2000,
|
|
150
|
-
});
|
|
151
|
-
assert.notEqual(sid1, sid2);
|
|
152
|
-
const open1 = openSessionId(m, sid1, 3600, () => 2000);
|
|
153
|
-
const open2 = openSessionId(m, sid2, 3600, () => 2000);
|
|
154
|
-
assert.equal(open1.iat, 1000);
|
|
155
|
-
assert.equal(open2.iat, 2000);
|
|
156
|
-
});
|
|
157
|
-
});
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import { after, before, describe, test } from "node:test";
|
|
2
|
-
import assert from "node:assert";
|
|
3
|
-
import { Buffer } from "node:buffer";
|
|
4
|
-
import fs from "node:fs";
|
|
5
|
-
import path, { dirname } from "node:path";
|
|
6
|
-
import { fileURLToPath } from "node:url";
|
|
7
|
-
import { cleanupServers, findAvailablePort, HOST, launchServer, TransportMode, } from "./utils/server-launcher.js";
|
|
8
|
-
import { findMockServerPort, MockGitLabServer } from "./utils/mock-gitlab-server.js";
|
|
9
|
-
import { CustomHeaderClient } from "./clients/custom-header-client.js";
|
|
10
|
-
const MOCK_TOKEN = "mock-concurrent-token-12345";
|
|
11
|
-
const TEST_PROJECT_ID = "123";
|
|
12
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
13
|
-
const __dirname = dirname(__filename);
|
|
14
|
-
const packageJsonPath = path.resolve(__dirname, "../package.json");
|
|
15
|
-
const PACKAGE_VERSION = JSON.parse(fs.readFileSync(packageJsonPath, "utf8")).version;
|
|
16
|
-
function fileResponse(filePath, content) {
|
|
17
|
-
return {
|
|
18
|
-
file_name: filePath.split("/").at(-1),
|
|
19
|
-
file_path: filePath,
|
|
20
|
-
encoding: "base64",
|
|
21
|
-
content: Buffer.from(content, "utf8").toString("base64"),
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
describe("Streamable HTTP concurrent session requests", { timeout: 20_000 }, () => {
|
|
25
|
-
let mockGitLab;
|
|
26
|
-
let server;
|
|
27
|
-
let mcpUrl;
|
|
28
|
-
before(async () => {
|
|
29
|
-
const mockPort = await findMockServerPort();
|
|
30
|
-
mockGitLab = new MockGitLabServer({
|
|
31
|
-
port: mockPort,
|
|
32
|
-
validTokens: [MOCK_TOKEN],
|
|
33
|
-
responseDelay: 100,
|
|
34
|
-
});
|
|
35
|
-
mockGitLab.addMockHandler("get", `/projects/${TEST_PROJECT_ID}/repository/files/package.json`, (_req, res) => {
|
|
36
|
-
res.json(fileResponse("package.json", "package file"));
|
|
37
|
-
});
|
|
38
|
-
mockGitLab.addMockHandler("get", `/projects/${TEST_PROJECT_ID}/repository/files/README.md`, (_req, res) => {
|
|
39
|
-
res.json(fileResponse("README.md", "readme file"));
|
|
40
|
-
});
|
|
41
|
-
await mockGitLab.start();
|
|
42
|
-
const port = await findAvailablePort(3460);
|
|
43
|
-
server = await launchServer({
|
|
44
|
-
mode: TransportMode.STREAMABLE_HTTP,
|
|
45
|
-
port,
|
|
46
|
-
timeout: 10_000,
|
|
47
|
-
env: {
|
|
48
|
-
STREAMABLE_HTTP: "true",
|
|
49
|
-
REMOTE_AUTHORIZATION: "true",
|
|
50
|
-
GITLAB_API_URL: `${mockGitLab.getUrl()}/api/v4`,
|
|
51
|
-
},
|
|
52
|
-
});
|
|
53
|
-
mcpUrl = `http://${HOST}:${port}/mcp`;
|
|
54
|
-
});
|
|
55
|
-
after(async () => {
|
|
56
|
-
cleanupServers([server]);
|
|
57
|
-
if (mockGitLab)
|
|
58
|
-
await mockGitLab.stop();
|
|
59
|
-
});
|
|
60
|
-
test("handles concurrent SDK tool calls with the same Mcp-Session-Id", async () => {
|
|
61
|
-
const client = new CustomHeaderClient({ Authorization: `Bearer ${MOCK_TOKEN}` });
|
|
62
|
-
await client.connect(mcpUrl);
|
|
63
|
-
try {
|
|
64
|
-
const initialSessionId = client.getSessionId();
|
|
65
|
-
assert.ok(initialSessionId, "initialize should return Mcp-Session-Id");
|
|
66
|
-
let timeoutHandle;
|
|
67
|
-
try {
|
|
68
|
-
const [packageResult, readmeResult] = await Promise.race([
|
|
69
|
-
Promise.all([
|
|
70
|
-
client.callTool("get_file_contents", {
|
|
71
|
-
project_id: TEST_PROJECT_ID,
|
|
72
|
-
file_path: "package.json",
|
|
73
|
-
ref: "main",
|
|
74
|
-
}),
|
|
75
|
-
client.callTool("get_file_contents", {
|
|
76
|
-
project_id: TEST_PROJECT_ID,
|
|
77
|
-
file_path: "README.md",
|
|
78
|
-
ref: "main",
|
|
79
|
-
}),
|
|
80
|
-
]),
|
|
81
|
-
new Promise((_, reject) => {
|
|
82
|
-
timeoutHandle = setTimeout(() => reject(new Error("concurrent tool calls timed out")), 5_000);
|
|
83
|
-
}),
|
|
84
|
-
]);
|
|
85
|
-
const packageText = packageResult.content?.[0]?.type === "text" ? packageResult.content[0].text : "";
|
|
86
|
-
const readmeText = readmeResult.content?.[0]?.type === "text" ? readmeResult.content[0].text : "";
|
|
87
|
-
assert.strictEqual(client.getSessionId(), initialSessionId, "concurrent calls should reuse the same Mcp-Session-Id");
|
|
88
|
-
assert.ok(packageText.includes("package file"), packageText);
|
|
89
|
-
assert.ok(readmeText.includes("readme file"), readmeText);
|
|
90
|
-
}
|
|
91
|
-
finally {
|
|
92
|
-
clearTimeout(timeoutHandle);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
finally {
|
|
96
|
-
await client.disconnect();
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
describe("Streamable HTTP health check capacity logging", { timeout: 20_000 }, () => {
|
|
101
|
-
let mockGitLab;
|
|
102
|
-
let server;
|
|
103
|
-
let mcpUrl;
|
|
104
|
-
let baseUrl;
|
|
105
|
-
let output = "";
|
|
106
|
-
before(async () => {
|
|
107
|
-
const mockPort = await findMockServerPort();
|
|
108
|
-
mockGitLab = new MockGitLabServer({
|
|
109
|
-
port: mockPort,
|
|
110
|
-
validTokens: [MOCK_TOKEN],
|
|
111
|
-
});
|
|
112
|
-
await mockGitLab.start();
|
|
113
|
-
const port = await findAvailablePort(3470);
|
|
114
|
-
server = await launchServer({
|
|
115
|
-
mode: TransportMode.STREAMABLE_HTTP,
|
|
116
|
-
port,
|
|
117
|
-
timeout: 10_000,
|
|
118
|
-
env: {
|
|
119
|
-
STREAMABLE_HTTP: "true",
|
|
120
|
-
REMOTE_AUTHORIZATION: "true",
|
|
121
|
-
GITLAB_API_URL: `${mockGitLab.getUrl()}/api/v4`,
|
|
122
|
-
MAX_SESSIONS: "1",
|
|
123
|
-
},
|
|
124
|
-
});
|
|
125
|
-
server.process.stdout?.on("data", data => {
|
|
126
|
-
output += data.toString();
|
|
127
|
-
});
|
|
128
|
-
server.process.stderr?.on("data", data => {
|
|
129
|
-
output += data.toString();
|
|
130
|
-
});
|
|
131
|
-
baseUrl = `http://${HOST}:${port}`;
|
|
132
|
-
mcpUrl = `${baseUrl}/mcp`;
|
|
133
|
-
});
|
|
134
|
-
after(async () => {
|
|
135
|
-
cleanupServers([server]);
|
|
136
|
-
if (mockGitLab)
|
|
137
|
-
await mockGitLab.stop();
|
|
138
|
-
});
|
|
139
|
-
test("reports server version when healthy", async () => {
|
|
140
|
-
const response = await fetch(`${baseUrl}/health`);
|
|
141
|
-
const body = (await response.json());
|
|
142
|
-
assert.strictEqual(response.status, 200);
|
|
143
|
-
assert.strictEqual(body.status, "healthy");
|
|
144
|
-
assert.strictEqual(body.version, PACKAGE_VERSION);
|
|
145
|
-
assert.strictEqual(body.activeSessions, 0);
|
|
146
|
-
});
|
|
147
|
-
test("logs active session capacity when health check is degraded", async () => {
|
|
148
|
-
const client = new CustomHeaderClient({ Authorization: `Bearer ${MOCK_TOKEN}` });
|
|
149
|
-
await client.connect(mcpUrl);
|
|
150
|
-
try {
|
|
151
|
-
const response = await fetch(`${baseUrl}/health`);
|
|
152
|
-
const body = (await response.json());
|
|
153
|
-
assert.strictEqual(response.status, 503);
|
|
154
|
-
assert.strictEqual(body.status, "degraded");
|
|
155
|
-
assert.strictEqual(body.version, PACKAGE_VERSION);
|
|
156
|
-
assert.strictEqual(body.activeSessions, 1);
|
|
157
|
-
assert.strictEqual(body.maxSessions, 1);
|
|
158
|
-
// ponytail: poll stdout; fixed 100ms sleep flakes under CI jitter
|
|
159
|
-
const deadline = Date.now() + 2000;
|
|
160
|
-
while (Date.now() < deadline && !/Health check degraded/.test(output)) {
|
|
161
|
-
await new Promise(resolve => setTimeout(resolve, 50));
|
|
162
|
-
}
|
|
163
|
-
assert.match(output, /Health check degraded/);
|
|
164
|
-
assert.match(output, /activeSessions.*1/);
|
|
165
|
-
assert.match(output, /maxSessions.*1/);
|
|
166
|
-
}
|
|
167
|
-
finally {
|
|
168
|
-
await client.disconnect();
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
});
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert/strict";
|
|
2
|
-
import { spawn } from "node:child_process";
|
|
3
|
-
import http from "node:http";
|
|
4
|
-
import { afterEach, describe, test } from "node:test";
|
|
5
|
-
import * as path from "node:path";
|
|
6
|
-
import { findAvailablePort } from "./utils/server-launcher.js";
|
|
7
|
-
import { MockGitLabServer, findMockServerPort } from "./utils/mock-gitlab-server.js";
|
|
8
|
-
const HOST = process.env.HOST || "127.0.0.1";
|
|
9
|
-
const SERVER_PATH = path.resolve(process.cwd(), "build/index.js");
|
|
10
|
-
const TEST_TOKEN = "test-token-123456789012345";
|
|
11
|
-
const running = new Set();
|
|
12
|
-
const mockGitLabServers = [];
|
|
13
|
-
function hostWithPort(host, port) {
|
|
14
|
-
const normalized = host.trim();
|
|
15
|
-
if (normalized.includes(":") && !normalized.startsWith("["))
|
|
16
|
-
return `[${normalized}]:${port}`;
|
|
17
|
-
return `${normalized}:${port}`;
|
|
18
|
-
}
|
|
19
|
-
function startServer(env, port) {
|
|
20
|
-
const child = spawn("node", [SERVER_PATH], {
|
|
21
|
-
env: {
|
|
22
|
-
...process.env,
|
|
23
|
-
GITLAB_API_URL: "https://gitlab.example.com",
|
|
24
|
-
HOST,
|
|
25
|
-
PORT: String(port),
|
|
26
|
-
STREAMABLE_HTTP: "true",
|
|
27
|
-
REMOTE_AUTHORIZATION: "true",
|
|
28
|
-
GITLAB_MCP_OAUTH: "false",
|
|
29
|
-
GITLAB_USE_OAUTH: "false",
|
|
30
|
-
GITLAB_PERSONAL_ACCESS_TOKEN: "",
|
|
31
|
-
GITLAB_JOB_TOKEN: "",
|
|
32
|
-
GITLAB_AUTH_COOKIE_PATH: "",
|
|
33
|
-
MCP_SERVER_URL: "",
|
|
34
|
-
GITLAB_OAUTH_APP_ID: "",
|
|
35
|
-
...env,
|
|
36
|
-
},
|
|
37
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
38
|
-
});
|
|
39
|
-
running.add(child);
|
|
40
|
-
child.once("exit", () => running.delete(child));
|
|
41
|
-
return child;
|
|
42
|
-
}
|
|
43
|
-
async function startAuthenticatedServer(env, port) {
|
|
44
|
-
const mockPort = await findMockServerPort();
|
|
45
|
-
const mockGitLab = new MockGitLabServer({
|
|
46
|
-
port: mockPort,
|
|
47
|
-
validTokens: [TEST_TOKEN],
|
|
48
|
-
});
|
|
49
|
-
await mockGitLab.start();
|
|
50
|
-
mockGitLabServers.push(mockGitLab);
|
|
51
|
-
startServer({
|
|
52
|
-
GITLAB_API_URL: `${mockGitLab.getUrl()}/api/v4`,
|
|
53
|
-
...env,
|
|
54
|
-
}, port);
|
|
55
|
-
}
|
|
56
|
-
async function waitForHealth(port, timeoutMs = 5000) {
|
|
57
|
-
const deadline = Date.now() + timeoutMs;
|
|
58
|
-
let lastError;
|
|
59
|
-
while (Date.now() < deadline) {
|
|
60
|
-
try {
|
|
61
|
-
const response = await fetch(`http://${hostWithPort(HOST, port)}/health`);
|
|
62
|
-
if (response.ok)
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
catch (error) {
|
|
66
|
-
lastError = error;
|
|
67
|
-
}
|
|
68
|
-
await new Promise(resolve => setTimeout(resolve, 100));
|
|
69
|
-
}
|
|
70
|
-
throw new Error(`server did not become healthy: ${String(lastError)}`);
|
|
71
|
-
}
|
|
72
|
-
function postMcp(port, headers, body = JSON.stringify({
|
|
73
|
-
jsonrpc: "2.0",
|
|
74
|
-
id: 1,
|
|
75
|
-
method: "initialize",
|
|
76
|
-
params: {
|
|
77
|
-
protocolVersion: "2025-03-26",
|
|
78
|
-
capabilities: {},
|
|
79
|
-
clientInfo: { name: "dns-rebinding-test", version: "1.0.0" },
|
|
80
|
-
},
|
|
81
|
-
})) {
|
|
82
|
-
return new Promise((resolve, reject) => {
|
|
83
|
-
const req = http.request({
|
|
84
|
-
host: HOST,
|
|
85
|
-
port,
|
|
86
|
-
path: "/mcp",
|
|
87
|
-
method: "POST",
|
|
88
|
-
headers: {
|
|
89
|
-
Host: hostWithPort(HOST, port),
|
|
90
|
-
"Content-Type": "application/json",
|
|
91
|
-
Accept: "application/json, text/event-stream",
|
|
92
|
-
"Private-Token": TEST_TOKEN,
|
|
93
|
-
"Content-Length": Buffer.byteLength(body).toString(),
|
|
94
|
-
...headers,
|
|
95
|
-
},
|
|
96
|
-
}, res => {
|
|
97
|
-
let responseBody = "";
|
|
98
|
-
res.setEncoding("utf8");
|
|
99
|
-
res.on("data", chunk => {
|
|
100
|
-
responseBody += chunk;
|
|
101
|
-
});
|
|
102
|
-
res.on("end", () => resolve({ status: res.statusCode ?? 0, body: responseBody }));
|
|
103
|
-
});
|
|
104
|
-
req.on("error", reject);
|
|
105
|
-
req.end(body);
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
afterEach(async () => {
|
|
109
|
-
for (const child of running) {
|
|
110
|
-
if (!child.killed)
|
|
111
|
-
child.kill("SIGTERM");
|
|
112
|
-
}
|
|
113
|
-
running.clear();
|
|
114
|
-
while (mockGitLabServers.length > 0) {
|
|
115
|
-
const mockGitLab = mockGitLabServers.pop();
|
|
116
|
-
if (mockGitLab) {
|
|
117
|
-
await mockGitLab.stop();
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
describe("Streamable HTTP DNS rebinding protection", () => {
|
|
122
|
-
test("rejects forged Host and Origin headers before handling /mcp", async () => {
|
|
123
|
-
const port = await findAvailablePort(4700);
|
|
124
|
-
await startAuthenticatedServer({}, port);
|
|
125
|
-
await waitForHealth(port);
|
|
126
|
-
const validHost = hostWithPort(HOST, port);
|
|
127
|
-
const badJson = await postMcp(port, {
|
|
128
|
-
Host: "attacker.example.test",
|
|
129
|
-
Origin: `http://${validHost}`,
|
|
130
|
-
}, "{");
|
|
131
|
-
assert.equal(badJson.status, 403);
|
|
132
|
-
assert.match(badJson.body, /Host header is not allowed/);
|
|
133
|
-
assert.match(badJson.body, /MCP_ALLOWED_HOSTS/);
|
|
134
|
-
const badHost = await postMcp(port, {
|
|
135
|
-
Host: "attacker.example.test",
|
|
136
|
-
Origin: `http://${validHost}`,
|
|
137
|
-
});
|
|
138
|
-
assert.equal(badHost.status, 403);
|
|
139
|
-
assert.match(badHost.body, /Host header is not allowed/);
|
|
140
|
-
assert.match(badHost.body, /MCP_ALLOWED_HOSTS/);
|
|
141
|
-
const badOrigin = await postMcp(port, {
|
|
142
|
-
Host: validHost,
|
|
143
|
-
Origin: "https://attacker.example.test",
|
|
144
|
-
});
|
|
145
|
-
assert.equal(badOrigin.status, 403);
|
|
146
|
-
assert.match(badOrigin.body, /Origin header is not allowed/);
|
|
147
|
-
assert.match(badOrigin.body, /MCP_ALLOWED_ORIGINS/);
|
|
148
|
-
const ok = await postMcp(port, { Host: validHost });
|
|
149
|
-
assert.equal(ok.status, 200);
|
|
150
|
-
});
|
|
151
|
-
test("allows loopback Host and Origin on any port (Docker port mapping)", async () => {
|
|
152
|
-
const port = await findAvailablePort(4720);
|
|
153
|
-
await startAuthenticatedServer({}, port);
|
|
154
|
-
await waitForHealth(port);
|
|
155
|
-
// e.g. docker run -p 3333:3002 -> client sends Host: localhost:3333
|
|
156
|
-
const remappedHost = await postMcp(port, { Host: `localhost:${port + 1000}` });
|
|
157
|
-
assert.equal(remappedHost.status, 200);
|
|
158
|
-
const remappedIpv4 = await postMcp(port, { Host: `127.0.0.1:${port + 1000}` });
|
|
159
|
-
assert.equal(remappedIpv4.status, 200);
|
|
160
|
-
const remappedOrigin = await postMcp(port, {
|
|
161
|
-
Host: `localhost:${port + 1000}`,
|
|
162
|
-
Origin: `http://localhost:${port + 1000}`,
|
|
163
|
-
});
|
|
164
|
-
assert.equal(remappedOrigin.status, 200);
|
|
165
|
-
const bareLoopback = await postMcp(port, { Host: "localhost" });
|
|
166
|
-
assert.equal(bareLoopback.status, 200);
|
|
167
|
-
const loopbackHostBadOrigin = await postMcp(port, {
|
|
168
|
-
Host: `localhost:${port + 1000}`,
|
|
169
|
-
Origin: "http://attacker.example.test",
|
|
170
|
-
});
|
|
171
|
-
assert.equal(loopbackHostBadOrigin.status, 403);
|
|
172
|
-
assert.match(loopbackHostBadOrigin.body, /Origin header is not allowed/);
|
|
173
|
-
assert.match(loopbackHostBadOrigin.body, /MCP_ALLOWED_ORIGINS/);
|
|
174
|
-
});
|
|
175
|
-
test("allows the configured MCP_SERVER_URL host and origin", async () => {
|
|
176
|
-
const port = await findAvailablePort(4710);
|
|
177
|
-
await startAuthenticatedServer({ MCP_SERVER_URL: "https://mcp.example.test" }, port);
|
|
178
|
-
await waitForHealth(port);
|
|
179
|
-
const ok = await postMcp(port, {
|
|
180
|
-
Host: "mcp.example.test",
|
|
181
|
-
Origin: "https://mcp.example.test",
|
|
182
|
-
});
|
|
183
|
-
assert.equal(ok.status, 200);
|
|
184
|
-
});
|
|
185
|
-
});
|