Files
SnapOtter/tests/unit/api/ssrf-response.test.ts
T
SnapOtterandGitHub ae6a4c8b7c fix: error-only Sentry telemetry, storm-proof capture, and crash fixes (#476)
Removes Sentry tracing entirely (BullMQ idle polling burned 4.8M transactions in 2 days at the baked 0.1 rate), decouples PostHog sampling, and replaces the type-only error scrub with a vetted-field sanitizer plus SafeError/ToolInputError contracts. One classified capture path with per-signature throttles and a per-process ceiling makes storms impossible (NODE-1E was 4,541 events from one 30s loop). Browser errors move to a dedicated web Sentry project with their own source maps. Adds the SNAPOTTER_TELEMETRY runtime kill switch and silences test fleets.

Crash fixes: remote 204/304 SSRF process kill (NODE-20), conversion-preset boot crash loop (NODE-21), Redis version preflight + unhandled subscribe rejection (NODE-1T), Sign PDF on plain-http origins (NODE-1K/1M), wavesurfer/pdf.js teardown rejections (NODE-1P/1N), bundle-import ZlibError to 400 (NODE-1Z), chart-maker input errors declassified (NODE-1H/1J), asset requests skip the session DB lookup (NODE-1D).
2026-07-10 21:41:49 +08:00

24 lines
1.0 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { toFetchResponse } from "../../../apps/api/src/lib/ssrf.js";
describe("toFetchResponse", () => {
it("null-body statuses never throw, even with a body buffer", async () => {
for (const status of [204, 304, 205]) {
const res = toFetchResponse(Buffer.from("stray body"), status, "", new Headers());
expect(res.status).toBe(status);
expect(await res.text()).toBe("");
}
});
it("clamps out-of-range statuses to 502", () => {
expect(toFetchResponse(Buffer.alloc(0), 100, "", new Headers()).status).toBe(502);
expect(toFetchResponse(Buffer.alloc(0), 700, "", new Headers()).status).toBe(502);
expect(toFetchResponse(Buffer.alloc(0), undefined, "", new Headers()).status).toBe(502);
});
it("passes normal responses through", async () => {
const res = toFetchResponse(Buffer.from("ok"), 200, "OK", new Headers({ "x-a": "b" }));
expect(res.status).toBe(200);
expect(await res.text()).toBe("ok");
expect(res.headers.get("x-a")).toBe("b");
});
});