claude-code-router/tests/main/web-management-server.test.mjs

14 lines
997 B
JavaScript

import assert from "node:assert/strict";
import test from "node:test";
import { normalizeExternalHttpTarget } from "../../packages/core/src/web/management-server.ts";
test("normalizeExternalHttpTarget accepts absolute http, https, and CCR plugin URLs only", () => {
assert.equal(normalizeExternalHttpTarget(""), undefined);
assert.equal(normalizeExternalHttpTarget(undefined), undefined);
assert.equal(normalizeExternalHttpTarget("about:blank"), undefined);
assert.equal(normalizeExternalHttpTarget(" https://example.com/path?q=1 "), "https://example.com/path?q=1");
assert.equal(normalizeExternalHttpTarget("http://localhost:3458/"), "http://localhost:3458/");
assert.throws(() => normalizeExternalHttpTarget("file:///etc/passwd"), /Only http, https, and CCR plugin URLs/);
assert.throws(() => normalizeExternalHttpTarget("javascript:alert(1)"), /Only http, https, and CCR plugin URLs/);
assert.throws(() => normalizeExternalHttpTarget("example.com"), /valid absolute URL/);
});