testing/cross_backend/body_size.ts

Cross-backend parity suite for the request body-size limit.

create_app_server (TS) and the Rust spine both cap the request body at a 1 MiB default (DEFAULT_BODY_LIMIT_BYTES, the same name in TS and in fuz_http; a backend capping its RPC path elsewhere passes rpc_max_body_bytes) and reject oversized payloads with 413 and the canonical flat REST body {error: 'payload_too_large'}. A declared Content-Length over the cap is refused on the header, *before* auth, origin, or dispatch run (middleware step 4). Each impl unit-tests this in isolation; this suite pins the cross-impl agreement on the status + body shape, and on the exact > cap boundary (not an off-by-one divergence). The cases:

  • over-limit POST (cap + 1 byte) → 413 payload_too_large, refused before any handler runs (the limit fires ahead of origin verification + the dispatcher, so an over-cap body is rejected regardless of how well-formed it is). Exactly one byte over — both impls reject on a strict >, so this is the tight upper boundary, and staying just over keeps it clear of any larger framework-default limit that would answer with a different body.
  • at-limit POST (exactly the cap) → not 413 — one byte under the rejection threshold passes the size gate and reaches the dispatcher (the downstream status is irrelevant; only "not size-rejected" is asserted). The boundary sibling of the case above.
  • under-limit POST (small) → 200 — a small, well-formed authenticated account_verify envelope sails through to a successful handler response, the positive control that the route works for normal traffic.
  • The cap answering a declared length ahead of the origin check and auth — over-cap with a disallowed Origin and no credential → 413 — is pinned per transport by the front-door table (transport_composition.ts), beside the under-cap 403 that shows the origin check still runs.
  • over-limit chunked POST (no Content-Length), authenticated → 413 — a body with no declared length is refused by the bytes that arrive.

Implementation-defined, not pinned here. Without a declared length the two spines measure at different points: the TS spine reads the body up to the cap before any later middleware runs, so its 413 comes ahead of the origin check and auth; the Rust spine counts as the handler reads, so a refusal made on the headers (a disallowed Origin) answers first and a handler that never reads the body answers its own status. Only the authenticated, allowed-origin chunked case — where nothing else refuses — has one answer on every backend. A repeated Content-Length with equal values is also the implementation's: the TS spine answers 400 invalid_content_length where its runtime's parser hands the repeat over, and hyper folds it into one value and accepts.

Over a real socket the over-cap cases send no byte the server won't read. A server that caps the body answers 413 and may close the connection with the rest of the upload unread — correct HTTP, since an unread request body can't share a keep-alive socket. A client still uploading then has its write fail (EPIPE) and can lose the 413 the server did send, so a whole over-cap body sent through fetch reads its answer only some of the time. Given a base_url, the suite speaks to the socket directly and holds back what the refusal doesn't need:

  • a declared over-cap length is sent as the request head alone (raw_http_send_head) — Content-Length one over the cap and not one body byte. The 413 must arrive within RAW_HTTP_READ_TIMEOUT_MS, which also pins that the refusal is made on the header: a backend that reads the body before refusing, or has no cap, waits for bytes that never come and fails the case.
  • the chunked body is sent up to one byte past the cap and never terminated (raw_http_exchange). The server has read every byte sent by the time it has counted past the cap, so nothing is left unread, and the 413 must arrive without the body's end.

With base_url: null there is no socket and no such race (the in-process app.request), so the same cases send whole bodies through the fixture's transport. The under-cap cases go through the transport either way.

Like origin/payload rejection, this is middleware-level flat REST — not the JSON-RPC envelope the conformance-table runner expects — so it's an imperative suite, not a conformance_table row. Runs both legs via the shared setup_test protocol: the in-process leg (auth/body_size_parity.db.test.ts, plain gro test) and the cross-process leg (cross_backend/spine_suites.cross.test.ts, the TS spine binaries + Rust testing_spine_stub over real HTTP). The body-size limit is on every spine, so the suite is ungated.

Cited property: docs/security.md §"Body Size Limiting".

view source

Declarations
#

2 declarations

BodySizeCrossTestOptions
#

testing/cross_backend/body_size.ts view source

BodySizeCrossTestOptions import type {BodySizeCrossTestOptions} from '@fuzdev/fuz_app/testing/cross_backend/body_size.js';

Options for the body-size parity suite — the standard RPC-dispatched cross-suite shape (setup_test / rpc_path) plus where the backend's socket is. The limit is on every spine, so no case is capability-gated and the flag bundle is not on the shape.

inheritance

base_url

Base URL the spawned backend is reachable at (e.g. http://localhost:1178), or null for an in-process run, which has no socket. Given a URL, the over-cap cases write to the socket directly and send only the bytes the refusal needs; with null they send whole bodies through the fixture's transport.

Pass the URL whenever the fixture's transport reaches a real socket. null there uploads each whole over-cap body through fetch, where the write races the close that follows the 413 and the case fails some of the time.

type string | null

readonly

rpc_max_body_bytes?

The backend's request-body cap on rpc_path, in bytes — the boundary the cases probe. Default SPINE_BODY_LIMIT_DEFAULT_BYTES; pass the backend's value when it caps its RPC path elsewhere.

type number

readonly

describe_body_size_cross_tests
#

Depends on
#

Imported by
#