@kya-os/mcp-i-runtime 1.2.5 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +1 -1
- package/dist/auth/types.d.ts +2 -2
- package/dist/auth/types.d.ts.map +1 -1
- package/dist/config/remote-config.d.ts +3 -3
- package/dist/config/remote-config.js +6 -6
- package/dist/config/remote-config.js.map +1 -1
- package/dist/identity/user-did-manager.d.ts +4 -4
- package/dist/identity/user-did-manager.js +5 -5
- package/dist/identity/user-did-manager.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -3
- package/dist/index.js.map +1 -1
- package/dist/runtime/audit.d.ts.map +1 -1
- package/dist/runtime/audit.js +22 -0
- package/dist/runtime/audit.js.map +1 -1
- package/dist/runtime/base.d.ts +14 -11
- package/dist/runtime/base.d.ts.map +1 -1
- package/dist/runtime/base.js +51 -29
- package/dist/runtime/base.js.map +1 -1
- package/dist/runtime/delegation-denial.d.ts +43 -0
- package/dist/runtime/delegation-denial.d.ts.map +1 -0
- package/dist/runtime/delegation-denial.js +83 -0
- package/dist/runtime/delegation-denial.js.map +1 -0
- package/dist/runtime/verified-delegation.d.ts +30 -0
- package/dist/runtime/verified-delegation.d.ts.map +1 -0
- package/dist/runtime/verified-delegation.js +62 -0
- package/dist/runtime/verified-delegation.js.map +1 -0
- package/dist/services/access-control.service.d.ts +4 -4
- package/dist/services/access-control.service.d.ts.map +1 -1
- package/dist/services/access-control.service.js +34 -34
- package/dist/services/access-control.service.js.map +1 -1
- package/dist/services/delegation-error-formatter.d.ts +15 -0
- package/dist/services/delegation-error-formatter.d.ts.map +1 -1
- package/dist/services/delegation-error-formatter.js +27 -1
- package/dist/services/delegation-error-formatter.js.map +1 -1
- package/dist/services/oauth-config.service.d.ts +4 -4
- package/dist/services/oauth-config.service.d.ts.map +1 -1
- package/dist/services/oauth-config.service.js +8 -8
- package/dist/services/oauth-config.service.js.map +1 -1
- package/dist/services/oauth-provider-registry.d.ts +6 -4
- package/dist/services/oauth-provider-registry.d.ts.map +1 -1
- package/dist/services/oauth-provider-registry.js +9 -5
- package/dist/services/oauth-provider-registry.js.map +1 -1
- package/dist/services/oauth-service.d.ts +17 -10
- package/dist/services/oauth-service.d.ts.map +1 -1
- package/dist/services/oauth-service.js +14 -14
- package/dist/services/oauth-service.js.map +1 -1
- package/dist/services/oauth-token-retrieval.service.d.ts +6 -6
- package/dist/services/oauth-token-retrieval.service.d.ts.map +1 -1
- package/dist/services/oauth-token-retrieval.service.js +5 -5
- package/dist/services/provider-resolver.d.ts +1 -1
- package/dist/services/provider-resolver.js +7 -7
- package/dist/services/provider-resolver.js.map +1 -1
- package/dist/services/session-registration.service.d.ts +5 -5
- package/dist/services/session-registration.service.d.ts.map +1 -1
- package/dist/services/session-registration.service.js +9 -9
- package/dist/services/session-registration.service.js.map +1 -1
- package/dist/services/tool-protection.service.d.ts +15 -15
- package/dist/services/tool-protection.service.js +18 -18
- package/dist/services/tool-protection.service.js.map +1 -1
- package/dist/types/tool-protection.d.ts +11 -4
- package/dist/types/tool-protection.d.ts.map +1 -1
- package/dist/types/tool-protection.js +8 -1
- package/dist/types/tool-protection.js.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/config/provider-runtime-config.test.ts +1 -1
- package/src/__tests__/config.test.ts +3 -3
- package/src/__tests__/index.test.ts +12 -0
- package/src/__tests__/integration/full-flow.test.ts +4 -4
- package/src/__tests__/regression/phase2-regression.test.ts +2 -2
- package/src/__tests__/runtime/audit-contracts-compat.test.ts +54 -0
- package/src/__tests__/runtime/audit.test.ts +172 -0
- package/src/__tests__/runtime/delegation-denial.test.ts +115 -0
- package/src/__tests__/runtime/process-tool-call-security.test.ts +326 -9
- package/src/__tests__/runtime/tool-protection-enforcement.test.ts +25 -10
- package/src/__tests__/runtime/verified-delegation.test.ts +129 -0
- package/src/__tests__/services/access-control-retry.test.ts +2 -2
- package/src/__tests__/services/cache-busting.test.ts +1 -1
- package/src/__tests__/services/{agentshield-integration.test.ts → checkpoint-integration.test.ts} +3 -3
- package/src/__tests__/services/former-names.test.ts +114 -0
- package/src/__tests__/services/oauth-service-errors.test.ts +5 -5
- package/src/__tests__/services/oauth-service-pkce.test.ts +2 -2
- package/src/__tests__/services/oauth-service-secret-resolution.test.ts +15 -15
- package/src/__tests__/services/provider-resolver-edge-cases.test.ts +11 -11
- package/src/__tests__/services/tool-protection.service.test.ts +1 -1
- package/src/auth/types.ts +2 -2
- package/src/config/remote-config.ts +6 -6
- package/src/identity/user-did-manager.ts +5 -5
- package/src/index.ts +15 -0
- package/src/runtime/audit.ts +26 -0
- package/src/runtime/base.ts +63 -32
- package/src/runtime/delegation-denial.ts +107 -0
- package/src/runtime/verified-delegation.ts +66 -0
- package/src/services/__tests__/access-control.integration.test.ts +3 -3
- package/src/services/__tests__/access-control.proof-response-validation.test.ts +15 -15
- package/src/services/__tests__/access-control.service.test.ts +14 -14
- package/src/services/__tests__/delegation-error-formatter.test.ts +156 -0
- package/src/services/__tests__/oauth-config.service.test.ts +2 -2
- package/src/services/__tests__/oauth-provider-registry.test.ts +11 -11
- package/src/services/__tests__/provider-resolution.integration.test.ts +6 -6
- package/src/services/__tests__/provider-resolver.test.ts +1 -1
- package/src/services/__tests__/session-registration.service.test.ts +1 -1
- package/src/services/access-control.service.ts +31 -31
- package/src/services/delegation-error-formatter.ts +42 -1
- package/src/services/oauth-config.service.d.ts +4 -4
- package/src/services/oauth-config.service.ts +9 -9
- package/src/services/oauth-provider-registry.d.ts +4 -2
- package/src/services/oauth-provider-registry.ts +10 -5
- package/src/services/oauth-service.ts +30 -19
- package/src/services/oauth-token-retrieval.service.ts +8 -8
- package/src/services/provider-resolver.ts +7 -7
- package/src/services/session-registration.service.ts +10 -10
- package/src/services/tool-protection.service.ts +19 -19
- package/src/types/tool-protection.ts +13 -4
- package/vitest.config.mts +1 -1
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* - Complete handshake → tool call → proof flow
|
|
6
6
|
* - Tool protection enforcement
|
|
7
7
|
* - Delegation flow (intercept → authorize → resume)
|
|
8
|
-
* -
|
|
8
|
+
* - Checkpoint integration
|
|
9
9
|
* - Caching behavior
|
|
10
10
|
*/
|
|
11
11
|
|
|
@@ -106,7 +106,7 @@ describe("Full Flow Integration", () => {
|
|
|
106
106
|
},
|
|
107
107
|
toolProtection: {
|
|
108
108
|
source: "agentshield",
|
|
109
|
-
|
|
109
|
+
checkpoint: {
|
|
110
110
|
apiUrl: "https://kya.vouched.id",
|
|
111
111
|
apiKey: "test-api-key",
|
|
112
112
|
},
|
|
@@ -376,8 +376,8 @@ describe("Full Flow Integration", () => {
|
|
|
376
376
|
});
|
|
377
377
|
});
|
|
378
378
|
|
|
379
|
-
describe("
|
|
380
|
-
test("should fetch tool protection config from
|
|
379
|
+
describe("Checkpoint integration flow", () => {
|
|
380
|
+
test("should fetch tool protection config from Checkpoint merged config", async () => {
|
|
381
381
|
// Merged config format - tools embedded at config.toolProtection.tools
|
|
382
382
|
const apiResponse = {
|
|
383
383
|
success: true,
|
|
@@ -121,7 +121,7 @@ describe("Phase 2 Regression Tests", () => {
|
|
|
121
121
|
.fn()
|
|
122
122
|
.mockReturnValue([{ clientId: "github_client_id" }]),
|
|
123
123
|
getProviderNames: vi.fn().mockReturnValue(["github"]),
|
|
124
|
-
|
|
124
|
+
loadFromCheckpoint: vi.fn().mockResolvedValue(undefined),
|
|
125
125
|
getConfiguredProvider: vi.fn().mockReturnValue("github"), // configuredProvider is github
|
|
126
126
|
} as any;
|
|
127
127
|
|
|
@@ -239,7 +239,7 @@ describe("Phase 2 Regression Tests", () => {
|
|
|
239
239
|
.fn()
|
|
240
240
|
.mockReturnValue([{ clientId: "github_client_id" }]),
|
|
241
241
|
getProviderNames: vi.fn().mockReturnValue(["github"]),
|
|
242
|
-
|
|
242
|
+
loadFromCheckpoint: vi.fn().mockResolvedValue(undefined),
|
|
243
243
|
getConfiguredProvider: vi.fn().mockReturnValue("github"), // configuredProvider is github
|
|
244
244
|
} as any;
|
|
245
245
|
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The runtime declares "@kya-os/contracts": "^1.12.1", so a consumer's
|
|
3
|
+
* lockfile can pair this runtime with a contracts release that predates the
|
|
4
|
+
* denial code list. The audit mapper must still classify verifier denials
|
|
5
|
+
* then, or every denial silently loses its tool.call.denied entry.
|
|
6
|
+
*/
|
|
7
|
+
import { describe, expect, it, vi } from "vitest";
|
|
8
|
+
|
|
9
|
+
vi.mock("@kya-os/contracts/config", async (importOriginal) => {
|
|
10
|
+
const actual = await importOriginal<Record<string, unknown>>();
|
|
11
|
+
// Simulate contracts 1.12.x: everything except the denial code list.
|
|
12
|
+
const { DELEGATION_DENIAL_CODES: _addedInLaterContracts, ...olderExports } =
|
|
13
|
+
actual;
|
|
14
|
+
return olderExports;
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const { terminalForToolError } = await import("../../runtime/audit");
|
|
18
|
+
const { DelegationRequiredError } = await import(
|
|
19
|
+
"../../types/tool-protection"
|
|
20
|
+
);
|
|
21
|
+
const { toDelegationDenial } = await import("../../runtime/delegation-denial");
|
|
22
|
+
|
|
23
|
+
describe("audit denial mapping against an older contracts release", () => {
|
|
24
|
+
it("still records a verifier denial as denied", () => {
|
|
25
|
+
const error = new DelegationRequiredError(
|
|
26
|
+
"orders.place",
|
|
27
|
+
["orders:place"],
|
|
28
|
+
"https://example.com/consent",
|
|
29
|
+
undefined,
|
|
30
|
+
"resume_token",
|
|
31
|
+
toDelegationDenial("delegation_revoked")
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
expect(terminalForToolError(error)).toEqual({
|
|
35
|
+
phase: "denied",
|
|
36
|
+
outcome: "denied",
|
|
37
|
+
reasonCode: "DELEGATION_REVOKED",
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("does not treat an inherited property name as a denial code", () => {
|
|
42
|
+
const error = new DelegationRequiredError("orders.place", ["orders:place"]);
|
|
43
|
+
(error as unknown as { denial: unknown }).denial = {
|
|
44
|
+
code: "constructor",
|
|
45
|
+
message: "x",
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
expect(terminalForToolError(error)).toEqual({
|
|
49
|
+
phase: "challenged",
|
|
50
|
+
outcome: "challenged",
|
|
51
|
+
reasonCode: "AUTHORIZATION_REQUIRED",
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -6,9 +6,14 @@ import {
|
|
|
6
6
|
createHmacRuntimeAuditContextFactory,
|
|
7
7
|
recordRuntimeConsentAudit,
|
|
8
8
|
recordRuntimeDelegationAudit,
|
|
9
|
+
terminalForToolError,
|
|
9
10
|
type RuntimeAuditConfig,
|
|
10
11
|
} from "../../runtime/audit";
|
|
11
12
|
import { createMockProviders } from "../utils/mock-providers";
|
|
13
|
+
import { DelegationRequiredError } from "../../types/tool-protection";
|
|
14
|
+
import { toDelegationDenial } from "../../runtime/delegation-denial";
|
|
15
|
+
import type { AccessControlApiService } from "../../services/access-control.service";
|
|
16
|
+
import type { ToolProtectionService } from "../../services/tool-protection.service";
|
|
12
17
|
|
|
13
18
|
function auditConfig(record: (event: AuditTrailEventInput) => Promise<unknown>): RuntimeAuditConfig {
|
|
14
19
|
return {
|
|
@@ -241,6 +246,173 @@ describe("canonical runtime audit lifecycle", () => {
|
|
|
241
246
|
});
|
|
242
247
|
});
|
|
243
248
|
|
|
249
|
+
describe("verifier denials in the audit ledger", () => {
|
|
250
|
+
async function protectedRuntimeWithAudit(
|
|
251
|
+
record: (event: AuditTrailEventInput) => Promise<unknown>,
|
|
252
|
+
verifyData: Record<string, unknown>
|
|
253
|
+
): Promise<MCPIRuntimeBase> {
|
|
254
|
+
const toolProtectionService = {
|
|
255
|
+
checkToolProtection: vi.fn().mockResolvedValue({
|
|
256
|
+
requiresDelegation: true,
|
|
257
|
+
requiredScopes: ["orders:place"],
|
|
258
|
+
}),
|
|
259
|
+
} as unknown as ToolProtectionService;
|
|
260
|
+
const accessControlService = {
|
|
261
|
+
verifyDelegation: vi.fn().mockResolvedValue({ data: verifyData }),
|
|
262
|
+
} as unknown as AccessControlApiService;
|
|
263
|
+
const runtime = new MCPIRuntimeBase({
|
|
264
|
+
...createMockProviders(),
|
|
265
|
+
environment: "production",
|
|
266
|
+
auditTrail: auditConfig(record),
|
|
267
|
+
toolProtectionService,
|
|
268
|
+
});
|
|
269
|
+
(runtime as unknown as { accessControlService: AccessControlApiService })
|
|
270
|
+
.accessControlService = accessControlService;
|
|
271
|
+
await runtime.initialize();
|
|
272
|
+
return runtime;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
it("records a revoked grant as tool.call.denied with DELEGATION_REVOKED", async () => {
|
|
276
|
+
const events: AuditTrailEventInput[] = [];
|
|
277
|
+
const runtime = await protectedRuntimeWithAudit(
|
|
278
|
+
async (event) => {
|
|
279
|
+
events.push(event);
|
|
280
|
+
return pendingResult(event, String(events.length));
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
valid: false,
|
|
284
|
+
error: { code: "delegation_revoked", message: "admin note: secret" },
|
|
285
|
+
}
|
|
286
|
+
);
|
|
287
|
+
const handler = vi.fn(async () => ({ ok: true }));
|
|
288
|
+
|
|
289
|
+
await expect(
|
|
290
|
+
runtime.processToolCall("orders.place", {}, handler, {
|
|
291
|
+
id: "session",
|
|
292
|
+
nonce: "nonce",
|
|
293
|
+
audience: "client",
|
|
294
|
+
delegationToken: "revoked-token",
|
|
295
|
+
})
|
|
296
|
+
).rejects.toThrow(DelegationRequiredError);
|
|
297
|
+
|
|
298
|
+
expect(handler).not.toHaveBeenCalled();
|
|
299
|
+
expect(events.map((event) => event.eventType)).toEqual([
|
|
300
|
+
"tool.call.started",
|
|
301
|
+
"tool.call.denied",
|
|
302
|
+
]);
|
|
303
|
+
expect(events[1]).toMatchObject({
|
|
304
|
+
outcome: "denied",
|
|
305
|
+
reason: { code: "DELEGATION_REVOKED" },
|
|
306
|
+
details: { phase: "denied" },
|
|
307
|
+
});
|
|
308
|
+
expect(JSON.stringify(events)).not.toContain("secret");
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
it("records a revoked grant on the native rail as DELEGATION_REVOKED, not a binding mismatch", async () => {
|
|
312
|
+
const events: AuditTrailEventInput[] = [];
|
|
313
|
+
const runtime = await protectedRuntimeWithAudit(
|
|
314
|
+
async (event) => {
|
|
315
|
+
events.push(event);
|
|
316
|
+
return pendingResult(event, String(events.length));
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
valid: false,
|
|
320
|
+
error: { code: "delegation_revoked", message: "Revoked" },
|
|
321
|
+
}
|
|
322
|
+
);
|
|
323
|
+
const handler = vi.fn(async () => ({ ok: true }));
|
|
324
|
+
|
|
325
|
+
await expect(
|
|
326
|
+
runtime.processToolCall("orders.place", {}, handler, {
|
|
327
|
+
id: "session",
|
|
328
|
+
nonce: "nonce",
|
|
329
|
+
audience: "client",
|
|
330
|
+
delegationToken: "revoked-token",
|
|
331
|
+
verifiedInvokerDid: "did:key:zAdmittedHolder",
|
|
332
|
+
})
|
|
333
|
+
).rejects.toThrow(DelegationRequiredError);
|
|
334
|
+
|
|
335
|
+
expect(handler).not.toHaveBeenCalled();
|
|
336
|
+
expect(events.map((event) => event.eventType)).toEqual([
|
|
337
|
+
"tool.call.started",
|
|
338
|
+
"tool.call.denied",
|
|
339
|
+
]);
|
|
340
|
+
expect(events[1]).toMatchObject({
|
|
341
|
+
outcome: "denied",
|
|
342
|
+
reason: { code: "DELEGATION_REVOKED" },
|
|
343
|
+
});
|
|
344
|
+
expect(JSON.stringify(events)).not.toContain("NATIVE_BINDING_MISMATCH");
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
it("still records a missing delegation as challenged AUTHORIZATION_REQUIRED", async () => {
|
|
348
|
+
const events: AuditTrailEventInput[] = [];
|
|
349
|
+
const runtime = await protectedRuntimeWithAudit(
|
|
350
|
+
async (event) => {
|
|
351
|
+
events.push(event);
|
|
352
|
+
return pendingResult(event, String(events.length));
|
|
353
|
+
},
|
|
354
|
+
{ valid: true }
|
|
355
|
+
);
|
|
356
|
+
|
|
357
|
+
await expect(
|
|
358
|
+
runtime.processToolCall("orders.place", {}, vi.fn(), {
|
|
359
|
+
id: "session",
|
|
360
|
+
nonce: "nonce",
|
|
361
|
+
audience: "client",
|
|
362
|
+
})
|
|
363
|
+
).rejects.toThrow(DelegationRequiredError);
|
|
364
|
+
|
|
365
|
+
expect(events.map((event) => event.eventType)).toEqual([
|
|
366
|
+
"tool.call.started",
|
|
367
|
+
"tool.call.challenged",
|
|
368
|
+
]);
|
|
369
|
+
expect(events[1]).toMatchObject({
|
|
370
|
+
outcome: "challenged",
|
|
371
|
+
reason: { code: "AUTHORIZATION_REQUIRED" },
|
|
372
|
+
});
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
it("maps a denial to the denied phase", () => {
|
|
376
|
+
const error = new DelegationRequiredError(
|
|
377
|
+
"orders.place",
|
|
378
|
+
["orders:place"],
|
|
379
|
+
"https://example.com/consent",
|
|
380
|
+
undefined,
|
|
381
|
+
"resume_token",
|
|
382
|
+
toDelegationDenial("agent_mismatch")
|
|
383
|
+
);
|
|
384
|
+
|
|
385
|
+
expect(terminalForToolError(error)).toEqual({
|
|
386
|
+
phase: "denied",
|
|
387
|
+
outcome: "denied",
|
|
388
|
+
reasonCode: "AGENT_MISMATCH",
|
|
389
|
+
});
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
it("keeps an unknown verifier reason as challenged", () => {
|
|
393
|
+
const error = new DelegationRequiredError("orders.place", ["orders:place"]);
|
|
394
|
+
|
|
395
|
+
expect(terminalForToolError(error)).toEqual({
|
|
396
|
+
phase: "challenged",
|
|
397
|
+
outcome: "challenged",
|
|
398
|
+
reasonCode: "AUTHORIZATION_REQUIRED",
|
|
399
|
+
});
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
it("ignores a denial whose code is not a known denial code", () => {
|
|
403
|
+
const error = new DelegationRequiredError("orders.place", ["orders:place"]);
|
|
404
|
+
(error as unknown as { denial: unknown }).denial = {
|
|
405
|
+
code: "free text from somewhere",
|
|
406
|
+
message: "x",
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
expect(terminalForToolError(error)).toMatchObject({
|
|
410
|
+
phase: "challenged",
|
|
411
|
+
reasonCode: "AUTHORIZATION_REQUIRED",
|
|
412
|
+
});
|
|
413
|
+
});
|
|
414
|
+
});
|
|
415
|
+
|
|
244
416
|
describe("HMAC audit references", () => {
|
|
245
417
|
it("is deterministic and does not expose capability-bearing identifiers", async () => {
|
|
246
418
|
const factory = createHmacRuntimeAuditContextFactory({
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for the verifier denial allowlist: Checkpoint error codes in, a fixed
|
|
3
|
+
* set of denial codes with product-neutral messages out.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { describe, it, expect } from "vitest";
|
|
7
|
+
import { DELEGATION_DENIAL_CODES } from "@kya-os/contracts/config";
|
|
8
|
+
import {
|
|
9
|
+
DEFAULT_DENIAL_MESSAGES,
|
|
10
|
+
nativeBindingDenial,
|
|
11
|
+
toDelegationDenial,
|
|
12
|
+
} from "../../runtime/delegation-denial";
|
|
13
|
+
|
|
14
|
+
describe("toDelegationDenial", () => {
|
|
15
|
+
it.each([
|
|
16
|
+
["delegation_revoked", "delegation_revoked"],
|
|
17
|
+
["delegation_expired", "delegation_expired"],
|
|
18
|
+
["delegation_not_yet_valid", "delegation_not_yet_valid"],
|
|
19
|
+
["delegation_inactive", "delegation_invalid"],
|
|
20
|
+
["delegation_not_found", "delegation_invalid"],
|
|
21
|
+
["invalid_token", "delegation_invalid"],
|
|
22
|
+
["invalid_jwt", "delegation_invalid"],
|
|
23
|
+
["agent_mismatch", "agent_mismatch"],
|
|
24
|
+
["user_mismatch", "user_mismatch"],
|
|
25
|
+
["max_calls_exceeded", "budget_exceeded"],
|
|
26
|
+
["insufficient_scopes", "insufficient_scope"],
|
|
27
|
+
["origin_not_allowed", "policy_denied"],
|
|
28
|
+
["origin_required", "policy_denied"],
|
|
29
|
+
["ip_not_whitelisted", "policy_denied"],
|
|
30
|
+
["client_ip_required", "policy_denied"],
|
|
31
|
+
])("maps Checkpoint code %s to %s", (upstreamCode, expectedCode) => {
|
|
32
|
+
expect(toDelegationDenial(upstreamCode)).toEqual({
|
|
33
|
+
code: expectedCode,
|
|
34
|
+
message: DEFAULT_DENIAL_MESSAGES[expectedCode as keyof typeof DEFAULT_DENIAL_MESSAGES],
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("keeps agent and user mismatches as distinct codes", () => {
|
|
39
|
+
const agentDenial = toDelegationDenial("agent_mismatch");
|
|
40
|
+
const userDenial = toDelegationDenial("user_mismatch");
|
|
41
|
+
|
|
42
|
+
expect(agentDenial?.code).not.toBe(userDenial?.code);
|
|
43
|
+
expect(agentDenial?.message).not.toBe(userDenial?.message);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it.each([
|
|
47
|
+
["an unknown code", "something_new"],
|
|
48
|
+
["a billing code", "billing_limit_reached"],
|
|
49
|
+
["limit_exceeded", "limit_exceeded"],
|
|
50
|
+
["project_not_found", "project_not_found"],
|
|
51
|
+
["revocation_check_failed", "revocation_check_failed"],
|
|
52
|
+
["an empty string", ""],
|
|
53
|
+
["a different case", "DELEGATION_REVOKED"],
|
|
54
|
+
["an inherited object key", "constructor"],
|
|
55
|
+
["a prototype key", "__proto__"],
|
|
56
|
+
])("returns undefined for %s", (_label, upstreamCode) => {
|
|
57
|
+
expect(toDelegationDenial(upstreamCode)).toBeUndefined();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("returns undefined when no code is given", () => {
|
|
61
|
+
expect(toDelegationDenial()).toBeUndefined();
|
|
62
|
+
expect(toDelegationDenial(undefined)).toBeUndefined();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("never echoes upstream text, only the fixed default message", () => {
|
|
66
|
+
const secret = "secret admin note: revoked because of fraud case 4411";
|
|
67
|
+
const denial = toDelegationDenial("delegation_revoked");
|
|
68
|
+
|
|
69
|
+
expect(JSON.stringify(denial)).not.toContain("secret");
|
|
70
|
+
expect(JSON.stringify(denial)).not.toContain(secret);
|
|
71
|
+
// Free text is not a code, so it maps to nothing rather than leaking.
|
|
72
|
+
expect(toDelegationDenial(secret)).toBeUndefined();
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
describe("nativeBindingDenial", () => {
|
|
77
|
+
it("reports the runtime's own holder-of-key comparison", () => {
|
|
78
|
+
expect(nativeBindingDenial()).toEqual({
|
|
79
|
+
code: "native_binding_mismatch",
|
|
80
|
+
message: DEFAULT_DENIAL_MESSAGES.native_binding_mismatch,
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("is not reachable from an upstream code", () => {
|
|
85
|
+
expect(toDelegationDenial("native_binding_mismatch")).toBeUndefined();
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
describe("DEFAULT_DENIAL_MESSAGES", () => {
|
|
90
|
+
it("has a message for every denial code", () => {
|
|
91
|
+
expect(Object.keys(DEFAULT_DENIAL_MESSAGES).sort()).toEqual(
|
|
92
|
+
[...DELEGATION_DENIAL_CODES].sort()
|
|
93
|
+
);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it.each(Object.entries(DEFAULT_DENIAL_MESSAGES))(
|
|
97
|
+
"%s says nothing was executed",
|
|
98
|
+
(_code, message) => {
|
|
99
|
+
expect(message).toMatch(/ Nothing was executed\.$/);
|
|
100
|
+
}
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
it("uses no em dashes and names no product", () => {
|
|
104
|
+
for (const message of Object.values(DEFAULT_DENIAL_MESSAGES)) {
|
|
105
|
+
expect(message).not.toContain("\u2014");
|
|
106
|
+
expect(message).not.toMatch(/checkpoint|agentshield|kya/i);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("never claims a holder binding", () => {
|
|
111
|
+
for (const code of Object.keys(DEFAULT_DENIAL_MESSAGES)) {
|
|
112
|
+
expect(code).not.toMatch(/holder/i);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
});
|