mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-02 21:32:10 +03:00
DNS toggle in AgentBridge was broken for 8 of 9 agents: addDNSEntry/ removeDNSEntry always resolved the legacy Antigravity default hosts regardless of which agent's dns_enabled flag was flipped. Both now accept an optional agentId and resolve hosts via ALL_TARGETS; the [id]/dns route passes id through and returns 404 for an unknown agent instead of silently falling back to the defaults. startMitmInternal() now wraps generateCert(), the provisionDnsEntries() call, and the PID-file write in try/catch so a mid-startup failure can't orphan the already-spawned MITM child process. On Windows, addDNSEntries/removeDNSEntries batch every missing/present entry into a single elevated PowerShell invocation instead of one UAC prompt per host line. Scope note: this PR originally bundled an unrelated SkillOpt feature (DB migration, 6 API routes, dashboard UI) and a checks-free CI build workflow alongside this DNS/startup fix. Both were dropped here as out-of-scope per review-group-prs analysis (2-implementing plan); only the DNS/startup-guard delta (dnsConfig.ts, manager.ts, the [id]/dns route, and their tests) is applied. Co-authored-by: hamsa0x7 <hamsa0x7@users.noreply.github.com> Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
61 lines
2.3 KiB
TypeScript
61 lines
2.3 KiB
TypeScript
/**
|
|
* Unit tests: POST /api/tools/agent-bridge/agents/[id]/dns — unknown-agent 404 guard.
|
|
*
|
|
* Before this fix, an unknown `id` fell through straight into `addDNSEntry`/
|
|
* `removeDNSEntry`, which silently resolved the legacy Antigravity default hosts
|
|
* instead of rejecting the request. The route now validates `id` against
|
|
* `ALL_TARGETS` first and returns 404 for unknown agents — verified here without
|
|
* touching /etc/hosts (the 404 short-circuits before any DNS call).
|
|
*/
|
|
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
const dnsRoute = await import(
|
|
"../../src/app/api/tools/agent-bridge/agents/[id]/dns/route.ts"
|
|
);
|
|
|
|
function makeRequest(body: unknown): Request {
|
|
return new Request("http://127.0.0.1/api/tools/agent-bridge/agents/x/dns", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify(body),
|
|
});
|
|
}
|
|
|
|
test("POST .../[id]/dns: unknown agent id returns 404 before any DNS call", async () => {
|
|
const res = await dnsRoute.POST(makeRequest({ enabled: true }), {
|
|
params: { id: "__nonexistent_agent__" },
|
|
});
|
|
assert.equal(res.status, 404);
|
|
const body = (await res.json()) as { error?: { message?: string } };
|
|
assert.ok(
|
|
JSON.stringify(body).includes("__nonexistent_agent__"),
|
|
"404 body should reference the unknown agent id"
|
|
);
|
|
});
|
|
|
|
test("POST .../[id]/dns: invalid body still returns 400 (schema validated first)", async () => {
|
|
const res = await dnsRoute.POST(makeRequest({ enabled: "not-a-boolean" }), {
|
|
params: { id: "__nonexistent_agent__" },
|
|
});
|
|
assert.equal(res.status, 400);
|
|
});
|
|
|
|
test("POST .../[id]/dns: malformed JSON body returns 400", async () => {
|
|
const req = new Request("http://127.0.0.1/api/tools/agent-bridge/agents/x/dns", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: "{not-json",
|
|
});
|
|
const res = await dnsRoute.POST(req, { params: { id: "cursor" } });
|
|
assert.equal(res.status, 400);
|
|
});
|
|
|
|
test("POST .../[id]/dns: error responses do not leak stack traces", async () => {
|
|
const res = await dnsRoute.POST(makeRequest({ enabled: true }), {
|
|
params: { id: "__nonexistent_agent__" },
|
|
});
|
|
const text = await res.text();
|
|
assert.ok(!text.includes("at /"), "stack trace leaked in dns route 404 response");
|
|
});
|