testing/attack_surface.ts

Adversarial auth enforcement test runners and the standard attack surface suite.

The combinatorial test runner (describe_adversarial_auth) generates test suites for routes x auth levels. The standard suite (describe_standard_attack_surface_tests) composes all attack surface test groups into a single call.

Stubs, app factories, and assertion helpers live in focused submodules:

  • test_auth_stubs — stub factories and pre-built dep bundles
  • test_auth_apps — auth-level test app factories
  • test_auth_assertions — snapshot, public route, and middleware assertions
view source

Declarations
#

4 declarations

AdversarialTestOptions
#

testing/attack_surface.ts view source

AdversarialTestOptions import type {AdversarialTestOptions} from '@fuzdev/fuz_app/testing/attack_surface.js';

Options for adversarial test runners (auth enforcement and input validation).

build

Build the app surface bundle (surface + route specs + middleware specs).

type (): AppSurfaceSpec

roles

All roles in the app (e.g. ['admin', 'keeper']).

type string[]

skip_routes?

Routes to skip, in 'METHOD /path' form (the surface key) — the escape hatch every sibling suite carries. Reach for it only when a route cannot be driven generically at all (a handler needing real seeded state, a path segment no schema can describe); a route whose params merely have a format is handled by the synthesizer.

type string[]

param_values?

Path param values for specific routes ('METHOD /path' → param name → value), used before the generated ones — needed for a {re} param whose pattern refuses the generated value. See RouteParamValues.

type Readonly<Record<string, Readonly<Record<string, string>>>>

describe_adversarial_auth
#

testing/attack_surface.ts view source

(options: AdversarialTestOptions): void import {describe_adversarial_auth} from '@fuzdev/fuz_app/testing/attack_surface.js';

Generate adversarial HTTP auth enforcement test suites.

Describe blocks:

  • unauthenticated → 401 — every protected route
  • wrong role → 403 — every role route the role apps' session credential reaches, tested with all non-matching roles
  • authenticated without role → 403 — the same routes, no-role context
  • credential-gated routes reject a disallowed credential → 403 — every route declaring auth.credential_types, probed on a channel it refuses
  • correct auth passes guard — every protected route, assert not 401/403

options

returns

void

describe_standard_attack_surface_tests
#

testing/attack_surface.ts view source

(options: StandardAttackSurfaceOptions): void import {describe_standard_attack_surface_tests} from '@fuzdev/fuz_app/testing/attack_surface.js';

Run the standard attack surface test suite.

Test groups:

  1. Snapshot — live surface matches committed JSON
  2. Determinism — building twice yields identical results
  3. Public routes — bidirectional check (no unexpected, no missing)
  4. Middleware stack — every API route has the full middleware chain
  5. Surface invariants — structural assertions over surface.routes (error schemas, descriptions, duplicates, consistency)
  6. RPC/WS surface invariants — structural assertions over surface.rpc_endpoints + surface.ws_endpoints (descriptions, protocol-action spread, kind ⇔ auth)
  7. Security policy — rate limiting on sensitive routes, no unexpected public mutations, method conventions
  8. Adversarial auth — unauthenticated/wrong-role/correct-auth enforcement, every refusal a status and code of the route's own error map
  9. Adversarial input — input body and params validation, each 400 a code of the route's own map
  10. Adversarial 404 — stub 404 handlers, validate response bodies against the route's declared 404

Consumer test files call this with project-specific options, then add any project-specific assertions in additional describe blocks.

options

returns

void

StandardAttackSurfaceOptions
#

testing/attack_surface.ts view source

StandardAttackSurfaceOptions import type {StandardAttackSurfaceOptions} from '@fuzdev/fuz_app/testing/attack_surface.js';

Options for the standard attack surface test suite.

build

Build the app surface bundle (surface + route specs + middleware specs).

type (): AppSurfaceSpec

snapshot_path

Absolute path to the committed snapshot JSON file.

type string

expected_public_routes

Expected public routes, e.g. ['GET /health', 'POST /api/account/login'].

type string[]

expected_api_middleware

Expected middleware names for API routes, e.g. ['trusted_proxy', 'origin', 'session', 'request_context', 'bearer_auth'].

type string[]

roles

All roles in the app (e.g. ['admin', 'keeper']).

type string[]

api_path_prefix?

Path prefix for middleware stack assertion. Default '/api/'.

type string

security_policy?

Security policy configuration. Omit for sensible defaults.

type SurfaceSecurityPolicyOptions

skip_routes?

Routes the three adversarial sub-suites skip, in 'METHOD /path' form — the escape hatch every sibling suite carries (round_trip, data_exposure). Reach for it only when a route cannot be driven generically at all; a route whose path params merely carry a format is handled by the params-schema-aware synthesizer.

type string[]

param_values?

Path param values for the three adversarial sub-suites, by route key and then param name. See AdversarialTestOptions.param_values.

type Readonly<Record<string, Readonly<Record<string, string>>>>

Depends on
#

Imported by
#