@fuzdev/fuz_app 0.164.0 → 0.166.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/dist/actions/CLAUDE.md +2 -2
- 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 +24 -15
- package/dist/actions/action_spec.d.ts +2 -2
- package/dist/actions/perform_action.d.ts +2 -1
- package/dist/actions/perform_action.d.ts.map +1 -1
- package/dist/auth/account_action_specs.d.ts +8 -8
- package/dist/auth/account_route_schema.d.ts +197 -164
- package/dist/auth/account_route_schema.d.ts.map +1 -1
- package/dist/auth/account_route_schema.js +19 -17
- package/dist/auth/account_routes.d.ts.map +1 -1
- package/dist/auth/account_routes.js +285 -294
- package/dist/auth/admin_action_specs.d.ts +64 -64
- package/dist/auth/audit_log_route_schema.d.ts +16 -8
- package/dist/auth/audit_log_route_schema.d.ts.map +1 -1
- package/dist/auth/audit_log_route_schema.js +4 -3
- package/dist/auth/audit_log_routes.d.ts +1 -1
- package/dist/auth/audit_log_routes.d.ts.map +1 -1
- package/dist/auth/audit_log_routes.js +112 -111
- package/dist/auth/audit_log_schema.d.ts +22 -22
- package/dist/auth/bootstrap_route_schema.d.ts +46 -69
- package/dist/auth/bootstrap_route_schema.d.ts.map +1 -1
- package/dist/auth/bootstrap_route_schema.js +8 -7
- package/dist/auth/bootstrap_routes.d.ts.map +1 -1
- package/dist/auth/bootstrap_routes.js +100 -98
- package/dist/auth/role_grant_offer_action_specs.d.ts +4 -4
- package/dist/auth/signup_route_schema.d.ts +9 -4
- package/dist/auth/signup_route_schema.d.ts.map +1 -1
- package/dist/auth/signup_route_schema.js +5 -3
- package/dist/auth/signup_routes.d.ts.map +1 -1
- package/dist/auth/signup_routes.js +170 -170
- package/dist/http/CLAUDE.md +50 -4
- 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 +13 -11
- package/dist/http/db_routes.d.ts.map +1 -1
- package/dist/http/db_routes.js +25 -28
- package/dist/http/error_schemas.d.ts +5 -1
- package/dist/http/error_schemas.d.ts.map +1 -1
- package/dist/http/error_schemas.js +5 -1
- package/dist/http/route_error_check.d.ts +21 -0
- package/dist/http/route_error_check.d.ts.map +1 -1
- package/dist/http/route_error_check.js +37 -1
- package/dist/http/route_result.d.ts +101 -0
- package/dist/http/route_result.d.ts.map +1 -0
- package/dist/http/route_result.js +56 -0
- package/dist/http/route_spec.d.ts +110 -6
- package/dist/http/route_spec.d.ts.map +1 -1
- package/dist/http/route_spec.js +82 -14
- package/dist/http/schema_helpers.d.ts +15 -1
- package/dist/http/schema_helpers.d.ts.map +1 -1
- package/dist/http/schema_helpers.js +12 -3
- package/dist/rate_limiter.d.ts +0 -9
- package/dist/rate_limiter.d.ts.map +1 -1
- package/dist/rate_limiter.js +0 -15
- package/dist/server/serve_fact_route.d.ts.map +1 -1
- package/dist/server/serve_fact_route.js +23 -21
- package/dist/server/surface_route.d.ts +1 -1
- package/dist/server/surface_route.d.ts.map +1 -1
- package/dist/server/surface_route.js +4 -2
- package/dist/testing/CLAUDE.md +80 -28
- package/dist/testing/admin_integration.js +1 -1
- package/dist/testing/adversarial_404.d.ts.map +1 -1
- package/dist/testing/adversarial_404.js +13 -8
- package/dist/testing/adversarial_input.js +2 -2
- package/dist/testing/assertions.d.ts +13 -3
- package/dist/testing/assertions.d.ts.map +1 -1
- package/dist/testing/assertions.js +21 -4
- package/dist/testing/attack_surface.d.ts +12 -0
- package/dist/testing/attack_surface.d.ts.map +1 -1
- package/dist/testing/attack_surface.js +8 -5
- 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/login_security.d.ts.map +1 -1
- package/dist/testing/cross_backend/login_security.js +3 -2
- package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts.map +1 -1
- package/dist/testing/cross_backend/rust_spine_consumer_surface.js +2 -6
- 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/data_exposure.d.ts +7 -0
- package/dist/testing/data_exposure.d.ts.map +1 -1
- package/dist/testing/data_exposure.js +3 -3
- package/dist/testing/error_coverage.d.ts +35 -33
- package/dist/testing/error_coverage.d.ts.map +1 -1
- package/dist/testing/error_coverage.js +53 -43
- package/dist/testing/integration.d.ts +28 -1
- package/dist/testing/integration.d.ts.map +1 -1
- package/dist/testing/integration.js +51 -18
- package/dist/testing/integration_helpers.d.ts.map +1 -1
- package/dist/testing/integration_helpers.js +4 -15
- 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/round_trip.d.ts +7 -0
- package/dist/testing/round_trip.d.ts.map +1 -1
- package/dist/testing/round_trip.js +3 -2
- package/dist/testing/schema_generators.d.ts +31 -9
- package/dist/testing/schema_generators.d.ts.map +1 -1
- package/dist/testing/schema_generators.js +53 -11
- package/dist/testing/stubs.d.ts +14 -3
- package/dist/testing/stubs.d.ts.map +1 -1
- package/dist/testing/stubs.js +21 -6
- 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/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,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
|
|
@@ -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
|
-
*
|
|
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.
|
|
683
|
-
*
|
|
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
|
-
*
|
|
686
|
-
*
|
|
687
|
-
*
|
|
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
|
-
* @
|
|
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
|
|
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
|
-
|
|
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
|
/**
|
package/dist/testing/stubs.d.ts
CHANGED
|
@@ -8,7 +8,8 @@ import type { BootstrapServerOptions } from '../server/app_server.js';
|
|
|
8
8
|
import type { AppServerContext } from '../server/app_server_context.js';
|
|
9
9
|
import type { AppBackend } from '../server/app_backend.js';
|
|
10
10
|
import { Db } from '../db/db.js';
|
|
11
|
-
import { type RouteSpec } from '../http/route_spec.js';
|
|
11
|
+
import { type RouteShape, type RouteSpec } from '../http/route_spec.js';
|
|
12
|
+
import { type RouteRaw } from '../http/route_result.js';
|
|
12
13
|
import { type AppSurfaceSpec, type RpcEndpointSpec } from '../http/surface.js';
|
|
13
14
|
import { type WsEndpointSpec } from '../actions/ws_endpoint_spec.js';
|
|
14
15
|
import type { EventSpec } from '../realtime/sse.js';
|
|
@@ -52,8 +53,18 @@ export declare const stub: any;
|
|
|
52
53
|
* - `transaction(fn)` calls `fn(db)` synchronously (no real transaction)
|
|
53
54
|
*/
|
|
54
55
|
export declare const create_stub_db: () => Db;
|
|
55
|
-
/** Stub handler that
|
|
56
|
-
export declare const stub_handler: () =>
|
|
56
|
+
/** Stub handler that answers a 200 `stub` text response, as a raw result. */
|
|
57
|
+
export declare const stub_handler: () => RouteRaw;
|
|
58
|
+
/**
|
|
59
|
+
* A route spec for a surface that is described and never served — a
|
|
60
|
+
* backend's routes declared from their shapes: `shape` with a handler that
|
|
61
|
+
* throws when it is run. Its handler is checked against nothing, as it
|
|
62
|
+
* returns nothing.
|
|
63
|
+
*
|
|
64
|
+
* @param shape - the route minus its handler (`define_route_shape`)
|
|
65
|
+
* @returns the spec, for surface generation
|
|
66
|
+
*/
|
|
67
|
+
export declare const stub_route_spec: (shape: RouteShape) => RouteSpec;
|
|
57
68
|
/** Stub middleware that passes through. */
|
|
58
69
|
export declare const stub_mw: (_c: any, next: any) => Promise<void>;
|
|
59
70
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stubs.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/stubs.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAa7B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAE9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAGrF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAE7D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACjC,OAAO,
|
|
1
|
+
{"version":3,"file":"stubs.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/stubs.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAa7B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAE9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAGrF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAE7D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,EA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IAC5F;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACxC;;;;;;;;OAQG;IACH,oBAAoB,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,cAAc,CAAC,KAAK,KAAK,CAAC,cAAc,CAAC,CAAC;IAC/E;;;;;;OAMG;IACH,iBAAiB,CAAC,EAAE,KAAK,CAAC,kBAAkB,CAAC,CAAC;IAC9C;;;;;;;;OAQG;IACH,SAAS,CAAC,EAAE,sBAAsB,CAAC;IACnC;;;;;;;OAOG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;;;;OAKG;IACH,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B;AAmBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,eAAO,MAAM,4BAA4B,GACxC,SAAS,+BAA+B,KACtC,cA+GF,CAAC"}
|
package/dist/testing/stubs.js
CHANGED
|
@@ -12,7 +12,8 @@ import { REST_FORBIDDEN_ORIGIN } from '../http/error_schemas.js';
|
|
|
12
12
|
import { body_limit_middleware_shape } from '../http/body_limit_schema.js';
|
|
13
13
|
import { create_realtime_closer } from '../actions/connection_closer.js';
|
|
14
14
|
import { Db } from '../db/db.js';
|
|
15
|
-
import { prefix_route_specs } from '../http/route_spec.js';
|
|
15
|
+
import { attach_route_handler, prefix_route_specs } from '../http/route_spec.js';
|
|
16
|
+
import { route_raw } from '../http/route_result.js';
|
|
16
17
|
import { bootstrap_route_shape } from '../auth/bootstrap_route_schema.js';
|
|
17
18
|
import { create_rpc_endpoint } from '../actions/action_rpc.js';
|
|
18
19
|
import { create_surface_route_spec } from '../server/surface_route.js';
|
|
@@ -90,8 +91,22 @@ export const create_stub_db = () => new Db({
|
|
|
90
91
|
client: { query: async () => ({ rows: [] }) },
|
|
91
92
|
transaction: async (fn) => fn(create_stub_db())
|
|
92
93
|
});
|
|
93
|
-
/** Stub handler that
|
|
94
|
-
export const stub_handler = () => new Response('stub');
|
|
94
|
+
/** Stub handler that answers a 200 `stub` text response, as a raw result. */
|
|
95
|
+
export const stub_handler = () => route_raw(new Response('stub'));
|
|
96
|
+
/**
|
|
97
|
+
* A route spec for a surface that is described and never served — a
|
|
98
|
+
* backend's routes declared from their shapes: `shape` with a handler that
|
|
99
|
+
* throws when it is run. Its handler is checked against nothing, as it
|
|
100
|
+
* returns nothing.
|
|
101
|
+
*
|
|
102
|
+
* @param shape - the route minus its handler (`define_route_shape`)
|
|
103
|
+
* @returns the spec, for surface generation
|
|
104
|
+
*/
|
|
105
|
+
export const stub_route_spec = (shape) =>
|
|
106
|
+
// a handler that never returns fits any route, so the shape's own types are not needed
|
|
107
|
+
attach_route_handler(shape, () => {
|
|
108
|
+
throw new Error(`stub_route_spec: ${shape.method} ${shape.path} is surface-only, its handler never runs`);
|
|
109
|
+
});
|
|
95
110
|
/** Stub middleware that passes through. */
|
|
96
111
|
export const stub_mw = async (_c, next) => next();
|
|
97
112
|
const stub_db = create_noop_stub('stub_db');
|
|
@@ -324,9 +339,9 @@ export const create_test_app_surface_spec = (options) => {
|
|
|
324
339
|
const bootstrap_route_specs = options.bootstrap && options.bootstrap.mode !== 'disabled'
|
|
325
340
|
? prefix_route_specs(options.bootstrap.route_prefix ?? '/api/account', [
|
|
326
341
|
// Surface generation reads the route shape only — the live hono
|
|
327
|
-
// handler never runs here, so a stub
|
|
328
|
-
//
|
|
329
|
-
|
|
342
|
+
// handler never runs here, so a stub stands in for it without
|
|
343
|
+
// pulling the in-process Hono app onto cross-process consumers.
|
|
344
|
+
attach_route_handler(bootstrap_route_shape, stub_handler)
|
|
330
345
|
])
|
|
331
346
|
: [];
|
|
332
347
|
for (const route of bootstrap_route_specs) {
|
|
@@ -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
|
|
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`,
|
|
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,CAA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,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`,
|
|
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
|
|
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:
|
|
115
|
+
Host: host,
|
|
110
116
|
...headers,
|
|
111
117
|
'Content-Length': String(content_length)
|
|
112
118
|
});
|