fix(engine): a registry or download refusal no longer says it was a capture (#8791)

This commit is contained in:
Miguel Ángel
2026-11-25 01:33:27 +00:00
committed by GitHub
parent 59bac900aa
commit cb9dfa8f0c
4 changed files with 20 additions and 24 deletions
@@ -37,7 +37,7 @@ async function resolveInChild(
it("gives up when neither DNS nor the system lookup answers, and the process is gone right after", async () => {
const run = await resolveInChild("silent", "stall");
expect(run.printed).toBe("Capture DNS timed out");
expect(run.printed).toBe("DNS timed out");
expect(run.livedOnMs).toBeLessThan(1_000);
}, 30_000);
@@ -62,13 +62,13 @@ it("takes the hosts file's answer over the DNS one, as the system lookup does",
it("refuses a host the hosts file blocks", async () => {
const hosts = "0.0.0.0 assets.capture-fixture.com\n";
const run = await resolveInChild("answer", "stall", "93.184.216.34", { HF_TEST_HOSTS: hosts });
expect(run.printed).toBe("Capture DNS returned a non-public address");
expect(run.printed).toBe("DNS returned a non-public address");
}, 30_000);
it("refuses a host when any of its hosts file addresses is not public", async () => {
const hosts = "8.8.4.4 assets.capture-fixture.com\n0.0.0.0 assets.capture-fixture.com\n";
const run = await resolveInChild("answer", "stall", "93.184.216.34", { HF_TEST_HOSTS: hosts });
expect(run.printed).toBe("Capture DNS returned a non-public address");
expect(run.printed).toBe("DNS returned a non-public address");
}, 30_000);
it("leaves no system lookup running when the CLI exits mid-lookup", async () => {
@@ -245,6 +245,7 @@ describe("registry resolver", () => {
});
await expect(resolved).rejects.toThrow("127.0.0.1:9 is not a public address");
await expect(resolved).rejects.not.toThrow(/contacted/i);
await expect(resolved).rejects.not.toThrow(/capture/i);
expect(fetch).not.toHaveBeenCalled();
});
@@ -98,16 +98,11 @@ describe("public address policy", () => {
);
it("fails when neither DNS nor the system lookup answers", async () => {
mocks.resolve4.mockRejectedValue(new Error("queryA ENOTFOUND"));
await expect(resolvePublicAddress("example.com")).rejects.toThrow(
"Capture DNS failed: ENOTFOUND",
);
await expect(resolvePublicAddress("example.com")).rejects.toThrow("DNS failed: ENOTFOUND");
});
it.each([
[{ code: 3221225794 }, "Capture DNS failed: the lookup helper exited with code 3221225794"],
[
{ code: null, signal: "SIGKILL" },
"Capture DNS failed: the lookup helper was ended by SIGKILL",
],
[{ code: 3221225794 }, "DNS failed: the lookup helper exited with code 3221225794"],
[{ code: null, signal: "SIGKILL" }, "DNS failed: the lookup helper was ended by SIGKILL"],
])(
"names how the system lookup helper ended when it says nothing (%j)",
async (ended, message) => {
@@ -139,11 +134,11 @@ describe("public address policy", () => {
(error: Error) => error.message,
);
await vi.advanceTimersByTimeAsync(1_000);
expect(await first).toBe("Capture DNS timed out");
expect(await first).toBe("DNS timed out");
await vi.advanceTimersByTimeAsync(8_000);
expect(await Promise.race([second, "still waiting"])).toBe("still waiting");
await vi.advanceTimersByTimeAsync(1_000);
expect(await second).toBe("Capture DNS timed out");
expect(await second).toBe("DNS timed out");
expect(mocks.execFile).toHaveBeenCalledOnce();
expect(mocks.resolve4).toHaveBeenCalledOnce();
} finally {
@@ -206,7 +201,7 @@ describe("refusal class", () => {
const error = await resolvePublicAddress("rebind.example.org").catch((e: unknown) => e);
expect(error).toBeInstanceOf(NonPublicHostError);
expect((error as NonPublicHostError).hostClass).toBe("link-local");
expect((error as Error).message).toBe("Capture DNS returned a non-public address");
expect((error as Error).message).toBe("DNS returned a non-public address");
});
});
@@ -26,9 +26,9 @@ export function isPublicIPv4(address: string): boolean {
return isIP(address) === 4 && !isBlockedNetworkHost(address);
}
const PUBLIC_IPV4 = "Capture requires a public IPv4 address";
const PUBLIC_HOSTNAME = "Capture requires a public hostname";
const PUBLIC_DNS = "Capture DNS returned a non-public address";
const PUBLIC_IPV4 = "Only a public IPv4 address is allowed";
const PUBLIC_HOSTNAME = "Only a public hostname is allowed";
const PUBLIC_DNS = "DNS returned a non-public address";
export type RefusedHostClass = NonPublicIPv4Class | "internal-name" | "ipv6";
@@ -123,7 +123,7 @@ function beforeDeadline<T>(work: Promise<T>, deadline: number): Promise<T> {
let timer: ReturnType<typeof setTimeout> | undefined;
const late = new Promise<never>((_resolve, reject) => {
timer = setTimeout(
() => reject(new Error("Capture DNS timed out")),
() => reject(new Error("DNS timed out")),
Math.max(0, deadline - Date.now()),
);
});
@@ -166,8 +166,8 @@ export function systemLookupInKillableChild(host: string, timeoutMs: number): Pr
env: { ...process.env, NODE_OPTIONS: "" },
},
(error, stdout, stderr) => {
if (error?.killed) reject(new Error("Capture DNS timed out"));
else if (!stdout) reject(new Error(`Capture DNS failed: ${stderr || helperEnded(error)}`));
if (error?.killed) reject(new Error("DNS timed out"));
else if (!stdout) reject(new Error(`DNS failed: ${stderr || helperEnded(error)}`));
else {
try {
resolve(JSON.parse(stdout) as string[]);
@@ -241,11 +241,11 @@ export async function publicRequest(
): Promise<Response> {
const target = new URL(url);
if (!["http:", "https:"].includes(target.protocol) || target.username || target.password) {
throw new Error("Capture requires an HTTP(S) URL without credentials");
throw new Error("Only an HTTP(S) URL without credentials is allowed");
}
const method = (init.method ?? "GET").toUpperCase();
if (!["GET", "HEAD"].includes(method) || init.body != null) {
throw new Error("Capture asset requests support only GET and HEAD without a body");
throw new Error("Public requests support only GET and HEAD without a body");
}
// Video callers budget the entire body transfer; a default must not shorten it.
const signal = init.signal ?? AbortSignal.timeout(30_000);
@@ -308,7 +308,7 @@ function assetResponse(incoming: IncomingMessage, req: ClientRequest, method: st
const headers = responseHeaders(incoming);
const encoding = headers.get("content-encoding")?.toLowerCase();
if (encoding && encoding !== "identity") {
throw new Error("Capture server ignored identity content encoding");
throw new Error("The server ignored identity content encoding");
}
const status = incoming.statusCode ?? 502;
if (method === "HEAD" || [204, 205, 304].includes(status)) {
@@ -338,7 +338,7 @@ function responseBody(incoming: IncomingMessage, req: ClientRequest): ReadableSt
controller.error(error);
};
incoming.once("error", fail);
incoming.once("aborted", () => fail(new Error("Capture response aborted")));
incoming.once("aborted", () => fail(new Error("The response was aborted")));
incoming.pause();
},
pull() {