@fuzdev/fuz_app 0.184.0 → 0.185.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 +4 -1
- package/dist/actions/register_action_ws.d.ts +14 -7
- package/dist/actions/register_action_ws.d.ts.map +1 -1
- package/dist/actions/ws_socket_session.d.ts +17 -4
- package/dist/actions/ws_socket_session.d.ts.map +1 -1
- package/dist/actions/ws_socket_session.js +38 -6
- package/dist/auth/CLAUDE.md +7 -4
- 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 +3 -2
- package/dist/auth/cleanup.d.ts +34 -3
- package/dist/auth/cleanup.d.ts.map +1 -1
- package/dist/auth/cleanup.js +11 -3
- package/dist/http/CLAUDE.md +1 -1
- package/dist/http/pending_effects.d.ts +8 -4
- package/dist/http/pending_effects.d.ts.map +1 -1
- package/dist/http/route_spec.d.ts +3 -3
- package/dist/http/route_spec.d.ts.map +1 -1
- package/dist/realtime/audit_log_sse.d.ts +1 -1
- package/dist/realtime/sse.d.ts +2 -2
- package/dist/realtime/sse.d.ts.map +1 -1
- package/dist/realtime/sse_constants.d.ts +1 -1
- package/dist/realtime/sse_constants.js +1 -1
- package/dist/server/app_server.d.ts +59 -71
- package/dist/server/app_server.d.ts.map +1 -1
- package/dist/server/app_server.js +52 -60
- package/dist/server/shutdown_drain.d.ts +69 -0
- package/dist/server/shutdown_drain.d.ts.map +1 -0
- package/dist/server/shutdown_drain.js +77 -0
- package/dist/testing/CLAUDE.md +73 -41
- package/dist/testing/admin_integration.d.ts +2 -2
- package/dist/testing/admin_integration.d.ts.map +1 -1
- package/dist/testing/admin_integration.js +36 -20
- package/dist/testing/cross_backend/bootstrap_backend.d.ts +3 -1
- package/dist/testing/cross_backend/bootstrap_backend.d.ts.map +1 -1
- package/dist/testing/cross_backend/bootstrap_backend.js +5 -1
- package/dist/testing/cross_backend/create_dual_spawn_global_setup.d.ts +10 -1
- package/dist/testing/cross_backend/create_dual_spawn_global_setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/create_dual_spawn_global_setup.js +33 -7
- package/dist/testing/cross_backend/in_process_setup.d.ts +1 -1
- package/dist/testing/cross_backend/in_process_setup.js +1 -1
- package/dist/testing/cross_backend/rpc_success_fixtures.d.ts.map +1 -1
- package/dist/testing/cross_backend/rpc_success_fixtures.js +2 -1
- package/dist/testing/cross_backend/spawn_backend.d.ts +14 -0
- package/dist/testing/cross_backend/spawn_backend.d.ts.map +1 -1
- package/dist/testing/cross_backend/spawn_backend.js +56 -8
- package/dist/testing/cross_backend/spine_suites.d.ts +17 -14
- package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
- package/dist/testing/cross_backend/spine_suites.js +33 -13
- package/dist/testing/cross_backend/standard.d.ts +18 -82
- package/dist/testing/cross_backend/standard.d.ts.map +1 -1
- package/dist/testing/cross_backend/standard.js +6 -21
- package/dist/testing/cross_backend/standard_auth.d.ts +74 -0
- package/dist/testing/cross_backend/standard_auth.d.ts.map +1 -0
- package/dist/testing/cross_backend/standard_auth.js +28 -0
- package/dist/testing/cross_backend/standard_bundle.d.ts +48 -0
- package/dist/testing/cross_backend/standard_bundle.d.ts.map +1 -0
- package/dist/testing/cross_backend/standard_bundle.js +43 -0
- package/dist/testing/cross_backend/testing_reset_actions.d.ts +11 -0
- package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_reset_actions.js +13 -0
- package/dist/testing/cross_backend/testing_server_bun.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_server_bun.js +5 -4
- package/dist/testing/cross_backend/testing_server_core.d.ts +16 -3
- package/dist/testing/cross_backend/testing_server_core.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_server_core.js +20 -4
- package/dist/testing/cross_backend/ts_spine_backend_config.d.ts +6 -2
- package/dist/testing/cross_backend/ts_spine_backend_config.d.ts.map +1 -1
- package/dist/testing/cross_backend/ts_spine_backend_config.js +7 -3
- package/dist/testing/error_coverage.d.ts +5 -0
- package/dist/testing/error_coverage.d.ts.map +1 -1
- package/dist/testing/error_coverage.js +2 -1
- package/dist/testing/integration.d.ts +4 -20
- package/dist/testing/integration.d.ts.map +1 -1
- package/dist/testing/integration.js +49 -79
- package/dist/testing/integration_helpers.d.ts +16 -0
- package/dist/testing/integration_helpers.d.ts.map +1 -1
- package/dist/testing/integration_helpers.js +29 -1
- package/dist/testing/middleware_gate_probes.d.ts +55 -1
- package/dist/testing/middleware_gate_probes.d.ts.map +1 -1
- package/dist/testing/middleware_gate_probes.js +69 -3
- package/dist/testing/test_app.d.ts +3 -2
- package/dist/testing/test_app.d.ts.map +1 -1
- package/dist/testing/test_app.js +5 -4
- package/package.json +1 -1
|
@@ -18,7 +18,7 @@ import './assert_dev_env.js';
|
|
|
18
18
|
*/
|
|
19
19
|
import { describe, test, assert, afterAll } from 'vitest';
|
|
20
20
|
import { parse_or_throw } from '@fuzdev/fuz_schema/schema.ts';
|
|
21
|
-
import { find_auth_route, assert_response_matches_spec, assert_no_error_info_leakage } from './integration_helpers.js';
|
|
21
|
+
import { find_auth_route, assert_response_matches_spec, assert_no_error_info_leakage, is_standard_integration_route, MIDDLEWARE_GATE_ERROR_CODES } from './integration_helpers.js';
|
|
22
22
|
import { find_rpc_action, rpc_call_for_spec, require_rpc_endpoint_path, resolve_rpc_endpoints_for_setup } from './rpc_helpers.js';
|
|
23
23
|
import { ErrorCoverageCollector, assert_error_coverage, DEFAULT_INTEGRATION_ERROR_COVERAGE } from './error_coverage.js';
|
|
24
24
|
import { is_public_auth } from '../http/auth_shape.js';
|
|
@@ -30,7 +30,6 @@ 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';
|
|
34
33
|
/**
|
|
35
34
|
* Standard integration test suite for fuz_app auth routes.
|
|
36
35
|
*
|
|
@@ -38,8 +37,10 @@ import { assert_middleware_gate_refusal, format_middleware_gate_probe, plan_midd
|
|
|
38
37
|
* revocation, password change (incl. API token revocation), origin
|
|
39
38
|
* verification, bearer auth (incl. browser context discard on mutations),
|
|
40
39
|
* token revocation, cross-account isolation, expired credential rejection,
|
|
41
|
-
* signup invite edge cases, response body validation
|
|
42
|
-
* gates each counted route's error map declares
|
|
40
|
+
* signup invite edge cases, and response body validation. The middleware
|
|
41
|
+
* gates each counted route's error map declares are
|
|
42
|
+
* `describe_middleware_gate_tests`' (`middleware_gate_probes.ts`), a suite of
|
|
43
|
+
* their own since over a socket they write raw request heads.
|
|
43
44
|
*
|
|
44
45
|
* Each test group asserts that required routes exist, failing with a descriptive
|
|
45
46
|
* message if the consumer's route specs are misconfigured.
|
|
@@ -74,17 +75,9 @@ export const describe_standard_integration_tests = (options) => {
|
|
|
74
75
|
const cookie_name = options.session_cookie_name;
|
|
75
76
|
// Error coverage tracking across test groups
|
|
76
77
|
const error_collector = new ErrorCoverageCollector(options.surface_source.route_error_maps);
|
|
77
|
-
// the auth routes this suite drives
|
|
78
|
-
//
|
|
79
|
-
|
|
80
|
-
const is_suite_auth_route = (s) => {
|
|
81
|
-
if (s.auth.roles?.includes('admin') ?? false)
|
|
82
|
-
return false;
|
|
83
|
-
const rest_suffixes = ['/login', '/logout', '/password', '/signup'];
|
|
84
|
-
if (rest_suffixes.some((suffix) => s.path.endsWith(suffix)))
|
|
85
|
-
return true;
|
|
86
|
-
return s.path === rpc_path;
|
|
87
|
-
};
|
|
78
|
+
// the auth routes this suite drives — admin-role routes belong to the
|
|
79
|
+
// admin suite
|
|
80
|
+
const is_suite_auth_route = (s) => is_standard_integration_route(s, rpc_path);
|
|
88
81
|
afterAll(() => {
|
|
89
82
|
// Scope coverage to auth routes this suite actually exercises:
|
|
90
83
|
// login / logout / password drivers + signup invite edge cases
|
|
@@ -97,8 +90,11 @@ export const describe_standard_integration_tests = (options) => {
|
|
|
97
90
|
// the admin suite instead.
|
|
98
91
|
const auth_routes = route_specs.filter(is_suite_auth_route);
|
|
99
92
|
const scoped_routes = auth_routes.length > 0 ? auth_routes : route_specs;
|
|
100
|
-
|
|
93
|
+
// the middleware gates' refusals are `describe_middleware_gate_tests`'
|
|
94
|
+
const filter = { ignore_codes: MIDDLEWARE_GATE_ERROR_CODES };
|
|
95
|
+
options.check_uncovered_errors?.(error_collector.uncovered(scoped_routes, filter));
|
|
101
96
|
assert_error_coverage(error_collector, scoped_routes, {
|
|
97
|
+
...filter,
|
|
102
98
|
min_coverage: options.error_coverage_min ?? DEFAULT_INTEGRATION_ERROR_COVERAGE
|
|
103
99
|
});
|
|
104
100
|
});
|
|
@@ -680,40 +676,43 @@ export const describe_standard_integration_tests = (options) => {
|
|
|
680
676
|
});
|
|
681
677
|
// --- 8. Cross-account isolation ---
|
|
682
678
|
describe('cross-account isolation', () => {
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
679
|
+
// admin routes are optional in the base suite — admin-specific coverage
|
|
680
|
+
// lives in describe_standard_admin_integration_tests.
|
|
681
|
+
//
|
|
682
|
+
// Pick an admin REST route where a clean role-denial 403 is
|
|
683
|
+
// reachable: account-grain (`actor: 'none'`, so the authorization
|
|
684
|
+
// phase doesn't first demand an acting actor → `actor_required`)
|
|
685
|
+
// and input/param/query-free (params and query still validate ahead
|
|
686
|
+
// of the auth phase — only body validation moved behind the gates,
|
|
687
|
+
// per the 401 → authz → 403 → 429 → 400 order). Admin surfaces are
|
|
688
|
+
// RPC-first now; a consumer may expose no such REST route (fuz_app
|
|
689
|
+
// itself, zzz) — then this REST-era check isn't registered and RPC denial
|
|
690
|
+
// is covered by `describe_rpc_attack_surface_tests`.
|
|
691
|
+
const admin_route = route_specs.find((s) => (s.auth.roles?.includes('admin') ?? false) &&
|
|
692
|
+
s.auth.actor === 'none' &&
|
|
693
|
+
!s.input &&
|
|
694
|
+
!s.params &&
|
|
695
|
+
!s.query);
|
|
696
|
+
// registered only where such a route exists: a plain skip would leave the
|
|
697
|
+
// transcript differential's run partial (its stale-ledger check unjudged),
|
|
698
|
+
// and a gated one would owe every consumer an `expected_skips` entry
|
|
699
|
+
if (admin_route) {
|
|
700
|
+
test('non-admin cannot access admin routes', async () => {
|
|
701
|
+
const fixture = await options.setup_test();
|
|
702
|
+
// Probe with a freshly-created account — it holds no admin role
|
|
703
|
+
// (the keeper fixture behind `create_session_headers` does, so it
|
|
704
|
+
// would pass the gate).
|
|
705
|
+
const non_admin = await fixture.create_account({ username: 'non_admin_admin_probe' });
|
|
706
|
+
const res = await fixture.transport(admin_route.path, {
|
|
707
|
+
method: admin_route.method,
|
|
708
|
+
headers: { cookie: `${cookie_name}=${non_admin.session_cookie}` }
|
|
709
|
+
});
|
|
710
|
+
assert.strictEqual(res.status, 403);
|
|
711
|
+
await error_collector.assert_and_record(route_specs, admin_route.method, admin_route.path, res);
|
|
712
|
+
const body = await res.json();
|
|
713
|
+
assert.strictEqual(body.error, 'insufficient_permissions');
|
|
714
|
+
});
|
|
715
|
+
}
|
|
717
716
|
test("user A cannot revoke user B's sessions", async () => {
|
|
718
717
|
const fixture = await options.setup_test();
|
|
719
718
|
// Create a second account
|
|
@@ -1052,35 +1051,6 @@ export const describe_standard_integration_tests = (options) => {
|
|
|
1052
1051
|
}
|
|
1053
1052
|
});
|
|
1054
1053
|
});
|
|
1055
|
-
// --- 12c. Middleware gates: each counted route's declared gates refuse ---
|
|
1056
|
-
describe('middleware gates', () => {
|
|
1057
|
-
// One probe per gate each counted route's error map declares — the
|
|
1058
|
-
// origin check, the Rust spine's host gate, the body limit — each a
|
|
1059
|
-
// bodiless head with no credential that the gate refuses before auth,
|
|
1060
|
-
// rate limiting or body parsing. A gate the map doesn't declare on a
|
|
1061
|
-
// route (a carve-out, a backend without the layer) gets no probe.
|
|
1062
|
-
const probes = plan_middleware_gate_probes({
|
|
1063
|
-
route_specs: route_specs.filter(is_suite_auth_route),
|
|
1064
|
-
route_error_maps: options.surface_source.route_error_maps,
|
|
1065
|
-
base_url: options.base_url,
|
|
1066
|
-
max_body_bytes: options.max_body_bytes,
|
|
1067
|
-
rpc_path,
|
|
1068
|
-
rpc_max_body_bytes: options.rpc_max_body_bytes
|
|
1069
|
-
});
|
|
1070
|
-
// in-process the probes share one fixture's transport, made by the first
|
|
1071
|
-
// to run; over a socket they need none, as they read and write no state
|
|
1072
|
-
let in_process_transport = null;
|
|
1073
|
-
const get_transport = () => (in_process_transport ??= options
|
|
1074
|
-
.setup_test()
|
|
1075
|
-
.then((fixture) => fixture.fresh_transport({ origin: null })));
|
|
1076
|
-
for (const probe of probes) {
|
|
1077
|
-
test(format_middleware_gate_probe(probe), async () => {
|
|
1078
|
-
const transport = options.base_url === null ? await get_transport() : null;
|
|
1079
|
-
const res = await send_middleware_gate_probe(probe, options.base_url, transport);
|
|
1080
|
-
await assert_middleware_gate_refusal(probe, res, error_collector, route_specs);
|
|
1081
|
-
});
|
|
1082
|
-
}
|
|
1083
|
-
});
|
|
1084
1054
|
// --- 13. Password change revokes API tokens ---
|
|
1085
1055
|
describe('password change revokes API tokens', () => {
|
|
1086
1056
|
test('API tokens are invalidated after password change', async () => {
|
|
@@ -40,6 +40,22 @@ export type RestAuthRouteSuffix = (typeof rest_auth_route_suffixes)[number];
|
|
|
40
40
|
* @throws Error if `suffix` is not in `rest_auth_route_suffixes`.
|
|
41
41
|
*/
|
|
42
42
|
export declare const find_auth_route: (specs: Array<RouteSpec>, suffix: RestAuthRouteSuffix, method: RouteMethod) => RouteSpec | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* The middleware gates' refusals: the origin check's, the host gate's and the
|
|
45
|
+
* body limit's. `describe_middleware_gate_tests` probes each on every counted
|
|
46
|
+
* route that declares it, so the integration suite's coverage leaves them out.
|
|
47
|
+
*/
|
|
48
|
+
export declare const MIDDLEWARE_GATE_ERROR_CODES: ReadonlyArray<string>;
|
|
49
|
+
/**
|
|
50
|
+
* Whether the standard integration suite counts a route: login, logout,
|
|
51
|
+
* password and signup (when wired), and the shared RPC endpoint — the routes
|
|
52
|
+
* its error coverage is scoped to and `describe_middleware_gate_tests` probes.
|
|
53
|
+
* An admin-role route belongs to the admin suite.
|
|
54
|
+
*
|
|
55
|
+
* @param spec - the route
|
|
56
|
+
* @param rpc_path - the RPC endpoint's path
|
|
57
|
+
*/
|
|
58
|
+
export declare const is_standard_integration_route: (spec: RouteSpec, rpc_path: string) => boolean;
|
|
43
59
|
/**
|
|
44
60
|
* Validate a response body against the route spec's declared schemas.
|
|
45
61
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"integration_helpers.d.ts","sourceRoot":"","sources":["../../src/lib/testing/integration_helpers.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAW7B,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;
|
|
1
|
+
{"version":3,"file":"integration_helpers.d.ts","sour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,MAAM,mBAAmB,GAAI,MAAM,SAAS,KAAG,aAKrD,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB,GAChC,WAAW,aAAa,EACxB,QAAQ,oBAAoB,EAC5B,gBAAgB,WAAW,EAC3B,eAAe,WAAW,KACxB,MAAM,CAAC,MAAM,EAAE,MAAM,CAavB,CAAC;AAEF,mFAAmF;AACnF,MAAM,WAAW,mBAAmB;IACnC,QAAQ,CAAC,SAAS,EAAE,gBAAgB,CAAC;IACrC,QAAQ,CAAC,eAAe,EAAE,CAAC,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,KAAK,gBAAgB,CAAC;CAC9F;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,sBAAsB,GAClC,WAAW,aAAa,EACxB,SAAS,mBAAmB,KAC1B,gBAWF,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,GAC7B,MAAM,SAAS,EACf,QAAQ,oBAAoB,EAC5B,gBAAgB,WAAW,EAC3B,eAAe,WAAW,KACxB,MAAM,CAAC,MAAM,EAAE,MAAM,CACoE,CAAC;AAE7F;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,6BAA6B,GACzC,WAAW,aAAa,EACxB,cAAc,OAAO,KACnB,OAAiD,CAAC;AAErD;;;;;;;;;GASG;AACH,eAAO,MAAM,0BAA0B,GAAI,QAAQ,MAAM,EAAE,QAAQ,OAAO,KAAG,OACQ,CAAC;AAEtF;;;;;;;;;GASG;AACH,eAAO,MAAM,0BAA0B,GAAI,QAAQ,MAAM,EAAE,QAAQ,OAAO,KAAG,OACjB,CAAC"}
|
|
@@ -9,7 +9,7 @@ import { parse } from '@fuzdev/fuz_schema/schema.ts';
|
|
|
9
9
|
import { is_null_schema } from '../http/schema_helpers.js';
|
|
10
10
|
import { get_route_error_map } from '../http/route_errors.js';
|
|
11
11
|
import { is_public_auth } from '../http/auth_shape.js';
|
|
12
|
-
import { ERROR_AUTHENTICATION_REQUIRED, ERROR_CREDENTIAL_TYPE_REQUIRED, ERROR_METHOD_NOT_ALLOWED, ERROR_ROUTE_NOT_FOUND, NOT_FOUND_TEXT } from '../http/error_schemas.js';
|
|
12
|
+
import { ERROR_AUTHENTICATION_REQUIRED, ERROR_CREDENTIAL_TYPE_REQUIRED, ERROR_METHOD_NOT_ALLOWED, ERROR_ROUTE_NOT_FOUND, NOT_FOUND_TEXT, REST_FORBIDDEN_HOST, REST_FORBIDDEN_ORIGIN, REST_INVALID_CONTENT_LENGTH, REST_PAYLOAD_TOO_LARGE } from '../http/error_schemas.js';
|
|
13
13
|
import { ROLE_ADMIN } from '../auth/role_schema.js';
|
|
14
14
|
import { create_test_request_headers } from './test_origin.js';
|
|
15
15
|
import { find_mounted_route, is_json_response, to_mounted_routes } from '../http/route_error_check.js';
|
|
@@ -83,6 +83,34 @@ export const find_auth_route = (specs, suffix, method) => {
|
|
|
83
83
|
}
|
|
84
84
|
return specs.find((s) => s.method === method && s.path.endsWith(suffix));
|
|
85
85
|
};
|
|
86
|
+
/**
|
|
87
|
+
* The middleware gates' refusals: the origin check's, the host gate's and the
|
|
88
|
+
* body limit's. `describe_middleware_gate_tests` probes each on every counted
|
|
89
|
+
* route that declares it, so the integration suite's coverage leaves them out.
|
|
90
|
+
*/
|
|
91
|
+
export const MIDDLEWARE_GATE_ERROR_CODES = [
|
|
92
|
+
REST_FORBIDDEN_ORIGIN.code,
|
|
93
|
+
REST_FORBIDDEN_HOST.code,
|
|
94
|
+
REST_PAYLOAD_TOO_LARGE.code,
|
|
95
|
+
REST_INVALID_CONTENT_LENGTH.code
|
|
96
|
+
];
|
|
97
|
+
/**
|
|
98
|
+
* Whether the standard integration suite counts a route: login, logout,
|
|
99
|
+
* password and signup (when wired), and the shared RPC endpoint — the routes
|
|
100
|
+
* its error coverage is scoped to and `describe_middleware_gate_tests` probes.
|
|
101
|
+
* An admin-role route belongs to the admin suite.
|
|
102
|
+
*
|
|
103
|
+
* @param spec - the route
|
|
104
|
+
* @param rpc_path - the RPC endpoint's path
|
|
105
|
+
*/
|
|
106
|
+
export const is_standard_integration_route = (spec, rpc_path) => {
|
|
107
|
+
if (spec.auth.roles?.includes('admin') ?? false)
|
|
108
|
+
return false;
|
|
109
|
+
const rest_suffixes = ['/login', '/logout', '/password', '/signup'];
|
|
110
|
+
if (rest_suffixes.some((suffix) => spec.path.endsWith(suffix)))
|
|
111
|
+
return true;
|
|
112
|
+
return spec.path === rpc_path;
|
|
113
|
+
};
|
|
86
114
|
/**
|
|
87
115
|
* Validate a response body against the route spec's declared schemas.
|
|
88
116
|
*
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import './assert_dev_env.js';
|
|
2
2
|
import type { RouteMethod, RouteSpec } from '../http/route_spec.js';
|
|
3
|
+
import type { AppSurfaceSpec } from '../http/surface.js';
|
|
3
4
|
import { type RouteErrorMap } from '../http/route_errors.js';
|
|
4
5
|
import { type RestErrorDef } from '../http/error_schemas.js';
|
|
5
|
-
import
|
|
6
|
+
import { ErrorCoverageCollector } from './error_coverage.js';
|
|
7
|
+
import { type RpcEndpointsSuiteOption } from './rpc_helpers.js';
|
|
8
|
+
import type { SetupTest } from './cross_backend/setup.js';
|
|
6
9
|
/** The `Origin` the origin probe sends — no allowlist names it. */
|
|
7
10
|
export declare const GATE_PROBE_FOREIGN_ORIGIN = "https://gate-probe.invalid";
|
|
8
11
|
/** The `Host` the host probe sends — neither loopback nor named by an allowed origin. */
|
|
@@ -87,4 +90,55 @@ export declare const send_middleware_gate_probe: (probe: MiddlewareGateProbe, ba
|
|
|
87
90
|
* declared refusal, or its body is off the route's map
|
|
88
91
|
*/
|
|
89
92
|
export declare const assert_middleware_gate_refusal: (probe: MiddlewareGateProbe, response: Response, collector: ErrorCoverageCollector, route_specs: Array<RouteSpec>) => Promise<void>;
|
|
93
|
+
/** Configuration for `describe_middleware_gate_tests`. */
|
|
94
|
+
export interface MiddlewareGateTestOptions {
|
|
95
|
+
/**
|
|
96
|
+
* Per-test fixture-producing function. Read in-process only, once, for the
|
|
97
|
+
* transport every probe shares; over a socket the probes need no fixture.
|
|
98
|
+
*/
|
|
99
|
+
setup_test: SetupTest;
|
|
100
|
+
/** App surface: the counted routes and their error maps, middleware included. */
|
|
101
|
+
surface_source: AppSurfaceSpec;
|
|
102
|
+
/** The session cookie's name, to resolve factory-form `rpc_endpoints` at setup. */
|
|
103
|
+
session_cookie_name: string;
|
|
104
|
+
/** RPC endpoint specs — the endpoint's path is a counted route. */
|
|
105
|
+
rpc_endpoints: RpcEndpointsSuiteOption;
|
|
106
|
+
/**
|
|
107
|
+
* Base URL the backend is reachable at, or `null` in-process. Over a socket
|
|
108
|
+
* the probes write their heads to it (`fetch` replaces a caller's `Host` and
|
|
109
|
+
* `Content-Length`); in-process they go through the fixture's transport.
|
|
110
|
+
*/
|
|
111
|
+
base_url: string | null;
|
|
112
|
+
/**
|
|
113
|
+
* The backend's request-body cap on every counted route but the RPC
|
|
114
|
+
* endpoint, in bytes — the body-limit probe declares one byte more.
|
|
115
|
+
*
|
|
116
|
+
* @default SPINE_BODY_LIMIT_DEFAULT_BYTES
|
|
117
|
+
*/
|
|
118
|
+
max_body_bytes?: number;
|
|
119
|
+
/**
|
|
120
|
+
* The backend's request-body cap on the RPC endpoint, in bytes, when it
|
|
121
|
+
* isn't `max_body_bytes`.
|
|
122
|
+
*/
|
|
123
|
+
rpc_max_body_bytes?: number;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* One test per middleware gate each route the standard integration suite
|
|
127
|
+
* counts declares in its error map (`plan_middleware_gate_probes`): the origin
|
|
128
|
+
* check, the host gate, the body limit, and in-process the unreadable length.
|
|
129
|
+
* Each probe is a bodiless head with no credential that the gate refuses
|
|
130
|
+
* before auth, rate limiting or body parsing, so the probes leave no state; a
|
|
131
|
+
* gate a route's map doesn't declare (a carve-out, a backend without the
|
|
132
|
+
* layer) gets no probe. Each refusal's body is held to the route's map.
|
|
133
|
+
*
|
|
134
|
+
* Every gate refusal (`MIDDLEWARE_GATE_ERROR_CODES`) a counted route declares
|
|
135
|
+
* must have a planned probe — the unreadable length aside over a socket — or
|
|
136
|
+
* the call throws at collection, so a planner that drops a probe can't pass by
|
|
137
|
+
* registering fewer tests, whatever a run filters or excludes.
|
|
138
|
+
*
|
|
139
|
+
* @param options - the routes, the backend's socket and its caps
|
|
140
|
+
* @throws Error at setup when `options.rpc_endpoints` names no single endpoint,
|
|
141
|
+
* or a declared gate refusal has no planned probe
|
|
142
|
+
*/
|
|
143
|
+
export declare const describe_middleware_gate_tests: (options: MiddlewareGateTestOptions) => void;
|
|
90
144
|
//# sourceMappingURL=middleware_gate_probes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware_gate_probes.d.ts","sourceRoot":"","sources":["../../src/lib/testing/middleware_gate_probes.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"middleware_gate_probes.d.ts","sourceRoot":"","sources":["../../src/lib/testing/middleware_gate_probes.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAqC7B,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAuB,KAAK,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAElF,OAAO,EAKN,KAAK,YAAY,EACjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAK7D,OAAO,EAGN,KAAK,uBAAuB,EAC5B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAK1D,mEAAmE;AACnE,eAAO,MAAM,yBAAyB,+BAA+B,CAAC;AAEtE,yFA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,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;AAEF,0DAA0D;AAC1D,MAAM,WAAW,yBAAyB;IACzC;;;OAGG;IACH,UAAU,EAAE,SAAS,CAAC;IACtB,iFAAiF;IACjF,cAAc,EAAE,cAAc,CAAC;IAC/B,mFAAmF;IACnF,mBAAmB,EAAE,MAAM,CAAC;IAC5B,mEAAmE;IACnE,aAAa,EAAE,uBAAuB,CAAC;IACvC;;;;OAIG;IACH,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB;;;;;OAKG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,8BAA8B,GAAI,SAAS,yBAAyB,KAAG,IAmDnF,CAAC"}
|
|
@@ -23,15 +23,21 @@ import './assert_dev_env.js';
|
|
|
23
23
|
* the answer a Bun server gives when a request repeats an equal
|
|
24
24
|
* `Content-Length`, which Bun hands over joined into one value.
|
|
25
25
|
*
|
|
26
|
-
* `
|
|
27
|
-
*
|
|
26
|
+
* `describe_middleware_gate_tests` runs one per declared gate of each route
|
|
27
|
+
* the standard integration suite counts (`is_standard_integration_route`). It
|
|
28
|
+
* is a suite of its own, not a group of that one, because over a socket it
|
|
29
|
+
* writes raw heads: the suites that send only through the fixture transports
|
|
30
|
+
* stay free of a raw-socket sender.
|
|
28
31
|
*
|
|
29
32
|
* @module
|
|
30
33
|
*/
|
|
31
|
-
import { assert } from 'vitest';
|
|
34
|
+
import { assert, describe, test } from 'vitest';
|
|
32
35
|
import { get_route_error_map } from '../http/route_errors.js';
|
|
33
36
|
import { split_route_template } from '../http/route_error_check.js';
|
|
34
37
|
import { REST_FORBIDDEN_HOST, REST_FORBIDDEN_ORIGIN, REST_INVALID_CONTENT_LENGTH, REST_PAYLOAD_TOO_LARGE } from '../http/error_schemas.js';
|
|
38
|
+
import { ErrorCoverageCollector } from './error_coverage.js';
|
|
39
|
+
import { is_standard_integration_route, MIDDLEWARE_GATE_ERROR_CODES } from './integration_helpers.js';
|
|
40
|
+
import { require_rpc_endpoint_path, resolve_rpc_endpoints_for_setup } from './rpc_helpers.js';
|
|
35
41
|
import { to_route_content_type } from './schema_generators.js';
|
|
36
42
|
import { raw_http_send_head } from './transports/raw_http.js';
|
|
37
43
|
import { SPINE_BODY_LIMIT_DEFAULT_BYTES } from './cross_backend/spine_surface_constants.js';
|
|
@@ -177,3 +183,63 @@ export const assert_middleware_gate_refusal = async (probe, response, collector,
|
|
|
177
183
|
assert.strictEqual(body?.error, probe.expected.code, `${label}: answered ${JSON.stringify(body)}`);
|
|
178
184
|
await collector.assert_and_record(route_specs, probe.method, probe.path, response);
|
|
179
185
|
};
|
|
186
|
+
/**
|
|
187
|
+
* One test per middleware gate each route the standard integration suite
|
|
188
|
+
* counts declares in its error map (`plan_middleware_gate_probes`): the origin
|
|
189
|
+
* check, the host gate, the body limit, and in-process the unreadable length.
|
|
190
|
+
* Each probe is a bodiless head with no credential that the gate refuses
|
|
191
|
+
* before auth, rate limiting or body parsing, so the probes leave no state; a
|
|
192
|
+
* gate a route's map doesn't declare (a carve-out, a backend without the
|
|
193
|
+
* layer) gets no probe. Each refusal's body is held to the route's map.
|
|
194
|
+
*
|
|
195
|
+
* Every gate refusal (`MIDDLEWARE_GATE_ERROR_CODES`) a counted route declares
|
|
196
|
+
* must have a planned probe — the unreadable length aside over a socket — or
|
|
197
|
+
* the call throws at collection, so a planner that drops a probe can't pass by
|
|
198
|
+
* registering fewer tests, whatever a run filters or excludes.
|
|
199
|
+
*
|
|
200
|
+
* @param options - the routes, the backend's socket and its caps
|
|
201
|
+
* @throws Error at setup when `options.rpc_endpoints` names no single endpoint,
|
|
202
|
+
* or a declared gate refusal has no planned probe
|
|
203
|
+
*/
|
|
204
|
+
export const describe_middleware_gate_tests = (options) => {
|
|
205
|
+
const route_specs = options.surface_source.route_specs;
|
|
206
|
+
const rpc_path = require_rpc_endpoint_path(resolve_rpc_endpoints_for_setup(options.rpc_endpoints, options.session_cookie_name));
|
|
207
|
+
const counted_routes = route_specs.filter((s) => is_standard_integration_route(s, rpc_path));
|
|
208
|
+
const probes = plan_middleware_gate_probes({
|
|
209
|
+
route_specs: counted_routes,
|
|
210
|
+
route_error_maps: options.surface_source.route_error_maps,
|
|
211
|
+
base_url: options.base_url,
|
|
212
|
+
max_body_bytes: options.max_body_bytes,
|
|
213
|
+
rpc_path,
|
|
214
|
+
rpc_max_body_bytes: options.rpc_max_body_bytes
|
|
215
|
+
});
|
|
216
|
+
// every gate refusal a counted route declares has a probe planned — checked
|
|
217
|
+
// at collection, so a planner that drops one fails whatever a run filters or
|
|
218
|
+
// excludes; the unreadable length goes unprobed over a socket (the module doc)
|
|
219
|
+
const planned = new Set(probes.map((p) => `${p.method} ${p.path} ${p.expected.status} ${p.expected.code}`));
|
|
220
|
+
const unplanned = new ErrorCoverageCollector(options.surface_source.route_error_maps)
|
|
221
|
+
.uncovered(counted_routes)
|
|
222
|
+
.filter(({ code }) => MIDDLEWARE_GATE_ERROR_CODES.includes(code) &&
|
|
223
|
+
!(options.base_url !== null && code === REST_INVALID_CONTENT_LENGTH.code))
|
|
224
|
+
.map(({ method, path, status, code }) => `${method} ${path} ${status} ${code}`)
|
|
225
|
+
.filter((key) => !planned.has(key));
|
|
226
|
+
if (unplanned.length > 0) {
|
|
227
|
+
throw new Error(`describe_middleware_gate_tests: declared gate refusals no probe plans: ${unplanned.join(', ')}`);
|
|
228
|
+
}
|
|
229
|
+
describe('middleware gates', () => {
|
|
230
|
+
const collector = new ErrorCoverageCollector(options.surface_source.route_error_maps);
|
|
231
|
+
// in-process the probes share one fixture's transport, made by the first
|
|
232
|
+
// to run; over a socket they need none, as they read and write no state
|
|
233
|
+
let in_process_transport = null;
|
|
234
|
+
const get_transport = () => (in_process_transport ??= options
|
|
235
|
+
.setup_test()
|
|
236
|
+
.then((fixture) => fixture.fresh_transport({ origin: null })));
|
|
237
|
+
for (const probe of probes) {
|
|
238
|
+
test(format_middleware_gate_probe(probe), async () => {
|
|
239
|
+
const transport = options.base_url === null ? await get_transport() : null;
|
|
240
|
+
const res = await send_middleware_gate_probe(probe, options.base_url, transport);
|
|
241
|
+
await assert_middleware_gate_refusal(probe, res, collector, route_specs);
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
};
|
|
@@ -13,6 +13,7 @@ import './assert_dev_env.js';
|
|
|
13
13
|
import type { Hono } from 'hono';
|
|
14
14
|
import type { Uuid } from '../primitive_schemas.js';
|
|
15
15
|
import { type AppServer, type AppServerOptions, type BootstrapServerOptions } from '../server/app_server.js';
|
|
16
|
+
import type { ShutdownDrainGivenUp } from '../server/shutdown_drain.js';
|
|
16
17
|
import type { AppServerContext } from '../server/app_server_context.js';
|
|
17
18
|
import type { AppSurface, AppSurfaceSpec } from '../http/surface.js';
|
|
18
19
|
import type { RouteSpec } from '../http/route_spec.js';
|
|
@@ -137,8 +138,8 @@ export interface TestApp {
|
|
|
137
138
|
* @throws Error listing every broken invariant and its rows
|
|
138
139
|
*/
|
|
139
140
|
assert_db_invariants: () => Promise<void>;
|
|
140
|
-
/** Cleanup resources — `AppServer.close`: stops an opted-in auth cleanup schedule, closes live connections, disposes the limiters the server built and removes the audit listeners and closer members it added, then the backend's `close
|
|
141
|
-
cleanup: () => Promise<
|
|
141
|
+
/** Cleanup resources — `AppServer.close`: stops an opted-in auth cleanup schedule, closes live connections, drains the work in flight within its bound, disposes the limiters the server built and removes the audit listeners and closer members it added, then the backend's `close`; resolves what the drain gave up on. Idempotent. */
|
|
142
|
+
cleanup: () => Promise<ShutdownDrainGivenUp>;
|
|
142
143
|
}
|
|
143
144
|
/**
|
|
144
145
|
* Create a fully assembled test app with a Hono server, middleware, and routes.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test_app.d.ts","sourceRoot":"","sources":["../../src/lib/testing/test_app.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAE7B;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AACjC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,EAEN,KAAK,SAAS,EACd,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,EAC3B,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACrE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAMvD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAEhE,OAAO,EAKN,KAAK,aAAa,EAClB,KAAK,oBAAoB,EACzB,MAAM,iBAAiB,CAAC;AAMzB,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAEvE;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,oBAAoB;IACjE,qEAAqE;IACrE,mBAAmB,EAAE,MAAM,CAAC;IAC5B,yEAAyE;IACzE,kBAAkB,EAA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AAK,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxF,qDAAqD;IACrD,cAAc,EAAE,CAAC,OAAO,CAAC,EAAE,wBAAwB,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC;IAC7E;;;;;;;OAOG;IACH,oBAAoB,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1C,2UAA2U;IAC3U,OAAO,EAAE,MAAM,OAAO,CAAC,oBAAoB,CAAC,CAAC;CAC7C;AAyCD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,eAAe,GAAU,SAAS,oBAAoB,KAAG,OAAO,CAAC,OAAO,CAwFpF,CAAC"}
|
package/dist/testing/test_app.js
CHANGED
|
@@ -14,7 +14,11 @@ const test_app_options = () => ({
|
|
|
14
14
|
// every limiter off unless `app_options` passes one — a rate-limit test
|
|
15
15
|
// enables just the limiter it pins
|
|
16
16
|
rate_limiters: 'disabled_for_testing',
|
|
17
|
-
await_pending_effects: true
|
|
17
|
+
await_pending_effects: true,
|
|
18
|
+
// off: a background pass would delete rows and write audit rows mid-test.
|
|
19
|
+
// A suite that opts in through `app_options` has the schedule stopped by
|
|
20
|
+
// `cleanup`.
|
|
21
|
+
auth_cleanup: 'off'
|
|
18
22
|
});
|
|
19
23
|
/** Build request headers carrying `session_cookie` in the `cookie_name` cookie. */
|
|
20
24
|
const create_session_headers_builder = (cookie_name, session_cookie) => (extra) => create_test_request_headers({ cookie: `${cookie_name}=${session_cookie}`, ...extra });
|
|
@@ -68,9 +72,6 @@ export const create_test_app = async (options) => {
|
|
|
68
72
|
daemon_token_state,
|
|
69
73
|
rpc_endpoints: options.rpc_endpoints,
|
|
70
74
|
bootstrap: options.bootstrap,
|
|
71
|
-
// `auth_cleanup` stays at its default, off: a background pass would
|
|
72
|
-
// delete rows and write audit rows mid-test. A suite that opts in
|
|
73
|
-
// through `app_options` has the schedule stopped by `cleanup`.
|
|
74
75
|
...options.app_options,
|
|
75
76
|
create_route_specs: options.create_route_specs
|
|
76
77
|
});
|