Files
NODEDC_LAUNCHER/server/internal-request-auth.test.mjs

40 lines
1.4 KiB
JavaScript

import { describe, expect, it } from "vitest";
import {
isInternalRequestTokenAuthorized,
isInternalRequestTokenConfigured,
} from "./internal-request-auth.mjs";
describe("scoped internal request authorization", () => {
it("accepts the Device Core key only for Device Core handoff calls", () => {
const base = {
authorization: "Bearer device-core-file-token",
globalToken: "broad-platform-token",
scopedToken: "device-core-file-token",
};
expect(isInternalRequestTokenAuthorized({ ...base, serviceSlug: "device-core" })).toBe(true);
expect(isInternalRequestTokenAuthorized({ ...base, serviceSlug: "module-foundry" })).toBe(false);
expect(isInternalRequestTokenAuthorized(base)).toBe(false);
});
it("keeps the existing global token valid for existing internal callers", () => {
expect(isInternalRequestTokenAuthorized({
authorization: "Bearer broad-platform-token",
globalToken: "broad-platform-token",
scopedToken: "device-core-file-token",
serviceSlug: "module-foundry",
})).toBe(true);
});
it("reports scoped configuration only for the bound service", () => {
expect(isInternalRequestTokenConfigured({
scopedToken: "device-core-file-token",
serviceSlug: "device-core",
})).toBe(true);
expect(isInternalRequestTokenConfigured({
scopedToken: "device-core-file-token",
serviceSlug: "operational-core",
})).toBe(false);
});
});