feat(hub): issue trusted Device Core session claims

This commit is contained in:
DCCONSTRUCTIONS
2026-08-10 21:37:50 +03:00
parent 64624293a8
commit 56ca94d242
5 changed files with 341 additions and 27 deletions
+39
View File
@@ -0,0 +1,39 @@
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);
});
});