Files
OmniRoute/tests/unit/mitm-tool-hosts.test.ts
Diego Rodrigues de Sa e Souza 3b2a2f02a9 test: exact host membership in MITM hosts test — CodeQL FP (#660)
Use exact array-element membership (.some((h) => h === host)) instead of Array.prototype.includes() in the MITM hosts unit test, so CodeQL's js/incomplete-url-substring-sanitization heuristic does not misread an Array.includes membership check as a String.includes URL-substring test. Functionally identical. Mirrors #4386 (already merged into release/v3.8.31). Closes the only open code-scanning alert (#660).
2026-06-20 11:23:07 -03:00

30 lines
1.4 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import { ALL_TARGETS } from "../../src/mitm/targets/index.ts";
import { MITM_TOOL_HOSTS, getMitmToolHosts } from "../../src/shared/constants/mitmToolHosts.ts";
// The dashboard cannot import the node-only MITM target modules, so MITM_TOOL_HOSTS is a
// client-safe copy of each target's hosts. This guards against the copy drifting from the
// canonical registry (port from 9router#788).
test("MITM_TOOL_HOSTS stays in sync with the canonical MITM target registry", () => {
const fromRegistry: Record<string, string[]> = {};
for (const target of ALL_TARGETS) {
fromRegistry[target.id] = target.hosts;
}
assert.deepEqual(
MITM_TOOL_HOSTS,
fromRegistry,
"MITM_TOOL_HOSTS must exactly match ALL_TARGETS hosts — update src/shared/constants/mitmToolHosts.ts"
);
});
test("getMitmToolHosts returns the hosts for a known tool and [] for unknown ids", () => {
// Exact array-element membership (getMitmToolHosts returns string[]). Use `.some(===)`
// rather than `.includes()` so CodeQL's js/incomplete-url-substring-sanitization does not
// misread this Array.includes as a String.includes URL-substring check (false positive).
assert.ok(getMitmToolHosts("antigravity").some((h) => h === "cloudcode-pa.googleapis.com"));
assert.deepEqual(getMitmToolHosts("does-not-exist"), []);
});