@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
@@ -1 +1 @@
1
- {"version":3,"file":"schema_generators.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/schema_generators.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAsB7B,OAAO,EAKN,KAAK,eAAe,EACpB,MAAM,WAAW,CAAC;AAInB,OAAO,EAIN,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,MAAM,qBAAqB,CAAC;AAE7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,oBAAoB,GAAI,cAAc,gBAAgB,KAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAe3F,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,yBAAyB,GAAI,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAG,MAAM,GAAG,IAWlF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,aAAa,GAAI,cAAc,gBAAgB,KAAG,MAAM,GAAG,IACV,CAAC;AAmI/D,2EAA2E;AAC3E,MAAM,WAAW,gBAAgB;IAChC,wCAAwC;IACxC,MAAM,EAAE,KA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EAChC,eAAe,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,KAC7C,MAgEF,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,mBAAmB,GAC/B,cAAc,gBAAgB,KAC5B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAW5B,CAAC"}
@@ -16,7 +16,7 @@ import { get_schema_entries, get_schema_fields, unwrap_schema } from '@fuzdev/fu
16
16
  import { to_json_schema } from '@fuzdev/fuz_schema/json_schema.ts';
17
17
  import { zod_unwrap_def, zod_get_base_type, zod_unwrap_to_object, zod_extract_fields } from '../zod.js';
18
18
  import { is_null_schema, is_void_schema } from '../http/schema_helpers.js';
19
- import { parse_route_param, split_route_template } from '../http/route_error_check.js';
19
+ import { compile_route_param_pattern, decode_route_path, parse_route_param, split_route_template } from '../http/route_error_check.js';
20
20
  import { assert_zod_schema, format_issues, parse_any } from '../schema_issues.js';
21
21
  /**
22
22
  * The JSON Schema of a field's input side — where its format, pattern and
@@ -670,7 +670,8 @@ export const to_route_content_type = (route) => route.raw_body ? 'application/oc
670
670
  * (`/v1/files:upload`) stays, and a `{re}` goes with its param. An optional
671
671
  * param is filled too.
672
672
  *
673
- * Without a params schema (or for a param the schema doesn't name) each
673
+ * A value in `param_values` is used first, percent-encoded. Otherwise,
674
+ * without a params schema (or for a param the schema doesn't name) each
674
675
  * param becomes `test_<name>` — fine for an unconstrained segment. With
675
676
  * one, `test_<name>` is still preferred wherever the field schema accepts
676
677
  * it, because the param name in the URL is what makes a failure message
@@ -679,22 +680,32 @@ export const to_route_content_type = (route) => route.raw_body ? 'application/oc
679
680
  * anything else is synthesized by `generate_valid_string`, so a
680
681
  * format-constrained segment (a `blake3:…` fact hash, a `tok_…` id)
681
682
  * resolves to a value its schema accepts instead of a `test_<name>` that
682
- * 400s before the route's real gates run. A `{re}` is not read: the value
683
- * comes from the schema alone.
683
+ * 400s before the route's real gates run. The synthesized value is
684
+ * percent-encoded, and a value containing `/` is refused (it would silently
685
+ * add a path segment and route elsewhere) — both fall back to `test_<name>`.
684
686
  *
685
- * The synthesized value is percent-encoded, and a value containing `/` is
686
- * refused (it would silently add a path segment and route elsewhere) —
687
- * both fall back to `test_<name>`.
687
+ * A `{re}` param's value, supplied or not, must match its pattern, grouped
688
+ * and anchored as Hono's RegExpRouter reads it — the stricter of its
689
+ * routers' readings, as TrieRouter leaves a top-level alternation ungrouped
690
+ * (`compile_route_param_pattern`, over the value as Hono decodes it,
691
+ * `decode_route_path`) — or the request would reach no route; no value is
692
+ * guessed from the pattern. A supplied value the URL would normalize away
693
+ * (`''`, `.`, `..`) is refused by name.
688
694
  *
689
695
  * @param path - the route's path template
690
696
  * @param params_schema - the route's params schema, a Zod or `@fuzdev/fuz_schema` object schema
691
- * @throws Error when `params_schema` is no object schema, or of neither library
697
+ * @param param_values - the route's supplied param values by name, its entry of `RouteParamValues`
698
+ * @throws Error when `params_schema` is no object schema, or of neither library;
699
+ * when `param_values` names no param of the path; when a supplied value is
700
+ * `''`, `.` or `..`, or holds a lone surrogate, which can't be encoded; and
701
+ * when a `{re}` param's value is one its pattern refuses, naming the route
702
+ * and the param
692
703
  */
693
- export const resolve_valid_path = (path, params_schema) => {
704
+ export const resolve_valid_path = (path, params_schema, param_values) => {
694
705
  const view = params_schema
695
706
  ? to_object_schema_view(params_schema, `resolve_valid_path(${path}): the params schema`)
696
707
  : null;
697
- const fill = (name) => {
708
+ const generate = (name) => {
698
709
  const fallback = encodeURIComponent(`test_${name}`);
699
710
  const field_schema = view?.field_schema(name);
700
711
  if (!field_schema)
@@ -711,10 +722,41 @@ export const resolve_valid_path = (path, params_schema) => {
711
722
  return fallback;
712
723
  return encodeURIComponent(generated);
713
724
  };
725
+ const encode_supplied = (name, supplied) => {
726
+ // the URL drops an empty segment's meaning and resolves `.` and `..` away
727
+ if (supplied === '' || supplied === '.' || supplied === '..') {
728
+ throw new Error(`resolve_valid_path: the value supplied for the param \`${name}\` of \`${path}\` is ${JSON.stringify(supplied)}, which the URL normalizes away, so the request would not reach the route`);
729
+ }
730
+ try {
731
+ return encodeURIComponent(supplied);
732
+ }
733
+ catch (error) {
734
+ if (!(error instanceof URIError))
735
+ throw error;
736
+ throw new Error(`resolve_valid_path: the value supplied for the param \`${name}\` of \`${path}\` holds a lone surrogate, which can't be percent-encoded`);
737
+ }
738
+ };
739
+ const names = new Set();
714
740
  const segments = split_route_template(path).map((segment) => {
715
741
  const param = parse_route_param(segment);
716
- return param ? fill(param.name) : segment;
742
+ if (!param)
743
+ return segment;
744
+ const { name, pattern } = param;
745
+ names.add(name);
746
+ const supplied = param_values && Object.hasOwn(param_values, name) ? param_values[name] : undefined;
747
+ const value = supplied === undefined ? generate(name) : encode_supplied(name, supplied);
748
+ if (pattern !== null && !compile_route_param_pattern(pattern).test(decode_route_path(value))) {
749
+ throw new Error(`resolve_valid_path: the param \`${name}\` of \`${path}\` resolves to ${JSON.stringify(value)}${supplied === undefined ? ',' : ', the value supplied for it,'} which its pattern \`{${pattern}}\` refuses, so the request would reach no route — supply a value the pattern accepts in the suite's \`param_values\`, under the route's key (\`'METHOD ${path}'\`) and then \`${name}\``);
750
+ }
751
+ return value;
717
752
  });
753
+ if (param_values) {
754
+ for (const name of Object.keys(param_values)) {
755
+ if (!names.has(name)) {
756
+ throw new Error(`resolve_valid_path: \`param_values\` names \`${name}\`, which is no param of \`${path}\``);
757
+ }
758
+ }
759
+ }
718
760
  return (path.startsWith('/') ? '/' : '') + segments.join('/');
719
761
  };
720
762
  /**
@@ -72,13 +72,20 @@ export interface RawHttpHeadRequest {
72
72
  readonly path: string;
73
73
  /**
74
74
  * Request headers beyond `Host` and `Content-Length`, which the helper
75
- * writes — naming either here, in any casing, throws. Nothing else is
75
+ * writes from `host` and `content_length` — naming either here, in any
76
+ * casing, throws. Nothing else is
76
77
  * defaulted — no `Origin`, no credential — so a request carries exactly
77
78
  * what the caller names.
78
79
  */
79
80
  readonly headers: Readonly<Record<string, string>>;
80
81
  /** The `Content-Length` to declare; no body byte is sent. */
81
82
  readonly content_length: number;
83
+ /**
84
+ * The `Host` to send, for a probe of a server's host check.
85
+ *
86
+ * @default the host of `base_url`
87
+ */
88
+ readonly host?: string;
82
89
  /**
83
90
  * How long to wait for the response.
84
91
  *
@@ -108,7 +115,8 @@ export interface RawHttpHeadRequest {
108
115
  * @param base_url - the server's base URL; only its host and port are used
109
116
  * @param request - the method, path, headers and declared length to send
110
117
  * @returns the parsed response; its `body` is the raw text
111
- * @throws Error when `request.headers` names `Host` or `Content-Length`, or
118
+ * @throws Error when `request.headers` names `Host` or `Content-Length`, when
119
+ * a header name or value or the host holds a CR or LF, or
112
120
  * when no whole response arrives — the connection was refused, the server
113
121
  * closed it before any byte or partway through a response, or it waited for
114
122
  * the body it should have refused without
@@ -1 +1 @@
1
- {"version":3,"file":"raw_http.d.ts","sourceRoot":"../src/lib/","sources":["../../../src/lib/testing/transports/raw_http.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAuB9B;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,OAAO,CAAC;AAE7C,uDAAuD;AACvD,MAAM,WAAW,eAAe;IAC/B,oDAAoD;IACpD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B;;;;OAIG;IACH,QAAQ,CAAC,gBAAgB,EAAE,OAAO,CAAC;CACnC;AAED,uCAAuC;AACvC,MAAM,WAAW,sBAAsB;IACtC,uDAAuD;IACvD,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC;;;;;;;;;;;;OAYG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,UAAU,CAAC;CACtC;AAED,oCAAoC;AACpC,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,gFAAgF;IAChF,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACnD,2DAA2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E,MAAM,CAAC;IAChC;;;;OAIG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB;;;;OAIG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;CAClC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,kBAAkB,GAC9B,UAAU,MAAM,EAChB,SAAS,kBAAkB,KACzB,OAAO,CAAC,eAAe,CAoDzB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,GAAI,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAG,MAG7D,CAAC;AAEZ;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,GAAI,MAAM,MAAM,KAAG,OAMlD,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,GAAI,KAAK,MAAM,KAAG,MACN,CAAC;AAElD,0FAA0F;AAC1F,eAAO,MAAM,qBAAqB,GAAI,KAAK,MAAM,KAAG,MAAM,GAAG,IAG5D,CAAC;AAyBF;;;;;;;;;GASG;AACH,eAAO,MAAM,uBAAuB,GAAI,KAAK,MAAM,KAAG,eAAe,GAAG,IAyBvE,CAAC"}
@@ -90,23 +90,29 @@ const SEND_HEAD_WRITTEN_HEADERS = ['host', 'content-length'];
90
90
  * @param base_url - the server's base URL; only its host and port are used
91
91
  * @param request - the method, path, headers and declared length to send
92
92
  * @returns the parsed response; its `body` is the raw text
93
- * @throws Error when `request.headers` names `Host` or `Content-Length`, or
93
+ * @throws Error when `request.headers` names `Host` or `Content-Length`, when
94
+ * a header name or value or the host holds a CR or LF, or
94
95
  * when no whole response arrives — the connection was refused, the server
95
96
  * closed it before any byte or partway through a response, or it waited for
96
97
  * the body it should have refused without
97
98
  */
98
99
  export const raw_http_send_head = async (base_url, request) => {
99
- const { method = 'POST', path, headers, content_length, read_timeout_ms = RAW_HTTP_READ_TIMEOUT_MS } = request;
100
+ const { method = 'POST', path, headers, content_length, host = new URL(base_url).host, read_timeout_ms = RAW_HTTP_READ_TIMEOUT_MS } = request;
100
101
  // a caller-named `Host` or `Content-Length` would replace the helper's line,
101
102
  // be dropped under it, or go out beside it as a second one, so the request
102
103
  // would no longer be the one the caller describes
103
104
  const collision = Object.keys(headers).find((name) => SEND_HEAD_WRITTEN_HEADERS.includes(name.toLowerCase()));
104
105
  if (collision !== undefined) {
105
106
  throw new Error(`raw_http_send_head writes Host and Content-Length itself; drop '${collision}' from ` +
106
- '`headers` and declare the length through `content_length`');
107
+ '`headers` and set them through `host` and `content_length`');
108
+ }
109
+ // a CR or LF would end the line early and smuggle a header or a request in
110
+ const broken = [host, ...Object.entries(headers).flat()].find((text) => /[\r\n]/.test(text));
111
+ if (broken !== undefined) {
112
+ throw new Error(`raw_http_send_head: a CR or LF in a header name or value or the host: ${JSON.stringify(broken)}`);
107
113
  }
108
114
  const header_lines = raw_http_header_lines({
109
- Host: new URL(base_url).host,
115
+ Host: host,
110
116
  ...headers,
111
117
  'Content-Length': String(content_length)
112
118
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fuzdev/fuz_app",
3
- "version": "0.164.0",
3
+ "version": "0.165.0",
4
4
  "description": "fullstack app library",
5
5
  "glyph": "🗝",
6
6
  "logo": "logo.svg",