Files
OmniRoute/tests/unit/video-bridge-drilldown-authz.test.ts
Markus Hartung 04dba0460e fix(responses-continuation): recover a real id/output for passthrough and translate-mode replies (#11434)
Retargetado para release/v3.8.51 (release/v3.8.50 está congelada — freeze issue #11439). Validado em lote combinado (batch-0824h2, junto de #11435/#11436/#11437) contra o tip de release/v3.8.51: typecheck:core limpo, gates estáticos OK, 127/127 testes focados passando.

Investigação sólida com repro real via container isolado, três causas independentes identificadas e corrigidas com testes de regressão dedicados para cada uma. Obrigado pela contribuição!
2026-08-24 19:57:12 -03:00

58 lines
2.0 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import {
buildVideoBridgeDrilldownHeaders,
VIDEO_BRIDGE_DRILLDOWN_PATH,
} from "../../src/lib/guardrails/videoBridgeBrokerAuth.ts";
import { managementPolicy } from "../../src/server/authz/policies/management.ts";
function policyContext(path: string, ip = "127.0.0.1") {
return {
request: {
method: "GET",
headers: new Headers(buildVideoBridgeDrilldownHeaders("principal-a")),
ip,
url: `http://localhost${path}`,
nextUrl: { pathname: path },
},
classification: {
routeClass: "MANAGEMENT" as const,
normalizedPath: path,
reason: "management_api",
},
requestId: "req_video_drilldown_authz",
};
}
test("drill-down principal is canonical visible ASCII and is never silently trimmed", () => {
assert.throws(() => buildVideoBridgeDrilldownHeaders(" principal-a "), /principal/i);
assert.throws(() => buildVideoBridgeDrilldownHeaders("principal-á"), /principal/i);
assert.doesNotThrow(() => buildVideoBridgeDrilldownHeaders("tenant:principal-a"));
});
test("management policy carries the token-bound drill-down self-hop to the route", async () => {
const outcome = await managementPolicy.evaluate(policyContext(VIDEO_BRIDGE_DRILLDOWN_PATH));
assert.equal(outcome.allow, true);
if (outcome.allow) {
assert.equal(outcome.subject.id, "video-bridge-drilldown");
assert.equal(outcome.subject.label, "internal-video-bridge-drilldown");
}
const adjacent = await managementPolicy.evaluate(
policyContext("/api/modality-bridge/video/runtime")
);
assert.notEqual(
adjacent.allow ? adjacent.subject.label : "rejected",
"internal-video-bridge-drilldown",
"the broker token must not authenticate an adjacent Video Bridge path"
);
const remote = await managementPolicy.evaluate(
policyContext(VIDEO_BRIDGE_DRILLDOWN_PATH, "203.0.113.10")
);
assert.equal(remote.allow, false);
if (!remote.allow) assert.equal(remote.code, "LOCAL_ONLY");
});