@fuzdev/fuz_app 0.163.0 → 0.165.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/actions/action_event_data.d.ts +1 -1
- package/dist/actions/action_rpc.d.ts.map +1 -1
- package/dist/actions/action_rpc.js +4 -0
- package/dist/actions/action_spec.d.ts +3 -3
- package/dist/actions/action_spec.d.ts.map +1 -1
- package/dist/auth/CLAUDE.md +1 -1
- package/dist/auth/account_route_schema.d.ts +3 -27
- package/dist/auth/account_route_schema.d.ts.map +1 -1
- package/dist/auth/account_route_schema.js +6 -20
- package/dist/auth/admin_action_specs.d.ts +56 -56
- package/dist/auth/audit_log_route_schema.d.ts +1 -1
- package/dist/auth/audit_log_route_schema.d.ts.map +1 -1
- package/dist/auth/audit_log_route_schema.js +4 -5
- package/dist/auth/audit_log_schema.d.ts +18 -18
- package/dist/auth/bootstrap_route_schema.d.ts +1 -30
- package/dist/auth/bootstrap_route_schema.d.ts.map +1 -1
- package/dist/auth/bootstrap_route_schema.js +3 -8
- package/dist/auth/daemon_token.d.ts +4 -4
- package/dist/auth/daemon_token.d.ts.map +1 -1
- package/dist/auth/daemon_token.js +3 -3
- package/dist/auth/daemon_token_middleware.d.ts +1 -1
- package/dist/auth/daemon_token_middleware.d.ts.map +1 -1
- package/dist/auth/daemon_token_middleware.js +5 -5
- package/dist/auth/middleware.js +4 -4
- package/dist/auth/role_grant_offer_action_specs.d.ts +2 -2
- package/dist/auth/signup_route_schema.d.ts.map +1 -1
- package/dist/auth/signup_route_schema.js +3 -7
- package/dist/db/CLAUDE.md +2 -1
- package/dist/db/file_fact_url.d.ts +11 -6
- package/dist/db/file_fact_url.d.ts.map +1 -1
- package/dist/db/file_fact_url.js +5 -5
- package/dist/db/schema_ready.d.ts +0 -5
- package/dist/db/schema_ready.d.ts.map +1 -1
- package/dist/db/schema_ready.js +0 -5
- package/dist/http/CLAUDE.md +105 -71
- package/dist/http/auth_shape.d.ts +48 -29
- package/dist/http/auth_shape.d.ts.map +1 -1
- package/dist/http/auth_shape.js +12 -85
- package/dist/http/body_limit.d.ts +12 -0
- package/dist/http/body_limit.d.ts.map +1 -1
- package/dist/http/body_limit.js +15 -0
- package/dist/http/body_limit_schema.d.ts +20 -0
- package/dist/http/body_limit_schema.d.ts.map +1 -0
- package/dist/http/body_limit_schema.js +20 -0
- package/dist/http/common_routes.d.ts +1 -1
- package/dist/http/common_routes.d.ts.map +1 -1
- package/dist/http/common_routes.js +11 -14
- package/dist/http/db_routes.d.ts.map +1 -1
- package/dist/http/db_routes.js +59 -69
- package/dist/http/dev_route_error_check.d.ts +70 -0
- package/dist/http/dev_route_error_check.d.ts.map +1 -0
- package/dist/http/dev_route_error_check.js +119 -0
- package/dist/http/error_schemas.d.ts +365 -189
- package/dist/http/error_schemas.d.ts.map +1 -1
- package/dist/http/error_schemas.js +256 -149
- package/dist/http/health_schema.d.ts +10 -6
- package/dist/http/health_schema.d.ts.map +1 -1
- package/dist/http/health_schema.js +3 -3
- package/dist/http/middleware_spec.d.ts +8 -3
- package/dist/http/middleware_spec.d.ts.map +1 -1
- package/dist/http/origin.d.ts +12 -43
- package/dist/http/origin.d.ts.map +1 -1
- package/dist/http/origin.js +10 -6
- package/dist/http/route_error_check.d.ts +179 -0
- package/dist/http/route_error_check.d.ts.map +1 -0
- package/dist/http/route_error_check.js +283 -0
- package/dist/http/route_errors.d.ts +80 -0
- package/dist/http/route_errors.d.ts.map +1 -0
- package/dist/http/route_errors.js +83 -0
- package/dist/http/route_spec.d.ts +33 -17
- package/dist/http/route_spec.d.ts.map +1 -1
- package/dist/http/route_spec.js +48 -62
- package/dist/http/schema_helpers.d.ts +15 -34
- package/dist/http/schema_helpers.d.ts.map +1 -1
- package/dist/http/schema_helpers.js +11 -47
- package/dist/http/surface.d.ts +19 -12
- package/dist/http/surface.d.ts.map +1 -1
- package/dist/http/surface.js +25 -38
- package/dist/http/surface_query.d.ts +11 -2
- package/dist/http/surface_query.d.ts.map +1 -1
- package/dist/http/surface_query.js +7 -1
- package/dist/primitive_schemas_fuz.d.ts +17 -3
- package/dist/primitive_schemas_fuz.d.ts.map +1 -1
- package/dist/primitive_schemas_fuz.js +13 -3
- package/dist/rate_limiter.d.ts +13 -0
- package/dist/rate_limiter.d.ts.map +1 -1
- package/dist/rate_limiter.js +20 -2
- package/dist/schema_issues.d.ts +29 -11
- package/dist/schema_issues.d.ts.map +1 -1
- package/dist/schema_issues.js +11 -10
- package/dist/schema_meta.d.ts +8 -1
- package/dist/schema_meta.d.ts.map +1 -1
- package/dist/schema_meta.js +2 -1
- package/dist/server/app_server.d.ts +3 -1
- package/dist/server/app_server.d.ts.map +1 -1
- package/dist/server/app_server.js +24 -10
- package/dist/server/serve_fact_route.d.ts.map +1 -1
- package/dist/server/serve_fact_route.js +8 -31
- package/dist/server/surface_route.d.ts.map +1 -1
- package/dist/server/surface_route.js +5 -6
- package/dist/server/x_accel.d.ts +12 -7
- package/dist/server/x_accel.d.ts.map +1 -1
- package/dist/server/x_accel.js +7 -9
- package/dist/testing/CLAUDE.md +105 -61
- package/dist/testing/admin_integration.js +2 -2
- package/dist/testing/adversarial_404.d.ts +4 -18
- package/dist/testing/adversarial_404.d.ts.map +1 -1
- package/dist/testing/adversarial_404.js +20 -52
- package/dist/testing/adversarial_headers.d.ts +3 -4
- package/dist/testing/adversarial_headers.d.ts.map +1 -1
- package/dist/testing/adversarial_headers.js +8 -6
- package/dist/testing/adversarial_input.d.ts.map +1 -1
- package/dist/testing/adversarial_input.js +20 -19
- package/dist/testing/assertions.d.ts +46 -14
- package/dist/testing/assertions.d.ts.map +1 -1
- package/dist/testing/assertions.js +73 -16
- package/dist/testing/attack_surface.d.ts +17 -35
- package/dist/testing/attack_surface.d.ts.map +1 -1
- package/dist/testing/attack_surface.js +36 -95
- package/dist/testing/auth_apps.d.ts.map +1 -1
- package/dist/testing/auth_apps.js +2 -1
- package/dist/testing/cross_backend/action_manifest.d.ts +126 -56
- package/dist/testing/cross_backend/action_manifest.d.ts.map +1 -1
- package/dist/testing/cross_backend/action_manifest.js +11 -11
- package/dist/testing/cross_backend/action_manifest_parity.d.ts +1 -1
- package/dist/testing/cross_backend/action_manifest_parity.d.ts.map +1 -1
- package/dist/testing/cross_backend/cell_crud.d.ts.map +1 -1
- package/dist/testing/cross_backend/cell_crud.js +2 -1
- package/dist/testing/cross_backend/conformance_table.js +1 -1
- package/dist/testing/cross_backend/fact_serving.js +3 -3
- package/dist/testing/cross_backend/in_process_setup.d.ts +7 -3
- package/dist/testing/cross_backend/in_process_setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/in_process_setup.js +11 -4
- package/dist/testing/cross_backend/origin_conformance.d.ts +278 -102
- package/dist/testing/cross_backend/origin_conformance.d.ts.map +1 -1
- package/dist/testing/cross_backend/origin_conformance.js +21 -21
- package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts.map +1 -1
- package/dist/testing/cross_backend/rust_spine_consumer_surface.js +7 -1
- package/dist/testing/cross_backend/setup.d.ts +13 -0
- package/dist/testing/cross_backend/setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/setup.js +24 -7
- package/dist/testing/cross_backend/spine_suites.d.ts +3 -2
- package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
- package/dist/testing/cross_backend/spine_suites.js +5 -2
- package/dist/testing/cross_backend/standard.d.ts +31 -0
- package/dist/testing/cross_backend/standard.d.ts.map +1 -1
- package/dist/testing/cross_backend/standard.js +9 -3
- package/dist/testing/cross_backend/testing_origin_check.d.ts +147 -71
- package/dist/testing/cross_backend/testing_origin_check.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_origin_check.js +16 -13
- package/dist/testing/cross_backend/testing_reset_actions.d.ts +70 -27
- package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
- package/dist/testing/data_exposure.d.ts +7 -0
- package/dist/testing/data_exposure.d.ts.map +1 -1
- package/dist/testing/data_exposure.js +8 -7
- package/dist/testing/error_coverage.d.ts +53 -61
- package/dist/testing/error_coverage.d.ts.map +1 -1
- package/dist/testing/error_coverage.js +86 -119
- package/dist/testing/integration.d.ts +28 -1
- package/dist/testing/integration.d.ts.map +1 -1
- package/dist/testing/integration.js +54 -29
- package/dist/testing/integration_helpers.d.ts +37 -9
- package/dist/testing/integration_helpers.d.ts.map +1 -1
- package/dist/testing/integration_helpers.js +75 -40
- package/dist/testing/middleware.d.ts +3 -5
- package/dist/testing/middleware.d.ts.map +1 -1
- package/dist/testing/middleware.js +5 -4
- package/dist/testing/middleware_gate_probes.d.ts +90 -0
- package/dist/testing/middleware_gate_probes.d.ts.map +1 -0
- package/dist/testing/middleware_gate_probes.js +179 -0
- package/dist/testing/rate_limiting.d.ts +1 -1
- package/dist/testing/rate_limiting.d.ts.map +1 -1
- package/dist/testing/rate_limiting.js +5 -4
- package/dist/testing/round_trip.d.ts +7 -0
- package/dist/testing/round_trip.d.ts.map +1 -1
- package/dist/testing/round_trip.js +8 -5
- package/dist/testing/schema_generators.d.ts +40 -11
- package/dist/testing/schema_generators.d.ts.map +1 -1
- package/dist/testing/schema_generators.js +71 -17
- package/dist/testing/stubs.d.ts +10 -1
- package/dist/testing/stubs.d.ts.map +1 -1
- package/dist/testing/stubs.js +15 -5
- package/dist/testing/surface_invariants.d.ts +36 -115
- package/dist/testing/surface_invariants.d.ts.map +1 -1
- package/dist/testing/surface_invariants.js +106 -269
- package/dist/testing/transports/raw_http.d.ts +10 -2
- package/dist/testing/transports/raw_http.d.ts.map +1 -1
- package/dist/testing/transports/raw_http.js +10 -4
- package/dist/ui/CLAUDE.md +4 -2
- package/dist/ui/auth_state.svelte.d.ts.map +1 -1
- package/dist/ui/auth_state.svelte.js +2 -8
- package/dist/ui/backend_probe.svelte.js +3 -3
- package/dist/ui/table_state.svelte.d.ts.map +1 -1
- package/dist/ui/table_state.svelte.js +1 -8
- package/dist/ui/ui_fetch.d.ts +12 -2
- package/dist/ui/ui_fetch.d.ts.map +1 -1
- package/dist/ui/ui_fetch.js +22 -4
- package/package.json +1 -1
package/dist/testing/CLAUDE.md
CHANGED
|
@@ -38,7 +38,7 @@ time (never runtime), where a throwing guard would break `vite build`.
|
|
|
38
38
|
- `create_stub_api_middleware({include_daemon_token?, origin_carve_outs?})` — stub `MiddlewareSpec[]` matching `create_auth_middleware_specs`'s output (origin, optional daemon_token, session, request_context, bearer_auth) for surface generation without booting real auth — the same names, paths, order, and declared `errors` (`origin` declares a 403; `bearer_auth` and `daemon_token` declare none, since both soft-fail through `next()`), pinned against the real factory by `auth/middleware.mounted.test.ts`. The surface merges middleware errors into every route under the path, so a stub declaring more would widen the test surface with statuses the live server never returns. Each spec gets its own pass-through handler (not the shared `stub_mw`), so `assert_middleware_stack_mounted` tells the layers apart. See `auth/CLAUDE.md` §Middleware for the real stack.
|
|
39
39
|
- `create_stub_app_backend(options?)` — stub `AppBackend` with no database: `create_stub_app_deps()` (or `options.deps`), no migration results, a `close` that does nothing (or `options.close`). For assembling a server in tests that never reach the database.
|
|
40
40
|
- `create_stub_app_server_context(session_options)` — stub `AppServerContext` over `create_stub_app_backend()`; rate limiters null, `bootstrap_status.available: false`.
|
|
41
|
-
- `create_test_app_surface_spec(options)` — builds an `AppSurfaceSpec` mirroring `create_app_server`'s route assembly, in its order (consumer routes, then bootstrap routes, RPC endpoint routes, and `GET /api/surface`, + stub middleware + surface generation). `GET /api/surface` is listed only with `surface_route: true`, as `create_app_server` mounts it only when opted in — pass the same value to both so the surface-derived suites probe it exactly when the live server serves it. `daemon_token: true` lists the `daemon_token` layer `create_app_server` mounts when given a `daemon_token_state` (`create_test_app` always passes one, and `default_in_process_suite_options` sets it, along with `app_options.surface_route`); `testing/test_app_server.db.test.ts` pins the stub's routes (order, auth, error schemas, applicable middleware) and middleware names against `create_test_app`'s for every `surface_route` setting. Its middleware list mirrors the real one — a stub `trusted_proxy` spec at `'*'`, then the stub auth stack — so every route's `applicable_middleware` starts with `trusted_proxy` (a route outside `/api/*` lists `['trusted_proxy', 'origin']`, since the origin check covers every path, and a route under an origin carve-out drops `origin`), as on the live server
|
|
41
|
+
- `create_test_app_surface_spec(options)` — builds an `AppSurfaceSpec` mirroring `create_app_server`'s route assembly, in its order (consumer routes, then bootstrap routes, RPC endpoint routes, and `GET /api/surface`, + stub middleware + surface generation). `GET /api/surface` is listed only with `surface_route: true`, as `create_app_server` mounts it only when opted in — pass the same value to both so the surface-derived suites probe it exactly when the live server serves it. `daemon_token: true` lists the `daemon_token` layer `create_app_server` mounts when given a `daemon_token_state` (`create_test_app` always passes one, and `default_in_process_suite_options` sets it, along with `app_options.surface_route`); `testing/test_app_server.db.test.ts` pins the stub's routes (order, auth, error schemas, applicable middleware) and middleware names against `create_test_app`'s for every `surface_route` setting. Its middleware list mirrors the real one — the body limit's shape at `'*'` (`body_limit_middleware_shape` with a stub handler, left out with `max_body_size: null`), a stub `trusted_proxy` spec at `'*'`, then the stub auth stack — so every route's `applicable_middleware` starts with `body_limit`, `trusted_proxy` (a route outside `/api/*` lists `['body_limit', 'trusted_proxy', 'origin']`, since the origin check covers every path, and a route under an origin carve-out drops `origin`), as on the live server, and every route's error map carries the limit's 413 and 400 and the origin check's 403 `forbidden_origin`. `CreateTestAppSurfaceSpecOptions`: `session_options`, `create_route_specs`, `env_schema?`, `event_specs?`, `rpc_endpoints?`, `ws_endpoints?`, `allowed_origins?`, `origin_carve_outs?`, `transform_middleware?`, `bootstrap?`, `surface_route?`, `daemon_token?`, `max_body_size?`. Throws, like `create_app_server`, on an endpoint path outside `AUTH_MIDDLEWARE_PATH` (`assert_endpoint_in_auth_scope`), on a route that reads or mints a credential outside it (`assert_credential_routes_in_auth_scope`), on an origin carve-out that overlaps that scope (`assert_origin_carve_outs_valid`), and on a `transform_middleware` that moves, drops, duplicates, reorders, wraps, or replaces the stub proxy spec or a stub auth spec (`assert_middleware_stack_mounted`); the transform receives shallow copies in a fresh array, so an in-place mutation can't slip past the check. Throws on a `ws_endpoints` spec with no `allowed_origins` of its own when no `allowed_origins` option is given (there is no server list to default from). Bootstrap is opt-in (symmetric with `create_app_server` — omit to skip; pass the same value as prod to mount routes at `bootstrap.route_prefix ?? '/api/account'`). Single source of truth for attack-surface tests — track `create_app_server` wiring changes here.
|
|
42
42
|
|
|
43
43
|
Throwing stubs surface mock escape: a test that accidentally reaches into
|
|
44
44
|
stub territory breaks immediately with a label-scoped error rather than
|
|
@@ -416,9 +416,10 @@ or Postgres and runs in the `cross-ts` CI job.
|
|
|
416
416
|
- `assert_surface_matches_snapshot(surface, path)` — compares live `AppSurface` against a committed JSON snapshot; failure message instructs `gro gen`.
|
|
417
417
|
- `assert_surface_deterministic(build_surface)` — build twice, `deepStrictEqual` results; catches nondeterminism in surface generation.
|
|
418
418
|
- `assert_only_expected_public_routes(surface, list)` — bidirectional: no unexpected public routes, no missing expected ones. Format: `['GET /health', 'POST /api/account/login']`.
|
|
419
|
-
- `assert_full_middleware_stack(surface, prefix, mws)` — every route under `prefix` has exactly `mws` as its middleware chain.
|
|
420
|
-
- `get_route_error_schema(lookup, route, status)` — reads
|
|
421
|
-
- `assert_error_schema_valid(lookup, route, status, body)` — assert
|
|
419
|
+
- `assert_full_middleware_stack(surface, prefix, mws)` — every route under `prefix` has exactly `mws` as its middleware chain, less each layer that carves it out (a layer whose `path` and one of whose `carve_outs` apply to the route, `middleware_carves_out`, with no other layer of its name running there) — the rule `applicable_middleware` and the route error map read. A route missing a layer no carve-out explains fails, and so does a carved-out route still listing it.
|
|
420
|
+
- `get_route_error_schema(lookup, route, status)` — reads the route's error map (`lookup` is `AppSurfaceSpec.route_error_maps`) at a status, a fuz_schema schema.
|
|
421
|
+
- `assert_error_schema_valid(lookup, route, status, body)` — assert the route declares the status, and the body parses against the status's schema (`parse_any`), a union of its definitions' `literal(code)` bodies, so a code the route doesn't declare at the status fails the parse; a mismatch throws an `Error` carrying the issues. Every adversarial refusal runs through it.
|
|
422
|
+
- `assert_error_response_declared(errors, jsonrpc, response, label)` — a JSON error response (400 and up) is one the route's map declares, by `check_route_error` (the DEV error check's rule: 500 `internal_error` / 503 `service_unavailable` always accepted, a JSON-RPC envelope on a `jsonrpc` route skipped, a success or non-JSON response passing); what the attack-surface suite's `correct auth passes guard` holds each answer to.
|
|
422
423
|
|
|
423
424
|
### `surface_invariants.ts` — structural + policy invariants
|
|
424
425
|
|
|
@@ -431,10 +432,10 @@ Structural invariants (options-free, universal):
|
|
|
431
432
|
- `assert_query_routes_declare_400` — every route with query has 400.
|
|
432
433
|
- `assert_descriptions_present` — every route has a non-empty description.
|
|
433
434
|
- `assert_no_duplicate_routes` — no duplicate method+path pairs.
|
|
434
|
-
- `assert_middleware_errors_propagated` — every middleware-declared error status appears on every applicable route.
|
|
435
|
-
- `
|
|
436
|
-
- `
|
|
437
|
-
- `
|
|
435
|
+
- `assert_middleware_errors_propagated` — every middleware-declared error status appears on every applicable route. Holds by construction on a generated surface (the route error map unions the layers); it checks a snapshot or a hand-built surface.
|
|
436
|
+
- `assert_error_codes_specific` — every declared error body (each union branch, routes and middleware) has an `error` that is a `const` or an `enum` — a definition built by `rest_error`; the one tightness invariant.
|
|
437
|
+
- `assert_error_codes_well_formed` — every declared `error` code matches `REST_ERROR_CODE_PATTERN` (`^[a-z][a-z0-9_]*$`): a code, never prose, which goes in `message`.
|
|
438
|
+
- `assert_error_code_status_consistency` — the same `const` error code (a definition's `literal`) never appears at two different HTTP statuses, read through every `anyOf` / `oneOf` branch.
|
|
438
439
|
|
|
439
440
|
RPC / WS structural invariants (options-free, apply over `surface.rpc_endpoints`
|
|
440
441
|
|
|
@@ -458,14 +459,6 @@ Policy invariants (configurable, sensible defaults):
|
|
|
458
459
|
- `assert_mutation_routes_use_post` — routes with input schemas must not be GET (bypasses browser GET idempotency assumptions).
|
|
459
460
|
- `assert_keeper_routes_under_prefix` — keeper routes must be under `keeper_route_prefixes` (default `['/api/']`).
|
|
460
461
|
|
|
461
|
-
Tightness audit:
|
|
462
|
-
|
|
463
|
-
- `audit_error_schema_tightness(surface) => Array<ErrorSchemaAuditEntry>` — classifies every route × status combination as `'literal' | 'enum' | 'generic'`.
|
|
464
|
-
- `assert_error_schema_tightness(surface, options?)` — fails routes below a threshold (`min_specificity`, default `'enum'`) with `allowlist` + `ignore_statuses` escape hatches.
|
|
465
|
-
- `fuz_app_stock_route_tightness_allowlist` — currently empty. Every fuz_app-shipped route (account login/password/bootstrap/signup, db health/tables/:name/tables/:name/rows/:id) has been tightened in place to `z.enum([...])` / `z.literal(...)` against every emit-site code. Kept as a forward-compatibility hook for future stock routes that need an interim exemption; paths assume the standard `/api/account` + `/api/db` prefixes.
|
|
466
|
-
- `default_error_schema_tightness` — `{ignore_statuses: [401, 403, 429], allowlist: fuz_app_stock_route_tightness_allowlist}`. Applied by `describe_standard_attack_surface_tests` when `error_schema_tightness` is omitted; pass an override config or `null` to opt out.
|
|
467
|
-
- **Merge semantics in `describe_standard_attack_surface_tests`**: consumer-supplied `allowlist` and `ignore_statuses` are concatenated underneath the defaults (stock entries first, consumer entries last), so consumer allowlists are additive rather than replacing. Scalar fields like `min_specificity` are overwritten by the consumer. Exported as `resolve_standard_error_schema_tightness(consumer_options)` for consumers calling `assert_error_schema_tightness` directly outside the suite.
|
|
468
|
-
|
|
469
462
|
Aggregate runners (called by the standard attack-surface suite):
|
|
470
463
|
|
|
471
464
|
- `assert_surface_invariants(surface)` — runs all route-level structural assertions.
|
|
@@ -474,21 +467,32 @@ Aggregate runners (called by the standard attack-surface suite):
|
|
|
474
467
|
|
|
475
468
|
### `error_coverage.ts` — reachability tracking
|
|
476
469
|
|
|
477
|
-
`ErrorCoverageCollector` tracks which declared error paths get exercised
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
470
|
+
`ErrorCoverageCollector` tracks which declared error paths get exercised:
|
|
471
|
+
each code of each route's error map (`resolve_route_error_map`), one path per
|
|
472
|
+
(status, code), read from its definitions. `new ErrorCoverageCollector(route_error_maps?)`
|
|
473
|
+
takes the maps (`AppSurfaceSpec.route_error_maps`, middleware included); without
|
|
474
|
+
them a route's own map is read. The standard suites pass
|
|
475
|
+
`surface_source.route_error_maps`.
|
|
476
|
+
Observations live in a `Set<string>` keyed by `"METHOD /spec-path:STATUS:CODE"`
|
|
477
|
+
for an observation with a code, which covers that path alone (a
|
|
478
|
+
`forbidden_origin` 403 leaves `credential_type_required` uncovered), or
|
|
479
|
+
`"METHOD /spec-path:STATUS"` for one recorded with a `null` code (a response
|
|
480
|
+
that carries none), which satisfies the "any-code" rule for every code declared
|
|
481
|
+
at that status — asked for explicitly, never had by omission.
|
|
482
482
|
|
|
483
483
|
Methods:
|
|
484
484
|
|
|
485
|
-
- `record(specs, method, path, status, code
|
|
486
|
-
|
|
487
|
-
|
|
485
|
+
- `record(specs, method, path, status, code: string | null)` — resolves concrete
|
|
486
|
+
paths back to spec templates (e.g. `/api/accounts/abc` → `/api/accounts/:id`);
|
|
487
|
+
`code` is the body's `error`, `null` only for a response that has none.
|
|
488
|
+
- `assert_and_record(specs, method, path, response, code?)` — wraps
|
|
489
|
+
`assert_response_matches_spec` and reads `body.error` from the JSON body via
|
|
490
|
+
`response.clone()` (`null` when there is none). Pass `code` when the body was
|
|
491
|
+
already consumed; without it a consumed body throws.
|
|
492
|
+
- `uncovered(specs, options?)` — one `{method, path, status, code}` row per declared code never observed.
|
|
488
493
|
|
|
489
494
|
Support functions:
|
|
490
495
|
|
|
491
|
-
- `extract_declared_error_codes(schema)` — reads the object's `error` field, Zod (`schema.shape.error`) or fuz_schema (`get_schema_entries`, any object kind under any wrappers); returns the literal value(s) for `z.literal` / `z.enum` / `literal` / `one_of`, `null` otherwise.
|
|
492
496
|
- `assert_error_coverage(collector, specs, options?)` — logs `[error coverage] covered/total (N.M%)` with uncovered list; fails when `min_coverage > 0` and the ratio falls below.
|
|
493
497
|
- `DEFAULT_INTEGRATION_ERROR_COVERAGE = 0.2` — conservative baseline for the standard integration/admin suites; consumers tighten as their own test coverage matures.
|
|
494
498
|
|
|
@@ -505,7 +509,7 @@ naming it.
|
|
|
505
509
|
- `detect_format(field_schema)` — `detect_json_schema_format` over `to_field_json_schema`: the `format`, `'pattern'` for a regex, or `null`.
|
|
506
510
|
- `generate_valid_value(field, field_schema)` — base-type switch producing a valid sample (UUIDs → nil UUID, strings → `'xxxxxxxxxx'`, numbers → `1`, objects → `generate_valid_object` against the field schema, so a nested refinement is satisfied too, enums → first entry, records → `{}`, a void field → `undefined`, etc.). For branded-string refinements, walks a fallback chain synthesized from the `pattern` string the JSON Schema representation exposes: fixed-length hex (`^[0-9a-f]{N}$` — blake3 / sha256 / md5 digests; `0`.repeat(N)), prefix-lengthed slug (`^<prefix>_[A-Za-z0-9_-]{N}$` — `ApiTokenId`-style ids; `<prefix>_` + `x`.repeat(N)), absolute path prefix, URL prefix, two `/`-joined segments (an `owner/name` slug). First candidate the field accepts is used.
|
|
507
511
|
- `generate_valid_string_param(field, field_schema)` — a string a URL-sourced field (route param, query value) accepts: the nil UUID for a UUID field, else the first of `test_value`, the generated valid value as a string, `1`, `0`, `true`, `false`, the field's JSON Schema `default` or lower bound as a string (a preprocessed integer whose minimum is above one) and a synthesized string the field accepts; `null` when none does. The params and query case generators build their base from it.
|
|
508
|
-
- `resolve_valid_path(path, params_schema?)` — swaps `:
|
|
512
|
+
- `resolve_valid_path(path, params_schema?, param_values?)` — swaps each whole param segment (`:name`, `:name{re}`, optional or not, read as Hono reads a template: `split_route_template` / `parse_route_param`) for a value the params schema accepts; a `:` inside a literal segment (`files:upload`) stays. Prefers `test_<name>` wherever the field schema admits it (the param name keeps failure messages readable); otherwise a UUID param takes the nil UUID and anything else is synthesized from the schema, percent-encoded. A synthesized value containing `/` is refused (it would route elsewhere) and falls back to `test_<name>`. A value in `param_values` (the route's entry of `RouteParamValues`, `'METHOD /path'` → param name → value, the option the path-resolving suites take) comes first, percent-encoded like the rest. A `:name{re}` param's value, supplied or generated, must match its pattern grouped and anchored, `^(?:re)$` (`compile_route_param_pattern`, over the value as Hono decodes it, `decode_route_path`) — Hono's RegExpRouter reading, the stricter of its routers', as TrieRouter leaves a top-level alternation ungrouped — else it throws naming the route and the param and pointing at `param_values`: no value is guessed from the pattern, and no route is skipped silently. A `param_values` entry naming no param of the path throws too, and so does a supplied `''`, `.` or `..` (the URL normalizes it away) or a lone surrogate. Supplied values are always encoded, so a `{re}` needing a literal `/` can't be met by one.
|
|
509
513
|
- `to_route_content_type(route)` — the `Content-Type` a well-formed request to the route sends: `application/json`, or `application/octet-stream` for a `raw_body` route. Every `POST` route refuses anything else with 415 before its other gates, so every probe in the harnesses (auth, params and query fuzz, 404, data exposure, round trip) sends it, body or not.
|
|
510
514
|
- `generate_valid_object(object_schema, schema) => {value, result}` — required and defaulted fields; when `schema` (refinements included) refuses those, each optional field alone in declaration order, the first that parses; failing that, the optional fields added cumulatively until it parses. Covers a `.refine()` over optional fields (at least one of, exactly one of, both of) at any depth, and, where one optional field suffices, keeps the others (an `acting` declared first) out. Returns the last `parse_any` result (`GeneratedObject`) and leaves the throw to the caller, which renders its issues with `format_issues` (`schema_issues.ts`).
|
|
511
515
|
- `generate_valid_object_with_field(object_schema, schema, base, field)` — a valid object carrying `field`, built from the valid `base`: `base` itself when it carries the field; else the field joins `base`, with the optional fields `base` omits filled as `generate_valid_object` fills them (a pair rule: `scope_kind` needs `scope_id`); failing that, the field replaces `base`'s optional fields, refilled around it (exactly one of: adding `slug` drops `id`). `null` when no object the generator builds carries the field. The body a single-fault case on a field the base omits changes.
|
|
@@ -513,9 +517,9 @@ naming it.
|
|
|
513
517
|
|
|
514
518
|
### `integration_helpers.ts` — route lookup + body checks
|
|
515
519
|
|
|
516
|
-
- `find_route_spec(specs, method, path)` —
|
|
520
|
+
- `find_route_spec(specs, method, path)` — the first spec in list (mount) order whose method and path template match, as Hono dispatches (the hono-free `find_mounted_route`; the DEV check reads Hono's own router), `HEAD` read as `GET`, the path read as Hono reads it (pathname, percent-decoded); a template passed as the path (a segment that is `*` or starts with `:`) finds its own spec first, outranking mount order.
|
|
517
521
|
- `find_auth_route(specs, suffix, method)` — suffix-ending match for REST auth routes; decouples tests from consumer prefix. `suffix` is typed as `RestAuthRouteSuffix` and throws at runtime on unknown values (only login/logout/password/verify/signup/bootstrap remain on REST).
|
|
518
|
-
- `assert_response_matches_spec(specs, method, path, response)` — 2xx → validates against `spec.output`;
|
|
522
|
+
- `assert_response_matches_spec(specs, method, path, response, route_error_maps?)` — 2xx → validates against `spec.output`; an error status (400 and up) → `assert_error_response_declared` against the route's error map — the one in `route_error_maps` (`AppSurfaceSpec.route_error_maps`, middleware included), else the route's own: a status the map lacks throws (`Undeclared error status (S): METHOD path: …`), as does a body off its schema, with the DEV error check's exemptions (500 `internal_error`, 503 `service_unavailable`, a JSON-RPC envelope on a `jsonrpc` route). Non-JSON responses allowed only when no schema applies. The round trips and `ErrorCoverageCollector.assert_and_record` run through it.
|
|
519
523
|
- `assert_no_error_info_leakage(body, context)` — rejects field-name patterns (`stack`, `trace`, `sql`, …) + value patterns (`node_modules`, stack-like `at …`, `.ts:NN`).
|
|
520
524
|
- `assert_rate_limit_retry_after_header(response, body)` — `Retry-After` numeric header equals `Math.ceil(body.retry_after)`.
|
|
521
525
|
- `sensitive_field_blocklist` — `['password_hash', 'token_hash']`; never in any response body.
|
|
@@ -532,12 +536,12 @@ Single-call bundle of 5 top-level groups (10 named tests + every adversarial
|
|
|
532
536
|
case per route):
|
|
533
537
|
|
|
534
538
|
1. **attack surface snapshot** — `matches committed snapshot`, `is deterministic`.
|
|
535
|
-
2. **attack surface structure** — `only expected public routes`, `full middleware stack on API routes`, `surface invariants`, `rpc/ws surface invariants`, `security policy
|
|
536
|
-
3. **adversarial HTTP auth enforcement** — `unauthenticated → 401`, `wrong role → 403` × roles, `authenticated without role → 403`, `credential-gated routes reject a disallowed credential → 403`, `correct auth passes guard`. The role blocks cover role routes the session-credentialed role apps reach (a keeper route's channel gate answers first); the credential block probes every `auth.credential_types` route on the first builtin channel its allowlist omits, using `AuthTestApps.by_credential_type` (one keeper-role app per builtin channel; `keeper` is its `daemon_token` entry).
|
|
539
|
+
2. **attack surface structure** — `only expected public routes`, `full middleware stack on API routes`, `surface invariants`, `rpc/ws surface invariants`, `security policy`.
|
|
540
|
+
3. **adversarial HTTP auth enforcement** — `unauthenticated → 401`, `wrong role → 403` × roles, `authenticated without role → 403`, `credential-gated routes reject a disallowed credential → 403`, `correct auth passes guard`. Every refusal is held to the route's own error map (`assert_error_schema_valid`: the status, the code at it, the body), and `correct auth passes guard`, which takes any status but the gates' from a handler on stub deps, holds a JSON error it answers to the map too (`assert_error_response_declared`). The role blocks cover role routes the session-credentialed role apps reach (a keeper route's channel gate answers first); the credential block probes every `auth.credential_types` route on the first builtin channel its allowlist omits, using `AuthTestApps.by_credential_type` (one keeper-role app per builtin channel; `keeper` is its `daemon_token` entry).
|
|
537
541
|
4. **adversarial input validation** — delegated to `describe_adversarial_input`.
|
|
538
542
|
5. **adversarial 404 response validation** — delegated to `describe_adversarial_404`.
|
|
539
543
|
|
|
540
|
-
Options: `{build: () => AppSurfaceSpec, snapshot_path, expected_public_routes, expected_api_middleware, roles, api_path_prefix?, security_policy?,
|
|
544
|
+
Options: `{build: () => AppSurfaceSpec, snapshot_path, expected_public_routes, expected_api_middleware, roles, api_path_prefix?, security_policy?, skip_routes?, param_values?}`.
|
|
541
545
|
|
|
542
546
|
`skip_routes` is a list of `'METHOD /path'` surface keys the three
|
|
543
547
|
adversarial sub-suites drop, forwarded to each of them (it also sits on
|
|
@@ -546,7 +550,9 @@ adversarial sub-suites drop, forwarded to each of them (it also sits on
|
|
|
546
550
|
escape hatch for a route that cannot be driven generically at all — a
|
|
547
551
|
handler needing real seeded state, a path segment no schema describes. A
|
|
548
552
|
route whose params merely carry a format needs no entry: `resolve_valid_path`
|
|
549
|
-
synthesizes a segment the route accepts.
|
|
553
|
+
synthesizes a segment the route accepts. A `{re}` param whose pattern refuses
|
|
554
|
+
every generated value takes a `param_values` entry instead, forwarded the same
|
|
555
|
+
way (`RouteParamValues`).
|
|
550
556
|
|
|
551
557
|
Also exported: `describe_adversarial_auth(options)` (group 3 on its own).
|
|
552
558
|
|
|
@@ -556,7 +562,9 @@ Also exported: `describe_adversarial_auth(options)` (group 3 on its own).
|
|
|
556
562
|
query validation failures at every route with correct-auth credentials so
|
|
557
563
|
validation middleware is actually exercised (not short-circuited by 401).
|
|
558
564
|
All cases expect 400 with one of `ERROR_INVALID_REQUEST_BODY` /
|
|
559
|
-
`_INVALID_JSON_BODY` / `_INVALID_ROUTE_PARAMS` / `_INVALID_QUERY_PARAMS
|
|
565
|
+
`_INVALID_JSON_BODY` / `_INVALID_ROUTE_PARAMS` / `_INVALID_QUERY_PARAMS`, a
|
|
566
|
+
code the route's own error map declares at 400, and a body its schema there
|
|
567
|
+
accepts (`assert_error_schema_valid`).
|
|
560
568
|
|
|
561
569
|
The generators live in the hono-free `adversarial_input_cases.ts`, so the
|
|
562
570
|
cross-process suites reuse them:
|
|
@@ -574,14 +582,11 @@ rather than `ERROR_INVALID_JSON_BODY`.
|
|
|
574
582
|
|
|
575
583
|
### `adversarial_404.ts` — 404 schema conformance
|
|
576
584
|
|
|
577
|
-
`describe_adversarial_404({build, roles})` — for every route with `params`
|
|
578
|
-
404 in `
|
|
579
|
-
`
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
which reads the output-side JSON Schema of a Zod or fuz_schema schema with
|
|
583
|
-
`unrepresentable: 'any'`, so a field JSON Schema can't say beside `error`
|
|
584
|
-
(a transform) no longer drops the route from the suite.
|
|
585
|
+
`describe_adversarial_404({build, roles})` — for every route with `params` and
|
|
586
|
+
a 404 definition of its own in `errors`, replaces the handler with a stub
|
|
587
|
+
returning `{error: <code>}` (the first 404 definition's code), fires with
|
|
588
|
+
nil-UUID params, asserts 404, a code the route error map declares at 404, and a body its 404
|
|
589
|
+
accepts (`assert_error_schema_valid`, `AppSurfaceSpec.route_error_maps`). No DB needed.
|
|
585
590
|
|
|
586
591
|
### `adversarial_headers.ts` — header injection suite
|
|
587
592
|
|
|
@@ -640,7 +645,7 @@ For every route spec, fires a valid request with matching auth and validates
|
|
|
640
645
|
the response against declared schemas. DB-backed via `create_test_app`.
|
|
641
646
|
Per-route test (`test.each`) — one line per route in the vitest output.
|
|
642
647
|
|
|
643
|
-
Options: `{setup_test, surface_source, skip_routes?, input_overrides?, success_fixtures?}`.
|
|
648
|
+
Options: `{setup_test, surface_source, skip_routes?, input_overrides?, success_fixtures?, param_values?}`.
|
|
644
649
|
Principals and the 401 check are the RPC round-trip's (`pick_auth_principal`;
|
|
645
650
|
`assert_route_authenticated` over `is_unauthenticated_refusal`, reading the
|
|
646
651
|
flat `error`), and a non-`GET` route called as the authed
|
|
@@ -797,7 +802,7 @@ has no JSON Schema form and a field inside a transformed subtree shows only
|
|
|
797
802
|
there. The input side is a superset, so a transform that deliberately drops a
|
|
798
803
|
blocklisted field is flagged too — skip that output by its key.
|
|
799
804
|
|
|
800
|
-
Options: `{setup_test, surface_source, sensitive_fields?, admin_only_fields?, skip_routes?}`.
|
|
805
|
+
Options: `{setup_test, surface_source, sensitive_fields?, admin_only_fields?, skip_routes?, param_values?}`.
|
|
801
806
|
`skip_routes` keys a route as `'METHOD /path'`, an RPC or WS method output
|
|
802
807
|
as `'/path method_name'`, and pushed WS params as `'/path method_name params'`
|
|
803
808
|
(the schema-level checks only).
|
|
@@ -806,7 +811,7 @@ as `'/path method_name'`, and pushed WS params as `'/path method_name params'`
|
|
|
806
811
|
|
|
807
812
|
Two test groups:
|
|
808
813
|
|
|
809
|
-
1. IP rate limiting on login — fires `max_attempts + 1` requests; last should be 429 with `
|
|
814
|
+
1. IP rate limiting on login — fires `max_attempts + 1` requests; last should be 429 with a `REST_RATE_LIMIT_EXCEEDED` body + valid `Retry-After` header.
|
|
810
815
|
2. Per-account rate limiting on login — same username exhausts the bucket; a different username is not blocked.
|
|
811
816
|
|
|
812
817
|
No bearer group — the bearer path carries no rate limiter on either spine
|
|
@@ -843,22 +848,54 @@ these thematic areas:
|
|
|
843
848
|
9. Token revocation + cross-account isolation
|
|
844
849
|
10. Response body schema validation + error-response information leakage
|
|
845
850
|
11. Signup invite edge cases + expired credential rejection + error-coverage breadth
|
|
851
|
+
12. Middleware gates — one test per gate each counted route's error map declares (`middleware_gate_probes.ts`, below)
|
|
846
852
|
|
|
847
853
|
An `ErrorCoverageCollector` runs across groups; `afterAll` filters to
|
|
848
|
-
|
|
849
|
-
and asserts `DEFAULT_INTEGRATION_ERROR_COVERAGE` (20%). Bootstrap is
|
|
854
|
+
the routes it counts — login, logout, password, signup (when wired) and the
|
|
855
|
+
RPC path — and asserts `DEFAULT_INTEGRATION_ERROR_COVERAGE` (20%). Bootstrap is
|
|
850
856
|
excluded because no describe block in this suite drives it — its declared
|
|
851
857
|
codes would always be uncovered. Consumer-specific routes aren't exercised
|
|
852
|
-
here either — they don't count against the baseline.
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
858
|
+
here either — they don't count against the baseline. The declared paths are
|
|
859
|
+
the route error maps of `surface_source`, middleware included (the origin
|
|
860
|
+
check's 403, the body limit's 413 and 400, and the Rust spine's host gate's
|
|
861
|
+
403 where the surface declares it), counted per (route, status, code), so
|
|
862
|
+
every error response a test asserts is recorded, and the middleware-gate group
|
|
863
|
+
probes each gate on each counted route. Override with
|
|
857
864
|
`error_coverage_min?: number` (set to `0` to skip the assertion — useful for
|
|
858
865
|
minimal route sets whose declared error codes outpace the suite's
|
|
859
866
|
denial-path drivers).
|
|
860
867
|
|
|
861
|
-
Options: `{setup_test, surface_source, session_options, rpc_endpoints,
|
|
868
|
+
Options: `{setup_test, surface_source, session_options, rpc_endpoints, base_url,
|
|
869
|
+
max_body_bytes?, rpc_max_body_bytes?, error_coverage_min?,
|
|
870
|
+
check_uncovered_errors?}`; the last is called with the declared paths left
|
|
871
|
+
uncovered before the floor is asserted, which fuz_app's own wirings hold to an
|
|
872
|
+
exact set. `base_url` is the
|
|
873
|
+
backend's socket, `null` in-process (`default_in_process_suite_options` gives
|
|
874
|
+
`null`, and `max_body_bytes` from `app_options.max_body_size`); the caps
|
|
875
|
+
default to `SPINE_BODY_LIMIT_DEFAULT_BYTES`, the RPC endpoint's to
|
|
876
|
+
`max_body_bytes`.
|
|
877
|
+
|
|
878
|
+
### `middleware_gate_probes.ts` — the integration suite's gate probes
|
|
879
|
+
|
|
880
|
+
`plan_middleware_gate_probes({route_specs, route_error_maps, base_url,
|
|
881
|
+
max_body_bytes?, rpc_path, rpc_max_body_bytes?})` plans one
|
|
882
|
+
`MiddlewareGateProbe` per gate a route's error map declares, so a carved-out
|
|
883
|
+
route or a backend without the layer gets none: a foreign `Origin`
|
|
884
|
+
(`GATE_PROBE_FOREIGN_ORIGIN`) → 403 `forbidden_origin`; a foreign `Host`
|
|
885
|
+
(`GATE_PROBE_FOREIGN_HOST`) → 403 `forbidden_host`; a declared
|
|
886
|
+
`Content-Length` one over the route's cap → 413 `payload_too_large`; and,
|
|
887
|
+
in-process only, an unreadable `Content-Length` → 400 `invalid_content_length`
|
|
888
|
+
(over a socket Node's parser and hyper answer that one themselves with a
|
|
889
|
+
bodiless 400, and `fetch` can't send it). Each probe is a request head with no
|
|
890
|
+
body and no credential, refused before auth, rate limiting and body parsing;
|
|
891
|
+
in-process the probes share one fixture. A route whose path has a param or
|
|
892
|
+
wildcard segment throws rather than be probed at its literal template.
|
|
893
|
+
`send_middleware_gate_probe(probe, base_url, transport)` writes it to the socket
|
|
894
|
+
with `raw_http_send_head` (`fetch` replaces a caller's `Host` and
|
|
895
|
+
`Content-Length`), or in-process through the transport, whose `Request` keeps
|
|
896
|
+
both. `assert_middleware_gate_refusal(probe, response, collector, route_specs)`
|
|
897
|
+
asserts the declared status and code, then `assert_and_record`s it.
|
|
898
|
+
`format_middleware_gate_probe` names a probe's test.
|
|
862
899
|
|
|
863
900
|
### `admin_integration.ts` — `describe_standard_admin_integration_tests`
|
|
864
901
|
|
|
@@ -1214,12 +1251,16 @@ the in-process backend exposes; wire-level audit observability lives in the
|
|
|
1214
1251
|
consumer's own audit `.cross.test.ts`). The omission rationale lives in the
|
|
1215
1252
|
module doc once instead of repeating in each consumer's `*.cross.test.ts`.
|
|
1216
1253
|
|
|
1254
|
+
`base_url` (required — the integration suite's middleware-gate probes write
|
|
1255
|
+
to the socket), `max_body_bytes` and `rpc_max_body_bytes` forward to the
|
|
1256
|
+
integration suite;
|
|
1217
1257
|
`rpc_success_fixtures`, `rpc_skip_methods` and `rpc_input_overrides`
|
|
1218
1258
|
forward to the RPC round-trip's `success_fixtures`, `skip_methods` and
|
|
1219
1259
|
`input_overrides` (`describe_spine_cross_suites` also forwards
|
|
1220
1260
|
`rpc_input_overrides` to `rpc_adversarial`) — `rpc_skip_methods` is the
|
|
1221
1261
|
consumer escape hatch for a method the generic round-trip can't drive in its
|
|
1222
|
-
test wiring.
|
|
1262
|
+
test wiring. `param_values` (`RouteParamValues`) forwards to both the
|
|
1263
|
+
round-trip and data exposure, the two that resolve route paths.
|
|
1223
1264
|
|
|
1224
1265
|
Hard-codes the cross-process-safe set with no `skip` knob; if a future
|
|
1225
1266
|
consumer needs partial opt-out, add the knob then.
|
|
@@ -1278,7 +1319,8 @@ here never reaches it.
|
|
|
1278
1319
|
request-body cap on `rpc_path` and its inbound WS message cap, when they
|
|
1279
1320
|
aren't the spine defaults (`SPINE_BODY_LIMIT_DEFAULT_BYTES`,
|
|
1280
1321
|
`DEFAULT_WS_MAX_MESSAGE_BYTES`). The first reaches `body_size`,
|
|
1281
|
-
`body_size_smuggling
|
|
1322
|
+
`body_size_smuggling`, `transport_composition`'s RPC over-cap row and the
|
|
1323
|
+
standard bundle's middleware-gate probes of the RPC endpoint (each
|
|
1282
1324
|
takes it as `rpc_max_body_bytes`), the second `ws_round_trip`'s
|
|
1283
1325
|
`max_message_bytes` — one value per limit for every suite probing it.
|
|
1284
1326
|
- **`exclude`** — `{[suite]: reason}`; the reason is required and shows in the
|
|
@@ -2169,13 +2211,15 @@ are `src/test/auth/cell_crud_parity.db.test.ts`
|
|
|
2169
2211
|
`raw_http_parse_json` (a body's JSON, `undefined` when it isn't), and
|
|
2170
2212
|
`RAW_HTTP_READ_TIMEOUT_MS`, the suites' default read window.
|
|
2171
2213
|
`raw_http_send_head(base_url, {method?, path, headers, content_length,
|
|
2172
|
-
read_timeout_ms?})` (`RawHttpHeadRequest`) is the over-cap probe
|
|
2173
|
-
them: the request head alone, declaring `content_length` body
|
|
2174
|
-
sending none, read until one whole response — so a server that
|
|
2175
|
-
the declared length answers and one that reads the body first
|
|
2176
|
-
read timeout. It writes `Host`
|
|
2177
|
-
`
|
|
2178
|
-
|
|
2214
|
+
host?, read_timeout_ms?})` (`RawHttpHeadRequest`) is the over-cap probe
|
|
2215
|
+
built on them: the request head alone, declaring `content_length` body
|
|
2216
|
+
bytes and sending none, read until one whole response — so a server that
|
|
2217
|
+
refuses on the declared length answers and one that reads the body first
|
|
2218
|
+
fails on the read timeout. It writes `Host` (`host`, default the base URL's)
|
|
2219
|
+
and `Content-Length` itself (naming either in `headers` throws), defaults
|
|
2220
|
+
nothing else, and throws on a CR or LF in the host or a header name or value,
|
|
2221
|
+
and when no whole response arrives. The middleware-gate probes and the
|
|
2222
|
+
body-size, body-size smuggling, credential-header,
|
|
2179
2223
|
origin-scope and transport-composition suites share this module; they take
|
|
2180
2224
|
the 1 MiB cap they probe from `SPINE_BODY_LIMIT_DEFAULT_BYTES`
|
|
2181
2225
|
(`spine_surface_constants.ts`).
|
|
@@ -85,7 +85,7 @@ export const describe_standard_admin_integration_tests = (options) => {
|
|
|
85
85
|
const { role_specs } = options.roles;
|
|
86
86
|
const grantable_role = pick_grantable_role(role_specs);
|
|
87
87
|
// Error coverage tracking across test groups
|
|
88
|
-
const error_collector = new ErrorCoverageCollector();
|
|
88
|
+
const error_collector = new ErrorCoverageCollector(options.surface_source.route_error_maps);
|
|
89
89
|
afterAll(() => {
|
|
90
90
|
// Scope coverage to admin auth-related routes. Account listing,
|
|
91
91
|
// session/token revoke-all, audit-log reads, and invite CRUD all
|
|
@@ -869,7 +869,7 @@ export const describe_standard_admin_integration_tests = (options) => {
|
|
|
869
869
|
headers: { host: 'localhost', 'content-type': to_route_content_type(route) }
|
|
870
870
|
});
|
|
871
871
|
if (res.status === 401 || res.status === 403) {
|
|
872
|
-
error_collector.
|
|
872
|
+
await error_collector.assert_and_record(route_specs, route.method, route.path, res);
|
|
873
873
|
}
|
|
874
874
|
}
|
|
875
875
|
});
|
|
@@ -1,28 +1,14 @@
|
|
|
1
1
|
import './assert_dev_env.js';
|
|
2
|
-
import { type ValidationSchema } from '../schema_issues.js';
|
|
3
2
|
import type { AdversarialTestOptions } from './attack_surface.js';
|
|
4
|
-
/**
|
|
5
|
-
* Extract the error code from a 404 error schema, Zod or `@fuzdev/fuz_schema`,
|
|
6
|
-
* for use in the stub handler.
|
|
7
|
-
*
|
|
8
|
-
* Reads the schema's output-side JSON Schema with `unrepresentable: 'any'`,
|
|
9
|
-
* so a field JSON Schema can't say (a transform, a `z.custom()`) beside
|
|
10
|
-
* `error` doesn't hide the code. Supports a literal (`{const: '...'}`) and an
|
|
11
|
-
* enum (`{enum: [...]}`, uses first value); `null` when `error` is neither.
|
|
12
|
-
* A schema either emitter refuses outright throws.
|
|
13
|
-
*
|
|
14
|
-
* @param schema - a route's declared 404 error schema
|
|
15
|
-
* @returns the code the stub handler answers with, or `null`
|
|
16
|
-
*/
|
|
17
|
-
export declare const extract_404_error_code: (schema: ValidationSchema) => string | null;
|
|
18
3
|
/**
|
|
19
4
|
* Generate adversarial 404 response validation tests.
|
|
20
5
|
*
|
|
21
|
-
* For each route with `params`
|
|
22
|
-
* 1. Creates a stub handler returning 404 with the
|
|
6
|
+
* For each route with `params` and a 404 definition of its own in `errors`:
|
|
7
|
+
* 1. Creates a stub handler returning 404 with the first such definition's code
|
|
23
8
|
* 2. Fires a request with valid-format params (nil UUIDs for UUID params)
|
|
24
9
|
* 3. Validates response status is 404
|
|
25
|
-
* 4. Validates
|
|
10
|
+
* 4. Validates the code is one the route's error map (`resolve_route_error_map`)
|
|
11
|
+
* declares at 404, and the body parses against its 404 (`assert_error_schema_valid`)
|
|
26
12
|
*/
|
|
27
13
|
export declare const describe_adversarial_404: (options: AdversarialTestOptions) => void;
|
|
28
14
|
//# sourceMappingURL=adversarial_404.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adversarial_404.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/adversarial_404.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"adversarial_404.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/adversarial_404.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAqB7B,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAOlE;;;;;;;;;GASG;AACH,eAAO,MAAM,wBAAwB,GAAI,SAAS,sBAAsB,KAAG,IA8E1E,CAAC"}
|
|
@@ -4,69 +4,38 @@ import './assert_dev_env.js';
|
|
|
4
4
|
*
|
|
5
5
|
* Creates stub handlers that return 404 with the declared error code,
|
|
6
6
|
* fires requests with valid-format-but-nonexistent params (nil UUIDs),
|
|
7
|
-
* and validates response bodies against the declared 404
|
|
8
|
-
* `@fuzdev/fuz_schema`.
|
|
7
|
+
* and validates response bodies against the route's declared 404.
|
|
9
8
|
*
|
|
10
9
|
* No DB needed — tests schema conformance of 404 responses, not real handlers.
|
|
11
10
|
*
|
|
12
11
|
* @module
|
|
13
12
|
*/
|
|
14
13
|
import { test, assert, describe } from 'vitest';
|
|
15
|
-
import {
|
|
16
|
-
import { is_schema } from '@fuzdev/fuz_schema/schema.ts';
|
|
17
|
-
import { to_json_schema } from '@fuzdev/fuz_schema/json_schema.ts';
|
|
14
|
+
import { format_route_key } from '../http/surface_query.js';
|
|
18
15
|
import { is_null_schema } from '../http/schema_helpers.js';
|
|
19
|
-
import {
|
|
16
|
+
import { assert_error_schema_valid } from './assertions.js';
|
|
20
17
|
import { create_auth_test_apps, create_route_skip_filter, select_auth_app } from './auth_apps.js';
|
|
21
18
|
import { resolve_valid_path, generate_valid_body, to_route_content_type } from './schema_generators.js';
|
|
22
|
-
/**
|
|
23
|
-
* Extract the error code from a 404 error schema, Zod or `@fuzdev/fuz_schema`,
|
|
24
|
-
* for use in the stub handler.
|
|
25
|
-
*
|
|
26
|
-
* Reads the schema's output-side JSON Schema with `unrepresentable: 'any'`,
|
|
27
|
-
* so a field JSON Schema can't say (a transform, a `z.custom()`) beside
|
|
28
|
-
* `error` doesn't hide the code. Supports a literal (`{const: '...'}`) and an
|
|
29
|
-
* enum (`{enum: [...]}`, uses first value); `null` when `error` is neither.
|
|
30
|
-
* A schema either emitter refuses outright throws.
|
|
31
|
-
*
|
|
32
|
-
* @param schema - a route's declared 404 error schema
|
|
33
|
-
* @returns the code the stub handler answers with, or `null`
|
|
34
|
-
*/
|
|
35
|
-
export const extract_404_error_code = (schema) => {
|
|
36
|
-
const json = (is_schema(schema)
|
|
37
|
-
? to_json_schema(schema, { unrepresentable: 'any' })
|
|
38
|
-
: z.toJSONSchema(schema, { unrepresentable: 'any' }));
|
|
39
|
-
if (json.type !== 'object' || !json.properties || typeof json.properties !== 'object')
|
|
40
|
-
return null;
|
|
41
|
-
const props = json.properties;
|
|
42
|
-
if (!props.error || typeof props.error !== 'object')
|
|
43
|
-
return null;
|
|
44
|
-
const error_schema = props.error;
|
|
45
|
-
if (typeof error_schema.const === 'string')
|
|
46
|
-
return error_schema.const;
|
|
47
|
-
if (Array.isArray(error_schema.enum) && typeof error_schema.enum[0] === 'string')
|
|
48
|
-
return error_schema.enum[0];
|
|
49
|
-
return null;
|
|
50
|
-
};
|
|
51
19
|
/**
|
|
52
20
|
* Generate adversarial 404 response validation tests.
|
|
53
21
|
*
|
|
54
|
-
* For each route with `params`
|
|
55
|
-
* 1. Creates a stub handler returning 404 with the
|
|
22
|
+
* For each route with `params` and a 404 definition of its own in `errors`:
|
|
23
|
+
* 1. Creates a stub handler returning 404 with the first such definition's code
|
|
56
24
|
* 2. Fires a request with valid-format params (nil UUIDs for UUID params)
|
|
57
25
|
* 3. Validates response status is 404
|
|
58
|
-
* 4. Validates
|
|
26
|
+
* 4. Validates the code is one the route's error map (`resolve_route_error_map`)
|
|
27
|
+
* declares at 404, and the body parses against its 404 (`assert_error_schema_valid`)
|
|
59
28
|
*/
|
|
60
29
|
export const describe_adversarial_404 = (options) => {
|
|
61
30
|
const { build, roles } = options;
|
|
62
|
-
const { surface, route_specs } = build();
|
|
31
|
+
const { surface, route_specs, route_error_maps } = build();
|
|
63
32
|
const is_skipped = create_route_skip_filter(options.skip_routes);
|
|
64
33
|
// Build spec lookup for schema access
|
|
65
34
|
const spec_lookup = new Map();
|
|
66
35
|
for (const spec of route_specs) {
|
|
67
|
-
spec_lookup.set(
|
|
36
|
+
spec_lookup.set(format_route_key(spec), spec);
|
|
68
37
|
}
|
|
69
|
-
// Find testable routes: params + 404
|
|
38
|
+
// Find testable routes: params + a 404 definition of the route's own
|
|
70
39
|
const testable = [];
|
|
71
40
|
for (const route of surface.routes) {
|
|
72
41
|
if (route.params_schema === null)
|
|
@@ -75,14 +44,14 @@ export const describe_adversarial_404 = (options) => {
|
|
|
75
44
|
continue;
|
|
76
45
|
if (is_skipped(route))
|
|
77
46
|
continue;
|
|
78
|
-
const key =
|
|
47
|
+
const key = format_route_key(route);
|
|
79
48
|
const spec = spec_lookup.get(key);
|
|
80
|
-
if (!spec?.params
|
|
49
|
+
if (!spec?.params)
|
|
81
50
|
continue;
|
|
82
|
-
const
|
|
83
|
-
if (!
|
|
51
|
+
const not_found = spec.errors?.find((def) => def.status === 404);
|
|
52
|
+
if (!not_found)
|
|
84
53
|
continue;
|
|
85
|
-
testable.push({ key, error_code, spec });
|
|
54
|
+
testable.push({ key, error_code: not_found.code, spec });
|
|
86
55
|
}
|
|
87
56
|
if (testable.length === 0)
|
|
88
57
|
return;
|
|
@@ -93,7 +62,7 @@ export const describe_adversarial_404 = (options) => {
|
|
|
93
62
|
error_code_by_key.set(entry.key, entry.error_code);
|
|
94
63
|
}
|
|
95
64
|
const stub_specs = route_specs.map((spec) => {
|
|
96
|
-
const error_code = error_code_by_key.get(
|
|
65
|
+
const error_code = error_code_by_key.get(format_route_key(spec));
|
|
97
66
|
if (!error_code)
|
|
98
67
|
return spec;
|
|
99
68
|
return {
|
|
@@ -104,9 +73,9 @@ export const describe_adversarial_404 = (options) => {
|
|
|
104
73
|
const apps = create_auth_test_apps(stub_specs, roles);
|
|
105
74
|
for (const { key, error_code, spec } of testable) {
|
|
106
75
|
test(key, async () => {
|
|
107
|
-
const route = surface.routes.find((r) =>
|
|
76
|
+
const route = surface.routes.find((r) => format_route_key(r) === key);
|
|
108
77
|
const app = select_auth_app(apps, route.auth);
|
|
109
|
-
const url = resolve_valid_path(route.path, spec.params);
|
|
78
|
+
const url = resolve_valid_path(route.path, spec.params, options.param_values?.[key]);
|
|
110
79
|
const request_init = {
|
|
111
80
|
method: route.method,
|
|
112
81
|
headers: { 'content-type': to_route_content_type(spec) }
|
|
@@ -122,9 +91,8 @@ export const describe_adversarial_404 = (options) => {
|
|
|
122
91
|
assert.strictEqual(res.status, 404, `Expected 404 for ${key}, got ${res.status}`);
|
|
123
92
|
const body = await res.json();
|
|
124
93
|
assert.strictEqual(body.error, error_code, `Expected error '${error_code}' for ${key}, got: ${body.error}`);
|
|
125
|
-
//
|
|
126
|
-
|
|
127
|
-
assert.ok(parsed.ok, `404 body for ${key} does not match its declared schema: ${parsed.ok ? '' : JSON.stringify(parsed.issues)}`);
|
|
94
|
+
// the code is the route's own at 404, and the body its schema there
|
|
95
|
+
assert_error_schema_valid(route_error_maps, route, 404, body);
|
|
128
96
|
});
|
|
129
97
|
}
|
|
130
98
|
});
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import './assert_dev_env.js';
|
|
2
|
-
import type
|
|
2
|
+
import { type RestErrorDef } from '../http/error_schemas.js';
|
|
3
3
|
import { type TestMiddlewareStackOptions } from './middleware.js';
|
|
4
4
|
/** A header-level attack case for middleware stack testing. */
|
|
5
5
|
export interface AdversarialHeaderCase {
|
|
6
6
|
name: string;
|
|
7
7
|
headers: Record<string, string>;
|
|
8
8
|
expected_status: number;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
expected_error_schema?: z.ZodType;
|
|
9
|
+
/** The error definition the JSON body must be — its code, and a body its schema accepts. */
|
|
10
|
+
expected_error?: RestErrorDef;
|
|
12
11
|
/** Whether the request should reach token validation or be short-circuited by earlier middleware. */
|
|
13
12
|
validate_expectation: 'called' | 'not_called';
|
|
14
13
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adversarial_headers.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/adversarial_headers.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"adversarial_headers.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/adversarial_headers.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAsB7B,OAAO,EAAyB,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACpF,OAAO,EAGN,KAAK,0BAA0B,EAC/B,MAAM,iBAAiB,CAAC;AAYzB,+DAA+D;AAC/D,MAAM,WAAW,qBAAqB;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,eAAe,EAAE,MAAM,CAAC;IACxB,4FAA4F;IAC5F,cAAc,CAAC,EAAE,YAAY,CAAC;IAC9B,qGAAqG;IACrG,oBAAoB,EAAE,QAAQ,GAAG,YAAY,CAAC;CAC9C;AAID;;;;;;;;;;GAUG;AACH,eAAO,MAAM,iCAAiC,GAC7C,gBAAgB,MAAM,KACpB,KAAK,CAAC,qBAAqB,CAiE7B,CAAC;AAIF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,qCAAqC,GACjD,YAAY,MAAM,EAClB,SAAS,0BAA0B,EACnC,gBAAgB,MAAM,EACtB,cAAc,KAAK,CAAC,qBAAqB,CAAC,KACxC,IAmCF,CAAC"}
|
|
@@ -16,7 +16,8 @@ import './assert_dev_env.js';
|
|
|
16
16
|
* @module
|
|
17
17
|
*/
|
|
18
18
|
import { test, assert, describe } from 'vitest';
|
|
19
|
-
import {
|
|
19
|
+
import { parse_any } from '../schema_issues.js';
|
|
20
|
+
import { REST_FORBIDDEN_ORIGIN } from '../http/error_schemas.js';
|
|
20
21
|
import { create_test_middleware_stack_app, TEST_MIDDLEWARE_PATH } from './middleware.js';
|
|
21
22
|
import { create_test_raw_api_token } from './entities.js';
|
|
22
23
|
/**
|
|
@@ -45,7 +46,7 @@ export const create_standard_adversarial_cases = (allowed_origin) => [
|
|
|
45
46
|
Origin: 'https://attacker.com'
|
|
46
47
|
},
|
|
47
48
|
expected_status: 403,
|
|
48
|
-
expected_error:
|
|
49
|
+
expected_error: REST_FORBIDDEN_ORIGIN,
|
|
49
50
|
validate_expectation: 'not_called'
|
|
50
51
|
},
|
|
51
52
|
{
|
|
@@ -70,7 +71,7 @@ export const create_standard_adversarial_cases = (allowed_origin) => [
|
|
|
70
71
|
Origin: ''
|
|
71
72
|
},
|
|
72
73
|
expected_status: 403,
|
|
73
|
-
expected_error:
|
|
74
|
+
expected_error: REST_FORBIDDEN_ORIGIN,
|
|
74
75
|
validate_expectation: 'not_called'
|
|
75
76
|
},
|
|
76
77
|
{
|
|
@@ -129,9 +130,10 @@ export const describe_standard_adversarial_headers = (suite_name, options, allow
|
|
|
129
130
|
assert.strictEqual(res.status, tc.expected_status);
|
|
130
131
|
const body = await res.json();
|
|
131
132
|
if (tc.expected_error) {
|
|
132
|
-
assert.strictEqual(body.error, tc.expected_error);
|
|
133
|
-
|
|
134
|
-
|
|
133
|
+
assert.strictEqual(body.error, tc.expected_error.code);
|
|
134
|
+
assert.strictEqual(res.status, tc.expected_error.status);
|
|
135
|
+
const parsed = parse_any(tc.expected_error.schema, body);
|
|
136
|
+
assert.ok(parsed.ok, `error body fails its schema: ${JSON.stringify(body)}`);
|
|
135
137
|
}
|
|
136
138
|
if (tc.expected_status === 200) {
|
|
137
139
|
assert.strictEqual(body.ok, true, 'expected ok to be true for 200 response');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adversarial_input.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/adversarial_input.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"adversarial_input.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/adversarial_input.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AA6B7B,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AA4BlE;;;;;;GAMG;AACH,eAAO,MAAM,0BAA0B,GAAI,SAAS,sBAAsB,KAAG,IAuN5E,CAAC"}
|