@zereight/mcp-gitlab 2.1.5 → 2.1.6

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.
@@ -0,0 +1,131 @@
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("roundtrips across pods", () => {
23
+ const s = secret();
24
+ const a = load(s);
25
+ const b = load(s);
26
+ const sid = mintSessionId(a, {
27
+ header: "Authorization",
28
+ token: "glpat-ABCDEFG123456789-abcdef",
29
+ apiUrl: "https://gitlab.example.com/api/v4",
30
+ });
31
+ assert.ok(looksLikeStatelessSessionId(sid));
32
+ const opened = openSessionId(b, sid, 3600);
33
+ assert.ok(opened);
34
+ assert.equal(opened.h, "Authorization");
35
+ assert.equal(opened.t, "glpat-ABCDEFG123456789-abcdef");
36
+ assert.equal(opened.u, "https://gitlab.example.com/api/v4");
37
+ });
38
+ test("preserves Private-Token / JOB-TOKEN headers", () => {
39
+ const m = load(secret());
40
+ for (const h of ["Private-Token", "JOB-TOKEN"]) {
41
+ const sid = mintSessionId(m, {
42
+ header: h,
43
+ token: "some-token-value-at-least-20-chars",
44
+ apiUrl: "https://gitlab.example.com/api/v4",
45
+ });
46
+ const opened = openSessionId(m, sid, 3600);
47
+ assert.ok(opened);
48
+ assert.equal(opened.h, h);
49
+ }
50
+ });
51
+ test("rejects unknown header values", () => {
52
+ // Hand-craft a payload with a bogus header value. We do this by minting a
53
+ // legitimate token then mutating the decoded payload via a second mint
54
+ // won't work (AEAD). Instead, assert the helper rejects garbage input
55
+ // by tampering with an unrelated value and checking it still fails safely.
56
+ const m = load(secret());
57
+ const sid = mintSessionId(m, {
58
+ header: "Authorization",
59
+ token: "t".repeat(25),
60
+ apiUrl: "u",
61
+ });
62
+ // Truncate to force bad ciphertext on open.
63
+ const broken = sid.slice(0, -3);
64
+ assert.equal(openSessionId(m, broken, 3600), null);
65
+ });
66
+ test("expired sid rejected", () => {
67
+ const m = load(secret());
68
+ const past = Math.floor(Date.now() / 1000) - 10_000;
69
+ const sid = mintSessionId(m, {
70
+ header: "Authorization",
71
+ token: "t".repeat(25),
72
+ apiUrl: "u",
73
+ now: () => past,
74
+ });
75
+ assert.equal(openSessionId(m, sid, 60), null);
76
+ });
77
+ test("different secret rejects", () => {
78
+ const a = load(secret());
79
+ const b = load(secret());
80
+ const sid = mintSessionId(a, {
81
+ header: "Authorization",
82
+ token: "t".repeat(25),
83
+ apiUrl: "u",
84
+ });
85
+ assert.equal(openSessionId(b, sid, 3600), null);
86
+ });
87
+ test("rotation: sid minted under previous secret opens on rotated pod", () => {
88
+ const s1 = secret();
89
+ const s2 = secret();
90
+ const old = load(s1);
91
+ const rotated = load(s2, s1);
92
+ const sid = mintSessionId(old, {
93
+ header: "Authorization",
94
+ token: "t".repeat(25),
95
+ apiUrl: "u",
96
+ });
97
+ const opened = openSessionId(rotated, sid, 3600);
98
+ assert.ok(opened);
99
+ });
100
+ test("looksLikeStatelessSessionId distinguishes legacy UUIDs", () => {
101
+ const m = load(secret());
102
+ const sid = mintSessionId(m, {
103
+ header: "Authorization",
104
+ token: "t".repeat(25),
105
+ apiUrl: "u",
106
+ });
107
+ assert.ok(looksLikeStatelessSessionId(sid));
108
+ assert.ok(!looksLikeStatelessSessionId("a4f1c2b8-f2c4-4ee6-bc14-2b7ab0e6ab11"));
109
+ assert.ok(!looksLikeStatelessSessionId(""));
110
+ });
111
+ test("fresh sid has different iat each time (rotation on every refresh)", () => {
112
+ const m = load(secret());
113
+ const sid1 = mintSessionId(m, {
114
+ header: "Authorization",
115
+ token: "t".repeat(25),
116
+ apiUrl: "u",
117
+ now: () => 1000,
118
+ });
119
+ const sid2 = mintSessionId(m, {
120
+ header: "Authorization",
121
+ token: "t".repeat(25),
122
+ apiUrl: "u",
123
+ now: () => 2000,
124
+ });
125
+ assert.notEqual(sid1, sid2);
126
+ const open1 = openSessionId(m, sid1, 3600, () => 2000);
127
+ const open2 = openSessionId(m, sid2, 3600, () => 2000);
128
+ assert.equal(open1.iat, 1000);
129
+ assert.equal(open2.iat, 2000);
130
+ });
131
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zereight/mcp-gitlab",
3
- "version": "2.1.5",
3
+ "version": "2.1.6",
4
4
  "mcpName": "io.github.zereight/gitlab-mcp",
5
5
  "description": "GitLab MCP server for projects, merge requests, issues, pipelines, wiki, releases, and more",
6
6
  "keywords": [
@@ -51,7 +51,8 @@
51
51
  "changelog": "auto-changelog -p",
52
52
  "test": "npm run test:all",
53
53
  "test:all": "npm run build && npm run test:mock && npm run test:live",
54
- "test:mock": "node --import tsx/esm --test test/remote-auth-simple-test.ts && node --import tsx/esm --test test/mcp-oauth-tests.ts && tsx test/oauth-tests.ts && tsx test/test-list-merge-requests.ts && tsx test/test-list-project-members.ts && tsx test/test-download-attachment.ts && node --import tsx/esm --test test/test-job-artifacts.ts && node --import tsx/esm --test test/test-deployment-tools.ts && node --import tsx/esm --test test/test-merge-request-approval-state-tools.ts && node --import tsx/esm --test test/test-search-code.ts && node --import tsx/esm --test test/test-toolset-filtering.ts && node --import tsx/esm --test test/test-auth-retry.ts",
54
+ "test:mock": "node --import tsx/esm --test test/remote-auth-simple-test.ts && node --import tsx/esm --test test/mcp-oauth-tests.ts && tsx test/oauth-tests.ts && tsx test/test-list-merge-requests.ts && tsx test/test-list-project-members.ts && tsx test/test-download-attachment.ts && node --import tsx/esm --test test/test-job-artifacts.ts && node --import tsx/esm --test test/test-deployment-tools.ts && node --import tsx/esm --test test/test-merge-request-approval-state-tools.ts && node --import tsx/esm --test test/test-search-code.ts && node --import tsx/esm --test test/test-toolset-filtering.ts && node --import tsx/esm --test test/test-auth-retry.ts && node --import tsx/esm --test test/stateless/codec.test.ts test/stateless/client-id.test.ts test/stateless/callback-proxy.test.ts test/stateless/session-id.test.ts test/stateless/session-id-integration.test.ts test/stateless/config-ttl.test.ts",
55
+ "test:stateless": "npm run build && node --import tsx/esm --test test/stateless/codec.test.ts test/stateless/client-id.test.ts test/stateless/callback-proxy.test.ts test/stateless/session-id.test.ts test/stateless/session-id-integration.test.ts test/stateless/config-ttl.test.ts",
55
56
  "test:mcp-oauth": "npm run build && node --import tsx/esm --test test/mcp-oauth-tests.ts",
56
57
  "test:live": "node test/validate-api.js",
57
58
  "test:remote-auth": "npm run build && node --import tsx/esm --test test/remote-auth-simple-test.ts",