mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-26 09:52:11 +03:00
* fix(mitm): gate Agent Bridge DNS and Trust Cert on sudo password (#7938) Extend the #7865 sudo gate to setup wizard DNS, Start DNS, and Trust Cert. Start server still runs without a password but skips privileged cert/DNS steps instead of spawning sudo -S with an empty string. Add a shared sudo password modal on the Agent Bridge page for DNS and trust-cert actions. Fixes #7938 * fix(mitm): use .tsx extension for MitmSudoPasswordModal hook JSX in a .ts file broke dashboard typecheck and ESLint on CI. * fix(mitm): skip DNS teardown on stop when sudo password missing (#7938) stopMitm() no longer invokes removeDNSEntry with an empty password when the server was started in skip mode. The MITM process is still killed. * refactor(mitm): extract privileged step helpers to satisfy file-size cap manager.ts exceeded the 800-line cap after #7938 gates. Move DNS teardown and the shared sudo skip runner into dedicated modules; behavior unchanged.
47 lines
1.7 KiB
TypeScript
47 lines
1.7 KiB
TypeScript
/**
|
|
* #7938 — Trust Cert must gate empty sudo the same way as Remove CA / Repair.
|
|
*/
|
|
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { isSudoPasswordRequired } from "../../src/mitm/dns/dnsConfig.ts";
|
|
|
|
const certRoute = await import("../../src/app/api/tools/agent-bridge/cert/route.ts");
|
|
const serverRoute = await import("../../src/app/api/tools/agent-bridge/server/route.ts");
|
|
|
|
function skipWhenSudoNotRequired() {
|
|
if (process.platform === "win32") return true;
|
|
if (!isSudoPasswordRequired()) return true;
|
|
const isRootUser = !!(process.getuid && process.getuid() === 0);
|
|
return isRootUser;
|
|
}
|
|
|
|
test("POST /cert returns 400 Missing sudoPassword when sudo is required and none supplied", async () => {
|
|
if (skipWhenSudoNotRequired()) return;
|
|
|
|
const res = await certRoute.POST(
|
|
new Request("http://127.0.0.1/api/tools/agent-bridge/cert", {
|
|
method: "POST",
|
|
headers: { "content-type": "application/json" },
|
|
body: JSON.stringify({}),
|
|
})
|
|
);
|
|
assert.equal(res.status, 400);
|
|
const body = (await res.json()) as { error?: { message?: string } };
|
|
assert.match(body.error?.message ?? "", /Missing sudoPassword/);
|
|
});
|
|
|
|
test("POST /server trust-cert returns 400 Missing sudoPassword when sudo is required", async () => {
|
|
if (skipWhenSudoNotRequired()) return;
|
|
|
|
const res = await serverRoute.POST(
|
|
new Request("http://127.0.0.1/api/tools/agent-bridge/server", {
|
|
method: "POST",
|
|
headers: { "content-type": "application/json" },
|
|
body: JSON.stringify({ action: "trust-cert" }),
|
|
})
|
|
);
|
|
assert.equal(res.status, 400);
|
|
const body = (await res.json()) as { error?: { message?: string } };
|
|
assert.match(body.error?.message ?? "", /Missing sudoPassword/);
|
|
});
|