@fuzdev/fuz_app 0.164.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.
Files changed (50) hide show
  1. package/dist/http/CLAUDE.md +2 -1
  2. package/dist/http/route_error_check.d.ts +21 -0
  3. package/dist/http/route_error_check.d.ts.map +1 -1
  4. package/dist/http/route_error_check.js +37 -1
  5. package/dist/http/schema_helpers.d.ts +15 -1
  6. package/dist/http/schema_helpers.d.ts.map +1 -1
  7. package/dist/http/schema_helpers.js +12 -3
  8. package/dist/testing/CLAUDE.md +75 -25
  9. package/dist/testing/admin_integration.js +1 -1
  10. package/dist/testing/adversarial_404.js +1 -1
  11. package/dist/testing/adversarial_input.js +2 -2
  12. package/dist/testing/assertions.d.ts +13 -3
  13. package/dist/testing/assertions.d.ts.map +1 -1
  14. package/dist/testing/assertions.js +21 -4
  15. package/dist/testing/attack_surface.d.ts +12 -0
  16. package/dist/testing/attack_surface.d.ts.map +1 -1
  17. package/dist/testing/attack_surface.js +8 -5
  18. package/dist/testing/cross_backend/in_process_setup.d.ts +7 -3
  19. package/dist/testing/cross_backend/in_process_setup.d.ts.map +1 -1
  20. package/dist/testing/cross_backend/in_process_setup.js +11 -4
  21. package/dist/testing/cross_backend/spine_suites.d.ts +3 -2
  22. package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
  23. package/dist/testing/cross_backend/spine_suites.js +5 -2
  24. package/dist/testing/cross_backend/standard.d.ts +31 -0
  25. package/dist/testing/cross_backend/standard.d.ts.map +1 -1
  26. package/dist/testing/cross_backend/standard.js +9 -3
  27. package/dist/testing/data_exposure.d.ts +7 -0
  28. package/dist/testing/data_exposure.d.ts.map +1 -1
  29. package/dist/testing/data_exposure.js +3 -3
  30. package/dist/testing/error_coverage.d.ts +35 -33
  31. package/dist/testing/error_coverage.d.ts.map +1 -1
  32. package/dist/testing/error_coverage.js +53 -43
  33. package/dist/testing/integration.d.ts +28 -1
  34. package/dist/testing/integration.d.ts.map +1 -1
  35. package/dist/testing/integration.js +51 -18
  36. package/dist/testing/integration_helpers.d.ts.map +1 -1
  37. package/dist/testing/integration_helpers.js +4 -15
  38. package/dist/testing/middleware_gate_probes.d.ts +90 -0
  39. package/dist/testing/middleware_gate_probes.d.ts.map +1 -0
  40. package/dist/testing/middleware_gate_probes.js +179 -0
  41. package/dist/testing/round_trip.d.ts +7 -0
  42. package/dist/testing/round_trip.d.ts.map +1 -1
  43. package/dist/testing/round_trip.js +3 -2
  44. package/dist/testing/schema_generators.d.ts +31 -9
  45. package/dist/testing/schema_generators.d.ts.map +1 -1
  46. package/dist/testing/schema_generators.js +53 -11
  47. package/dist/testing/transports/raw_http.d.ts +10 -2
  48. package/dist/testing/transports/raw_http.d.ts.map +1 -1
  49. package/dist/testing/transports/raw_http.js +10 -4
  50. package/package.json +1 -1
@@ -30,6 +30,7 @@ import { assert_iso8601_seconds, assert_iso8601_seconds_nullable } from './cross
30
30
  import { DEFAULT_TEST_PASSWORD } from './test_credentials.js';
31
31
  import { create_test_request_headers, TEST_ORIGIN } from './test_origin.js';
32
32
  import { create_test_raw_api_token } from './entities.js';
33
+ import { assert_middleware_gate_refusal, format_middleware_gate_probe, plan_middleware_gate_probes, send_middleware_gate_probe } from './middleware_gate_probes.js';
33
34
  /**
34
35
  * Standard integration test suite for fuz_app auth routes.
35
36
  *
@@ -37,7 +38,8 @@ import { create_test_raw_api_token } from './entities.js';
37
38
  * revocation, password change (incl. API token revocation), origin
38
39
  * verification, bearer auth (incl. browser context discard on mutations),
39
40
  * token revocation, cross-account isolation, expired credential rejection,
40
- * signup invite edge cases, and response body validation.
41
+ * signup invite edge cases, response body validation, and the middleware
42
+ * gates each counted route's error map declares (`middleware_gate_probes.ts`).
41
43
  *
42
44
  * Each test group asserts that required routes exist, failing with a descriptive
43
45
  * message if the consumer's route specs are misconfigured.
@@ -97,7 +99,9 @@ export const describe_standard_integration_tests = (options) => {
97
99
  // routes would dilute the ratio; admin-role routes are scoped to
98
100
  // the admin suite instead.
99
101
  const auth_routes = route_specs.filter(is_suite_auth_route);
100
- assert_error_coverage(error_collector, auth_routes.length > 0 ? auth_routes : route_specs, {
102
+ const scoped_routes = auth_routes.length > 0 ? auth_routes : route_specs;
103
+ options.check_uncovered_errors?.(error_collector.uncovered(scoped_routes));
104
+ assert_error_coverage(error_collector, scoped_routes, {
101
105
  min_coverage: options.error_coverage_min ?? DEFAULT_INTEGRATION_ERROR_COVERAGE
102
106
  });
103
107
  });
@@ -530,7 +534,7 @@ export const describe_standard_integration_tests = (options) => {
530
534
  })
531
535
  });
532
536
  assert.strictEqual(res.status, 401);
533
- error_collector.record(route_specs, 'POST', password_route.path, 401);
537
+ await error_collector.assert_and_record(route_specs, 'POST', password_route.path, res);
534
538
  // Session should still be valid (password didn't change)
535
539
  const verify_res = await rpc_call_for_spec({
536
540
  app: { request: fixture.transport },
@@ -707,6 +711,7 @@ export const describe_standard_integration_tests = (options) => {
707
711
  headers: { cookie: `${cookie_name}=${non_admin.session_cookie}` }
708
712
  });
709
713
  assert.strictEqual(res.status, 403);
714
+ await error_collector.assert_and_record(route_specs, admin_route.method, admin_route.path, res);
710
715
  const body = await res.json();
711
716
  assert.strictEqual(body.error, 'insufficient_permissions');
712
717
  });
@@ -860,7 +865,7 @@ export const describe_standard_integration_tests = (options) => {
860
865
  })
861
866
  });
862
867
  assert.strictEqual(res.status, 401);
863
- await assert_response_matches_spec(route_specs, 'POST', login_route.path, res, options.surface_source.route_error_maps);
868
+ await error_collector.assert_and_record(route_specs, 'POST', login_route.path, res);
864
869
  });
865
870
  test('POST /logout 200 response matches output schema', async () => {
866
871
  const fixture = await options.setup_test();
@@ -886,7 +891,7 @@ export const describe_standard_integration_tests = (options) => {
886
891
  body: JSON.stringify({})
887
892
  });
888
893
  assert.strictEqual(res.status, 401);
889
- await assert_response_matches_spec(route_specs, 'POST', logout_route.path, res, options.surface_source.route_error_maps);
894
+ await error_collector.assert_and_record(route_specs, 'POST', logout_route.path, res);
890
895
  });
891
896
  });
892
897
  // Rate-limit behavior is covered end-to-end by
@@ -898,11 +903,12 @@ export const describe_standard_integration_tests = (options) => {
898
903
  describe('error coverage breadth', () => {
899
904
  test('exercises 401 on multiple auth-required routes for error coverage', async () => {
900
905
  const fixture = await options.setup_test();
901
- // Hit several auth-required RPC methods without credentials to
902
- // broaden error coverage beyond just /login. RPC 401s are tracked
903
- // against the shared endpoint path. The dispatcher runs auth before
904
- // params validation, so any well-formed param body works — we just
905
- // need each call to be type-correct wrt its spec.
906
+ // Hit several auth-required RPC methods without credentials. A
907
+ // refusal on the RPC endpoint is a JSON-RPC envelope, not a declared
908
+ // REST error, so these assert the 401 without recording it; the
909
+ // logout probe below is the REST one that counts. The dispatcher runs
910
+ // auth before params validation, so any well-formed param body works
911
+ // — we just need each call to be type-correct wrt its spec.
906
912
  //
907
913
  // Fresh transport so the per-test session cookie in
908
914
  // `fixture.transport`'s jar doesn't leak into these unauthed
@@ -916,7 +922,6 @@ export const describe_standard_integration_tests = (options) => {
916
922
  headers: { host: 'localhost' }
917
923
  });
918
924
  assert.strictEqual(session_list.status, 401);
919
- error_collector.record(route_specs, 'POST', rpc_path, 401);
920
925
  const session_revoke_all = await rpc_call_for_spec({
921
926
  app: { request: unauthed },
922
927
  path: rpc_path,
@@ -925,7 +930,6 @@ export const describe_standard_integration_tests = (options) => {
925
930
  headers: { host: 'localhost' }
926
931
  });
927
932
  assert.strictEqual(session_revoke_all.status, 401);
928
- error_collector.record(route_specs, 'POST', rpc_path, 401);
929
933
  const token_list = await rpc_call_for_spec({
930
934
  app: { request: unauthed },
931
935
  path: rpc_path,
@@ -934,7 +938,6 @@ export const describe_standard_integration_tests = (options) => {
934
938
  headers: { host: 'localhost' }
935
939
  });
936
940
  assert.strictEqual(token_list.status, 401);
937
- error_collector.record(route_specs, 'POST', rpc_path, 401);
938
941
  const token_create = await rpc_call_for_spec({
939
942
  app: { request: unauthed },
940
943
  path: rpc_path,
@@ -947,7 +950,6 @@ export const describe_standard_integration_tests = (options) => {
947
950
  headers: { host: 'localhost' }
948
951
  });
949
952
  assert.strictEqual(token_create.status, 401);
950
- error_collector.record(route_specs, 'POST', rpc_path, 401);
951
953
  const verify = await rpc_call_for_spec({
952
954
  app: { request: unauthed },
953
955
  path: rpc_path,
@@ -956,7 +958,6 @@ export const describe_standard_integration_tests = (options) => {
956
958
  headers: { host: 'localhost' }
957
959
  });
958
960
  assert.strictEqual(verify.status, 401);
959
- error_collector.record(route_specs, 'POST', rpc_path, 401);
960
961
  // Also exercise POST /logout without auth (still REST)
961
962
  const logout_route = find_auth_route(route_specs, '/logout', 'POST');
962
963
  if (logout_route) {
@@ -966,7 +967,7 @@ export const describe_standard_integration_tests = (options) => {
966
967
  body: JSON.stringify({})
967
968
  });
968
969
  assert.strictEqual(res.status, 401, 'POST /logout without auth should return 401');
969
- error_collector.record(route_specs, 'POST', logout_route.path, 401);
970
+ await error_collector.assert_and_record(route_specs, 'POST', logout_route.path, res);
970
971
  }
971
972
  });
972
973
  });
@@ -1015,7 +1016,7 @@ export const describe_standard_integration_tests = (options) => {
1015
1016
  }
1016
1017
  });
1017
1018
  assert.strictEqual(res.status, 401, 'Bearer with Origin should be discarded → unauthenticated');
1018
- error_collector.record(route_specs, 'POST', logout_route.path, 401);
1019
+ await error_collector.assert_and_record(route_specs, 'POST', logout_route.path, res);
1019
1020
  });
1020
1021
  test('bearer token with Referer header discarded on POST password', async () => {
1021
1022
  const fixture = await options.setup_test();
@@ -1029,7 +1030,7 @@ export const describe_standard_integration_tests = (options) => {
1029
1030
  headers: { ...bearer_headers, referer: `${TEST_ORIGIN}/admin` }
1030
1031
  });
1031
1032
  assert.strictEqual(res.status, 401, 'Bearer with Referer should be discarded → unauthenticated');
1032
- error_collector.record(route_specs, 'POST', password_route.path, 401);
1033
+ await error_collector.assert_and_record(route_specs, 'POST', password_route.path, res);
1033
1034
  });
1034
1035
  });
1035
1036
  // --- 12b. Content type: every JSON POST route refuses an untyped body ---
@@ -1049,6 +1050,35 @@ export const describe_standard_integration_tests = (options) => {
1049
1050
  }
1050
1051
  });
1051
1052
  });
1053
+ // --- 12c. Middleware gates: each counted route's declared gates refuse ---
1054
+ describe('middleware gates', () => {
1055
+ // One probe per gate each counted route's error map declares — the
1056
+ // origin check, the Rust spine's host gate, the body limit — each a
1057
+ // bodiless head with no credential that the gate refuses before auth,
1058
+ // rate limiting or body parsing. A gate the map doesn't declare on a
1059
+ // route (a carve-out, a backend without the layer) gets no probe.
1060
+ const probes = plan_middleware_gate_probes({
1061
+ route_specs: route_specs.filter(is_suite_auth_route),
1062
+ route_error_maps: options.surface_source.route_error_maps,
1063
+ base_url: options.base_url,
1064
+ max_body_bytes: options.max_body_bytes,
1065
+ rpc_path,
1066
+ rpc_max_body_bytes: options.rpc_max_body_bytes
1067
+ });
1068
+ // in-process the probes share one fixture's transport, made by the first
1069
+ // to run; over a socket they need none, as they read and write no state
1070
+ let in_process_transport = null;
1071
+ const get_transport = () => (in_process_transport ??= options
1072
+ .setup_test()
1073
+ .then((fixture) => fixture.fresh_transport({ origin: null })));
1074
+ for (const probe of probes) {
1075
+ test(format_middleware_gate_probe(probe), async () => {
1076
+ const transport = options.base_url === null ? await get_transport() : null;
1077
+ const res = await send_middleware_gate_probe(probe, options.base_url, transport);
1078
+ await assert_middleware_gate_refusal(probe, res, error_collector, route_specs);
1079
+ });
1080
+ }
1081
+ });
1052
1082
  // --- 13. Password change revokes API tokens ---
1053
1083
  describe('password change revokes API tokens', () => {
1054
1084
  test('API tokens are invalidated after password change', async () => {
@@ -1150,6 +1180,7 @@ export const describe_standard_integration_tests = (options) => {
1150
1180
  })
1151
1181
  });
1152
1182
  assert.strictEqual(signup_res.status, 403, 'Signup with non-matching email should be rejected');
1183
+ await error_collector.assert_and_record(route_specs, 'POST', signup_route.path, signup_res);
1153
1184
  const body = await signup_res.json();
1154
1185
  assert.strictEqual(body.error, 'no_matching_invite');
1155
1186
  });
@@ -1200,6 +1231,7 @@ export const describe_standard_integration_tests = (options) => {
1200
1231
  })
1201
1232
  });
1202
1233
  assert.strictEqual(no_match_res.status, 403, 'Expected 403 for non-matching invite');
1234
+ await error_collector.assert_and_record(route_specs, 'POST', signup_route.path, no_match_res);
1203
1235
  const no_match_body = await no_match_res.json();
1204
1236
  // Create invite for a different email via RPC
1205
1237
  const conflict_email = 'conflict-test@example.com';
@@ -1224,6 +1256,7 @@ export const describe_standard_integration_tests = (options) => {
1224
1256
  })
1225
1257
  });
1226
1258
  assert.strictEqual(conflict_res.status, 409, 'Expected 409 for username conflict');
1259
+ await error_collector.assert_and_record(route_specs, 'POST', signup_route.path, conflict_res);
1227
1260
  const conflict_body = await conflict_res.json();
1228
1261
  // Assert both failure responses have identical Object.keys()
1229
1262
  const no_match_keys = Object.keys(no_match_body).sort();
@@ -1 +1 @@
1
- {"version":3,"file":"integration_helpers.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/integration_helpers.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAU7B,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEpE,OAAO,EAAuB,KAAK,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAClF,OAAO,EAAkB,KAAK,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAGvE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAkCnD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,eAAe,GAC3B,OAAO,KAAK,CAAC,SAAS,CAAC,EACvB,QAAQ,MAAM,EACd,MAAM,MAAM,KACV,SAAS,GAAG,SAcd,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,iFAO3B,CAAC;AACX,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,wBAAwB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE5E;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,GAC3B,OAAO,KAAK,CAAC,SAAS,C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;AAErD;;;;;;;;;GASG;AACH,eAAO,MAAM,0BAA0B,GAAI,QAAQ,MAAM,EAAE,QAAQ,OAAO,KAAG,OACQ,CAAC"}
@@ -12,27 +12,16 @@ import { ERROR_AUTHENTICATION_REQUIRED } from '../http/error_schemas.js';
12
12
  import { ROLE_ADMIN } from '../auth/role_schema.js';
13
13
  import { create_test_request_headers } from './test_origin.js';
14
14
  import { parse_any } from '../schema_issues.js';
15
- import { find_mounted_route, is_json_response, to_mounted_routes } from '../http/route_error_check.js';
15
+ import { decode_route_path, find_mounted_route, is_json_response, to_mounted_routes } from '../http/route_error_check.js';
16
16
  import { assert_error_response_declared } from './assertions.js';
17
17
  /** Each spec list's compiled routes, so a list is compiled once. */
18
18
  const mounted_routes_cache = new WeakMap();
19
19
  /**
20
20
  * A request path as Hono reads it: the URL's pathname (a query string
21
- * dropped, `.` and `..` segments resolved), percent-decoded by `decodeURI`
22
- * with `%25` kept, or the raw path when decoding fails.
21
+ * dropped, `.` and `..` segments resolved), percent-decoded as
22
+ * `decode_route_path` decodes it.
23
23
  */
24
- const to_hono_path = (path) => {
25
- let pathname = new URL(path, 'http://localhost').pathname;
26
- if (pathname.includes('%')) {
27
- try {
28
- pathname = decodeURI(pathname.replaceAll('%25', '%2525'));
29
- }
30
- catch {
31
- // a malformed escape: Hono matches the raw path
32
- }
33
- }
34
- return pathname;
35
- };
24
+ const to_hono_path = (path) => decode_route_path(new URL(path, 'http://localhost').pathname);
36
25
  /**
37
26
  * Find the route spec a request reaches: the first in list (mount) order
38
27
  * whose method and path template match it, `HEAD` read as `GET` — the order
@@ -0,0 +1,90 @@
1
+ import './assert_dev_env.js';
2
+ import type { RouteMethod, RouteSpec } from '../http/route_spec.js';
3
+ import { type RouteErrorMap } from '../http/route_errors.js';
4
+ import { type RestErrorDef } from '../http/error_schemas.js';
5
+ import type { ErrorCoverageCollector } from './error_coverage.js';
6
+ /** The `Origin` the origin probe sends — no allowlist names it. */
7
+ export declare const GATE_PROBE_FOREIGN_ORIGIN = "https://gate-probe.invalid";
8
+ /** The `Host` the host probe sends — neither loopback nor named by an allowed origin. */
9
+ export declare const GATE_PROBE_FOREIGN_HOST = "gate-probe.invalid";
10
+ /** The `Content-Length` the unreadable-length probe sends. */
11
+ export declare const GATE_PROBE_UNREADABLE_LENGTH = "not-a-length";
12
+ /** One probe: a request head a route's declared gate must refuse with `expected`. */
13
+ export interface MiddlewareGateProbe {
14
+ readonly method: RouteMethod;
15
+ /** The route's path, a template with no params among the routes probed. */
16
+ readonly path: string;
17
+ /** The refusal the route's error map declares for the gate. */
18
+ readonly expected: RestErrorDef;
19
+ /** Request headers beyond `Host` and `Content-Length`. */
20
+ readonly headers: Readonly<Record<string, string>>;
21
+ /** The `Host` to send, `null` for the backend's own. */
22
+ readonly host: string | null;
23
+ /** The `Content-Length` to declare; no body byte is sent. */
24
+ readonly content_length: number | string;
25
+ }
26
+ /** Options for `plan_middleware_gate_probes`. */
27
+ export interface MiddlewareGateProbePlanOptions {
28
+ /** The routes to probe, each a path with no params. */
29
+ readonly route_specs: ReadonlyArray<RouteSpec>;
30
+ /** Each route's error map, middleware included (`AppSurfaceSpec.route_error_maps`). */
31
+ readonly route_error_maps: ReadonlyMap<string, RouteErrorMap> | null;
32
+ /**
33
+ * The backend's base URL, or `null` in-process. Without a socket the
34
+ * unreadable-length probe is planned too.
35
+ */
36
+ readonly base_url: string | null;
37
+ /**
38
+ * The request-body cap on every route but `rpc_path`, in bytes.
39
+ *
40
+ * @default SPINE_BODY_LIMIT_DEFAULT_BYTES
41
+ */
42
+ readonly max_body_bytes?: number;
43
+ /** The RPC endpoint's path, whose cap is `rpc_max_body_bytes`. */
44
+ readonly rpc_path: string;
45
+ /**
46
+ * The request-body cap on `rpc_path`, in bytes.
47
+ *
48
+ * @default max_body_bytes
49
+ */
50
+ readonly rpc_max_body_bytes?: number;
51
+ }
52
+ /**
53
+ * Plan the gate probes of each route: one per gate its error map declares,
54
+ * in route order.
55
+ *
56
+ * @param options - the routes, their maps, the socket and the caps
57
+ * @returns the probes, none for a gate a route's map doesn't declare
58
+ * @throws Error when a route's path has a param or a wildcard segment, which a
59
+ * probe would send as the literal template
60
+ */
61
+ export declare const plan_middleware_gate_probes: (options: MiddlewareGateProbePlanOptions) => Array<MiddlewareGateProbe>;
62
+ /** A probe's name: the route and the refusal it expects. */
63
+ export declare const format_middleware_gate_probe: (probe: MiddlewareGateProbe) => string;
64
+ /** The in-process transport a probe is sent through. */
65
+ export type MiddlewareGateProbeTransport = (url: string, init: RequestInit) => Promise<Response>;
66
+ /**
67
+ * Send a probe: over the socket when there is one, else through `transport`.
68
+ *
69
+ * @param probe - the probe
70
+ * @param base_url - the backend's base URL, or `null` in-process
71
+ * @param transport - the in-process transport, read only without a `base_url`
72
+ * @returns the response, its body JSON when the server sent JSON
73
+ * @throws Error when an unreadable length is to go over a socket, or no
74
+ * transport is given in-process
75
+ */
76
+ export declare const send_middleware_gate_probe: (probe: MiddlewareGateProbe, base_url: string | null, transport: MiddlewareGateProbeTransport | null) => Promise<Response>;
77
+ /**
78
+ * Assert a probe was refused as its route declares, then record the refusal
79
+ * in `collector`, which checks the body against the route's map.
80
+ *
81
+ * @param probe - the probe sent
82
+ * @param response - its response
83
+ * @param collector - the error coverage to record the refusal in
84
+ * @param route_specs - the routes the collector resolves the path against
85
+ * @mutates collector - records the probe's route, status and code
86
+ * @throws AssertionError when the response's status or `error` code isn't the
87
+ * declared refusal, or its body is off the route's map
88
+ */
89
+ export declare const assert_middleware_gate_refusal: (probe: MiddlewareGateProbe, response: Response, collector: ErrorCoverageCollector, route_specs: Array<RouteSpec>) => Promise<void>;
90
+ //# sourceMappingURL=middleware_gate_probes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware_gate_probes.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/middleware_gate_probes.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAkC7B,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EA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AAM,CAAC;IAC1B;;;;OAIG;IACH,QAAQ,CAAC,kBAAkB,CAAC,EAAE,MAAM,CAAC;CACrC;AAMD;;;;;;;;GAQG;AACH,eAAO,MAAM,2BAA2B,GACvC,SAAS,8BAA8B,KACrC,KAAK,CAAC,mBAAmB,CA4D3B,CAAC;AAEF,4DAA4D;AAC5D,eAAO,MAAM,4BAA4B,GAAI,OAAO,mBAAmB,KAAG,MACQ,CAAC;AAEnF,wDAAwD;AACxD,MAAM,MAAM,4BAA4B,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEjG;;;;;;;;;GASG;AACH,eAAO,MAAM,0BAA0B,GACtC,OAAO,mBAAmB,EAC1B,UAAU,MAAM,GAAG,IAAI,EACvB,WAAW,4BAA4B,GAAG,IAAI,KAC5C,OAAO,CAAC,QAAQ,CA+BlB,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,8BAA8B,GAC1C,OAAO,mBAAmB,EAC1B,UAAU,QAAQ,EAClB,WAAW,sBAAsB,EACjC,aAAa,KAAK,CAAC,SAAS,CAAC,KAC3B,OAAO,CAAC,IAAI,CAmBd,CAAC"}
@@ -0,0 +1,179 @@
1
+ import './assert_dev_env.js';
2
+ /**
3
+ * Probes of the middleware gates a route's error map declares: a foreign
4
+ * `Origin` (403 `forbidden_origin`), a `Host` the server doesn't answer to
5
+ * (403 `forbidden_host`, the Rust spine's host gate), a declared
6
+ * `Content-Length` one byte over the route's cap (413 `payload_too_large`),
7
+ * and a `Content-Length` that isn't a length (400 `invalid_content_length`).
8
+ *
9
+ * The map drives which probes a route gets: a gate the route's map doesn't
10
+ * declare — a carved-out path, a backend without the layer, a disabled limit —
11
+ * is not probed. Every probe is a request head with no body and no
12
+ * credential, so the gate answers it before auth, rate limiting or body
13
+ * parsing, and it leaves no state behind.
14
+ *
15
+ * Over a socket (`base_url`) each probe is written raw
16
+ * (`raw_http_send_head`): `fetch` replaces a caller's `Host` and
17
+ * `Content-Length` with its own. In-process the head goes through the
18
+ * fixture's transport, whose `Request` keeps both headers as given. The
19
+ * unreadable-length probe runs in-process only: over a socket the runtime's
20
+ * HTTP parser (Node's, hyper) refuses such a length with a bodiless 400 of its
21
+ * own before the application sees it, and `fetch` can't send one. In-process
22
+ * the length reaches the body limit unparsed, and the 400 is the limit's own —
23
+ * the answer a Deno or Bun server gives when a request repeats an equal
24
+ * `Content-Length`, which those runtimes hand over joined into one value.
25
+ *
26
+ * `describe_standard_integration_tests` runs one per declared gate of each
27
+ * route it counts and records each answer in its error coverage.
28
+ *
29
+ * @module
30
+ */
31
+ import { assert } from 'vitest';
32
+ import { get_route_error_map } from '../http/route_errors.js';
33
+ import { split_route_template } from '../http/route_error_check.js';
34
+ import { REST_FORBIDDEN_HOST, REST_FORBIDDEN_ORIGIN, REST_INVALID_CONTENT_LENGTH, REST_PAYLOAD_TOO_LARGE } from '../http/error_schemas.js';
35
+ import { to_route_content_type } from './schema_generators.js';
36
+ import { raw_http_send_head } from './transports/raw_http.js';
37
+ import { SPINE_BODY_LIMIT_DEFAULT_BYTES } from './cross_backend/spine_surface_constants.js';
38
+ /** The `Origin` the origin probe sends — no allowlist names it. */
39
+ export const GATE_PROBE_FOREIGN_ORIGIN = 'https://gate-probe.invalid';
40
+ /** The `Host` the host probe sends — neither loopback nor named by an allowed origin. */
41
+ export const GATE_PROBE_FOREIGN_HOST = 'gate-probe.invalid';
42
+ /** The `Content-Length` the unreadable-length probe sends. */
43
+ export const GATE_PROBE_UNREADABLE_LENGTH = 'not-a-length';
44
+ /** Whether `defs` declares `def`'s status and code. */
45
+ const declares = (defs, def) => defs.some((d) => d.status === def.status && d.code === def.code);
46
+ /**
47
+ * Plan the gate probes of each route: one per gate its error map declares,
48
+ * in route order.
49
+ *
50
+ * @param options - the routes, their maps, the socket and the caps
51
+ * @returns the probes, none for a gate a route's map doesn't declare
52
+ * @throws Error when a route's path has a param or a wildcard segment, which a
53
+ * probe would send as the literal template
54
+ */
55
+ export const plan_middleware_gate_probes = (options) => {
56
+ const max_body_bytes = options.max_body_bytes ?? SPINE_BODY_LIMIT_DEFAULT_BYTES;
57
+ const rpc_max_body_bytes = options.rpc_max_body_bytes ?? max_body_bytes;
58
+ const probes = [];
59
+ for (const spec of options.route_specs) {
60
+ const { defs } = get_route_error_map(options.route_error_maps, spec);
61
+ const { method, path } = spec;
62
+ if (split_route_template(path).some((segment) => segment.startsWith(':') || segment === '*')) {
63
+ throw new Error(`plan_middleware_gate_probes: ${method} ${path} has a param or wildcard segment, ` +
64
+ 'which a probe would send as the literal template');
65
+ }
66
+ // a `POST` refuses anything but its content type with 415, so each probe
67
+ // sends it and the gate is the only refusal left
68
+ const headers = method === 'POST' ? { 'content-type': to_route_content_type(spec) } : {};
69
+ const cap = path === options.rpc_path ? rpc_max_body_bytes : max_body_bytes;
70
+ if (declares(defs, REST_FORBIDDEN_ORIGIN)) {
71
+ probes.push({
72
+ method,
73
+ path,
74
+ expected: REST_FORBIDDEN_ORIGIN,
75
+ headers: { ...headers, origin: GATE_PROBE_FOREIGN_ORIGIN },
76
+ host: null,
77
+ content_length: 0
78
+ });
79
+ }
80
+ if (declares(defs, REST_FORBIDDEN_HOST)) {
81
+ probes.push({
82
+ method,
83
+ path,
84
+ expected: REST_FORBIDDEN_HOST,
85
+ headers,
86
+ host: GATE_PROBE_FOREIGN_HOST,
87
+ content_length: 0
88
+ });
89
+ }
90
+ if (declares(defs, REST_PAYLOAD_TOO_LARGE)) {
91
+ probes.push({
92
+ method,
93
+ path,
94
+ expected: REST_PAYLOAD_TOO_LARGE,
95
+ headers,
96
+ host: null,
97
+ content_length: cap + 1
98
+ });
99
+ }
100
+ if (options.base_url === null && declares(defs, REST_INVALID_CONTENT_LENGTH)) {
101
+ probes.push({
102
+ method,
103
+ path,
104
+ expected: REST_INVALID_CONTENT_LENGTH,
105
+ headers,
106
+ host: null,
107
+ content_length: GATE_PROBE_UNREADABLE_LENGTH
108
+ });
109
+ }
110
+ }
111
+ return probes;
112
+ };
113
+ /** A probe's name: the route and the refusal it expects. */
114
+ export const format_middleware_gate_probe = (probe) => `${probe.method} ${probe.path} → ${probe.expected.status} ${probe.expected.code}`;
115
+ /**
116
+ * Send a probe: over the socket when there is one, else through `transport`.
117
+ *
118
+ * @param probe - the probe
119
+ * @param base_url - the backend's base URL, or `null` in-process
120
+ * @param transport - the in-process transport, read only without a `base_url`
121
+ * @returns the response, its body JSON when the server sent JSON
122
+ * @throws Error when an unreadable length is to go over a socket, or no
123
+ * transport is given in-process
124
+ */
125
+ export const send_middleware_gate_probe = async (probe, base_url, transport) => {
126
+ if (base_url !== null) {
127
+ if (typeof probe.content_length !== 'number') {
128
+ throw new Error(`${format_middleware_gate_probe(probe)}: an unreadable length can't be sent over a socket`);
129
+ }
130
+ const raw = await raw_http_send_head(base_url, {
131
+ method: probe.method,
132
+ path: probe.path,
133
+ headers: probe.headers,
134
+ content_length: probe.content_length,
135
+ ...(probe.host !== null && { host: probe.host })
136
+ });
137
+ const content_type = raw.headers['content-type'];
138
+ return new Response(raw.body === '' ? null : raw.body, {
139
+ status: raw.status,
140
+ headers: content_type === undefined ? {} : { 'content-type': content_type }
141
+ });
142
+ }
143
+ if (!transport) {
144
+ throw new Error(`${format_middleware_gate_probe(probe)}: no transport to send it in-process`);
145
+ }
146
+ return transport(probe.path, {
147
+ method: probe.method,
148
+ headers: {
149
+ ...probe.headers,
150
+ ...(probe.host !== null && { host: probe.host }),
151
+ 'content-length': String(probe.content_length)
152
+ }
153
+ });
154
+ };
155
+ /**
156
+ * Assert a probe was refused as its route declares, then record the refusal
157
+ * in `collector`, which checks the body against the route's map.
158
+ *
159
+ * @param probe - the probe sent
160
+ * @param response - its response
161
+ * @param collector - the error coverage to record the refusal in
162
+ * @param route_specs - the routes the collector resolves the path against
163
+ * @mutates collector - records the probe's route, status and code
164
+ * @throws AssertionError when the response's status or `error` code isn't the
165
+ * declared refusal, or its body is off the route's map
166
+ */
167
+ export const assert_middleware_gate_refusal = async (probe, response, collector, route_specs) => {
168
+ const label = format_middleware_gate_probe(probe);
169
+ let body;
170
+ try {
171
+ body = await response.clone().json();
172
+ }
173
+ catch {
174
+ // not JSON — the status or code check below names it
175
+ }
176
+ assert.strictEqual(response.status, probe.expected.status, `${label}: answered ${response.status} ${JSON.stringify(body)}`);
177
+ assert.strictEqual(body?.error, probe.expected.code, `${label}: answered ${JSON.stringify(body)}`);
178
+ await collector.assert_and_record(route_specs, probe.method, probe.path, response);
179
+ };
@@ -1,5 +1,6 @@
1
1
  import './assert_dev_env.js';
2
2
  import { type AuthPrincipal } from './integration_helpers.js';
3
+ import { type RouteParamValues } from './schema_generators.js';
3
4
  import type { SetupTest, TestFixture } from './cross_backend/setup.js';
4
5
  import type { AppSurfaceSpec } from '../http/surface.js';
5
6
  /** Options for `describe_round_trip_validation`. */
@@ -20,6 +21,12 @@ export interface RoundTripTestOptions {
20
21
  skip_routes?: Array<string>;
21
22
  /** Override generated bodies for specific routes (`'METHOD /path'` → body). */
22
23
  input_overrides?: Map<string, Record<string, unknown>>;
24
+ /**
25
+ * Path param values for specific routes (`'METHOD /path'` → param name →
26
+ * value), used before the generated ones — needed for a `{re}` param whose
27
+ * pattern refuses the generated value. See `RouteParamValues`.
28
+ */
29
+ param_values?: RouteParamValues;
23
30
  /**
24
31
  * Success-case fixtures for routes whose **populated success body** the
25
32
  * generic nil-id input can't reach — referential REST routes whose path
@@ -1 +1 @@
1
- {"version":3,"file":"round_trip.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/round_trip.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AA8B7B,OAAO,EAON,KAAK,aAAa,EAClB,MAAM,0BAA0B,CAAC;AAMlC,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEzD,oDAAoD;AACpD,MA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H,cAAc,EAAE,cAAc,CAAC;IAC/B,kDAAkD;IAClD,WAAW,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC5B,+EAA+E;IAC/E,eAAe,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACvD;;;;OAIG;IACH,YAAY,CAAC,EAAE,gBAAgB,CAAC;IAChC;;;;;;;;;;;;;OAaG;IACH,gBAAgB,CAAC,EAAE,GAAG,CACrB,MAAM,EACN,CAAC,OAAO,EAAE,WAAW,KAAK,OAAO,CAAC;QAAE,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAC,CACnF,CAAC;CACF;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,0BAA0B,GACtC,WAAW,MAAM,EACjB,QAAQ,MAAM,EACd,MAAM,OAAO,EACb,WAAW,aAAa,KACtB,IAUF,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,8BAA8B,GAAI,SAAS,oBAAoB,KAAG,IAkK9E,CAAC"}
@@ -110,7 +110,7 @@ export const describe_round_trip_validation = (options) => {
110
110
  // every consumer hand-list them in `skip_routes`.
111
111
  if (spec.raw_body)
112
112
  return;
113
- const url = resolve_valid_path(spec.path, spec.params);
113
+ const url = resolve_valid_path(spec.path, spec.params, options.param_values?.[route_key]);
114
114
  const override = options.input_overrides?.get(route_key);
115
115
  let body = override ?? generate_valid_body(spec.input);
116
116
  // a mutation called as the authed account runs on a fresh one, so a
@@ -169,7 +169,8 @@ export const describe_round_trip_validation = (options) => {
169
169
  const spec = describe_time_specs.find((s) => s.method === method && s.path === path);
170
170
  assert.ok(spec, `success_fixtures references unknown route '${route_key}'`);
171
171
  const seeded = await build(fixture);
172
- const url = seeded.url ?? resolve_valid_path(spec.path, spec.params);
172
+ const url = seeded.url ??
173
+ resolve_valid_path(spec.path, spec.params, options.param_values?.[route_key]);
173
174
  const body = seeded.body;
174
175
  const headers = pick_auth_headers(spec, fixture, authed_account, admin_account);
175
176
  const res = await fixture.transport(url, {
@@ -167,6 +167,17 @@ export declare const to_body_input: (input_schema: ValidationSchema, label: stri
167
167
  export declare const to_route_content_type: (route: {
168
168
  raw_body?: boolean;
169
169
  }) => string;
170
+ /**
171
+ * Caller-supplied path param values, keyed by route key (`format_route_key`,
172
+ * `'METHOD /path'`) and then by param name — what the suites that resolve a
173
+ * route's path (`resolve_valid_path`) fill a param with before generating
174
+ * one. A route needs an entry when a param of it is a `:name{re}` whose
175
+ * pattern refuses every value the generator reaches, as a `{.+\.git}` refuses
176
+ * `test_<name>`. Each value is the param as the handler reads it, unencoded.
177
+ * Values are always percent-encoded, so a `{re}` that needs a literal `/` can't
178
+ * be met by a supplied value: its `/` arrives as `%2F`.
179
+ */
180
+ export type RouteParamValues = Readonly<Record<string, Readonly<Record<string, string>>>>;
170
181
  /**
171
182
  * Resolve a route path with valid-ish param values so params validation passes.
172
183
  * Used when testing input on routes that also have params.
@@ -177,7 +188,8 @@ export declare const to_route_content_type: (route: {
177
188
  * (`/v1/files:upload`) stays, and a `{re}` goes with its param. An optional
178
189
  * param is filled too.
179
190
  *
180
- * Without a params schema (or for a param the schema doesn't name) each
191
+ * A value in `param_values` is used first, percent-encoded. Otherwise,
192
+ * without a params schema (or for a param the schema doesn't name) each
181
193
  * param becomes `test_<name>` — fine for an unconstrained segment. With
182
194
  * one, `test_<name>` is still preferred wherever the field schema accepts
183
195
  * it, because the param name in the URL is what makes a failure message
@@ -186,18 +198,28 @@ export declare const to_route_content_type: (route: {
186
198
  * anything else is synthesized by `generate_valid_string`, so a
187
199
  * format-constrained segment (a `blake3:…` fact hash, a `tok_…` id)
188
200
  * resolves to a value its schema accepts instead of a `test_<name>` that
189
- * 400s before the route's real gates run. A `{re}` is not read: the value
190
- * comes from the schema alone.
191
- *
192
- * The synthesized value is percent-encoded, and a value containing `/` is
193
- * refused (it would silently add a path segment and route elsewhere) —
194
- * both fall back to `test_<name>`.
201
+ * 400s before the route's real gates run. The synthesized value is
202
+ * percent-encoded, and a value containing `/` is refused (it would silently
203
+ * add a path segment and route elsewhere) — both fall back to `test_<name>`.
204
+ *
205
+ * A `{re}` param's value, supplied or not, must match its pattern, grouped
206
+ * and anchored as Hono's RegExpRouter reads it — the stricter of its
207
+ * routers' readings, as TrieRouter leaves a top-level alternation ungrouped
208
+ * (`compile_route_param_pattern`, over the value as Hono decodes it,
209
+ * `decode_route_path`) — or the request would reach no route; no value is
210
+ * guessed from the pattern. A supplied value the URL would normalize away
211
+ * (`''`, `.`, `..`) is refused by name.
195
212
  *
196
213
  * @param path - the route's path template
197
214
  * @param params_schema - the route's params schema, a Zod or `@fuzdev/fuz_schema` object schema
198
- * @throws Error when `params_schema` is no object schema, or of neither library
215
+ * @param param_values - the route's supplied param values by name, its entry of `RouteParamValues`
216
+ * @throws Error when `params_schema` is no object schema, or of neither library;
217
+ * when `param_values` names no param of the path; when a supplied value is
218
+ * `''`, `.` or `..`, or holds a lone surrogate, which can't be encoded; and
219
+ * when a `{re}` param's value is one its pattern refuses, naming the route
220
+ * and the param
199
221
  */
200
- export declare const resolve_valid_path: (path: string, params_schema?: ValidationSchema) => string;
222
+ export declare const resolve_valid_path: (path: string, params_schema?: ValidationSchema, param_values?: Readonly<Record<string, string>>) => string;
201
223
  /**
202
224
  * Generate a valid request body for a route's or action's input schema.
203
225
  *