Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

test(http): expect 413 for a body the budget can never admit

Yudhi Armyndharisf1bf9835668b
diff --git a/test/configure-app.e2e-spec.ts b/test/configure-app.e2e-spec.ts
index d9da8074a..643ad8b84 100644
--- a/test/configure-app.e2e-spec.ts
+++ b/test/configure-app.e2e-spec.ts
@@ -205,9 +205,11 @@ describe('production HTTP surface (configureApp)', () => {
expect(omittedOn).not.toMatch(/malformed/i);
});
- it('refuses a declared body over the aggregate in-flight budget with 503, a different layer', async () => {
+ it('refuses a declared body the in-flight budget can never admit with 413, before reading it', async () => {
// The budget is a PRE-guard: it answers on the DECLARED length, before the parser reads a byte,
- // which is what stops slow-body memory pinning that no route guard can reach. Asserting it by
+ // which is what stops slow-body memory pinning that no route guard can reach. A declared size the
+ // whole budget can never hold gets 413 without Retry-After, since retrying cannot help; a body that
+ // fits once the budget frees gets 503 + Retry-After (the tiers suite below). Asserting it by
// actually uploading an oversized body is timing-dependent: the server refuses and destroys
// the socket while the client is still writing, so the client sees ECONNRESET instead of the
// response often enough to flake. Declaring the size and sending almost nothing tests the same
@@ -221,8 +223,8 @@ describe('production HTTP surface (configureApp)', () => {
.timeout({ deadline: 5000, response: 5000 })
.send('{}');
- expect(res.status).toBe(503);
- expect(res.headers['retry-after']).toBeDefined();
+ expect(res.status).toBe(413);
+ expect(res.headers['retry-after']).toBeUndefined();
});
it('refuses a DELETE whose path ends in a slash instead of matching the route without it', async () => {
@@ -284,7 +286,7 @@ describe('production HTTP surface (configureApp)', () => {
await post().set('Content-Encoding', 'gzip').send('{}'),
];
- expect(rejections.map(res => res.status)).toEqual([400, 413, 503, 415]);
+ expect(rejections.map(res => res.status)).toEqual([400, 413, 413, 415]);
for (const res of rejections) {
// Without the CORS header a cross-origin browser sees an opaque network error, not the status.
expect(res.headers['access-control-allow-origin']).toBe('https://allowed.example');
@@ -341,6 +343,7 @@ describe('in-flight body budget tiers (configureApp)', () => {
.set('Content-Type', 'application/json')
.send({ small: true });
expect(anonymous.status).toBe(503);
+ expect(anonymous.headers['retry-after']).toBeDefined();
const keyed = await request(app.getHttpServer())
.post('/api/echo')