test: tighten shared policy helper coverage

This commit is contained in:
Peter Steinberger
2026-03-13 21:53:11 +00:00
parent 4de268587c
commit 52900b48ad
2 changed files with 18 additions and 0 deletions

View File

@@ -2,6 +2,16 @@ import { describe, expect, it } from "vitest";
import { roleScopesAllow } from "./operator-scope-compat.js";
describe("roleScopesAllow", () => {
it("allows empty requested scope lists regardless of granted scopes", () => {
expect(
roleScopesAllow({
role: "operator",
requestedScopes: [],
allowedScopes: [],
}),
).toBe(true);
});
it("treats operator.read as satisfied by read/write/admin scopes", () => {
expect(
roleScopesAllow({
@@ -85,6 +95,13 @@ describe("roleScopesAllow", () => {
allowedScopes: ["operator.admin"],
}),
).toBe(false);
expect(
roleScopesAllow({
role: " node ",
requestedScopes: [" system.run ", "system.run", " "],
allowedScopes: ["system.run", "operator.admin"],
}),
).toBe(true);
});
it("normalizes blank and duplicate scopes before evaluating", () => {