@terreno/api 57.21.0 → 58.0.0-beta.1
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 +43 -0
- package/README.md +1 -1
- package/biome.jsonc +2 -2
- package/dist/api.d.ts +0 -13
- package/dist/api.js +0 -9
- package/dist/auth.d.ts +3 -2
- package/dist/auth.js +95 -5
- package/dist/authRecovery.d.ts +2 -1
- package/dist/authRecovery.js +35 -17
- package/dist/collectionRegistry.d.ts +3 -4
- package/dist/collectionRegistry.js +0 -1
- package/dist/consentApp.d.ts +1 -1
- package/dist/consentApp.js +58 -2
- package/dist/index.d.ts +4 -5
- package/dist/index.js +8 -20
- package/dist/mcp/adminTracking.js +1 -1
- package/dist/mcp/serviceTokens.d.ts +21 -1
- package/dist/mcp/serviceTokens.js +159 -183
- package/dist/migrations/builtin/mcpServiceTokenStringIds.d.ts +18 -0
- package/dist/migrations/builtin/mcpServiceTokenStringIds.js +67 -0
- package/dist/models/mcpRequestLog.js +1 -1
- package/dist/models/mcpServiceToken.js +36 -4
- package/dist/openApiBuilder.d.ts +4 -0
- package/dist/openApiBuilder.js +2 -0
- package/dist/rbac/realtimeAccess.d.ts +5 -4
- package/dist/rbac/realtimeAccess.js +17 -64
- package/dist/realtime/changeStreamWatcher.d.ts +8 -63
- package/dist/realtime/changeStreamWatcher.js +32 -391
- package/dist/realtime/realtimeApp.d.ts +14 -27
- package/dist/realtime/realtimeApp.js +14 -220
- package/dist/realtime/types.d.ts +0 -64
- package/dist/sync/executors.js +14 -2
- package/dist/sync/socketHandlers.d.ts +1 -1
- package/dist/sync/socketHandlers.js +1 -1
- package/dist/terrenoApp.d.ts +7 -5
- package/dist/terrenoApp.js +18 -14
- package/dist/tests/openApiResponseSchema.d.ts +39 -0
- package/dist/tests/openApiResponseSchema.js +56 -0
- package/dist/tests.d.ts +1 -0
- package/dist/tests.js +4 -1
- package/dist/types/mcpAdmin.d.ts +1 -1
- package/dist/types/mcpServiceToken.d.ts +7 -4
- package/dist/versionCheckPlugin.d.ts +1 -1
- package/dist/versionCheckPlugin.js +25 -2
- package/package.json +10 -6
- package/src/__snapshots__/openApi.test.ts.snap +4986 -2478
- package/src/__snapshots__/openApiBuilder.test.ts.snap +836 -0
- package/src/__tests__/openApiResponseSchema.test.ts +148 -0
- package/src/__tests__/versionCheckPlugin.test.ts +72 -0
- package/src/api.test.ts +9 -7
- package/src/api.ts +0 -24
- package/src/auth.ts +116 -5
- package/src/authOpenApi.test.ts +316 -0
- package/src/authRecovery.ts +47 -19
- package/src/betterAuthOAuthHandoff.test.ts +13 -5
- package/src/collectionRegistry.ts +3 -5
- package/src/consentApp.test.ts +98 -0
- package/src/consentApp.ts +67 -2
- package/src/index.ts +6 -28
- package/src/mcp/actionTools.test.ts +2 -2
- package/src/mcp/adminTracking.ts +1 -1
- package/src/mcp/auth.test.ts +7 -3
- package/src/mcp/oauth.test.ts +12 -12
- package/src/mcp/serviceTokens.sync.test.ts +230 -0
- package/src/mcp/serviceTokens.test.ts +112 -61
- package/src/mcp/serviceTokens.ts +193 -212
- package/src/migrations/builtin/mcpServiceTokenStringIds.test.ts +194 -0
- package/src/migrations/builtin/mcpServiceTokenStringIds.ts +121 -0
- package/src/models/mcpRequestLog.ts +1 -1
- package/src/models/mcpServiceToken.test.ts +52 -5
- package/src/models/mcpServiceToken.ts +51 -14
- package/src/openApiBuilder.test.ts +34 -1
- package/src/openApiBuilder.ts +5 -0
- package/src/rateLimit/rateLimit.test.ts +25 -10
- package/src/rbac/realtimeAccess.test.ts +20 -172
- package/src/rbac/realtimeAccess.ts +17 -82
- package/src/realtime/changeStreamWatcher.ts +43 -506
- package/src/realtime/realtime.test.ts +205 -2545
- package/src/realtime/realtimeApp.ts +16 -295
- package/src/realtime/types.ts +0 -72
- package/src/sync/executors.test.ts +28 -0
- package/src/sync/executors.ts +23 -2
- package/src/sync/socketHandlers.ts +1 -1
- package/src/sync/syncSocket.test.ts +77 -113
- package/src/terrenoApp.mcpServiceTokens.test.ts +14 -6
- package/src/terrenoApp.ts +24 -18
- package/src/tests/openApiResponseSchema.ts +104 -0
- package/src/tests.ts +7 -0
- package/src/types/mcpAdmin.ts +1 -1
- package/src/types/mcpServiceToken.ts +7 -4
- package/src/versionCheckPlugin.ts +41 -2
- package/dist/realtime/deprecation.d.ts +0 -13
- package/dist/realtime/deprecation.js +0 -31
- package/dist/realtime/queryStore.d.ts +0 -37
- package/dist/realtime/queryStore.js +0 -103
- package/dist/realtime/registry.d.ts +0 -15
- package/dist/realtime/registry.js +0 -52
- package/src/realtime/deprecation.test.ts +0 -60
- package/src/realtime/deprecation.ts +0 -33
- package/src/realtime/queryStore.ts +0 -122
- package/src/realtime/registry.ts +0 -84
|
@@ -9,11 +9,19 @@ import type TestAgent from "supertest/lib/agent";
|
|
|
9
9
|
import {type UserModel as AuthUserModel, addAuthRoutes, setupAuth} from "../auth";
|
|
10
10
|
import {apiErrorMiddleware, apiUnauthorizedMiddleware} from "../errors";
|
|
11
11
|
import {McpServiceToken} from "../models/mcpServiceToken";
|
|
12
|
+
import {clearSyncRegistry} from "../sync/registry";
|
|
12
13
|
import {TerrenoApp} from "../terrenoApp";
|
|
13
14
|
import {authAsUser, getBaseServer, setupDb, UserModel} from "../tests";
|
|
14
15
|
import {addMcpServiceTokenRoutes, MAX_ACTIVE_MCP_SERVICE_TOKENS} from "./serviceTokens";
|
|
15
16
|
|
|
16
17
|
const PUBLIC_MCP_URL = "https://api.example.com";
|
|
18
|
+
const CREATE_PATH = "/mcp/service-tokens/create";
|
|
19
|
+
const revokePath = (id: string): string => `/mcp/service-tokens/${id}/revoke`;
|
|
20
|
+
|
|
21
|
+
// The collection is synced once the router registers, and syncPlugin rejects Model.deleteMany.
|
|
22
|
+
const clearTokens = async (): Promise<void> => {
|
|
23
|
+
await McpServiceToken.collection.deleteMany({});
|
|
24
|
+
};
|
|
17
25
|
|
|
18
26
|
const assertNoSecrets = (body: unknown): void => {
|
|
19
27
|
const serialized = JSON.stringify(body);
|
|
@@ -38,7 +46,7 @@ describe("MCP service token routes", () => {
|
|
|
38
46
|
beforeEach(async () => {
|
|
39
47
|
const users = await setupDb();
|
|
40
48
|
notAdminId = users[1]._id as mongoose.Types.ObjectId;
|
|
41
|
-
await
|
|
49
|
+
await clearTokens();
|
|
42
50
|
|
|
43
51
|
app = getBaseServer();
|
|
44
52
|
setupAuth(app, UserModel as never);
|
|
@@ -51,8 +59,13 @@ describe("MCP service token routes", () => {
|
|
|
51
59
|
adminAgent = await authAsUser(app, "admin");
|
|
52
60
|
});
|
|
53
61
|
|
|
62
|
+
afterEach(async () => {
|
|
63
|
+
await clearTokens();
|
|
64
|
+
clearSyncRegistry();
|
|
65
|
+
});
|
|
66
|
+
|
|
54
67
|
it("creates a token once and returns mcpUrl with the plaintext", async () => {
|
|
55
|
-
const res = await agent.post(
|
|
68
|
+
const res = await agent.post(CREATE_PATH).send({name: "Perplexity laptop"});
|
|
56
69
|
|
|
57
70
|
assert.equal(res.status, 200);
|
|
58
71
|
assert.match(res.body.data.token, /^mcp_[0-9a-f]{64}$/);
|
|
@@ -62,19 +75,63 @@ describe("MCP service token routes", () => {
|
|
|
62
75
|
assert.isUndefined(res.body.data.tokenHash);
|
|
63
76
|
|
|
64
77
|
const stored = await McpServiceToken.findExactlyOne({_id: res.body.data.id});
|
|
78
|
+
assert.isString(stored._id);
|
|
65
79
|
assert.notEqual(stored.tokenHash, res.body.data.token);
|
|
66
80
|
assert.notInclude(JSON.stringify(stored.toJSON()), res.body.data.token);
|
|
67
81
|
});
|
|
68
82
|
|
|
83
|
+
it("returns the plaintext only from create, never from list or read", async () => {
|
|
84
|
+
const created = await agent.post(CREATE_PATH).send({name: "Once"});
|
|
85
|
+
const plaintext = created.body.data.token as string;
|
|
86
|
+
assert.match(plaintext, /^mcp_[0-9a-f]{64}$/);
|
|
87
|
+
|
|
88
|
+
const listed = await agent.get("/mcp/service-tokens");
|
|
89
|
+
const read = await agent.get(`/mcp/service-tokens/${created.body.data.id}`);
|
|
90
|
+
|
|
91
|
+
assert.equal(read.status, 200);
|
|
92
|
+
for (const res of [listed, read]) {
|
|
93
|
+
assert.notInclude(JSON.stringify(res.body), plaintext);
|
|
94
|
+
assertNoSecrets(res.body);
|
|
95
|
+
}
|
|
96
|
+
assert.notProperty(read.body.data, "token");
|
|
97
|
+
assert.notProperty(read.body.data, "tokenHash");
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("disables REST create, update, and delete on the collection", async () => {
|
|
101
|
+
const created = await agent.post(CREATE_PATH).send({name: "Locked"});
|
|
102
|
+
const tokenId = created.body.data.id as string;
|
|
103
|
+
|
|
104
|
+
const rawCreate = await agent
|
|
105
|
+
.post("/mcp/service-tokens")
|
|
106
|
+
.send({name: "Raw", tokenHash: "x", tokenPrefix: "x", userId: String(notAdminId)});
|
|
107
|
+
const update = await agent.patch(`/mcp/service-tokens/${tokenId}`).send({name: "Renamed"});
|
|
108
|
+
const remove = await agent.delete(`/mcp/service-tokens/${tokenId}`);
|
|
109
|
+
|
|
110
|
+
assert.equal(rawCreate.status, 405);
|
|
111
|
+
assert.equal(update.status, 405);
|
|
112
|
+
assert.equal(remove.status, 405);
|
|
113
|
+
const stored = await McpServiceToken.findExactlyOne({_id: tokenId});
|
|
114
|
+
assert.equal(stored.name, "Locked");
|
|
115
|
+
assert.isUndefined(stored.revokedAt);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it("does not let another user read a token", async () => {
|
|
119
|
+
const created = await agent.post(CREATE_PATH).send({name: "Private"});
|
|
120
|
+
|
|
121
|
+
const res = await adminAgent.get(`/mcp/service-tokens/${created.body.data.id}`);
|
|
122
|
+
|
|
123
|
+
assert.equal(res.status, 403);
|
|
124
|
+
assertNoSecrets(res.body);
|
|
125
|
+
});
|
|
126
|
+
|
|
69
127
|
it("lists only the caller's tokens without plaintext or hash", async () => {
|
|
70
|
-
const mine = await agent.post(
|
|
71
|
-
await adminAgent.post(
|
|
128
|
+
const mine = await agent.post(CREATE_PATH).send({name: "Mine"});
|
|
129
|
+
await adminAgent.post(CREATE_PATH).send({name: "Admin token"});
|
|
72
130
|
|
|
73
131
|
const res = await agent.get("/mcp/service-tokens");
|
|
74
132
|
|
|
75
133
|
assert.equal(res.status, 200);
|
|
76
134
|
assert.equal(res.body.total, 1);
|
|
77
|
-
assert.equal(res.body.page, 1);
|
|
78
135
|
assert.equal(res.body.more, false);
|
|
79
136
|
assert.equal(res.body.data.length, 1);
|
|
80
137
|
assert.equal(res.body.data[0].id, mine.body.data.id);
|
|
@@ -84,7 +141,7 @@ describe("MCP service token routes", () => {
|
|
|
84
141
|
|
|
85
142
|
it("accepts an optional future ISO expiresAt on create", async () => {
|
|
86
143
|
const expiresAt = DateTime.now().plus({day: 1}).toUTC().toISO();
|
|
87
|
-
const res = await agent.post(
|
|
144
|
+
const res = await agent.post(CREATE_PATH).send({
|
|
88
145
|
expiresAt,
|
|
89
146
|
name: "Expiring",
|
|
90
147
|
});
|
|
@@ -94,22 +151,24 @@ describe("MCP service token routes", () => {
|
|
|
94
151
|
});
|
|
95
152
|
|
|
96
153
|
it("revokes an owned token and hides it from other users", async () => {
|
|
97
|
-
const created = await agent.post(
|
|
154
|
+
const created = await agent.post(CREATE_PATH).send({name: "To revoke"});
|
|
98
155
|
const tokenId = created.body.data.id as string;
|
|
99
156
|
|
|
100
|
-
const
|
|
101
|
-
assert.equal(
|
|
157
|
+
const otherRevoke = await adminAgent.post(revokePath(tokenId));
|
|
158
|
+
assert.equal(otherRevoke.status, 404);
|
|
102
159
|
|
|
103
|
-
const revoked = await agent.
|
|
160
|
+
const revoked = await agent.post(revokePath(tokenId));
|
|
104
161
|
assert.equal(revoked.status, 200);
|
|
105
162
|
assert.equal(revoked.body.data.id, tokenId);
|
|
106
163
|
assert.isString(revoked.body.data.revokedAt);
|
|
164
|
+
assertNoSecrets(revoked.body);
|
|
165
|
+
assert.notProperty(revoked.body.data, "tokenHash");
|
|
107
166
|
|
|
108
167
|
const listed = await agent.get("/mcp/service-tokens");
|
|
109
168
|
assert.equal(listed.body.data[0].id, tokenId);
|
|
110
169
|
assert.isString(listed.body.data[0].revokedAt);
|
|
111
170
|
|
|
112
|
-
const again = await agent.
|
|
171
|
+
const again = await agent.post(revokePath(tokenId));
|
|
113
172
|
assert.equal(again.status, 404);
|
|
114
173
|
});
|
|
115
174
|
|
|
@@ -118,7 +177,7 @@ describe("MCP service token routes", () => {
|
|
|
118
177
|
await McpServiceToken.issueFor({_id: notAdminId}, {name: `Token ${index}`});
|
|
119
178
|
}
|
|
120
179
|
|
|
121
|
-
const res = await agent.post(
|
|
180
|
+
const res = await agent.post(CREATE_PATH).send({name: "One too many"});
|
|
122
181
|
|
|
123
182
|
assert.equal(res.status, 400);
|
|
124
183
|
assert.match(res.body.title, /Maximum of 10 active MCP service tokens/);
|
|
@@ -126,18 +185,18 @@ describe("MCP service token routes", () => {
|
|
|
126
185
|
});
|
|
127
186
|
|
|
128
187
|
it("rejects mcp_ bearer tokens on self-serve routes", async () => {
|
|
129
|
-
const created = await agent.post(
|
|
188
|
+
const created = await agent.post(CREATE_PATH).send({name: "Connector"});
|
|
130
189
|
const mcpToken = created.body.data.token as string;
|
|
131
190
|
|
|
132
191
|
const listed = await supertest(app)
|
|
133
192
|
.get("/mcp/service-tokens")
|
|
134
193
|
.set("Authorization", `Bearer ${mcpToken}`);
|
|
135
194
|
const minted = await supertest(app)
|
|
136
|
-
.post(
|
|
195
|
+
.post(CREATE_PATH)
|
|
137
196
|
.set("Authorization", `Bearer ${mcpToken}`)
|
|
138
197
|
.send({name: "Nested"});
|
|
139
198
|
const revoked = await supertest(app)
|
|
140
|
-
.
|
|
199
|
+
.post(revokePath(created.body.data.id))
|
|
141
200
|
.set("Authorization", `Bearer ${mcpToken}`);
|
|
142
201
|
|
|
143
202
|
assert.equal(listed.status, 401);
|
|
@@ -151,19 +210,17 @@ describe("MCP service token routes", () => {
|
|
|
151
210
|
});
|
|
152
211
|
|
|
153
212
|
it("returns 404 for an unknown token id", async () => {
|
|
154
|
-
const res = await agent.
|
|
155
|
-
`/mcp/service-tokens/${new mongoose.Types.ObjectId().toString()}`
|
|
156
|
-
);
|
|
213
|
+
const res = await agent.post(revokePath(new mongoose.Types.ObjectId().toString()));
|
|
157
214
|
assert.equal(res.status, 404);
|
|
158
215
|
});
|
|
159
216
|
|
|
160
217
|
it("returns 404 for a malformed token id", async () => {
|
|
161
|
-
const res = await agent.
|
|
218
|
+
const res = await agent.post(revokePath("not-an-object-id"));
|
|
162
219
|
assert.equal(res.status, 404);
|
|
163
220
|
});
|
|
164
221
|
|
|
165
222
|
it("rejects a raw mcp_ authorization header without the Bearer prefix", async () => {
|
|
166
|
-
const created = await agent.post(
|
|
223
|
+
const created = await agent.post(CREATE_PATH).send({name: "Raw"});
|
|
167
224
|
const mcpToken = created.body.data.token as string;
|
|
168
225
|
|
|
169
226
|
const res = await supertest(app).get("/mcp/service-tokens").set("Authorization", mcpToken);
|
|
@@ -171,18 +228,21 @@ describe("MCP service token routes", () => {
|
|
|
171
228
|
});
|
|
172
229
|
|
|
173
230
|
it("rejects a missing, non-string, or blank name", async () => {
|
|
174
|
-
const missing = await agent.post(
|
|
175
|
-
const nonString = await agent.post(
|
|
176
|
-
const blank = await agent.post(
|
|
231
|
+
const missing = await agent.post(CREATE_PATH).send({});
|
|
232
|
+
const nonString = await agent.post(CREATE_PATH).send({name: 42});
|
|
233
|
+
const blank = await agent.post(CREATE_PATH).send({name: " "});
|
|
177
234
|
|
|
178
|
-
for (const res of [missing, nonString
|
|
235
|
+
for (const res of [missing, nonString]) {
|
|
179
236
|
assert.equal(res.status, 400);
|
|
180
|
-
assert.equal(res.body.title, "
|
|
237
|
+
assert.equal(res.body.title, "Validation failed");
|
|
181
238
|
}
|
|
239
|
+
assert.equal(blank.status, 400);
|
|
240
|
+
assert.equal(blank.body.title, "name is required");
|
|
241
|
+
assert.equal(await McpServiceToken.countActiveForUser(notAdminId), 0);
|
|
182
242
|
});
|
|
183
243
|
|
|
184
244
|
it("trims the name and treats an empty expiresAt as unset", async () => {
|
|
185
|
-
const res = await agent.post(
|
|
245
|
+
const res = await agent.post(CREATE_PATH).send({expiresAt: "", name: " Padded "});
|
|
186
246
|
|
|
187
247
|
assert.equal(res.status, 200);
|
|
188
248
|
assert.equal(res.body.data.name, "Padded");
|
|
@@ -190,42 +250,26 @@ describe("MCP service token routes", () => {
|
|
|
190
250
|
});
|
|
191
251
|
|
|
192
252
|
it("rejects non-string, invalid, and past expiresAt values", async () => {
|
|
193
|
-
const nonString = await agent.post(
|
|
194
|
-
const invalid = await agent
|
|
195
|
-
|
|
196
|
-
.send({expiresAt: "not-a-date", name: "B"});
|
|
197
|
-
const past = await agent.post("/mcp/service-tokens").send({
|
|
253
|
+
const nonString = await agent.post(CREATE_PATH).send({expiresAt: 123, name: "A"});
|
|
254
|
+
const invalid = await agent.post(CREATE_PATH).send({expiresAt: "not-a-date", name: "B"});
|
|
255
|
+
const past = await agent.post(CREATE_PATH).send({
|
|
198
256
|
expiresAt: DateTime.now().minus({day: 1}).toUTC().toISO(),
|
|
199
257
|
name: "C",
|
|
200
258
|
});
|
|
201
259
|
|
|
202
260
|
assert.equal(nonString.status, 400);
|
|
203
|
-
assert.equal(nonString.body.title, "
|
|
261
|
+
assert.equal(nonString.body.title, "Validation failed");
|
|
204
262
|
assert.equal(invalid.status, 400);
|
|
205
263
|
assert.equal(invalid.body.title, "expiresAt must be an ISO-8601 datetime string");
|
|
206
264
|
assert.equal(past.status, 400);
|
|
207
265
|
assert.equal(past.body.title, "expiresAt must be in the future");
|
|
208
266
|
});
|
|
209
267
|
|
|
210
|
-
it("
|
|
268
|
+
it("applies page and limit on list and caps the limit at 100", async () => {
|
|
211
269
|
for (const name of ["One", "Two", "Three"]) {
|
|
212
|
-
await agent.post(
|
|
270
|
+
await agent.post(CREATE_PATH).send({name});
|
|
213
271
|
}
|
|
214
272
|
|
|
215
|
-
const badPage = await agent.get("/mcp/service-tokens?page=0");
|
|
216
|
-
assert.equal(badPage.status, 400);
|
|
217
|
-
assert.equal(badPage.body.title, "Invalid page");
|
|
218
|
-
|
|
219
|
-
const fractionalPage = await agent.get("/mcp/service-tokens?page=1.5");
|
|
220
|
-
assert.equal(fractionalPage.status, 400);
|
|
221
|
-
|
|
222
|
-
const badLimit = await agent.get("/mcp/service-tokens?limit=abc");
|
|
223
|
-
assert.equal(badLimit.status, 400);
|
|
224
|
-
assert.equal(badLimit.body.title, "Invalid limit");
|
|
225
|
-
|
|
226
|
-
const zeroLimit = await agent.get("/mcp/service-tokens?limit=0");
|
|
227
|
-
assert.equal(zeroLimit.status, 400);
|
|
228
|
-
|
|
229
273
|
const paged = await agent.get("/mcp/service-tokens?page=2&limit=2");
|
|
230
274
|
assert.equal(paged.status, 200);
|
|
231
275
|
assert.equal(paged.body.page, 2);
|
|
@@ -236,7 +280,7 @@ describe("MCP service token routes", () => {
|
|
|
236
280
|
|
|
237
281
|
const capped = await agent.get("/mcp/service-tokens?limit=10000");
|
|
238
282
|
assert.equal(capped.status, 200);
|
|
239
|
-
assert.
|
|
283
|
+
assert.equal(capped.body.limit, 100);
|
|
240
284
|
});
|
|
241
285
|
});
|
|
242
286
|
|
|
@@ -255,10 +299,11 @@ describe("MCP service token mcpUrl resolution", () => {
|
|
|
255
299
|
|
|
256
300
|
beforeEach(async () => {
|
|
257
301
|
await setupDb();
|
|
258
|
-
await
|
|
302
|
+
await clearTokens();
|
|
259
303
|
});
|
|
260
304
|
|
|
261
305
|
afterEach(() => {
|
|
306
|
+
clearSyncRegistry();
|
|
262
307
|
if (originalBetterAuthUrl === undefined) {
|
|
263
308
|
delete process.env.BETTER_AUTH_URL;
|
|
264
309
|
} else {
|
|
@@ -270,7 +315,7 @@ describe("MCP service token mcpUrl resolution", () => {
|
|
|
270
315
|
const app = buildApp("https://api.example.com/mcp/");
|
|
271
316
|
const agent = await authAsUser(app, "notAdmin");
|
|
272
317
|
|
|
273
|
-
const res = await agent.post(
|
|
318
|
+
const res = await agent.post(CREATE_PATH).send({name: "Configured"});
|
|
274
319
|
|
|
275
320
|
assert.equal(res.status, 200);
|
|
276
321
|
assert.equal(res.body.data.mcpUrl, "https://api.example.com/mcp");
|
|
@@ -281,7 +326,7 @@ describe("MCP service token mcpUrl resolution", () => {
|
|
|
281
326
|
const app = buildApp();
|
|
282
327
|
const agent = await authAsUser(app, "notAdmin");
|
|
283
328
|
|
|
284
|
-
const res = await agent.post(
|
|
329
|
+
const res = await agent.post(CREATE_PATH).send({name: "Env"});
|
|
285
330
|
|
|
286
331
|
assert.equal(res.status, 200);
|
|
287
332
|
assert.equal(res.body.data.mcpUrl, "https://auth.example.com/mcp");
|
|
@@ -292,7 +337,7 @@ describe("MCP service token mcpUrl resolution", () => {
|
|
|
292
337
|
const app = buildApp();
|
|
293
338
|
const agent = await authAsUser(app, "notAdmin");
|
|
294
339
|
|
|
295
|
-
const res = await agent.post(
|
|
340
|
+
const res = await agent.post(CREATE_PATH).send({name: "Host"});
|
|
296
341
|
|
|
297
342
|
assert.equal(res.status, 200);
|
|
298
343
|
assert.match(res.body.data.mcpUrl, /^http:\/\/127\.0\.0\.1:\d+\/mcp$/);
|
|
@@ -300,6 +345,10 @@ describe("MCP service token mcpUrl resolution", () => {
|
|
|
300
345
|
});
|
|
301
346
|
|
|
302
347
|
describe("MCP service token OpenAPI", () => {
|
|
348
|
+
afterEach(() => {
|
|
349
|
+
clearSyncRegistry();
|
|
350
|
+
});
|
|
351
|
+
|
|
303
352
|
it("documents create, list, and revoke on /openapi.json", async () => {
|
|
304
353
|
const app = new TerrenoApp({
|
|
305
354
|
configureApp: (router, options) => {
|
|
@@ -316,16 +365,18 @@ describe("MCP service token OpenAPI", () => {
|
|
|
316
365
|
const res = await supertest(app).get("/openapi.json");
|
|
317
366
|
|
|
318
367
|
assert.equal(res.status, 200);
|
|
319
|
-
|
|
320
|
-
assert.equal(
|
|
321
|
-
assert.
|
|
322
|
-
|
|
323
|
-
"
|
|
368
|
+
const create = res.body.paths["/mcp/service-tokens/create"].post;
|
|
369
|
+
assert.equal(create.operationId, "mcpServiceTokens_create");
|
|
370
|
+
assert.property(
|
|
371
|
+
create.responses["200"].content["application/json"].schema.properties.data.properties,
|
|
372
|
+
"token"
|
|
324
373
|
);
|
|
325
374
|
assert.equal(
|
|
326
|
-
res.body.paths["/mcp/service-tokens"].post.
|
|
327
|
-
|
|
328
|
-
"object"
|
|
375
|
+
res.body.paths["/mcp/service-tokens/{id}/revoke"].post.operationId,
|
|
376
|
+
"mcpServiceTokens_revoke"
|
|
329
377
|
);
|
|
378
|
+
const list = res.body.paths["/mcp/service-tokens/"].get;
|
|
379
|
+
assert.deepEqual(list["x-terreno-sync"], {collection: "mcp/service-tokens", scope: "owner"});
|
|
380
|
+
assert.notProperty(res.body.paths["/mcp/service-tokens/"], "post");
|
|
330
381
|
});
|
|
331
382
|
});
|