fix(e2e): harden kitchen sink probe body caps

This commit is contained in:
Vincent Koc
2026-05-29 20:12:23 +02:00
parent 75ef73d4f7
commit 18d2bc441c
2 changed files with 71 additions and 4 deletions

View File

@@ -636,6 +636,56 @@ describe("kitchen-sink RPC process sampling", () => {
});
});
it("rejects oversized HTTP probe responses before reading declared large bodies", async () => {
let canceled = false;
const response = new Response(
new ReadableStream({
cancel() {
canceled = true;
},
}),
{
headers: {
"content-length": "1025",
},
},
);
await expect(readBoundedResponseText(response, 1024)).rejects.toMatchObject({
code: "ETOOBIG",
message: "fetch response body exceeded 1024 bytes",
});
expect(canceled).toBe(true);
});
it("bounds HTTP probe response bodies without a readable stream", async () => {
const response = {
headers: new Headers(),
text: vi.fn(async () => "x".repeat(1025)),
};
await expect(readBoundedResponseText(response, 1024)).rejects.toMatchObject({
code: "ETOOBIG",
message: "fetch response body exceeded 1024 bytes",
});
expect(response.text).toHaveBeenCalledTimes(1);
});
it("rejects declared large HTTP probe responses without a readable stream", async () => {
const response = {
headers: new Headers({
"content-length": "1025",
}),
text: vi.fn(async () => "not read"),
};
await expect(readBoundedResponseText(response, 1024)).rejects.toMatchObject({
code: "ETOOBIG",
message: "fetch response body exceeded 1024 bytes",
});
expect(response.text).not.toHaveBeenCalled();
});
it("reads bounded response streams", async () => {
await expect(readBoundedResponseText(new Response('{"status":"live"}'), 1024)).resolves.toBe(
'{"status":"live"}',