@fuzdev/fuz_app 0.182.0 → 0.184.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/actions/CLAUDE.md +535 -1223
- package/dist/actions/action_codegen.d.ts +1 -1
- package/dist/actions/action_codegen.d.ts.map +1 -1
- package/dist/actions/action_codegen.js +3 -2
- package/dist/actions/connection_closer.d.ts +11 -9
- package/dist/actions/connection_closer.d.ts.map +1 -1
- package/dist/actions/connection_closer.js +11 -9
- package/dist/actions/frontend_rpc_client.d.ts +1 -1
- package/dist/actions/register_action_ws.d.ts +14 -1
- package/dist/actions/register_action_ws.d.ts.map +1 -1
- package/dist/actions/register_action_ws.js +2 -1
- package/dist/actions/ws_socket_session.d.ts +9 -1
- package/dist/actions/ws_socket_session.d.ts.map +1 -1
- package/dist/actions/ws_socket_session.js +43 -19
- package/dist/auth/CLAUDE.md +430 -1024
- package/dist/auth/account_queries.d.ts +1 -1
- package/dist/auth/account_queries.js +1 -1
- package/dist/auth/account_routes.d.ts +9 -8
- package/dist/auth/account_routes.d.ts.map +1 -1
- package/dist/auth/account_routes.js +78 -75
- package/dist/auth/admin_actions.d.ts.map +1 -1
- package/dist/auth/admin_actions.js +32 -28
- package/dist/auth/api_token.d.ts +20 -3
- package/dist/auth/api_token.d.ts.map +1 -1
- package/dist/auth/api_token.js +28 -9
- package/dist/auth/api_token_queries.d.ts +2 -2
- package/dist/auth/api_token_queries.js +2 -2
- package/dist/auth/audit_emitter.d.ts +75 -84
- package/dist/auth/audit_emitter.d.ts.map +1 -1
- package/dist/auth/audit_emitter.js +83 -71
- package/dist/auth/audit_log_schema.d.ts +25 -14
- package/dist/auth/audit_log_schema.d.ts.map +1 -1
- package/dist/auth/audit_log_schema.js +23 -8
- package/dist/auth/auth_guard_resolver.d.ts +1 -1
- package/dist/auth/auth_guard_resolver.js +1 -1
- package/dist/auth/bearer_auth.d.ts +2 -5
- package/dist/auth/bearer_auth.d.ts.map +1 -1
- package/dist/auth/bearer_auth.js +4 -13
- package/dist/auth/bootstrap_account.d.ts +42 -26
- package/dist/auth/bootstrap_account.d.ts.map +1 -1
- package/dist/auth/bootstrap_account.js +36 -19
- package/dist/auth/bootstrap_routes.d.ts +20 -21
- package/dist/auth/bootstrap_routes.d.ts.map +1 -1
- package/dist/auth/bootstrap_routes.js +26 -31
- package/dist/auth/bootstrap_token_store.d.ts +3 -4
- package/dist/auth/bootstrap_token_store.d.ts.map +1 -1
- package/dist/auth/bootstrap_token_store.js +1 -1
- package/dist/auth/daemon_token.d.ts +5 -1
- package/dist/auth/daemon_token.d.ts.map +1 -1
- package/dist/auth/daemon_token_middleware.d.ts +12 -8
- package/dist/auth/daemon_token_middleware.d.ts.map +1 -1
- package/dist/auth/daemon_token_middleware.js +15 -21
- package/dist/auth/deps.d.ts +19 -5
- package/dist/auth/deps.d.ts.map +1 -1
- package/dist/auth/deps.js +3 -2
- package/dist/auth/invite_queries.d.ts +51 -3
- package/dist/auth/invite_queries.d.ts.map +1 -1
- package/dist/auth/invite_queries.js +81 -6
- package/dist/auth/invite_schema.d.ts +2 -1
- package/dist/auth/invite_schema.d.ts.map +1 -1
- package/dist/auth/middleware.d.ts +2 -3
- package/dist/auth/middleware.d.ts.map +1 -1
- package/dist/auth/middleware.js +3 -3
- package/dist/auth/request_context.d.ts +3 -3
- package/dist/auth/request_context.js +3 -3
- package/dist/auth/resolved_auth.d.ts +7 -7
- package/dist/auth/resolved_auth.d.ts.map +1 -1
- package/dist/auth/resolved_auth.js +4 -4
- package/dist/auth/role_grant_offer_actions.d.ts +27 -3
- package/dist/auth/role_grant_offer_actions.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_actions.js +42 -35
- package/dist/auth/role_grant_offer_queries.d.ts +60 -4
- package/dist/auth/role_grant_offer_queries.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_queries.js +79 -5
- package/dist/auth/role_grant_queries.d.ts +3 -52
- package/dist/auth/role_grant_queries.d.ts.map +1 -1
- package/dist/auth/role_grant_queries.js +5 -80
- package/dist/auth/self_service_role_actions.d.ts.map +1 -1
- package/dist/auth/self_service_role_actions.js +11 -22
- package/dist/auth/session_cookie.d.ts +82 -174
- package/dist/auth/session_cookie.d.ts.map +1 -1
- package/dist/auth/session_cookie.js +80 -130
- package/dist/auth/session_middleware.d.ts +8 -17
- package/dist/auth/session_middleware.d.ts.map +1 -1
- package/dist/auth/session_middleware.js +14 -23
- package/dist/auth/session_queries.d.ts +15 -17
- package/dist/auth/session_queries.d.ts.map +1 -1
- package/dist/auth/session_queries.js +28 -20
- package/dist/auth/signup_routes.d.ts.map +1 -1
- package/dist/auth/signup_routes.js +93 -43
- package/dist/db/CLAUDE.md +5 -3
- package/dist/db/sql_columns.d.ts +1 -1
- package/dist/db/sql_columns.js +1 -1
- package/dist/dev/setup.d.ts +3 -1
- package/dist/dev/setup.d.ts.map +1 -1
- package/dist/dev/setup.js +3 -1
- package/dist/http/CLAUDE.md +315 -763
- package/dist/http/db_routes.d.ts +8 -23
- package/dist/http/db_routes.d.ts.map +1 -1
- package/dist/http/db_routes.js +73 -73
- package/dist/http/origin.d.ts +7 -8
- package/dist/http/origin.d.ts.map +1 -1
- package/dist/http/origin.js +7 -8
- package/dist/http/pending_effects.d.ts +118 -6
- package/dist/http/pending_effects.d.ts.map +1 -1
- package/dist/http/pending_effects.js +114 -6
- package/dist/http/route_result.d.ts +1 -1
- package/dist/http/route_spec.d.ts +14 -11
- package/dist/http/route_spec.d.ts.map +1 -1
- package/dist/realtime/sse.d.ts +4 -23
- package/dist/realtime/sse.d.ts.map +1 -1
- package/dist/realtime/sse.js +4 -25
- package/dist/server/app_backend.d.ts +4 -5
- package/dist/server/app_backend.d.ts.map +1 -1
- package/dist/server/app_backend.js +3 -1
- package/dist/server/app_server.d.ts +80 -16
- package/dist/server/app_server.d.ts.map +1 -1
- package/dist/server/app_server.js +113 -31
- package/dist/server/app_server_context.d.ts +1 -2
- package/dist/server/app_server_context.d.ts.map +1 -1
- package/dist/server/env.js +2 -2
- package/dist/testing/CLAUDE.md +265 -796
- package/dist/testing/admin_integration.d.ts +2 -3
- package/dist/testing/admin_integration.d.ts.map +1 -1
- package/dist/testing/admin_integration.js +3 -3
- package/dist/testing/adversarial_404.d.ts +6 -1
- package/dist/testing/adversarial_404.d.ts.map +1 -1
- package/dist/testing/adversarial_404.js +38 -17
- package/dist/testing/app_server.d.ts +23 -148
- package/dist/testing/app_server.d.ts.map +1 -1
- package/dist/testing/app_server.js +53 -131
- package/dist/testing/attack_surface.d.ts +1 -1
- package/dist/testing/attack_surface.d.ts.map +1 -1
- package/dist/testing/audit_completeness.d.ts +2 -3
- package/dist/testing/audit_completeness.d.ts.map +1 -1
- package/dist/testing/audit_completeness.js +1 -1
- package/dist/testing/audit_drift_guard.d.ts +11 -6
- package/dist/testing/audit_drift_guard.d.ts.map +1 -1
- package/dist/testing/audit_drift_guard.js +15 -8
- package/dist/testing/cross_backend/audit_cross_helpers.d.ts +12 -9
- package/dist/testing/cross_backend/audit_cross_helpers.d.ts.map +1 -1
- package/dist/testing/cross_backend/audit_cross_helpers.js +13 -14
- package/dist/testing/cross_backend/capabilities.d.ts +9 -6
- package/dist/testing/cross_backend/capabilities.d.ts.map +1 -1
- package/dist/testing/cross_backend/capabilities.js +11 -7
- package/dist/testing/cross_backend/capability_mounts.d.ts +103 -0
- package/dist/testing/cross_backend/capability_mounts.d.ts.map +1 -0
- package/dist/testing/cross_backend/capability_mounts.js +428 -0
- package/dist/testing/cross_backend/cell_moderate.js +2 -2
- package/dist/testing/cross_backend/cell_relations.d.ts.map +1 -1
- package/dist/testing/cross_backend/cell_relations.js +12 -11
- package/dist/testing/cross_backend/conformance_principal.d.ts +54 -0
- package/dist/testing/cross_backend/conformance_principal.d.ts.map +1 -0
- package/dist/testing/cross_backend/conformance_principal.js +283 -0
- package/dist/testing/cross_backend/conformance_table.d.ts +7 -56
- package/dist/testing/cross_backend/conformance_table.d.ts.map +1 -1
- package/dist/testing/cross_backend/conformance_table.js +6 -274
- package/dist/testing/cross_backend/cookie_attributes.js +1 -1
- package/dist/testing/cross_backend/credential_deadline.d.ts.map +1 -1
- package/dist/testing/cross_backend/credential_deadline.js +2 -0
- package/dist/testing/cross_backend/credential_wire.d.ts +1 -1
- package/dist/testing/cross_backend/credential_wire.d.ts.map +1 -1
- package/dist/testing/cross_backend/db_state_diff.d.ts +72 -0
- package/dist/testing/cross_backend/db_state_diff.d.ts.map +1 -0
- package/dist/testing/cross_backend/db_state_diff.js +444 -0
- package/dist/testing/cross_backend/declared_skips.d.ts +68 -0
- package/dist/testing/cross_backend/declared_skips.d.ts.map +1 -0
- package/dist/testing/cross_backend/declared_skips.js +132 -0
- package/dist/testing/cross_backend/default_backend_configs.d.ts +3 -3
- package/dist/testing/cross_backend/default_spine_surface.d.ts +0 -6
- package/dist/testing/cross_backend/default_spine_surface.d.ts.map +1 -1
- package/dist/testing/cross_backend/default_spine_surface.js +4 -9
- package/dist/testing/cross_backend/differential.d.ts +13 -5
- package/dist/testing/cross_backend/differential.d.ts.map +1 -1
- package/dist/testing/cross_backend/differential.js +35 -11
- package/dist/testing/cross_backend/differential_normalize.d.ts +12 -0
- package/dist/testing/cross_backend/differential_normalize.d.ts.map +1 -1
- package/dist/testing/cross_backend/differential_normalize.js +16 -0
- package/dist/testing/cross_backend/full_spine_mount.d.ts +1 -42
- package/dist/testing/cross_backend/full_spine_mount.d.ts.map +1 -1
- package/dist/testing/cross_backend/full_spine_mount.js +45 -4
- package/dist/testing/cross_backend/in_process_setup.d.ts +28 -19
- package/dist/testing/cross_backend/in_process_setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/in_process_setup.js +156 -142
- package/dist/testing/cross_backend/login_security.d.ts +12 -0
- package/dist/testing/cross_backend/login_security.d.ts.map +1 -1
- package/dist/testing/cross_backend/login_security.js +21 -4
- package/dist/testing/cross_backend/request_target_conformance_wire.d.ts +0 -2
- package/dist/testing/cross_backend/request_target_conformance_wire.d.ts.map +1 -1
- package/dist/testing/cross_backend/request_target_conformance_wire.js +3 -1
- package/dist/testing/cross_backend/revocation_drivers.d.ts +18 -5
- package/dist/testing/cross_backend/revocation_drivers.d.ts.map +1 -1
- package/dist/testing/cross_backend/revocation_drivers.js +18 -10
- package/dist/testing/cross_backend/role_grant_cross_helpers.d.ts +1 -1
- package/dist/testing/cross_backend/role_grant_cross_helpers.d.ts.map +1 -1
- package/dist/testing/cross_backend/role_grant_offer_lifecycle.d.ts.map +1 -1
- package/dist/testing/cross_backend/role_grant_offer_lifecycle.js +33 -1
- package/dist/testing/cross_backend/role_grant_participation.js +4 -4
- package/dist/testing/cross_backend/rpc_adversarial.js +1 -1
- package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts +3 -4
- 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 -2
- package/dist/testing/cross_backend/session_cap.d.ts +2 -2
- package/dist/testing/cross_backend/session_cap.d.ts.map +1 -1
- package/dist/testing/cross_backend/session_cap.js +22 -11
- package/dist/testing/cross_backend/setup.d.ts +32 -2
- package/dist/testing/cross_backend/setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/setup.js +32 -1
- package/dist/testing/cross_backend/spine_suites.d.ts +125 -15
- package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
- package/dist/testing/cross_backend/spine_suites.js +459 -62
- package/dist/testing/cross_backend/spine_surface_constants.d.ts +1 -1
- package/dist/testing/cross_backend/spine_surface_constants.d.ts.map +1 -1
- package/dist/testing/cross_backend/spine_surface_constants.js +1 -0
- package/dist/testing/cross_backend/sse_round_trip.d.ts +9 -1
- package/dist/testing/cross_backend/sse_round_trip.d.ts.map +1 -1
- package/dist/testing/cross_backend/sse_round_trip.js +123 -27
- package/dist/testing/cross_backend/standard.d.ts +2 -3
- package/dist/testing/cross_backend/standard.d.ts.map +1 -1
- package/dist/testing/cross_backend/standard.js +3 -3
- package/dist/testing/cross_backend/testing_backdoor.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_backdoor.js +4 -2
- package/dist/testing/cross_backend/testing_credential_read.d.ts +10 -11
- package/dist/testing/cross_backend/testing_credential_read.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_credential_read.js +12 -12
- package/dist/testing/cross_backend/testing_reset_actions.d.ts +84 -47
- package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_reset_actions.js +95 -63
- package/dist/testing/cross_backend/testing_server_core.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_server_core.js +2 -3
- package/dist/testing/cross_backend/transport_composition.d.ts +1 -1
- package/dist/testing/cross_backend/transport_composition.d.ts.map +1 -1
- package/dist/testing/cross_backend/transport_composition.js +7 -3
- package/dist/testing/cross_backend/ws_round_trip.d.ts +5 -0
- package/dist/testing/cross_backend/ws_round_trip.d.ts.map +1 -1
- package/dist/testing/cross_backend/ws_round_trip.js +54 -8
- package/dist/testing/daemon_token_rotation.d.ts.map +1 -1
- package/dist/testing/daemon_token_rotation.js +2 -3
- package/dist/testing/data_exposure.d.ts.map +1 -1
- package/dist/testing/data_exposure.js +3 -0
- package/dist/testing/db.d.ts +0 -32
- package/dist/testing/db.d.ts.map +1 -1
- package/dist/testing/db.js +0 -86
- package/dist/testing/db_entities.d.ts +14 -0
- package/dist/testing/db_entities.d.ts.map +1 -1
- package/dist/testing/db_entities.js +17 -0
- package/dist/testing/db_invariant_queries.d.ts +259 -0
- package/dist/testing/db_invariant_queries.d.ts.map +1 -0
- package/dist/testing/db_invariant_queries.js +400 -0
- package/dist/testing/db_invariants.d.ts +106 -0
- package/dist/testing/db_invariants.d.ts.map +1 -0
- package/dist/testing/db_invariants.gen.sql.d.ts +11 -0
- package/dist/testing/db_invariants.gen.sql.d.ts.map +1 -0
- package/dist/testing/db_invariants.gen.sql.js +13 -0
- package/dist/testing/db_invariants.js +141 -0
- package/dist/testing/db_invariants.sql +152 -0
- package/dist/testing/describe_db.d.ts +36 -0
- package/dist/testing/describe_db.d.ts.map +1 -0
- package/dist/testing/describe_db.js +71 -0
- package/dist/testing/integration.d.ts +8 -12
- package/dist/testing/integration.d.ts.map +1 -1
- package/dist/testing/integration.js +13 -17
- package/dist/testing/integration_helpers.d.ts +1 -1
- package/dist/testing/integration_helpers.d.ts.map +1 -1
- package/dist/testing/rate_limiting.d.ts +3 -4
- package/dist/testing/rate_limiting.d.ts.map +1 -1
- package/dist/testing/rate_limiting.js +6 -5
- package/dist/testing/role_grant_helpers.d.ts +1 -1
- package/dist/testing/role_grant_helpers.d.ts.map +1 -1
- package/dist/testing/round_trip.d.ts.map +1 -1
- package/dist/testing/round_trip.js +3 -0
- package/dist/testing/rpc_attack_surface.d.ts +8 -6
- package/dist/testing/rpc_attack_surface.d.ts.map +1 -1
- package/dist/testing/rpc_attack_surface.js +69 -6
- package/dist/testing/rpc_helpers.d.ts +1 -2
- package/dist/testing/rpc_helpers.d.ts.map +1 -1
- package/dist/testing/rpc_helpers.js +3 -3
- package/dist/testing/rpc_round_trip.d.ts +3 -4
- package/dist/testing/rpc_round_trip.d.ts.map +1 -1
- package/dist/testing/rpc_round_trip.js +4 -1
- package/dist/testing/sse_round_trip.d.ts +3 -4
- package/dist/testing/sse_round_trip.d.ts.map +1 -1
- package/dist/testing/sse_round_trip.js +15 -6
- package/dist/testing/stubs.d.ts +9 -8
- package/dist/testing/stubs.d.ts.map +1 -1
- package/dist/testing/stubs.js +20 -13
- package/dist/testing/test_app.d.ts +168 -0
- package/dist/testing/test_app.d.ts.map +1 -0
- package/dist/testing/test_app.js +123 -0
- package/dist/testing/ws_round_trip.d.ts.map +1 -1
- package/dist/testing/ws_round_trip.js +3 -0
- package/dist/ui/ui_format.d.ts.map +1 -1
- package/dist/ui/ui_format.js +1 -2
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"round_trip.d.ts","sourceRoot":"","sources":["../../src/lib/testing/round_trip.ts"],"names":[],"m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9E,CAAC"}
|
|
@@ -21,6 +21,7 @@ import './assert_dev_env.js';
|
|
|
21
21
|
* @module
|
|
22
22
|
*/
|
|
23
23
|
import { describe, test, beforeAll, assert } from 'vitest';
|
|
24
|
+
import { check_db_invariants_after_all } from './db_invariants.js';
|
|
24
25
|
import { ROLE_ADMIN } from '../auth/role_schema.js';
|
|
25
26
|
import { format_route_key } from '../http/surface_query.js';
|
|
26
27
|
import { ERROR_CREDENTIAL_TYPE_REQUIRED } from '../http/error_schemas.js';
|
|
@@ -79,6 +80,8 @@ export const describe_round_trip_validation = (options) => {
|
|
|
79
80
|
const skip_set = new Set(options.skip_routes);
|
|
80
81
|
describe('round-trip validation', () => {
|
|
81
82
|
let fixture;
|
|
83
|
+
// `fixture` is unassigned until `beforeAll` runs, which the check allows for
|
|
84
|
+
check_db_invariants_after_all(() => fixture);
|
|
82
85
|
let authed_account;
|
|
83
86
|
let admin_account;
|
|
84
87
|
beforeAll(async () => {
|
|
@@ -7,12 +7,14 @@ export interface RpcAttackSurfaceOptions {
|
|
|
7
7
|
/** All roles in the app (e.g. `['admin', 'keeper']`). */
|
|
8
8
|
roles: Array<string>;
|
|
9
9
|
/**
|
|
10
|
-
* Valid params per method (method name → params)
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
10
|
+
* Valid params per method (method name → params), in place of the
|
|
11
|
+
* generated base — for an input whose valid shape the generator can't
|
|
12
|
+
* reach. They seed the adversarial params cases and the "correct auth
|
|
13
|
+
* passes" request. Each must pass the method's input schema: in the params
|
|
14
|
+
* group one that doesn't throws at collection, naming the method; in
|
|
15
|
+
* "correct auth passes" its 400 fails the method's test, the handler
|
|
16
|
+
* unreached. The params cases are sent as a single-actor principal, so an
|
|
17
|
+
* override omits `acting`. The cross-process twin is
|
|
16
18
|
* `RpcAdversarialCrossTestOptions.input_overrides`.
|
|
17
19
|
*/
|
|
18
20
|
input_overrides?: ReadonlyMap<string, Record<string, unknown>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpc_attack_surface.d.ts","sourceRoot":"","sources":["../../src/lib/testing/rpc_attack_surface.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"rpc_attack_surface.d.ts","sourceRoot":"","sources":["../../src/lib/testing/rpc_attack_surface.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAmB7B,OAAO,KAAK,EAGX,cAAc,EACd,MAAM,oBAAoB,CAAC;AAmC5B,uDAAuD;AACvD,MAAM,WAAW,uBAAuB;IACvC,+FAA+F;IAC/F,KAAK,EAAE,MAAM,cAAc,CAAC;IAC5B,yDAAyD;IACzD,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACrB;;;;;;;;;;OAUG;IACH,eAAe,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CAC/D;AAuaD;;;;;;;;;GASG;AACH,eAAO,MAAM,iCAAiC,GAAI,SAAS,uBAAuB,KAAG,IAOpF,CAAC"}
|
|
@@ -13,10 +13,14 @@ import './assert_dev_env.js';
|
|
|
13
13
|
* @module
|
|
14
14
|
*/
|
|
15
15
|
import { test, assert, describe } from 'vitest';
|
|
16
|
+
import { Logger } from '@fuzdev/fuz_util/log.ts';
|
|
16
17
|
import { is_keeper_auth, is_public_auth, is_role_auth } from '../http/auth_shape.js';
|
|
17
18
|
import { JSONRPC_ERROR_CODES } from '../http/jsonrpc_errors.js';
|
|
18
19
|
import { create_auth_test_apps, create_test_app_from_specs, create_test_request_context, select_auth_app } from './auth_apps.js';
|
|
19
20
|
import { generate_valid_body } from './schema_generators.js';
|
|
21
|
+
import { create_rpc_endpoint } from '../actions/action_rpc.js';
|
|
22
|
+
import { format_route_key } from '../http/surface_query.js';
|
|
23
|
+
import { noop_notification_sender } from '../actions/notification_sender.js';
|
|
20
24
|
import { create_rpc_post_init, create_rpc_get_url, assert_jsonrpc_error_response } from './rpc_helpers.js';
|
|
21
25
|
import { assert_rpc_envelope_refusal, create_rpc_envelope_cases, generate_rpc_params_test_cases, to_rpc_envelope_request } from './rpc_envelope_cases.js';
|
|
22
26
|
import { expected_invalid_reason } from './adversarial_input_cases.js';
|
|
@@ -35,6 +39,57 @@ const find_rpc_action = (rpc_endpoint_specs, endpoint_path, method_name) => {
|
|
|
35
39
|
const ep = rpc_endpoint_specs.find((e) => e.path === endpoint_path);
|
|
36
40
|
return ep?.actions.find((a) => a.spec.method === method_name);
|
|
37
41
|
};
|
|
42
|
+
/** The key a recording stub notes its call under: the endpoint path and method. */
|
|
43
|
+
const to_reached_key = (endpoint_path, method_name) => `${endpoint_path} ${method_name}`;
|
|
44
|
+
/**
|
|
45
|
+
* The route specs with every RPC endpoint's routes rebuilt over its actions,
|
|
46
|
+
* each handler swapped for a stub that records its call in `reached` and
|
|
47
|
+
* answers `null`, so a test that the handler is reached never depends on
|
|
48
|
+
* what the handler would do over stub deps (a live re-read's 401). Each
|
|
49
|
+
* endpoint's routes take the place of its first route in the list, matched
|
|
50
|
+
* on method and path, so another route at the endpoint's path stays; the
|
|
51
|
+
* rest of the list is kept in order. The endpoints mount with no rate limiters,
|
|
52
|
+
* a silent logger (a stub's `null` fails a non-null output schema, which DEV
|
|
53
|
+
* validation only logs), and the no-op notification sender.
|
|
54
|
+
*
|
|
55
|
+
* @param route_specs - the app's route specs, the endpoints' routes among them
|
|
56
|
+
* @param rpc_endpoint_specs - the endpoints whose handlers are stubbed
|
|
57
|
+
* @param reached - where each stub records its call (`to_reached_key`)
|
|
58
|
+
* @returns the route specs with the endpoints rebuilt
|
|
59
|
+
*/
|
|
60
|
+
const stub_rpc_endpoint_handlers = (route_specs, rpc_endpoint_specs, reached) => {
|
|
61
|
+
const log = new Logger('test:rpc_attack_surface', { level: 'off' });
|
|
62
|
+
// each endpoint's rebuilt routes, keyed by every `METHOD path` they serve
|
|
63
|
+
const rebuilt_by_key = new Map();
|
|
64
|
+
for (const endpoint of rpc_endpoint_specs) {
|
|
65
|
+
const rebuilt = create_rpc_endpoint({
|
|
66
|
+
path: endpoint.path,
|
|
67
|
+
actions: endpoint.actions.map((action) => ({
|
|
68
|
+
spec: action.spec,
|
|
69
|
+
handler: () => {
|
|
70
|
+
reached.add(to_reached_key(endpoint.path, action.spec.method));
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
})),
|
|
74
|
+
log,
|
|
75
|
+
action_ip_rate_limiter: null,
|
|
76
|
+
action_account_rate_limiter: null,
|
|
77
|
+
notification_sender: noop_notification_sender
|
|
78
|
+
});
|
|
79
|
+
for (const spec of rebuilt)
|
|
80
|
+
rebuilt_by_key.set(format_route_key(spec), rebuilt);
|
|
81
|
+
}
|
|
82
|
+
const mounted = new Set();
|
|
83
|
+
return route_specs.flatMap((spec) => {
|
|
84
|
+
const rebuilt = rebuilt_by_key.get(format_route_key(spec));
|
|
85
|
+
if (!rebuilt)
|
|
86
|
+
return [spec];
|
|
87
|
+
if (mounted.has(rebuilt))
|
|
88
|
+
return [];
|
|
89
|
+
mounted.add(rebuilt);
|
|
90
|
+
return rebuilt;
|
|
91
|
+
});
|
|
92
|
+
};
|
|
38
93
|
// --- Auth enforcement ---
|
|
39
94
|
/**
|
|
40
95
|
* Generate adversarial auth enforcement tests for RPC endpoints.
|
|
@@ -48,7 +103,9 @@ const find_rpc_action = (rpc_endpoint_specs, endpoint_path, method_name) => {
|
|
|
48
103
|
* - wrong role → error code -32002 — every role method with non-matching roles
|
|
49
104
|
* - authenticated without role → -32002 — every role method, no-role context
|
|
50
105
|
* - keeper rejects non-daemon credentials → -32002 — session and api_token rejected
|
|
51
|
-
* - correct auth passes — every protected method,
|
|
106
|
+
* - correct auth passes — every protected method, sent valid params by the
|
|
107
|
+
* app its auth admits, reaches its handler, a recording stub
|
|
108
|
+
* (`stub_rpc_endpoint_handlers`), at 200
|
|
52
109
|
*/
|
|
53
110
|
const describe_rpc_auth = (options) => {
|
|
54
111
|
const { build, roles } = options;
|
|
@@ -56,6 +113,8 @@ const describe_rpc_auth = (options) => {
|
|
|
56
113
|
if (surface.rpc_endpoints.length === 0)
|
|
57
114
|
return;
|
|
58
115
|
const apps = create_auth_test_apps(route_specs, roles);
|
|
116
|
+
const reached = new Set();
|
|
117
|
+
const stubbed_apps = create_auth_test_apps(stub_rpc_endpoint_handlers(route_specs, rpc_endpoint_specs, reached), roles);
|
|
59
118
|
describe('RPC auth enforcement', () => {
|
|
60
119
|
for (const endpoint of surface.rpc_endpoints) {
|
|
61
120
|
const protected_methods = filter_protected_rpc_methods(endpoint);
|
|
@@ -138,11 +197,15 @@ const describe_rpc_auth = (options) => {
|
|
|
138
197
|
describe('correct auth passes', () => {
|
|
139
198
|
for (const method of protected_methods) {
|
|
140
199
|
test(method.name, async () => {
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
200
|
+
const action = find_rpc_action(rpc_endpoint_specs, endpoint.path, method.name);
|
|
201
|
+
assert.ok(action, `surface has method '${method.name}' but no matching RpcAction in rpc_endpoints`);
|
|
202
|
+
const params = options.input_overrides?.get(method.name) ?? generate_valid_body(action.spec.input);
|
|
203
|
+
const key = to_reached_key(endpoint.path, method.name);
|
|
204
|
+
reached.delete(key);
|
|
205
|
+
const app = select_auth_app(stubbed_apps, method.auth);
|
|
206
|
+
const res = await app.request(endpoint.path, create_rpc_post_init(method.name, params));
|
|
207
|
+
assert.ok(reached.has(key), `${method.name} should reach its handler, got ${res.status}: ${await res.text()}`);
|
|
208
|
+
assert.strictEqual(res.status, 200, `${method.name} should answer 200`);
|
|
146
209
|
});
|
|
147
210
|
}
|
|
148
211
|
});
|
|
@@ -5,7 +5,6 @@ import type { RequestResponseActionSpec } from '../actions/action_spec.js';
|
|
|
5
5
|
import type { RpcAction } from '../actions/action_types.js';
|
|
6
6
|
import type { AppSurfaceRpcEndpoint, AppSurfaceRpcMethod, RpcEndpointSpec } from '../http/surface.js';
|
|
7
7
|
import type { AppServerContext } from '../server/app_server_context.js';
|
|
8
|
-
import type { SessionOptions } from '../auth/session_cookie.js';
|
|
9
8
|
/**
|
|
10
9
|
* Union accepted by the suite-level `rpc_endpoints` option — eager array or
|
|
11
10
|
* a factory that takes an `AppServerContext` and returns endpoint specs. The
|
|
@@ -39,7 +38,7 @@ export type RpcEndpointsSuiteOption = Array<RpcEndpointSpec> | ((ctx: AppServerC
|
|
|
39
38
|
* @throws Error if the factory's two stub-ctx invocations produce different
|
|
40
39
|
* `(path, method-list)` shapes — surfaces non-pure factories at setup time.
|
|
41
40
|
*/
|
|
42
|
-
export declare const resolve_rpc_endpoints_for_setup: (rpc_endpoints: RpcEndpointsSuiteOption,
|
|
41
|
+
export declare const resolve_rpc_endpoints_for_setup: (rpc_endpoints: RpcEndpointsSuiteOption, session_cookie_name: string) => Array<RpcEndpointSpec>;
|
|
43
42
|
/**
|
|
44
43
|
* Create a `RequestInit` for a JSON-RPC POST request.
|
|
45
44
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpc_helpers.d.ts","sourceRoot":"","sources":["../../src/lib/testing/rpc_helpers.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAa7B,OAAO,EAAa,KAAK,MAAM,EAAE,KAAK,KAAK,EAAE,KAAK,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAElG,OAAO,EAIN,KAAK,gBAAgB,EACrB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AAC3E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,KAAK,EACX,qBAAqB,EACrB,mBAAmB,EACnB,eAAe,EACf,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"rpc_helpers.d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AC,eAAe,CAAC,EAC7C,QAAQ,MAAM,KACZ;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,SAAS,CAAA;CAAE,GAAG,SAOxC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAC3B,eAAe,aAAa,CAAC,qBAAqB,CAAC,EACnD,QAAQ,MAAM,KACZ;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,mBAAmB,CAAA;CAAE,GAAG,SAOvD,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,yBAAyB,GACrC,eAAe,aAAa,CAAC,eAAe,CAAC,KAC3C,MAcF,CAAC"}
|
|
@@ -35,11 +35,11 @@ import { TEST_ORIGIN } from './test_origin.js';
|
|
|
35
35
|
* @throws Error if the factory's two stub-ctx invocations produce different
|
|
36
36
|
* `(path, method-list)` shapes — surfaces non-pure factories at setup time.
|
|
37
37
|
*/
|
|
38
|
-
export const resolve_rpc_endpoints_for_setup = (rpc_endpoints,
|
|
38
|
+
export const resolve_rpc_endpoints_for_setup = (rpc_endpoints, session_cookie_name) => {
|
|
39
39
|
if (typeof rpc_endpoints !== 'function')
|
|
40
40
|
return rpc_endpoints;
|
|
41
|
-
const first = rpc_endpoints(create_stub_app_server_context(
|
|
42
|
-
const second = rpc_endpoints(create_stub_app_server_context(
|
|
41
|
+
const first = rpc_endpoints(create_stub_app_server_context(session_cookie_name));
|
|
42
|
+
const second = rpc_endpoints(create_stub_app_server_context(session_cookie_name));
|
|
43
43
|
const summarize = (eps) => JSON.stringify(eps
|
|
44
44
|
.map((ep) => ({
|
|
45
45
|
path: ep.path,
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import './assert_dev_env.js';
|
|
2
|
-
import type { TestAccount } from './
|
|
2
|
+
import type { TestAccount } from './test_app.js';
|
|
3
3
|
import type { AppSurfaceSpec, AppSurfaceRpcMethod } from '../http/surface.js';
|
|
4
4
|
import { type RpcEndpointsSuiteOption } from './rpc_helpers.js';
|
|
5
5
|
import { type AuthPrincipal, type KeeperHeaderProvider } from './integration_helpers.js';
|
|
6
6
|
import type { SetupTest, TestFixture } from './cross_backend/setup.js';
|
|
7
|
-
import type { SessionOptions } from '../auth/session_cookie.js';
|
|
8
7
|
/** Options for `describe_rpc_round_trip_tests`. */
|
|
9
8
|
export interface RpcRoundTripTestOptions {
|
|
10
9
|
/** Per-test fixture-producing function (per-describe cadence). */
|
|
@@ -16,12 +15,12 @@ export interface RpcRoundTripTestOptions {
|
|
|
16
15
|
*/
|
|
17
16
|
surface_source: AppSurfaceSpec;
|
|
18
17
|
/**
|
|
19
|
-
*
|
|
18
|
+
* The session cookie's name — only needed to resolve factory-form `rpc_endpoints`
|
|
20
19
|
* against a stub `AppServerContext` at setup time (the actions' input
|
|
21
20
|
* schemas drive params generation; auth/dispatch run against the real
|
|
22
21
|
* backend through the fixture's transports).
|
|
23
22
|
*/
|
|
24
|
-
|
|
23
|
+
session_cookie_name: string;
|
|
25
24
|
/**
|
|
26
25
|
* RPC endpoint specs — eager array or factory. The factory must return
|
|
27
26
|
* the same endpoint `path` + `spec.method` list regardless of ctx
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpc_round_trip.d.ts","sourceRoot":"","sources":["../../src/lib/testing/rpc_round_trip.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"rpc_round_trip.d.ts","sourceRoot":"","sources":["../../src/lib/testing/rpc_round_trip.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AA0C7B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjD,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9E,OAAO,EAQN,KAAK,uBAAuB,EAC5B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAON,KAAK,aAAa,EAClB,KAAK,oBAAoB,EACzB,M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B,WAAW,EAC3B,eAAe,WAAW,KACxB,gBAMF,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,wBAAwB,GACpC,QAAQ,MAAM,EACd,QAAQ,MAAM,EACd,MAAM,OAAO,EACb,WAAW,aAAa,KACtB,IAwBF,CAAC;AA8GF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,6BAA6B,GAAI,SAAS,uBAAuB,KAAG,IAuKhF,CAAC"}
|
|
@@ -26,6 +26,7 @@ import './assert_dev_env.js';
|
|
|
26
26
|
* @module
|
|
27
27
|
*/
|
|
28
28
|
import { describe, test, beforeAll, assert } from 'vitest';
|
|
29
|
+
import { check_db_invariants_after_all } from './db_invariants.js';
|
|
29
30
|
import { is, parse } from '@fuzdev/fuz_schema/schema.ts';
|
|
30
31
|
import { ROLE_ADMIN } from '../auth/role_schema.js';
|
|
31
32
|
import { JSONRPC_INTERNAL_ERROR, JSONRPC_METHOD_NOT_FOUND, JsonrpcErrorResponse } from '../http/jsonrpc.js';
|
|
@@ -209,10 +210,12 @@ export const describe_rpc_round_trip_tests = (options) => {
|
|
|
209
210
|
// whatever the backend was started with — `action.spec.method` /
|
|
210
211
|
// `.input` / `.output` are ctx-independent, so the stub-resolved specs
|
|
211
212
|
// match what the running backend serves.
|
|
212
|
-
const rpc_endpoints_for_setup = resolve_rpc_endpoints_for_setup(options.rpc_endpoints, options.
|
|
213
|
+
const rpc_endpoints_for_setup = resolve_rpc_endpoints_for_setup(options.rpc_endpoints, options.session_cookie_name);
|
|
213
214
|
const surface_rpc_endpoints = options.surface_source.surface.rpc_endpoints;
|
|
214
215
|
describe('RPC round-trip validation', () => {
|
|
215
216
|
let fixture;
|
|
217
|
+
// `fixture` is unassigned until `beforeAll` runs, which the check allows for
|
|
218
|
+
check_db_invariants_after_all(() => fixture);
|
|
216
219
|
let authed_account;
|
|
217
220
|
let admin_account;
|
|
218
221
|
beforeAll(async () => {
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import './assert_dev_env.js';
|
|
2
2
|
import type { RouteSpec } from '../http/route_spec.js';
|
|
3
3
|
import type { AppServerContext } from '../server/app_server_context.js';
|
|
4
|
-
import type { SessionOptions } from '../auth/session_cookie.js';
|
|
5
4
|
import type { EventSpec } from '../realtime/sse.js';
|
|
6
5
|
import type { AuditLogEvent } from '../auth/audit_log_schema.js';
|
|
7
|
-
import { type SuiteAppOptions, type TestApp, type TestAccount } from './
|
|
6
|
+
import { type SuiteAppOptions, type TestApp, type TestAccount } from './test_app.js';
|
|
8
7
|
import { type DbFactory } from './db.js';
|
|
9
8
|
import { type RpcEndpointsSuiteOption } from './rpc_helpers.js';
|
|
10
9
|
/** Config for a single SSE route under test. */
|
|
@@ -35,8 +34,8 @@ export interface SseRouteTestSpec {
|
|
|
35
34
|
}
|
|
36
35
|
/** Options for `describe_sse_route_tests`. */
|
|
37
36
|
export interface SseRouteTestOptions {
|
|
38
|
-
/**
|
|
39
|
-
|
|
37
|
+
/** The session cookie's name. */
|
|
38
|
+
session_cookie_name: string;
|
|
40
39
|
/** Route spec factory — same shape as production. */
|
|
41
40
|
create_route_specs: (ctx: AppServerContext) => Array<RouteSpec>;
|
|
42
41
|
/** Optional overrides for `AppServerOptions`. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sse_round_trip.d.ts","sourceRoot":"","sources":["../../src/lib/testing/sse_round_trip.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAoB7B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"sse_round_trip.d.ts","sourceRoot":"","sources":["../../src/lib/testing/sse_round_trip.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAoB7B,OAAO,KAAK,EAAE,SAAS,EAAE,M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B;IAC9B,MAAM,EAAE,KAAK,CAAC,gBAAgB,CAAC,CAAC;CAChC;AAmDD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,wBAAwB,GAAI,SAAS,mBAAmB,KAAG,IAyIvE,CAAC"}
|
|
@@ -18,7 +18,8 @@ import { parse } from '@fuzdev/fuz_schema/schema.ts';
|
|
|
18
18
|
import { SSE_CONNECTED_COMMENT } from '../realtime/sse_constants.js';
|
|
19
19
|
import { ROLE_ADMIN } from '../auth/role_schema.js';
|
|
20
20
|
import { create_audit_emitter } from '../auth/audit_emitter.js';
|
|
21
|
-
import { create_test_app } from './
|
|
21
|
+
import { create_test_app } from './test_app.js';
|
|
22
|
+
import { check_db_invariants_after_suite } from './db_invariants.js';
|
|
22
23
|
import { create_default_db_factory } from './db.js';
|
|
23
24
|
import { find_route_spec, pick_auth_headers } from './integration_helpers.js';
|
|
24
25
|
import { rpc_call, require_rpc_endpoint_path, resolve_rpc_endpoints_for_setup } from './rpc_helpers.js';
|
|
@@ -70,7 +71,7 @@ export const describe_sse_route_tests = (options) => {
|
|
|
70
71
|
// confusing test failure when `rpc_endpoints` is missing. Factory-form
|
|
71
72
|
// callers are resolved with a stub ctx purely to extract the endpoint
|
|
72
73
|
// path; real handlers run per-test via the top-level `rpc_endpoints` slot on `CreateTestAppOptions`.
|
|
73
|
-
const rpc_endpoints_for_setup = resolve_rpc_endpoints_for_setup(options.rpc_endpoints, options.
|
|
74
|
+
const rpc_endpoints_for_setup = resolve_rpc_endpoints_for_setup(options.rpc_endpoints, options.session_cookie_name);
|
|
74
75
|
const rpc_path = require_rpc_endpoint_path(rpc_endpoints_for_setup);
|
|
75
76
|
const init_schema = async (db) => {
|
|
76
77
|
await run_migrations(db, [AUTH_MIGRATION_NS]);
|
|
@@ -96,7 +97,7 @@ export const describe_sse_route_tests = (options) => {
|
|
|
96
97
|
? (params) => create_audit_emitter({ ...params, on_audit_event })
|
|
97
98
|
: undefined;
|
|
98
99
|
test_app = await create_test_app({
|
|
99
|
-
|
|
100
|
+
session_cookie_name: options.session_cookie_name,
|
|
100
101
|
create_route_specs: options.create_route_specs,
|
|
101
102
|
db,
|
|
102
103
|
rpc_endpoints: options.rpc_endpoints,
|
|
@@ -112,9 +113,17 @@ export const describe_sse_route_tests = (options) => {
|
|
|
112
113
|
roles: [ROLE_ADMIN]
|
|
113
114
|
});
|
|
114
115
|
});
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
// the app is built in `beforeAll`, outside any test, so it is checked
|
|
117
|
+
// once the describe's tests are done, ahead of the cleanup
|
|
118
|
+
// eslint-disable-next-line no-empty-pattern
|
|
119
|
+
afterAll(async ({}, suite) => {
|
|
120
|
+
try {
|
|
121
|
+
await check_db_invariants_after_suite(suite, test_app);
|
|
122
|
+
}
|
|
123
|
+
finally {
|
|
124
|
+
await test_app.cleanup();
|
|
125
|
+
await factory.close(db);
|
|
126
|
+
}
|
|
118
127
|
});
|
|
119
128
|
test('opens, emits payload, closes on revoke', async () => {
|
|
120
129
|
const spec = find_route_spec(test_app.route_specs, 'GET', route_config.path);
|
package/dist/testing/stubs.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import './assert_dev_env.js';
|
|
2
2
|
import type { AnySchema } from '@fuzdev/fuz_schema/schema.ts';
|
|
3
|
-
import type { SessionOptions } from '../auth/session_cookie.js';
|
|
4
3
|
import type { MiddlewareCarveOut, MiddlewareSpec } from '../http/middleware_spec.js';
|
|
5
4
|
import type { AppDeps } from '../auth/deps.js';
|
|
6
5
|
import type { AuditEmitter } from '../auth/audit_emitter.js';
|
|
@@ -50,7 +49,9 @@ export declare const stub: any;
|
|
|
50
49
|
* Returns a real `Db` instance with:
|
|
51
50
|
* - `query` returns empty rows (safety net for unmocked query functions)
|
|
52
51
|
* - `query_one` returns undefined
|
|
53
|
-
* - `transaction(fn)` calls `fn(
|
|
52
|
+
* - `transaction(fn)` calls `fn(tx)` with a stub transaction `Db` (no real
|
|
53
|
+
* transaction): it reads as one (`in_transaction`) and refuses a nested
|
|
54
|
+
* transaction, as a production transaction `Db` does
|
|
54
55
|
*/
|
|
55
56
|
export declare const create_stub_db: () => Db;
|
|
56
57
|
/** Stub handler that answers a 200 `stub` text response, as a raw result. */
|
|
@@ -75,7 +76,7 @@ export declare const stub_mw: (_c: any, next: any) => Promise<void>;
|
|
|
75
76
|
* wires a listener fails loudly instead of silently never firing
|
|
76
77
|
* (`create_recording_audit_emitter` accepts listeners); `listener_count`
|
|
77
78
|
* returns 0; `drain_inflight` resolves immediately, since nothing is ever
|
|
78
|
-
* written, and `
|
|
79
|
+
* written, and `inflight_count` returns 0. Tests asserting on
|
|
79
80
|
* real audit-row persistence (or on listener fan-out) build a real emitter
|
|
80
81
|
* via `create_audit_emitter` against a stub or real DB — `create_test_app`
|
|
81
82
|
* already does this on the test backend.
|
|
@@ -129,16 +130,16 @@ export declare const create_stub_api_middleware: (options?: {
|
|
|
129
130
|
/**
|
|
130
131
|
* Create a stub `AppServerContext` for attack surface testing.
|
|
131
132
|
*
|
|
132
|
-
* Provides sensible defaults for all fields. Pass `
|
|
133
|
+
* Provides sensible defaults for all fields. Pass `session_cookie_name` since
|
|
133
134
|
* it varies per consumer; other fields use stubs/nulls.
|
|
134
135
|
*
|
|
135
|
-
* @param
|
|
136
|
+
* @param session_cookie_name - consumer's session cookie name (required — varies per app)
|
|
136
137
|
*/
|
|
137
|
-
export declare const create_stub_app_server_context: (
|
|
138
|
+
export declare const create_stub_app_server_context: (session_cookie_name: string) => AppServerContext;
|
|
138
139
|
/** Options for `create_test_app_surface_spec`. */
|
|
139
140
|
export interface CreateTestAppSurfaceSpecOptions {
|
|
140
|
-
/**
|
|
141
|
-
|
|
141
|
+
/** The session cookie's name (required — varies per app). */
|
|
142
|
+
session_cookie_name: string;
|
|
142
143
|
/** Consumer's route factory — receives the same `AppServerContext` as production. */
|
|
143
144
|
create_route_specs: (ctx: AppServerContext) => Array<RouteSpec>;
|
|
144
145
|
/** Env schema for surface generation (default: `BaseServerEnv`). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stubs.d.ts","sourceRoot":"","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,
|
|
1
|
+
{"version":3,"file":"stubs.d.ts","sourceRoot":"","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,kBAAkB,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAIrF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAG7D,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,EAAyB,MAAM,aAAa,CAAC;AACxD,OAAO,EAGN,KAAK,UAAU,EACf,KAAK,SAAS,EACd,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAa,KAAK,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAInE,OAAO,EAEN,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAwB,KAAK,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAC3F,OAAO,KAAK,EAAE,SAAS,EAAmB,MAAM,oBAAoB,CAAC;AACrE,OAAO,EAA+B,KAAK,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAe7F;;;;;;;;;;;;;;;GAeG;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EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACpB;AAmBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,eAAO,MAAM,4BAA4B,GACxC,SAAS,+BAA+B,KACtC,cAmHF,CAAC"}
|
package/dist/testing/stubs.js
CHANGED
|
@@ -13,7 +13,7 @@ import { body_limit_middleware_shape } from '../http/body_limit_schema.js';
|
|
|
13
13
|
import { host_gate_middleware_shape } from '../http/host.js';
|
|
14
14
|
import { create_realtime_closer } from '../actions/connection_closer.js';
|
|
15
15
|
import { create_realtime_notification_sender } from '../actions/notification_sender.js';
|
|
16
|
-
import { Db } from '../db/db.js';
|
|
16
|
+
import { Db, no_nested_transaction } from '../db/db.js';
|
|
17
17
|
import { attach_route_handler, prefix_route_specs } from '../http/route_spec.js';
|
|
18
18
|
import { route_raw } from '../http/route_result.js';
|
|
19
19
|
import { bootstrap_route_shape } from '../auth/bootstrap_route_schema.js';
|
|
@@ -26,6 +26,7 @@ import { SseRegistry } from '../realtime/sse_registry.js';
|
|
|
26
26
|
import { ROLE_ADMIN } from '../auth/role_schema.js';
|
|
27
27
|
import { BaseServerEnv } from '../server/env.js';
|
|
28
28
|
import { AUTH_MIDDLEWARE_PATH, ORIGIN_MIDDLEWARE_PATH, assert_credential_routes_in_auth_scope, assert_endpoint_in_auth_scope, assert_middleware_stack_mounted, assert_origin_carve_outs_valid, freeze_origin_carve_outs } from '../auth/middleware.js';
|
|
29
|
+
import { create_request_tracker } from '../http/pending_effects.js';
|
|
29
30
|
/**
|
|
30
31
|
* Create a Proxy that throws descriptive errors on any property access or method call.
|
|
31
32
|
*
|
|
@@ -87,11 +88,16 @@ export const stub = create_throwing_stub('stub');
|
|
|
87
88
|
* Returns a real `Db` instance with:
|
|
88
89
|
* - `query` returns empty rows (safety net for unmocked query functions)
|
|
89
90
|
* - `query_one` returns undefined
|
|
90
|
-
* - `transaction(fn)` calls `fn(
|
|
91
|
+
* - `transaction(fn)` calls `fn(tx)` with a stub transaction `Db` (no real
|
|
92
|
+
* transaction): it reads as one (`in_transaction`) and refuses a nested
|
|
93
|
+
* transaction, as a production transaction `Db` does
|
|
91
94
|
*/
|
|
92
95
|
export const create_stub_db = () => new Db({
|
|
93
96
|
client: { query: async () => ({ rows: [] }) },
|
|
94
|
-
transaction: async (fn) => fn(
|
|
97
|
+
transaction: async (fn) => fn(new Db({
|
|
98
|
+
client: { query: async () => ({ rows: [] }) },
|
|
99
|
+
transaction: no_nested_transaction
|
|
100
|
+
}))
|
|
95
101
|
});
|
|
96
102
|
/** Stub handler that answers a 200 `stub` text response, as a raw result. */
|
|
97
103
|
export const stub_handler = () => route_raw({ status: 200, headers: { 'Content-Type': 'text/plain;charset=UTF-8' }, body: 'stub' });
|
|
@@ -120,7 +126,7 @@ const stub_db = create_noop_stub('stub_db');
|
|
|
120
126
|
* wires a listener fails loudly instead of silently never firing
|
|
121
127
|
* (`create_recording_audit_emitter` accepts listeners); `listener_count`
|
|
122
128
|
* returns 0; `drain_inflight` resolves immediately, since nothing is ever
|
|
123
|
-
* written, and `
|
|
129
|
+
* written, and `inflight_count` returns 0. Tests asserting on
|
|
124
130
|
* real audit-row persistence (or on listener fan-out) build a real emitter
|
|
125
131
|
* via `create_audit_emitter` against a stub or real DB — `create_test_app`
|
|
126
132
|
* already does this on the test backend.
|
|
@@ -135,7 +141,7 @@ export const create_test_audit_emitter = () => ({
|
|
|
135
141
|
},
|
|
136
142
|
listener_count: () => 0,
|
|
137
143
|
drain_inflight: async () => { },
|
|
138
|
-
|
|
144
|
+
inflight_count: () => 0
|
|
139
145
|
});
|
|
140
146
|
/**
|
|
141
147
|
* Build a no-op `AuditLogSse` for tests that wire `audit_sse` into the
|
|
@@ -162,8 +168,8 @@ export const create_stub_audit_sse = () => {
|
|
|
162
168
|
* Create no-op `AppDeps` for auth surface testing.
|
|
163
169
|
*/
|
|
164
170
|
export const create_stub_app_deps = () => ({
|
|
165
|
-
// `sign` answers a string, as a keyring does
|
|
166
|
-
//
|
|
171
|
+
// `sign` answers a string, as a keyring does, so a route that signs a
|
|
172
|
+
// session cookie on stub deps writes a line
|
|
167
173
|
keyring: create_noop_stub('keyring', {
|
|
168
174
|
sign: async (value) => `${value}.stub_signature`
|
|
169
175
|
}),
|
|
@@ -172,7 +178,8 @@ export const create_stub_app_deps = () => ({
|
|
|
172
178
|
log: new Logger('test', { level: 'off' }),
|
|
173
179
|
audit: create_test_audit_emitter(),
|
|
174
180
|
connection_closer: create_realtime_closer(),
|
|
175
|
-
notification_sender: create_realtime_notification_sender()
|
|
181
|
+
notification_sender: create_realtime_notification_sender(),
|
|
182
|
+
request_tracker: create_request_tracker()
|
|
176
183
|
});
|
|
177
184
|
/**
|
|
178
185
|
* Create a stub `AppBackend` with no database behind it — no migration
|
|
@@ -234,18 +241,18 @@ export const create_stub_api_middleware = (options) => {
|
|
|
234
241
|
/**
|
|
235
242
|
* Create a stub `AppServerContext` for attack surface testing.
|
|
236
243
|
*
|
|
237
|
-
* Provides sensible defaults for all fields. Pass `
|
|
244
|
+
* Provides sensible defaults for all fields. Pass `session_cookie_name` since
|
|
238
245
|
* it varies per consumer; other fields use stubs/nulls.
|
|
239
246
|
*
|
|
240
|
-
* @param
|
|
247
|
+
* @param session_cookie_name - consumer's session cookie name (required — varies per app)
|
|
241
248
|
*/
|
|
242
|
-
export const create_stub_app_server_context = (
|
|
249
|
+
export const create_stub_app_server_context = (session_cookie_name) => {
|
|
243
250
|
const backend = create_stub_app_backend();
|
|
244
251
|
return {
|
|
245
252
|
deps: backend.deps,
|
|
246
253
|
backend,
|
|
247
254
|
bootstrap_status: { available: false },
|
|
248
|
-
|
|
255
|
+
session_cookie_name,
|
|
249
256
|
login_ip_rate_limiter: null,
|
|
250
257
|
signup_ip_rate_limiter: null,
|
|
251
258
|
bootstrap_ip_rate_limiter: null,
|
|
@@ -307,7 +314,7 @@ const assert_self_resolved_ws_origins = (endpoint) => {
|
|
|
307
314
|
* reorders, wraps, or replaces the stub host gate, proxy or auth spec
|
|
308
315
|
*/
|
|
309
316
|
export const create_test_app_surface_spec = (options) => {
|
|
310
|
-
const ctx = create_stub_app_server_context(options.
|
|
317
|
+
const ctx = create_stub_app_server_context(options.session_cookie_name);
|
|
311
318
|
const consumer_routes = options.create_route_specs(ctx);
|
|
312
319
|
// Auto-mount rpc endpoints (mirrors create_app_server) so consumer
|
|
313
320
|
// `create_route_specs` does not need to call `create_rpc_endpoint`.
|