65 lines
1.8 KiB
TypeScript
65 lines
1.8 KiB
TypeScript
import { describe, expect, test } from "vitest";
|
|
import { isCapabilityCallWithinScope } from "./capability-scope.js";
|
|
|
|
/**
|
|
* Coverage for the "structured request is present but the discriminating
|
|
* field is missing / wrong-typed" branches of each scoped capability —
|
|
* these short-circuit to a deny before the scope comparison runs.
|
|
*/
|
|
|
|
describe("isCapabilityCallWithinScope — malformed request fields", () => {
|
|
test("denies http.outbound when the request carries no string url", () => {
|
|
expect(
|
|
isCapabilityCallWithinScope({
|
|
capability: "http.outbound",
|
|
callArgs: [{ method: "GET" }],
|
|
scope: { allowedHosts: ["api.example.com"] },
|
|
})
|
|
).toBe(false);
|
|
|
|
expect(
|
|
isCapabilityCallWithinScope({
|
|
capability: "http.outbound",
|
|
callArgs: [{ url: 1234 }],
|
|
scope: { allowedHosts: ["api.example.com"] },
|
|
})
|
|
).toBe(false);
|
|
});
|
|
|
|
test("denies secret.read when the request key is not a string", () => {
|
|
expect(
|
|
isCapabilityCallWithinScope({
|
|
capability: "secret.read",
|
|
callArgs: [{ key: 42 }],
|
|
scope: { keyPattern: "payment_*" },
|
|
})
|
|
).toBe(false);
|
|
|
|
expect(
|
|
isCapabilityCallWithinScope({
|
|
capability: "secret.read",
|
|
callArgs: [{ notKey: "payment_x" }],
|
|
scope: { keyPattern: "payment_*" },
|
|
})
|
|
).toBe(false);
|
|
});
|
|
|
|
test("denies db.read / db.write when the request table is not a string", () => {
|
|
expect(
|
|
isCapabilityCallWithinScope({
|
|
capability: "db.read",
|
|
callArgs: [{ table: 7 }],
|
|
scope: { tablePrefix: "plugin_" },
|
|
})
|
|
).toBe(false);
|
|
|
|
expect(
|
|
isCapabilityCallWithinScope({
|
|
capability: "db.write",
|
|
callArgs: [{ rows: [] }],
|
|
scope: { tablePrefix: "plugin_" },
|
|
})
|
|
).toBe(false);
|
|
});
|
|
});
|