testing/middleware_gate_probes.ts

Probes of the middleware gates a route's error map declares: a foreign Origin (403 forbidden_origin), a Host the server doesn't answer to (403 forbidden_host, the Rust spine's host gate), a declared Content-Length one byte over the route's cap (413 payload_too_large), and a Content-Length that isn't a length (400 invalid_content_length).

The map drives which probes a route gets: a gate the route's map doesn't declare — a carved-out path, a backend without the layer, a disabled limit — is not probed. Every probe is a request head with no body and no credential, so the gate answers it before auth, rate limiting or body parsing, and it leaves no state behind.

Over a socket (base_url) each probe is written raw (raw_http_send_head): fetch replaces a caller's Host and Content-Length with its own. In-process the head goes through the fixture's transport, whose Request keeps both headers as given. The unreadable-length probe runs in-process only: over a socket the runtime's HTTP parser (Node's, hyper) refuses such a length with a bodiless 400 of its own before the application sees it, and fetch can't send one. In-process the length reaches the body limit unparsed, and the 400 is the limit's own — the answer a Bun server gives when a request repeats an equal Content-Length, which Bun hands over joined into one value.

describe_standard_integration_tests runs one per declared gate of each route it counts and records each answer in its error coverage.

view source

Declarations
#

10 declarations

assert_middleware_gate_refusal
#

testing/middleware_gate_probes.ts view source

(probe: MiddlewareGateProbe, response: Response, collector: ErrorCoverageCollector, route_specs: RouteSpec[]): Promise<...> import {assert_middleware_gate_refusal} from '@fuzdev/fuz_app/testing/middleware_gate_probes.js';

Assert a probe was refused as its route declares, then record the refusal in collector, which checks the body against the route's map.

probe

the probe sent

response

its response

type Response

collector

the error coverage to record the refusal in

route_specs

the routes the collector resolves the path against

type RouteSpec[]

returns

Promise<void>

throws

  • AssertionError - when the response's status or `error` code isn't the declared refusal, or its body is off the route's map

mutates

  • collector — records the probe's route, status and code

format_middleware_gate_probe
#

GATE_PROBE_FOREIGN_HOST
#

testing/middleware_gate_probes.ts view source

"gate-probe.invalid" import {GATE_PROBE_FOREIGN_HOST} from '@fuzdev/fuz_app/testing/middleware_gate_probes.js';

The Host the host probe sends — neither loopback nor named by an allowed origin.

GATE_PROBE_FOREIGN_ORIGIN
#

testing/middleware_gate_probes.ts view source

"https://gate-probe.invalid" import {GATE_PROBE_FOREIGN_ORIGIN} from '@fuzdev/fuz_app/testing/middleware_gate_probes.js';

The Origin the origin probe sends — no allowlist names it.

GATE_PROBE_UNREADABLE_LENGTH
#

MiddlewareGateProbe
#

testing/middleware_gate_probes.ts view source

MiddlewareGateProbe import type {MiddlewareGateProbe} from '@fuzdev/fuz_app/testing/middleware_gate_probes.js';

One probe: a request head a route's declared gate must refuse with expected.

method

type RouteMethod

readonly

path

The route's path, a template with no params among the routes probed.

type string

readonly

expected

The refusal the route's error map declares for the gate.

type RestErrorDef<number, string, SchemaEntries>

readonly

headers

Request headers beyond Host and Content-Length.

type Readonly<Record<string, string>>

readonly

host

The Host to send, null for the backend's own.

type string | null

readonly

content_length

The Content-Length to declare; no body byte is sent.

type number | string

readonly

MiddlewareGateProbePlanOptions
#

testing/middleware_gate_probes.ts view source

MiddlewareGateProbePlanOptions import type {MiddlewareGateProbePlanOptions} from '@fuzdev/fuz_app/testing/middleware_gate_probes.js';

route_specs

The routes to probe, each a path with no params.

type readonly RouteSpec[]

readonly

route_error_maps

Each route's error map, middleware included (AppSurfaceSpec.route_error_maps).

type ReadonlyMap<string, RouteErrorMap> | null

readonly

base_url

The backend's base URL, or null in-process. Without a socket the unreadable-length probe is planned too.

type string | null

readonly

max_body_bytes?

The request-body cap on every route but rpc_path, in bytes.

type number

readonly
default SPINE_BODY_LIMIT_DEFAULT_BYTES

rpc_path

The RPC endpoint's path, whose cap is rpc_max_body_bytes.

type string

readonly

rpc_max_body_bytes?

The request-body cap on rpc_path, in bytes.

type number

readonly
default max_body_bytes

MiddlewareGateProbeTransport
#

testing/middleware_gate_probes.ts view source

MiddlewareGateProbeTransport import type {MiddlewareGateProbeTransport} from '@fuzdev/fuz_app/testing/middleware_gate_probes.js';

The in-process transport a probe is sent through.

(call)

type (url: string, init: RequestInit): Promise<Response>

url

type string

init

type RequestInit
returns Promise<Response>

plan_middleware_gate_probes
#

testing/middleware_gate_probes.ts view source

(options: MiddlewareGateProbePlanOptions): MiddlewareGateProbe[] import {plan_middleware_gate_probes} from '@fuzdev/fuz_app/testing/middleware_gate_probes.js';

Plan the gate probes of each route: one per gate its error map declares, in route order.

options

the routes, their maps, the socket and the caps

returns

MiddlewareGateProbe[]

the probes, none for a gate a route's map doesn't declare

throws

  • Error - when a route's path has a param or a wildcard segment, which a probe would send as the literal template

send_middleware_gate_probe
#

testing/middleware_gate_probes.ts view source

(probe: MiddlewareGateProbe, base_url: string | null, transport: MiddlewareGateProbeTransport | null): Promise<Response> import {send_middleware_gate_probe} from '@fuzdev/fuz_app/testing/middleware_gate_probes.js';

Send a probe: over the socket when there is one, else through transport.

probe

the probe

base_url

the backend's base URL, or null in-process

type string | null

transport

the in-process transport, read only without a base_url

type (MiddlewareGateProbeTransport) | null

returns

Promise<Response>

the response, its body JSON when the server sent JSON

throws

  • Error - when an unreadable length is to go over a socket, or no transport is given in-process

Depends on
#

Imported by
#