@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,231 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Server launcher utility for testing different transport modes
|
|
3
|
-
* Manages server processes and provides clean shutdown
|
|
4
|
-
*/
|
|
5
|
-
import { spawn } from "child_process";
|
|
6
|
-
import * as path from "path";
|
|
7
|
-
export const HOST = process.env.HOST || "127.0.0.1";
|
|
8
|
-
export var TransportMode;
|
|
9
|
-
(function (TransportMode) {
|
|
10
|
-
TransportMode["STDIO"] = "stdio";
|
|
11
|
-
TransportMode["SSE"] = "sse";
|
|
12
|
-
TransportMode["STREAMABLE_HTTP"] = "streamable-http";
|
|
13
|
-
})(TransportMode || (TransportMode = {}));
|
|
14
|
-
/**
|
|
15
|
-
* Launch a server with specified configuration
|
|
16
|
-
*/
|
|
17
|
-
export async function launchServer(config) {
|
|
18
|
-
console.log("Launcher: launchServer function entered.");
|
|
19
|
-
const { mode, port = 3002, env = {}, timeout = 3000 } = config;
|
|
20
|
-
// Prepare environment variables based on transport mode
|
|
21
|
-
// Use same configuration pattern as existing validate-api.js
|
|
22
|
-
const GITLAB_API_URL = process.env.GITLAB_API_URL || "https://gitlab.com";
|
|
23
|
-
const GITLAB_TOKEN = process.env.GITLAB_TOKEN_TEST || process.env.GITLAB_TOKEN;
|
|
24
|
-
const TEST_PROJECT_ID = process.env.TEST_PROJECT_ID;
|
|
25
|
-
// Check which auth modes are active
|
|
26
|
-
const isRemoteAuth = env.REMOTE_AUTHORIZATION === "true";
|
|
27
|
-
const isMcpOAuth = env.GITLAB_MCP_OAUTH === "true";
|
|
28
|
-
// Both REMOTE_AUTHORIZATION and GITLAB_MCP_OAUTH manage tokens at the HTTP layer;
|
|
29
|
-
// neither requires a pre-configured GITLAB_TOKEN on the server process.
|
|
30
|
-
const isServerManagedAuth = isRemoteAuth || isMcpOAuth;
|
|
31
|
-
// Validate that we have required configuration (unless using a server-managed auth mode)
|
|
32
|
-
if (!GITLAB_TOKEN && !isServerManagedAuth) {
|
|
33
|
-
throw new Error("GITLAB_TOKEN_TEST or GITLAB_TOKEN environment variable is required for server testing");
|
|
34
|
-
}
|
|
35
|
-
if (!TEST_PROJECT_ID && !isServerManagedAuth && env.ENABLE_DYNAMIC_API_URL !== "true") {
|
|
36
|
-
throw new Error("TEST_PROJECT_ID environment variable is required for server testing");
|
|
37
|
-
}
|
|
38
|
-
const serverEnv = {
|
|
39
|
-
...process.env,
|
|
40
|
-
...env,
|
|
41
|
-
};
|
|
42
|
-
// Only set GITLAB_PERSONAL_ACCESS_TOKEN if not using a server-managed auth mode
|
|
43
|
-
if (!isServerManagedAuth && GITLAB_TOKEN) {
|
|
44
|
-
serverEnv.GITLAB_PERSONAL_ACCESS_TOKEN = GITLAB_TOKEN;
|
|
45
|
-
}
|
|
46
|
-
// Set transport-specific environment variables
|
|
47
|
-
switch (mode) {
|
|
48
|
-
case TransportMode.SSE:
|
|
49
|
-
serverEnv.SSE = "true";
|
|
50
|
-
serverEnv.PORT = port.toString();
|
|
51
|
-
break;
|
|
52
|
-
case TransportMode.STREAMABLE_HTTP:
|
|
53
|
-
serverEnv.STREAMABLE_HTTP = "true";
|
|
54
|
-
serverEnv.PORT = port.toString();
|
|
55
|
-
break;
|
|
56
|
-
case TransportMode.STDIO:
|
|
57
|
-
// Stdio mode doesn't need port configuration - uses process communication
|
|
58
|
-
throw new Error(`${TransportMode.STDIO} mode is not supported for server testing, because it uses process communication.`);
|
|
59
|
-
}
|
|
60
|
-
const serverPath = path.resolve(process.cwd(), "build/index.js");
|
|
61
|
-
console.log("Launcher: Spawning server process", { mode, port });
|
|
62
|
-
const serverProcess = spawn("node", [serverPath], {
|
|
63
|
-
env: serverEnv,
|
|
64
|
-
stdio: ["pipe", "pipe", "pipe"],
|
|
65
|
-
shell: false,
|
|
66
|
-
detached: false,
|
|
67
|
-
});
|
|
68
|
-
console.log(`Launcher: Server process spawned with PID: ${serverProcess.pid}`);
|
|
69
|
-
console.log("Launcher: Server process spawned.");
|
|
70
|
-
// Wait for server to start
|
|
71
|
-
await waitForServerStart(serverProcess, mode, port, timeout);
|
|
72
|
-
const instance = {
|
|
73
|
-
process: serverProcess,
|
|
74
|
-
port: port,
|
|
75
|
-
mode,
|
|
76
|
-
kill: () => {
|
|
77
|
-
if (!serverProcess.killed) {
|
|
78
|
-
serverProcess.kill("SIGTERM");
|
|
79
|
-
// Force kill if not terminated within 5 seconds
|
|
80
|
-
const forceKillTimer = setTimeout(() => {
|
|
81
|
-
if (!serverProcess.killed) {
|
|
82
|
-
serverProcess.kill("SIGKILL");
|
|
83
|
-
}
|
|
84
|
-
}, 5000);
|
|
85
|
-
forceKillTimer.unref();
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
};
|
|
89
|
-
return instance;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Wait for server to start based on transport mode
|
|
93
|
-
*/
|
|
94
|
-
async function waitForServerStart(process, mode, port, timeout) {
|
|
95
|
-
return new Promise((resolve, reject) => {
|
|
96
|
-
const timer = setTimeout(() => {
|
|
97
|
-
reject(new Error(`Server failed to start within ${timeout}ms for mode ${mode}`));
|
|
98
|
-
}, timeout);
|
|
99
|
-
let outputBuffer = "";
|
|
100
|
-
const onData = (data) => {
|
|
101
|
-
try {
|
|
102
|
-
const output = data.toString();
|
|
103
|
-
console.log(`[Server Output]: ${output}`);
|
|
104
|
-
outputBuffer += output;
|
|
105
|
-
}
|
|
106
|
-
catch (e) {
|
|
107
|
-
console.error("Error converting server output to string:", e);
|
|
108
|
-
reject(e);
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
// Check for server start messages
|
|
112
|
-
const startMessages = [
|
|
113
|
-
"Starting GitLab MCP Server with stdio transport",
|
|
114
|
-
"Starting GitLab MCP Server with SSE transport",
|
|
115
|
-
"Starting GitLab MCP Server with Streamable HTTP transport",
|
|
116
|
-
"GitLab MCP Server running",
|
|
117
|
-
`port ${port}`,
|
|
118
|
-
];
|
|
119
|
-
const hasStartMessage = startMessages.some(msg => outputBuffer.includes(msg));
|
|
120
|
-
if (hasStartMessage) {
|
|
121
|
-
clearTimeout(timer);
|
|
122
|
-
// process.stdout?.removeListener('data', onData);
|
|
123
|
-
// process.stderr?.removeListener('data', onData);
|
|
124
|
-
// Additional wait for HTTP servers to be fully ready
|
|
125
|
-
if (mode !== TransportMode.STDIO) {
|
|
126
|
-
setTimeout(resolve, 1000);
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
resolve();
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
const onError = (error) => {
|
|
134
|
-
clearTimeout(timer);
|
|
135
|
-
reject(new Error(`Server process error: ${error.message}`));
|
|
136
|
-
};
|
|
137
|
-
const onExit = (code) => {
|
|
138
|
-
console.log(`[Launcher DEBUG] Process ${process.pid} exited with code ${code}`);
|
|
139
|
-
// We don't reject here immediately, we wait for 'close' to ensure streams are flushed
|
|
140
|
-
};
|
|
141
|
-
const onClose = (code) => {
|
|
142
|
-
console.log(`[Launcher DEBUG] Process ${process.pid} closed with code ${code}`);
|
|
143
|
-
clearTimeout(timer);
|
|
144
|
-
reject(new Error(`Server process exited with code ${code} before starting`));
|
|
145
|
-
};
|
|
146
|
-
process.stdout?.on("data", onData);
|
|
147
|
-
process.on("close", onClose);
|
|
148
|
-
process.stderr?.on("data", onData);
|
|
149
|
-
process.on("error", onError);
|
|
150
|
-
process.on("exit", onExit);
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Find an available port starting from a base port
|
|
155
|
-
*/
|
|
156
|
-
export async function findAvailablePort(basePort = 3002) {
|
|
157
|
-
const net = await import("net");
|
|
158
|
-
return new Promise((resolve, reject) => {
|
|
159
|
-
const server = net.createServer();
|
|
160
|
-
server.listen(basePort, () => {
|
|
161
|
-
const address = server.address();
|
|
162
|
-
const port = typeof address === "object" && address ? address.port : basePort;
|
|
163
|
-
server.close(() => resolve(port));
|
|
164
|
-
});
|
|
165
|
-
server.on("error", (err) => {
|
|
166
|
-
if (err.code === "EADDRINUSE") {
|
|
167
|
-
// Port is in use, try next one
|
|
168
|
-
resolve(findAvailablePort(basePort + 1));
|
|
169
|
-
}
|
|
170
|
-
else {
|
|
171
|
-
reject(err);
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* Clean shutdown for multiple server instances
|
|
178
|
-
*/
|
|
179
|
-
export function cleanupServers(servers) {
|
|
180
|
-
servers.forEach(server => {
|
|
181
|
-
try {
|
|
182
|
-
server.kill();
|
|
183
|
-
}
|
|
184
|
-
catch (error) {
|
|
185
|
-
console.warn(`Failed to kill server process: ${error}`);
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Create AbortController with timeout
|
|
191
|
-
*/
|
|
192
|
-
export function createTimeoutController(timeout) {
|
|
193
|
-
const controller = new AbortController();
|
|
194
|
-
setTimeout(() => controller.abort(), timeout);
|
|
195
|
-
return controller;
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* Check if a health endpoint is responding
|
|
199
|
-
*/
|
|
200
|
-
export async function checkHealthEndpoint(port, maxRetries = 5) {
|
|
201
|
-
let lastError;
|
|
202
|
-
for (let i = 0; i < maxRetries; i++) {
|
|
203
|
-
try {
|
|
204
|
-
const controller = createTimeoutController(5000);
|
|
205
|
-
const response = await fetch(`http://${HOST}:${port}/health`, {
|
|
206
|
-
method: "GET",
|
|
207
|
-
signal: controller.signal,
|
|
208
|
-
});
|
|
209
|
-
if (response.ok) {
|
|
210
|
-
const healthData = (await response.json());
|
|
211
|
-
return healthData;
|
|
212
|
-
}
|
|
213
|
-
else {
|
|
214
|
-
throw new Error(`Health check failed with status ${response.status}`);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
catch (error) {
|
|
218
|
-
if (error instanceof Error && error.name === "AbortError") {
|
|
219
|
-
lastError = new Error("Request timeout after 5000ms");
|
|
220
|
-
}
|
|
221
|
-
else {
|
|
222
|
-
lastError = error instanceof Error ? error : new Error(String(error));
|
|
223
|
-
}
|
|
224
|
-
if (i < maxRetries - 1) {
|
|
225
|
-
// Wait before retry
|
|
226
|
-
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
throw lastError;
|
|
231
|
-
}
|
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert/strict";
|
|
2
|
-
import { describe, test } from "node:test";
|
|
3
|
-
import { appendFilterParam, appendFilterParams, cleanMutuallyExclusiveIdUsernameOptions, dropBlankArrayEntries, isBlankFilterValue, LIST_MERGE_REQUESTS_ID_USERNAME_PAIRS, sanitizeToolArguments, } from "../../utils/tool-args.js";
|
|
4
|
-
describe("When sanitizeToolArguments runs", () => {
|
|
5
|
-
describe("with top-level null optionals", () => {
|
|
6
|
-
test("should omit null and undefined keys for generic tools", () => {
|
|
7
|
-
const result = sanitizeToolArguments("create_draft_note", {
|
|
8
|
-
project_id: "g/p",
|
|
9
|
-
merge_request_iid: "1",
|
|
10
|
-
body: "note",
|
|
11
|
-
position: null,
|
|
12
|
-
resolve_discussion: undefined,
|
|
13
|
-
});
|
|
14
|
-
assert.deepEqual(result, {
|
|
15
|
-
project_id: "g/p",
|
|
16
|
-
merge_request_iid: "1",
|
|
17
|
-
body: "note",
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
describe("with nested objects", () => {
|
|
22
|
-
test("should not strip nulls inside nested position objects", () => {
|
|
23
|
-
const position = {
|
|
24
|
-
base_sha: "abc",
|
|
25
|
-
head_sha: "def",
|
|
26
|
-
start_sha: "ghi",
|
|
27
|
-
position_type: "text",
|
|
28
|
-
old_line: null,
|
|
29
|
-
new_line: 12,
|
|
30
|
-
};
|
|
31
|
-
const result = sanitizeToolArguments("create_draft_note", {
|
|
32
|
-
project_id: "g/p",
|
|
33
|
-
merge_request_iid: "1",
|
|
34
|
-
body: "note",
|
|
35
|
-
position,
|
|
36
|
-
});
|
|
37
|
-
assert.deepEqual(result.position, position);
|
|
38
|
-
});
|
|
39
|
-
test("should preserve null entries inside execute_graphql variables", () => {
|
|
40
|
-
const variables = { milestoneId: null, title: "x" };
|
|
41
|
-
const result = sanitizeToolArguments("execute_graphql", {
|
|
42
|
-
query: "query { project { id } }",
|
|
43
|
-
variables,
|
|
44
|
-
});
|
|
45
|
-
assert.deepEqual(result.variables, variables);
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
describe("with meaningful falsy values", () => {
|
|
49
|
-
test("should preserve false and zero", () => {
|
|
50
|
-
const result = sanitizeToolArguments("update_merge_request_discussion_note", {
|
|
51
|
-
resolved: false,
|
|
52
|
-
straight: false,
|
|
53
|
-
count: 0,
|
|
54
|
-
label: "",
|
|
55
|
-
});
|
|
56
|
-
assert.deepEqual(result, {
|
|
57
|
-
resolved: false,
|
|
58
|
-
straight: false,
|
|
59
|
-
count: 0,
|
|
60
|
-
label: "",
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
describe("with create_label", () => {
|
|
65
|
-
test("should preserve explicit null priority", () => {
|
|
66
|
-
const result = sanitizeToolArguments("create_label", {
|
|
67
|
-
project_id: "g/p",
|
|
68
|
-
name: "bug",
|
|
69
|
-
color: "#ff0000",
|
|
70
|
-
priority: null,
|
|
71
|
-
});
|
|
72
|
-
assert.equal(result.priority, null);
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
describe("When cleanMutuallyExclusiveIdUsernameOptions runs", () => {
|
|
77
|
-
describe("with list_issues author filters", () => {
|
|
78
|
-
test("should drop author_id when author_username is also set", () => {
|
|
79
|
-
const result = cleanMutuallyExclusiveIdUsernameOptions({
|
|
80
|
-
author_id: "42",
|
|
81
|
-
author_username: "alice",
|
|
82
|
-
state: "opened",
|
|
83
|
-
});
|
|
84
|
-
assert.deepEqual(result, {
|
|
85
|
-
author_username: "alice",
|
|
86
|
-
state: "opened",
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
describe("with list_issues assignee filters", () => {
|
|
91
|
-
test("should drop assignee_id when assignee_username is also set", () => {
|
|
92
|
-
const result = cleanMutuallyExclusiveIdUsernameOptions({
|
|
93
|
-
assignee_id: "7",
|
|
94
|
-
assignee_username: ["bob"],
|
|
95
|
-
});
|
|
96
|
-
assert.deepEqual(result, {
|
|
97
|
-
assignee_username: ["bob"],
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
test("should keep assignee_id when assignee_username is an empty array", () => {
|
|
101
|
-
const result = cleanMutuallyExclusiveIdUsernameOptions({
|
|
102
|
-
assignee_id: "7",
|
|
103
|
-
assignee_username: [],
|
|
104
|
-
});
|
|
105
|
-
assert.deepEqual(result, {
|
|
106
|
-
assignee_id: "7",
|
|
107
|
-
assignee_username: [],
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
test("should keep assignee_id when assignee_username holds only blank entries", () => {
|
|
111
|
-
// The blank entries are dropped when the query is built, so counting them as a
|
|
112
|
-
// value here would delete the id filter and leave the request unfiltered.
|
|
113
|
-
const result = cleanMutuallyExclusiveIdUsernameOptions({
|
|
114
|
-
assignee_id: "7",
|
|
115
|
-
assignee_username: ["", " "],
|
|
116
|
-
});
|
|
117
|
-
assert.deepEqual(result, {
|
|
118
|
-
assignee_id: "7",
|
|
119
|
-
assignee_username: ["", " "],
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
test("should drop assignee_id when a username survives the blank entries", () => {
|
|
123
|
-
const result = cleanMutuallyExclusiveIdUsernameOptions({
|
|
124
|
-
assignee_id: "7",
|
|
125
|
-
assignee_username: ["", "bob"],
|
|
126
|
-
});
|
|
127
|
-
assert.deepEqual(result, {
|
|
128
|
-
assignee_username: ["", "bob"],
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
test("should keep assignee_id when assignee_username is a blank scalar", () => {
|
|
132
|
-
// Boolean(" ") is true, so a whitespace-only scalar used to delete the id and then
|
|
133
|
-
// be dropped by the blank guard, leaving the request with no filter at all.
|
|
134
|
-
for (const blank of ["", " ", " \t "]) {
|
|
135
|
-
const result = cleanMutuallyExclusiveIdUsernameOptions({
|
|
136
|
-
assignee_id: "7",
|
|
137
|
-
assignee_username: blank,
|
|
138
|
-
});
|
|
139
|
-
assert.deepEqual(result, { assignee_id: "7", assignee_username: blank }, `blank scalar ${JSON.stringify(blank)} must not drop the id`);
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
describe("with list_merge_requests reviewer filters", () => {
|
|
144
|
-
test("should drop reviewer_id when reviewer_username is also set", () => {
|
|
145
|
-
const result = cleanMutuallyExclusiveIdUsernameOptions({
|
|
146
|
-
reviewer_id: "3",
|
|
147
|
-
reviewer_username: "carol",
|
|
148
|
-
}, LIST_MERGE_REQUESTS_ID_USERNAME_PAIRS);
|
|
149
|
-
assert.deepEqual(result, {
|
|
150
|
-
reviewer_username: "carol",
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
describe("When dropBlankArrayEntries runs", () => {
|
|
156
|
-
test("should drop blank string entries and keep meaningful ones", () => {
|
|
157
|
-
assert.deepEqual(dropBlankArrayEntries(["", " ", "bug"]), ["bug"]);
|
|
158
|
-
assert.deepEqual(dropBlankArrayEntries(["\t", "alice", ""]), ["alice"]);
|
|
159
|
-
});
|
|
160
|
-
test("should leave non-array values untouched", () => {
|
|
161
|
-
assert.equal(dropBlankArrayEntries("bug"), "bug");
|
|
162
|
-
assert.equal(dropBlankArrayEntries(" "), " ");
|
|
163
|
-
assert.equal(dropBlankArrayEntries(undefined), undefined);
|
|
164
|
-
assert.equal(dropBlankArrayEntries(false), false);
|
|
165
|
-
});
|
|
166
|
-
test("should keep non-string array entries", () => {
|
|
167
|
-
assert.deepEqual(dropBlankArrayEntries([0, "bug", false]), [0, "bug", false]);
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
describe("When isBlankFilterValue runs", () => {
|
|
171
|
-
test("should treat undefined, blank strings and empty arrays as blank", () => {
|
|
172
|
-
assert.equal(isBlankFilterValue(undefined), true);
|
|
173
|
-
assert.equal(isBlankFilterValue(""), true);
|
|
174
|
-
assert.equal(isBlankFilterValue(" \t\n"), true);
|
|
175
|
-
assert.equal(isBlankFilterValue([]), true);
|
|
176
|
-
});
|
|
177
|
-
test("should keep meaningful values, including false and zero", () => {
|
|
178
|
-
assert.equal(isBlankFilterValue("bug"), false);
|
|
179
|
-
assert.equal(isBlankFilterValue(["bug"]), false);
|
|
180
|
-
assert.equal(isBlankFilterValue(0), false);
|
|
181
|
-
assert.equal(isBlankFilterValue(false), false);
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
describe("When appendFilterParams runs", () => {
|
|
185
|
-
test("should omit blank scalars, blank array entries and empty arrays", () => {
|
|
186
|
-
const searchParams = new URLSearchParams();
|
|
187
|
-
appendFilterParams(searchParams, {
|
|
188
|
-
search: "",
|
|
189
|
-
ref: " ",
|
|
190
|
-
labels: ["", "bug"],
|
|
191
|
-
iids: [],
|
|
192
|
-
omitted: undefined,
|
|
193
|
-
});
|
|
194
|
-
assert.deepEqual([...searchParams.entries()], [["labels", "bug"]]);
|
|
195
|
-
});
|
|
196
|
-
test("should keep booleans, zero and non-blank values", () => {
|
|
197
|
-
const searchParams = new URLSearchParams();
|
|
198
|
-
appendFilterParams(searchParams, { with_labels_details: false, page: 0, search: "bug" });
|
|
199
|
-
assert.deepEqual([...searchParams.entries()], [
|
|
200
|
-
["with_labels_details", "false"],
|
|
201
|
-
["page", "0"],
|
|
202
|
-
["search", "bug"],
|
|
203
|
-
]);
|
|
204
|
-
});
|
|
205
|
-
test("should append a single parameter without dropping a meaningful value", () => {
|
|
206
|
-
const searchParams = new URLSearchParams();
|
|
207
|
-
appendFilterParam(searchParams, "filter[environment_scope]", "production");
|
|
208
|
-
assert.deepEqual([...searchParams.entries()], [["filter[environment_scope]", "production"]]);
|
|
209
|
-
});
|
|
210
|
-
});
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert/strict";
|
|
2
|
-
import { describe, test } from "node:test";
|
|
3
|
-
import { encodeGitLabPath, encodeGitLabPathSegment, isCleartextRemoteUrl, normalizeGitLabApiUrl, } from "../../utils/url.js";
|
|
4
|
-
describe("When isCleartextRemoteUrl runs", () => {
|
|
5
|
-
test("should flag http to a remote host", () => {
|
|
6
|
-
assert.equal(isCleartextRemoteUrl("http://gitlab.example.com/api/v4"), true);
|
|
7
|
-
});
|
|
8
|
-
test("should allow https", () => {
|
|
9
|
-
assert.equal(isCleartextRemoteUrl("https://gitlab.example.com/api/v4"), false);
|
|
10
|
-
});
|
|
11
|
-
test("should allow http to loopback hosts", () => {
|
|
12
|
-
assert.equal(isCleartextRemoteUrl("http://127.0.0.1:8080/api/v4"), false);
|
|
13
|
-
assert.equal(isCleartextRemoteUrl("http://localhost/api/v4"), false);
|
|
14
|
-
assert.equal(isCleartextRemoteUrl("http://[::1]:3000/api/v4"), false);
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
describe("When normalizeGitLabApiUrl runs", () => {
|
|
18
|
-
test("should default to gitlab.com", () => {
|
|
19
|
-
assert.equal(normalizeGitLabApiUrl(""), "https://gitlab.com/api/v4");
|
|
20
|
-
});
|
|
21
|
-
test("should append the API path", () => {
|
|
22
|
-
assert.equal(normalizeGitLabApiUrl("https://gitlab.example.com"), "https://gitlab.example.com/api/v4");
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
describe("When encodeGitLabPathSegment runs", () => {
|
|
26
|
-
describe("with ordinary values", () => {
|
|
27
|
-
test("should keep plain segments", () => {
|
|
28
|
-
assert.equal(encodeGitLabPathSegment("feature-branch"), "feature-branch");
|
|
29
|
-
});
|
|
30
|
-
test("should encode spaces and reserved characters", () => {
|
|
31
|
-
assert.equal(encodeGitLabPathSegment("a b"), "a%20b");
|
|
32
|
-
assert.equal(encodeGitLabPathSegment("a?b#c"), "a%3Fb%23c");
|
|
33
|
-
});
|
|
34
|
-
test("should keep an encoded separator inside one segment", () => {
|
|
35
|
-
// GitLab accepts percent-encoded slashes for branch names such as release/1.0
|
|
36
|
-
assert.equal(encodeGitLabPathSegment("release%2F1.0"), "release%2F1.0");
|
|
37
|
-
});
|
|
38
|
-
test("should keep values that only look like dot segments", () => {
|
|
39
|
-
assert.equal(encodeGitLabPathSegment("..."), "...");
|
|
40
|
-
assert.equal(encodeGitLabPathSegment("v1.0.0"), "v1.0.0");
|
|
41
|
-
});
|
|
42
|
-
test("should encode a project path as one segment", () => {
|
|
43
|
-
assert.equal(encodeGitLabPathSegment("group/project"), "group%2Fproject");
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
describe("with traversal payloads", () => {
|
|
47
|
-
const payloads = [
|
|
48
|
-
".",
|
|
49
|
-
"..",
|
|
50
|
-
"../user",
|
|
51
|
-
"..%2F..%2Fuser",
|
|
52
|
-
"%2E%2E%2Fuser",
|
|
53
|
-
"..%5C..%5Cuser",
|
|
54
|
-
"/etc/passwd",
|
|
55
|
-
"a/../b",
|
|
56
|
-
];
|
|
57
|
-
for (const payload of payloads) {
|
|
58
|
-
test(`should reject ${JSON.stringify(payload)}`, () => {
|
|
59
|
-
assert.throws(() => encodeGitLabPathSegment(payload), /Cannot use value as a GitLab URL path segment/);
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
describe("with payloads that are not visible after one decode", () => {
|
|
64
|
-
// One decode is not enough to recognize these: "%252E" only becomes "." on the
|
|
65
|
-
// second pass, so a single-decode guard passes the payload through and the
|
|
66
|
-
// receiving server sees a traversal sequence.
|
|
67
|
-
const payloads = [
|
|
68
|
-
"..%252Fuser",
|
|
69
|
-
"%252E%252E%252Fuser",
|
|
70
|
-
"%252E%252E%252F%252E%252E%252Fuser",
|
|
71
|
-
"..%25252Fuser",
|
|
72
|
-
"..%252F..%252F..%252Fuser",
|
|
73
|
-
];
|
|
74
|
-
for (const payload of payloads) {
|
|
75
|
-
test(`should reject ${JSON.stringify(payload)}`, () => {
|
|
76
|
-
assert.throws(() => encodeGitLabPathSegment(payload), /Cannot use value as a GitLab URL path segment/);
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
describe("with control characters", () => {
|
|
81
|
-
const payloads = ["..%00", "%00../user", "a%0Ab", "%7F..%2Fuser"];
|
|
82
|
-
for (const payload of payloads) {
|
|
83
|
-
test(`should reject ${JSON.stringify(payload)}`, () => {
|
|
84
|
-
assert.throws(() => encodeGitLabPathSegment(payload), /Cannot use value as a GitLab URL path segment/);
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
describe("with a literal percent sign", () => {
|
|
89
|
-
test("should encode a percent that starts no escape instead of rejecting it", () => {
|
|
90
|
-
// decodeURIComponent throws for these too, but a percent sign is valid in a
|
|
91
|
-
// file or branch name. Only a broken escape next to a valid one is a payload
|
|
92
|
-
// the guard cannot inspect.
|
|
93
|
-
assert.equal(encodeGitLabPathSegment("report-100%.pdf"), "report-100%25.pdf");
|
|
94
|
-
assert.equal(encodeGitLabPathSegment("100%"), "100%25");
|
|
95
|
-
assert.equal(encodeGitLabPathSegment("bad%zz/path"), "bad%25zz%2Fpath");
|
|
96
|
-
// The encoded form of such a name decodes back to the literal sign.
|
|
97
|
-
assert.equal(encodeGitLabPathSegment("save%20100%25.txt"), "save%20100%25.txt");
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
describe("with a value that cannot be decoded", () => {
|
|
101
|
-
test("should reject a malformed escape sequence next to a valid one", () => {
|
|
102
|
-
// These must not be treated as safe just because decodeURIComponent threw:
|
|
103
|
-
// the valid escape may still hide a separator or a dot segment.
|
|
104
|
-
for (const payload of ["%2E%2E%2F%ZZ", "%2E%2E%2F%..", "%2E%GG"]) {
|
|
105
|
-
assert.throws(() => encodeGitLabPathSegment(payload), /Cannot use value as a GitLab URL path segment/, payload);
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
test("should reject a value with more encoding layers than it will unwrap", () => {
|
|
109
|
-
assert.throws(() => encodeGitLabPathSegment("%25252525252F"), /Cannot use value as a GitLab URL path segment/);
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
describe("When encodeGitLabPath runs", () => {
|
|
114
|
-
test("should encode every slash-separated segment", () => {
|
|
115
|
-
assert.equal(encodeGitLabPath("docs/read me.txt"), "docs/read%20me.txt");
|
|
116
|
-
});
|
|
117
|
-
test("should keep an encoded separator", () => {
|
|
118
|
-
assert.equal(encodeGitLabPath("release%2F1.0"), "release%2F1.0");
|
|
119
|
-
});
|
|
120
|
-
test("should reject a traversal payload", () => {
|
|
121
|
-
for (const payload of [
|
|
122
|
-
"../../../user",
|
|
123
|
-
"1/../../../../admin/ci/variables",
|
|
124
|
-
"..%2F..%2Fuser",
|
|
125
|
-
"a/..%2F..%2Fb",
|
|
126
|
-
"a/..%252F..%252Fb",
|
|
127
|
-
]) {
|
|
128
|
-
assert.throws(() => encodeGitLabPath(payload), /Cannot use value as a GitLab URL path segment/, payload);
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
test("should reject an absolute path instead of collapsing the leading segment", () => {
|
|
132
|
-
for (const payload of ["/etc/passwd", "/", "/project/-/raw/main/x"]) {
|
|
133
|
-
assert.throws(() => encodeGitLabPath(payload), /Cannot use value as a GitLab URL path/, payload);
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
test("should reject empty and empty-segment paths", () => {
|
|
137
|
-
for (const payload of ["", "a//b", "a/"]) {
|
|
138
|
-
assert.throws(() => encodeGitLabPath(payload), /Cannot use value as a GitLab URL path/, payload);
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
});
|