57 lines
2.0 KiB
TypeScript
57 lines
2.0 KiB
TypeScript
import { describe, expect, test } from "vitest";
|
|
import { isCapabilityGrantScopeSatisfied } from "./capability-grants.js";
|
|
|
|
/**
|
|
* Coverage for capability-grants branches where the declared scope sets
|
|
* one dimension but the granted scope additionally claims another the
|
|
* manifest never declared — each extra dimension must reject the grant.
|
|
* Also covers the "declared scope present but grant is null" rejection.
|
|
*/
|
|
|
|
describe("isCapabilityGrantScopeSatisfied — broadened dimensions", () => {
|
|
test("rejects a grant that adds allowedHosts the manifest never declared", () => {
|
|
expect(
|
|
isCapabilityGrantScopeSatisfied({
|
|
declaredScope: { keyPattern: "payment_*" },
|
|
grantedScopeJson: { keyPattern: "payment_*", allowedHosts: ["api.example.com"] },
|
|
})
|
|
).toBe(false);
|
|
});
|
|
|
|
test("rejects a grant that adds a keyPattern the manifest never declared", () => {
|
|
expect(
|
|
isCapabilityGrantScopeSatisfied({
|
|
declaredScope: { allowedHosts: ["api.example.com"] },
|
|
grantedScopeJson: { allowedHosts: ["api.example.com"], keyPattern: "payment_*" },
|
|
})
|
|
).toBe(false);
|
|
});
|
|
|
|
test("rejects a grant that adds a tablePrefix the manifest never declared", () => {
|
|
expect(
|
|
isCapabilityGrantScopeSatisfied({
|
|
declaredScope: { allowedHosts: ["api.example.com"] },
|
|
grantedScopeJson: { allowedHosts: ["api.example.com"], tablePrefix: "plugin_" },
|
|
})
|
|
).toBe(false);
|
|
});
|
|
|
|
test("rejects a null grant when the manifest declares a non-empty scope", () => {
|
|
expect(
|
|
isCapabilityGrantScopeSatisfied({
|
|
declaredScope: { keyPattern: "payment_*" },
|
|
grantedScopeJson: null,
|
|
})
|
|
).toBe(false);
|
|
});
|
|
|
|
test("accepts an exact-match multi-dimension grant", () => {
|
|
expect(
|
|
isCapabilityGrantScopeSatisfied({
|
|
declaredScope: { allowedHosts: ["api.example.com"], keyPattern: "payment_*", tablePrefix: "plugin_" },
|
|
grantedScopeJson: { allowedHosts: ["api.example.com"], keyPattern: "payment_*", tablePrefix: "plugin_" },
|
|
})
|
|
).toBe(true);
|
|
});
|
|
});
|