@fuzdev/fuz_app 0.181.0 → 0.183.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 +28 -10
- package/dist/actions/action_rpc.d.ts +11 -1
- package/dist/actions/action_rpc.d.ts.map +1 -1
- package/dist/actions/action_rpc.js +3 -2
- package/dist/actions/action_types.d.ts +16 -1
- package/dist/actions/action_types.d.ts.map +1 -1
- package/dist/actions/action_types.js +1 -1
- package/dist/actions/notification_sender.d.ts +83 -0
- package/dist/actions/notification_sender.d.ts.map +1 -0
- package/dist/actions/notification_sender.js +85 -0
- package/dist/actions/perform_action.d.ts +9 -0
- package/dist/actions/perform_action.d.ts.map +1 -1
- package/dist/actions/perform_action.js +22 -13
- package/dist/actions/register_action_ws.d.ts +14 -0
- package/dist/actions/register_action_ws.d.ts.map +1 -1
- package/dist/actions/register_action_ws.js +3 -2
- package/dist/actions/ws_socket_session.d.ts +3 -0
- package/dist/actions/ws_socket_session.d.ts.map +1 -1
- package/dist/actions/ws_socket_session.js +2 -1
- package/dist/auth/CLAUDE.md +113 -70
- package/dist/auth/account_actions.d.ts.map +1 -1
- package/dist/auth/account_actions.js +13 -3
- package/dist/auth/account_queries.d.ts +158 -16
- package/dist/auth/account_queries.d.ts.map +1 -1
- package/dist/auth/account_queries.js +189 -18
- package/dist/auth/account_routes.d.ts +6 -4
- package/dist/auth/account_routes.d.ts.map +1 -1
- package/dist/auth/account_routes.js +98 -92
- package/dist/auth/admin_actions.d.ts.map +1 -1
- package/dist/auth/admin_actions.js +93 -45
- package/dist/auth/api_token_queries.d.ts +13 -5
- package/dist/auth/api_token_queries.d.ts.map +1 -1
- package/dist/auth/api_token_queries.js +24 -9
- 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 +10 -5
- package/dist/auth/audit_log_schema.d.ts.map +1 -1
- package/dist/auth/audit_log_schema.js +22 -6
- package/dist/auth/bearer_auth.d.ts.map +1 -1
- package/dist/auth/bearer_auth.js +3 -2
- package/dist/auth/bootstrap_account.d.ts +31 -13
- package/dist/auth/bootstrap_account.d.ts.map +1 -1
- package/dist/auth/bootstrap_account.js +34 -15
- package/dist/auth/bootstrap_routes.d.ts +1 -1
- package/dist/auth/bootstrap_routes.d.ts.map +1 -1
- package/dist/auth/bootstrap_routes.js +7 -14
- package/dist/auth/daemon_token_middleware.d.ts.map +1 -1
- package/dist/auth/daemon_token_middleware.js +12 -1
- package/dist/auth/deps.d.ts +18 -5
- package/dist/auth/deps.d.ts.map +1 -1
- package/dist/auth/deps.js +3 -2
- package/dist/auth/request_context.d.ts +73 -73
- package/dist/auth/request_context.d.ts.map +1 -1
- package/dist/auth/request_context.js +78 -96
- package/dist/auth/resolved_auth.d.ts +16 -11
- package/dist/auth/resolved_auth.d.ts.map +1 -1
- package/dist/auth/resolved_auth.js +6 -6
- package/dist/auth/role_grant_offer_action_specs.d.ts +1 -1
- package/dist/auth/role_grant_offer_action_specs.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_action_specs.js +2 -1
- package/dist/auth/role_grant_offer_actions.d.ts +32 -12
- package/dist/auth/role_grant_offer_actions.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_actions.js +91 -116
- package/dist/auth/role_grant_offer_notifications.d.ts +87 -38
- package/dist/auth/role_grant_offer_notifications.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_notifications.js +75 -22
- package/dist/auth/role_grant_offer_queries.d.ts +155 -18
- package/dist/auth/role_grant_offer_queries.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_queries.js +262 -73
- package/dist/auth/role_grant_offer_schema.js +1 -1
- package/dist/auth/role_grant_queries.d.ts +43 -52
- package/dist/auth/role_grant_queries.d.ts.map +1 -1
- package/dist/auth/role_grant_queries.js +50 -74
- package/dist/auth/role_grant_sql.d.ts +21 -0
- package/dist/auth/role_grant_sql.d.ts.map +1 -1
- package/dist/auth/role_grant_sql.js +21 -0
- package/dist/auth/self_service_role_actions.d.ts.map +1 -1
- package/dist/auth/self_service_role_actions.js +17 -21
- package/dist/auth/session_queries.d.ts +40 -16
- package/dist/auth/session_queries.d.ts.map +1 -1
- package/dist/auth/session_queries.js +68 -29
- package/dist/auth/signup_routes.d.ts.map +1 -1
- package/dist/auth/signup_routes.js +90 -38
- package/dist/auth/standard_rpc_actions.d.ts +6 -19
- package/dist/auth/standard_rpc_actions.d.ts.map +1 -1
- package/dist/auth/standard_rpc_actions.js +5 -6
- package/dist/auth/token_scope.d.ts +1 -1
- package/dist/auth/token_scope.js +1 -1
- package/dist/db/sql_columns.d.ts +1 -1
- package/dist/db/sql_columns.js +1 -1
- package/dist/http/CLAUDE.md +22 -16
- package/dist/http/auth_shape.d.ts +1 -1
- package/dist/http/db_routes.d.ts +7 -22
- package/dist/http/db_routes.d.ts.map +1 -1
- package/dist/http/db_routes.js +72 -72
- package/dist/http/error_schemas.d.ts +9 -21
- package/dist/http/error_schemas.d.ts.map +1 -1
- package/dist/http/error_schemas.js +14 -24
- package/dist/http/pending_effects.d.ts +42 -4
- package/dist/http/pending_effects.d.ts.map +1 -1
- package/dist/http/pending_effects.js +34 -4
- package/dist/http/route_spec.d.ts +2 -2
- 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 +69 -18
- package/dist/server/app_server.d.ts.map +1 -1
- package/dist/server/app_server.js +74 -10
- package/dist/server/serve_fact_route.d.ts +3 -3
- package/dist/server/serve_fact_route.js +12 -12
- package/dist/testing/CLAUDE.md +259 -790
- 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 +20 -140
- package/dist/testing/app_server.d.ts.map +1 -1
- package/dist/testing/app_server.js +48 -125
- 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/auth_apps.js +1 -1
- package/dist/testing/cross_backend/account_lifecycle.d.ts.map +1 -1
- package/dist/testing/cross_backend/account_lifecycle.js +43 -0
- 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 +423 -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 +2 -50
- package/dist/testing/cross_backend/conformance_table.d.ts.map +1 -1
- package/dist/testing/cross_backend/conformance_table.js +2 -270
- 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_spine_surface.d.ts +1 -26
- package/dist/testing/cross_backend/default_spine_surface.d.ts.map +1 -1
- package/dist/testing/cross_backend/default_spine_surface.js +2 -6
- package/dist/testing/cross_backend/differential.d.ts +11 -2
- 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 +3 -10
- package/dist/testing/cross_backend/full_spine_mount.d.ts.map +1 -1
- package/dist/testing/cross_backend/full_spine_mount.js +4 -4
- package/dist/testing/cross_backend/in_process_setup.d.ts +22 -12
- package/dist/testing/cross_backend/in_process_setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/in_process_setup.js +151 -134
- 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_offer_notification_ws.d.ts +5 -4
- package/dist/testing/cross_backend/role_grant_offer_notification_ws.d.ts.map +1 -1
- package/dist/testing/cross_backend/role_grant_offer_notification_ws.js +183 -30
- 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/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 +48 -16
- package/dist/testing/cross_backend/setup.d.ts +31 -1
- 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 +123 -12
- package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
- package/dist/testing/cross_backend/spine_suites.js +454 -57
- 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/testing_backdoor.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_backdoor.js +4 -2
- package/dist/testing/cross_backend/testing_reset_actions.d.ts +59 -27
- package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_reset_actions.js +66 -42
- 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/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 +6 -9
- package/dist/testing/integration.d.ts.map +1 -1
- package/dist/testing/integration.js +9 -13
- package/dist/testing/integration_helpers.d.ts +1 -1
- package/dist/testing/integration_helpers.d.ts.map +1 -1
- package/dist/testing/middleware.d.ts +1 -1
- package/dist/testing/middleware.js +5 -5
- package/dist/testing/rate_limiting.d.ts +1 -1
- package/dist/testing/rate_limiting.d.ts.map +1 -1
- package/dist/testing/rate_limiting.js +3 -2
- package/dist/testing/resolved_auth.d.ts +3 -1
- package/dist/testing/resolved_auth.d.ts.map +1 -1
- package/dist/testing/resolved_auth.js +4 -4
- 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_round_trip.d.ts +1 -1
- package/dist/testing/rpc_round_trip.d.ts.map +1 -1
- package/dist/testing/rpc_round_trip.js +3 -0
- package/dist/testing/sse_round_trip.d.ts +1 -1
- package/dist/testing/sse_round_trip.d.ts.map +1 -1
- package/dist/testing/sse_round_trip.js +13 -4
- package/dist/testing/stubs.d.ts +4 -2
- package/dist/testing/stubs.d.ts.map +1 -1
- package/dist/testing/stubs.js +15 -7
- package/dist/testing/test_app.d.ts +166 -0
- package/dist/testing/test_app.d.ts.map +1 -0
- package/dist/testing/test_app.js +124 -0
- package/dist/testing/ws_round_trip.d.ts.map +1 -1
- package/dist/testing/ws_round_trip.js +8 -4
- package/package.json +1 -1
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import '../assert_dev_env.js';
|
|
2
|
+
/**
|
|
3
|
+
* The conformance principals' credentials: how each `ConformancePrincipal`
|
|
4
|
+
* resolves onto the transport and headers it sends with, read from the
|
|
5
|
+
* per-test `TestFixture` — the table (`describe_conformance_table_tests`)
|
|
6
|
+
* and the suites that send a principal's requests themselves
|
|
7
|
+
* (`describe_rpc_adversarial_cross_tests`). Its own module, apart from the
|
|
8
|
+
* table's WebSocket leg, so a suite resolving principals over HTTP reaches
|
|
9
|
+
* no socket transport.
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
import { DAEMON_TOKEN_HEADER, is_daemon_token_shaped } from '../../auth/daemon_token.js';
|
|
14
|
+
import { API_TOKEN_PREFIX, is_api_token_shaped } from '../../auth/api_token.js';
|
|
15
|
+
import { account_token_create_action_spec } from '../../auth/account_action_specs.js';
|
|
16
|
+
import { find_rpc_action } from '../rpc_helpers.js';
|
|
17
|
+
import { SCOPED_TOKEN_ADMITTED_METHOD } from './conformance_case.js';
|
|
18
|
+
import { mint_narrowed_api_token } from './narrowed_api_token.js';
|
|
19
|
+
/**
|
|
20
|
+
* A deliberately malformed `X-Daemon-Token` value for the `invalid_daemon`
|
|
21
|
+
* principal. Fails the `DaemonToken` schema (not 43 base64url chars), so
|
|
22
|
+
* the daemon-token middleware soft-fail-discards it rather than authenticating
|
|
23
|
+
* — the request falls through with no identity, surfacing
|
|
24
|
+
* `credential_type_required` on a daemon-gated action (matching the Rust
|
|
25
|
+
* spine's `None`). Sent over a no-Origin transport so it lands on the
|
|
26
|
+
* invalid-token path, not the browser-context discard.
|
|
27
|
+
*/
|
|
28
|
+
const INVALID_DAEMON_TOKEN_VALUE = 'not-a-valid-daemon-token';
|
|
29
|
+
/**
|
|
30
|
+
* The `wrong_daemon` principal's token: well-shaped (43 base64url characters),
|
|
31
|
+
* so it passes the shape precheck and is refused by the compare — never the
|
|
32
|
+
* server's, whose tokens are random.
|
|
33
|
+
*/
|
|
34
|
+
const WRONG_DAEMON_TOKEN_VALUE = 'A'.repeat(43);
|
|
35
|
+
/**
|
|
36
|
+
* The `unknown_bearer` principal's token: well-shaped (the prefix and 43
|
|
37
|
+
* base64url characters), so it costs the lookup no row answers.
|
|
38
|
+
*/
|
|
39
|
+
const UNKNOWN_BEARER_TOKEN_VALUE = `${API_TOKEN_PREFIX}${'A'.repeat(43)}`;
|
|
40
|
+
if (!is_daemon_token_shaped(WRONG_DAEMON_TOKEN_VALUE)) {
|
|
41
|
+
throw new Error('conformance: WRONG_DAEMON_TOKEN_VALUE must be daemon-token-shaped');
|
|
42
|
+
}
|
|
43
|
+
if (!is_api_token_shaped(UNKNOWN_BEARER_TOKEN_VALUE)) {
|
|
44
|
+
throw new Error('conformance: UNKNOWN_BEARER_TOKEN_VALUE must be api-token-shaped');
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The keeper's session cookie with its MAC corrupted: the first character of
|
|
48
|
+
* the signature (after the last `.`) changed, so the signature keeps its
|
|
49
|
+
* shape and the keyring refuses it on the compare, not the shape check.
|
|
50
|
+
*/
|
|
51
|
+
const tamper_session_cookie = (cookie) => {
|
|
52
|
+
const dot = cookie.lastIndexOf('.');
|
|
53
|
+
const first = cookie[dot + 1];
|
|
54
|
+
if (dot === -1 || first === undefined) {
|
|
55
|
+
throw new Error(`conformance: principal 'tampered_cookie' found no signed session cookie`);
|
|
56
|
+
}
|
|
57
|
+
return `${cookie.slice(0, dot + 1)}${first === 'A' ? 'B' : 'A'}${cookie.slice(dot + 2)}`;
|
|
58
|
+
};
|
|
59
|
+
/** A dead bearer presented alone: no cookie, no `Origin`, so the token is looked up. */
|
|
60
|
+
const as_lone_bearer = (fixture, token) => ({
|
|
61
|
+
transport: fixture.fresh_transport({ origin: null }),
|
|
62
|
+
headers: { authorization: `Bearer ${token}` },
|
|
63
|
+
suppress_default_origin: true
|
|
64
|
+
});
|
|
65
|
+
/**
|
|
66
|
+
* Mint the `scoped_token` principal's narrowed bearer token over the
|
|
67
|
+
* production `account_token_create` path.
|
|
68
|
+
*
|
|
69
|
+
* Minted rather than seeded, and minted *here* rather than in a case. The
|
|
70
|
+
* seed stays `full` because `_testing_reset`'s api token backs every other
|
|
71
|
+
* bearer principal, and a case that minted its own credential would be the
|
|
72
|
+
* setup-DSL trap the case schema exists to avoid.
|
|
73
|
+
*
|
|
74
|
+
* `account_token_create` is session-only, so this runs over the keeper's
|
|
75
|
+
* session — which also makes the mint itself a live assertion that a narrowed
|
|
76
|
+
* scope is *accepted* at the mint boundary, not merely stored.
|
|
77
|
+
*/
|
|
78
|
+
const mint_scoped_token = async (fixture, resolved_rpc_endpoints) => {
|
|
79
|
+
const found = find_rpc_action(resolved_rpc_endpoints, account_token_create_action_spec.method);
|
|
80
|
+
if (!found) {
|
|
81
|
+
throw new Error(`conformance: principal 'scoped_token' needs '${account_token_create_action_spec.method}' ` +
|
|
82
|
+
`on the surface to mint its narrowed token, but the method is not registered on ` +
|
|
83
|
+
`rpc_endpoints.`);
|
|
84
|
+
}
|
|
85
|
+
return mint_narrowed_api_token({
|
|
86
|
+
app: fixture.transport,
|
|
87
|
+
rpc_path: found.path,
|
|
88
|
+
session_headers: fixture.create_session_headers(),
|
|
89
|
+
methods: [SCOPED_TOKEN_ADMITTED_METHOD],
|
|
90
|
+
name: 'conformance scoped token'
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Map a `ConformancePrincipal` onto the transport + headers it
|
|
95
|
+
* authenticates with, reading exclusively from the per-test `TestFixture`.
|
|
96
|
+
*
|
|
97
|
+
* The always-available principals resolve from fixture accessors (the dead
|
|
98
|
+
* credentials that need a server-side state — a revoked session or token, an
|
|
99
|
+
* expired token — from the fixture's `mint_*` seams); `role_holder` /
|
|
100
|
+
* `wrong_role` read a seeded `extra_accounts` entry named via
|
|
101
|
+
* `options.principals` (throws a clear setup error when unconfigured);
|
|
102
|
+
* `scoped_token` mints its narrowed credential over the production path.
|
|
103
|
+
* Also used outside the table by suites that send a principal's requests
|
|
104
|
+
* themselves (`describe_rpc_adversarial_cross_tests`).
|
|
105
|
+
*
|
|
106
|
+
* @param fixture - the per-test fixture
|
|
107
|
+
* @param as - the principal
|
|
108
|
+
* @param principals - usernames for `role_holder` / `wrong_role`
|
|
109
|
+
* @param resolved_rpc_endpoints - the endpoints `scoped_token` mints through
|
|
110
|
+
* @returns the transport and headers the principal sends with
|
|
111
|
+
*/
|
|
112
|
+
export const resolve_conformance_principal = async (fixture, as, principals, resolved_rpc_endpoints = []) => {
|
|
113
|
+
switch (as) {
|
|
114
|
+
case 'keeper':
|
|
115
|
+
// Keeper carries its session cookie via `create_session_headers`
|
|
116
|
+
// (in-process the transport is stateless; cross-process the jar
|
|
117
|
+
// also holds it — the explicit header is the same value).
|
|
118
|
+
return {
|
|
119
|
+
transport: fixture.transport,
|
|
120
|
+
headers: fixture.create_session_headers(),
|
|
121
|
+
actor_id: fixture.actor.id
|
|
122
|
+
};
|
|
123
|
+
case 'daemon':
|
|
124
|
+
// Daemon-token is a non-browser credential — empty jar + no Origin.
|
|
125
|
+
return {
|
|
126
|
+
transport: fixture.fresh_transport({ origin: null }),
|
|
127
|
+
headers: fixture.create_daemon_token_headers(),
|
|
128
|
+
suppress_default_origin: true,
|
|
129
|
+
actor_id: fixture.actor.id
|
|
130
|
+
};
|
|
131
|
+
case 'invalid_daemon':
|
|
132
|
+
// A malformed `X-Daemon-Token` carried ALONGSIDE the keeper's session
|
|
133
|
+
// cookie, over a non-browser (no-Origin) transport. The invalid daemon
|
|
134
|
+
// token is soft-fail-discarded (matching the Rust spine's `None`), so
|
|
135
|
+
// auth falls through to the session leg: the request authenticates as
|
|
136
|
+
// the keeper-via-session (clearing `require_auth`), then the daemon-gated
|
|
137
|
+
// action's credential-type gate refuses the session credential →
|
|
138
|
+
// `403 credential_type_required`. No-Origin keeps the daemon token on
|
|
139
|
+
// the invalid-token path, NOT the browser-context discard. Without the
|
|
140
|
+
// base credential this would 401 (anonymous) — the session is what makes
|
|
141
|
+
// the *credential-type* gate, not the auth gate, the refusing layer.
|
|
142
|
+
return {
|
|
143
|
+
transport: fixture.fresh_transport({ origin: null }),
|
|
144
|
+
headers: fixture.create_session_headers({
|
|
145
|
+
[DAEMON_TOKEN_HEADER]: INVALID_DAEMON_TOKEN_VALUE
|
|
146
|
+
}),
|
|
147
|
+
suppress_default_origin: true,
|
|
148
|
+
actor_id: fixture.actor.id
|
|
149
|
+
};
|
|
150
|
+
case 'daemon_browser':
|
|
151
|
+
// A VALID `X-Daemon-Token` carried in a browser context (default Origin
|
|
152
|
+
// present) ALONGSIDE the keeper's session cookie. The daemon-token
|
|
153
|
+
// middleware discards a header-bearing daemon token as browser context
|
|
154
|
+
// (mirroring the bearer guard + the Rust spine's `is_browser_context`),
|
|
155
|
+
// so the valid token is dropped and auth falls through to the session
|
|
156
|
+
// leg → keeper-via-session → a daemon-gated action refuses the session
|
|
157
|
+
// credential with `credential_type_required`. Origin is NOT suppressed —
|
|
158
|
+
// its presence is the browser-context signal under test. Unlike the
|
|
159
|
+
// `daemon` principal (no Origin → token honored → reaches the 400 confirm
|
|
160
|
+
// guard), the 403 here proves the valid token was discarded, not honored.
|
|
161
|
+
return {
|
|
162
|
+
transport: fixture.transport,
|
|
163
|
+
headers: fixture.create_session_headers(fixture.create_daemon_token_headers()),
|
|
164
|
+
actor_id: fixture.actor.id
|
|
165
|
+
};
|
|
166
|
+
case 'token':
|
|
167
|
+
// Bearer is discarded in a browser context — empty jar + no Origin.
|
|
168
|
+
return {
|
|
169
|
+
transport: fixture.fresh_transport({ origin: null }),
|
|
170
|
+
headers: fixture.create_bearer_headers(),
|
|
171
|
+
suppress_default_origin: true,
|
|
172
|
+
actor_id: fixture.actor.id
|
|
173
|
+
};
|
|
174
|
+
case 'bearer_browser':
|
|
175
|
+
// A VALID bearer api-token in a browser context (default Origin
|
|
176
|
+
// present), fresh jar so no session rides alongside. The bearer
|
|
177
|
+
// middleware discards a header-bearing token as browser context
|
|
178
|
+
// (mirroring the daemon guard + the Rust spine's `is_browser_context`),
|
|
179
|
+
// so the request arrives anonymous → an authed action 401s. Origin is
|
|
180
|
+
// NOT suppressed (its presence is the browser-context signal) — the
|
|
181
|
+
// inverse of the `token` principal, which suppresses it so the same
|
|
182
|
+
// token is honored. The 401 proves the valid token was discarded, not
|
|
183
|
+
// honored (a non-discarding leg would authenticate → 200).
|
|
184
|
+
return {
|
|
185
|
+
transport: fixture.fresh_transport(),
|
|
186
|
+
headers: fixture.create_bearer_headers()
|
|
187
|
+
};
|
|
188
|
+
case 'malformed_bearer': {
|
|
189
|
+
// The keeper's valid token minus its last character — prefixed, one char
|
|
190
|
+
// short — over the same no-Origin, empty-jar transport as `token`, so the
|
|
191
|
+
// shape precheck (not the browser-context discard) is what refuses it.
|
|
192
|
+
const valid = fixture.create_bearer_headers().authorization;
|
|
193
|
+
if (!valid)
|
|
194
|
+
throw new Error(`conformance: principal 'malformed_bearer' found no bearer header`);
|
|
195
|
+
return {
|
|
196
|
+
transport: fixture.fresh_transport({ origin: null }),
|
|
197
|
+
headers: { authorization: valid.slice(0, -1) },
|
|
198
|
+
suppress_default_origin: true
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
case 'scoped_token': {
|
|
202
|
+
// A narrowed bearer, otherwise identical to `token` — empty jar + no
|
|
203
|
+
// Origin, so the credential is honored rather than browser-discarded
|
|
204
|
+
// and the scope gate is what any denial comes from.
|
|
205
|
+
const token = await mint_scoped_token(fixture, resolved_rpc_endpoints);
|
|
206
|
+
return {
|
|
207
|
+
transport: fixture.fresh_transport({ origin: null }),
|
|
208
|
+
headers: { authorization: `Bearer ${token}` },
|
|
209
|
+
suppress_default_origin: true,
|
|
210
|
+
actor_id: fixture.actor.id
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
case 'anonymous':
|
|
214
|
+
// Fresh jar so the keeper cookie (cross-process) can't leak in.
|
|
215
|
+
return { transport: fixture.fresh_transport(), headers: {} };
|
|
216
|
+
case 'fresh_non_admin': {
|
|
217
|
+
const account = await fixture.create_account();
|
|
218
|
+
return {
|
|
219
|
+
transport: fixture.fresh_transport(),
|
|
220
|
+
headers: account.create_session_headers(),
|
|
221
|
+
actor_id: account.actor.id
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
case 'expired_session': {
|
|
225
|
+
// The keeper presented via an expired server-side session — fresh
|
|
226
|
+
// jar so only the (expired) cookie this seam returns is sent. The
|
|
227
|
+
// minted cookie payload is valid; the backdated `auth_session` row
|
|
228
|
+
// is what the DB-row expiry gate refuses.
|
|
229
|
+
const cookie = await fixture.mint_expired_session();
|
|
230
|
+
return {
|
|
231
|
+
transport: fixture.fresh_transport(),
|
|
232
|
+
headers: { cookie },
|
|
233
|
+
actor_id: fixture.actor.id
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
case 'tampered_cookie': {
|
|
237
|
+
// fresh jar, so the tampered cookie is the only one sent
|
|
238
|
+
const { cookie } = fixture.create_session_headers();
|
|
239
|
+
if (!cookie)
|
|
240
|
+
throw new Error(`conformance: principal 'tampered_cookie' found no cookie`);
|
|
241
|
+
return {
|
|
242
|
+
transport: fixture.fresh_transport(),
|
|
243
|
+
headers: { cookie: tamper_session_cookie(cookie) }
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
case 'wrong_daemon':
|
|
247
|
+
// no Origin, so the token reaches the compare, not the browser-context discard
|
|
248
|
+
return {
|
|
249
|
+
transport: fixture.fresh_transport({ origin: null }),
|
|
250
|
+
headers: { [DAEMON_TOKEN_HEADER]: WRONG_DAEMON_TOKEN_VALUE },
|
|
251
|
+
suppress_default_origin: true
|
|
252
|
+
};
|
|
253
|
+
case 'unknown_bearer':
|
|
254
|
+
return as_lone_bearer(fixture, UNKNOWN_BEARER_TOKEN_VALUE);
|
|
255
|
+
case 'revoked_session':
|
|
256
|
+
return {
|
|
257
|
+
transport: fixture.fresh_transport(),
|
|
258
|
+
headers: { cookie: await fixture.mint_revoked_session() }
|
|
259
|
+
};
|
|
260
|
+
case 'revoked_token':
|
|
261
|
+
return as_lone_bearer(fixture, await fixture.mint_revoked_token());
|
|
262
|
+
case 'expired_token':
|
|
263
|
+
return as_lone_bearer(fixture, await fixture.mint_expired_token());
|
|
264
|
+
case 'role_holder':
|
|
265
|
+
case 'wrong_role': {
|
|
266
|
+
const username = principals?.[as];
|
|
267
|
+
if (!username) {
|
|
268
|
+
throw new Error(`conformance: principal '${as}' requires options.principals.${as} naming a seeded ` +
|
|
269
|
+
`extra_accounts username (declare the account at setup via extra_accounts).`);
|
|
270
|
+
}
|
|
271
|
+
const extra = fixture.extra_accounts[username];
|
|
272
|
+
if (!extra) {
|
|
273
|
+
throw new Error(`conformance: extra_accounts['${username}'] not seeded for principal '${as}' — ` +
|
|
274
|
+
`declare it in the suite's extra_accounts option.`);
|
|
275
|
+
}
|
|
276
|
+
return {
|
|
277
|
+
transport: fixture.fresh_transport(),
|
|
278
|
+
headers: extra.create_session_headers(),
|
|
279
|
+
actor_id: extra.actor.id
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
};
|
|
@@ -4,23 +4,11 @@ import type { RouteSpec } from '../../http/route_spec.js';
|
|
|
4
4
|
import type { RpcAction } from '../../actions/action_types.js';
|
|
5
5
|
import type { SessionOptions } from '../../auth/session_cookie.js';
|
|
6
6
|
import { resolve_rpc_endpoints_for_setup, type RpcEndpointsSuiteOption } from '../rpc_helpers.js';
|
|
7
|
-
import type
|
|
8
|
-
import { type ConformanceCase, type ConformancePrincipal } from './conformance_case.js';
|
|
7
|
+
import { type ConformanceCase } from './conformance_case.js';
|
|
9
8
|
import type { BackendCapabilities } from './capabilities.js';
|
|
10
9
|
import type { SetupTest, TestFixture } from './setup.js';
|
|
11
10
|
import type { WsEndpointTarget } from './ws_endpoint.js';
|
|
12
|
-
|
|
13
|
-
* Names a seeded `extra_accounts` username for the `role_holder` /
|
|
14
|
-
* `wrong_role` principals — the only two that aren't backed by an
|
|
15
|
-
* always-available fixture accessor. Suites exercising those principals
|
|
16
|
-
* declare the matching `extra_accounts` at setup and name them here.
|
|
17
|
-
*/
|
|
18
|
-
export interface ConformancePrincipalConfig {
|
|
19
|
-
/** `extra_accounts` username for the `role_holder` principal. */
|
|
20
|
-
readonly role_holder?: string;
|
|
21
|
-
/** `extra_accounts` username for the `wrong_role` principal. */
|
|
22
|
-
readonly wrong_role?: string;
|
|
23
|
-
}
|
|
11
|
+
import { type ConformancePrincipalConfig } from './conformance_principal.js';
|
|
24
12
|
/** Options for `describe_conformance_table_tests`. */
|
|
25
13
|
export interface ConformanceTableOptions {
|
|
26
14
|
/** The conformance cases to run, in order. */
|
|
@@ -85,42 +73,6 @@ export declare const resolve_conformance_rpc_endpoints: (options: ConformanceRpc
|
|
|
85
73
|
* @returns whether the WS leg runs it
|
|
86
74
|
*/
|
|
87
75
|
export declare const is_ws_conformance_case: (c: ConformanceCase) => boolean;
|
|
88
|
-
/** A resolved principal: the transport + headers a case fires through. */
|
|
89
|
-
export interface ResolvedConformancePrincipal {
|
|
90
|
-
readonly transport: FetchTransport;
|
|
91
|
-
readonly headers: Record<string, string>;
|
|
92
|
-
/**
|
|
93
|
-
* Suppress the default `Origin` header on the request. Required for
|
|
94
|
-
* non-browser credential probes (bearer / daemon) — `bearer_auth`
|
|
95
|
-
* discards the token when `Origin` / `Referer` is present.
|
|
96
|
-
*/
|
|
97
|
-
readonly suppress_default_origin?: boolean;
|
|
98
|
-
/**
|
|
99
|
-
* The actor of the account the credential names — what the `principal`
|
|
100
|
-
* acting binding writes. Absent for principals that present no account.
|
|
101
|
-
*/
|
|
102
|
-
readonly actor_id?: string;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Map a `ConformancePrincipal` onto the transport + headers it
|
|
106
|
-
* authenticates with, reading exclusively from the per-test `TestFixture`.
|
|
107
|
-
*
|
|
108
|
-
* The always-available principals resolve from fixture accessors (the dead
|
|
109
|
-
* credentials that need a server-side state — a revoked session or token, an
|
|
110
|
-
* expired token — from the fixture's `mint_*` seams); `role_holder` /
|
|
111
|
-
* `wrong_role` read a seeded `extra_accounts` entry named via
|
|
112
|
-
* `options.principals` (throws a clear setup error when unconfigured);
|
|
113
|
-
* `scoped_token` mints its narrowed credential over the production path.
|
|
114
|
-
* Also used outside the table by suites that send a principal's requests
|
|
115
|
-
* themselves (`describe_rpc_adversarial_cross_tests`).
|
|
116
|
-
*
|
|
117
|
-
* @param fixture - the per-test fixture
|
|
118
|
-
* @param as - the principal
|
|
119
|
-
* @param principals - usernames for `role_holder` / `wrong_role`
|
|
120
|
-
* @param resolved_rpc_endpoints - the endpoints `scoped_token` mints through
|
|
121
|
-
* @returns the transport and headers the principal sends with
|
|
122
|
-
*/
|
|
123
|
-
export declare const resolve_conformance_principal: (fixture: TestFixture, as: ConformancePrincipal, principals?: ConformancePrincipalConfig, resolved_rpc_endpoints?: ReturnType<typeof resolve_rpc_endpoints_for_setup>) => Promise<ResolvedConformancePrincipal>;
|
|
124
76
|
/**
|
|
125
77
|
* Response headers that fingerprint the backend implementation or framework.
|
|
126
78
|
* Neither spine emits these; the runner asserts they stay absent on EVERY
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conformance_table.d.ts","sourceRoot":"","sources":["../../../src/lib/testing/cross_backend/conformance_table.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAwD9B,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,u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AAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAC5C,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;CACvB;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,qBAAqB,GACjC,GAAG,eAAe,EAClB,SAAS,0BAA0B,KACjC,OAAO,CAAC,uBAAuB,CAwFjC,CAAC;AA2OF;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,uBAAuB,GAAI,OAAO,aAAa,CAAC,eAAe,CAAC,KAAG,IA0B/E,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gCAAgC,GAAI,SAAS,uBAAuB,KAAG,IAwEnF,CAAC"}
|
|
@@ -51,18 +51,15 @@ import '../assert_dev_env.js';
|
|
|
51
51
|
*/
|
|
52
52
|
import { assert, describe, test } from 'vitest';
|
|
53
53
|
import { parse } from '@fuzdev/fuz_schema/schema.ts';
|
|
54
|
-
import { DAEMON_TOKEN_HEADER, is_daemon_token_shaped } from '../../auth/daemon_token.js';
|
|
55
|
-
import { API_TOKEN_PREFIX, is_api_token_shaped } from '../../auth/api_token.js';
|
|
56
54
|
import { find_auth_route, rest_auth_route_suffixes } from '../integration_helpers.js';
|
|
57
55
|
import { find_rpc_action, headers_to_record, parse_rpc_call_result, rpc_call_raw, create_rpc_request_text, resolve_rpc_endpoints_for_setup } from '../rpc_helpers.js';
|
|
58
|
-
import { account_token_create_action_spec } from '../../auth/account_action_specs.js';
|
|
59
56
|
import { http_status_to_jsonrpc_error_code, jsonrpc_error_code_to_http_status } from '../../http/jsonrpc_errors.js';
|
|
60
57
|
import { create_admitted_ws_transport } from '../transports/ws_transport.js';
|
|
61
58
|
import { is_response_for } from '../transports/ws_client.js';
|
|
62
|
-
import {
|
|
59
|
+
import {} from './conformance_case.js';
|
|
63
60
|
import { classify_session_cookie_effect, filter_session_set_cookies, find_session_cookie_mints } from './session_cookie_effect.js';
|
|
64
|
-
import { mint_narrowed_api_token } from './narrowed_api_token.js';
|
|
65
61
|
import { xfail_until } from './xfail.js';
|
|
62
|
+
import { resolve_conformance_principal } from './conformance_principal.js';
|
|
66
63
|
/**
|
|
67
64
|
* Resolve the endpoints a conformance case's RPC method is looked up in: the
|
|
68
65
|
* declared `rpc_endpoints`, then `live_rpc_endpoints`. `find_rpc_action`
|
|
@@ -114,271 +111,6 @@ export const is_ws_conformance_case = (c) => !c.request.method.startsWith('/') &
|
|
|
114
111
|
!Object.values(c.expect.headers ?? {}).some((value) => value !== null) &&
|
|
115
112
|
(c.expect.set_cookie ?? 'none') === 'none' &&
|
|
116
113
|
!WS_UNAVAILABLE_PRINCIPALS.has(c.request.as);
|
|
117
|
-
/**
|
|
118
|
-
* A deliberately malformed `X-Daemon-Token` value for the `invalid_daemon`
|
|
119
|
-
* principal. Fails the `DaemonToken` schema (not 43 base64url chars), so
|
|
120
|
-
* the daemon-token middleware soft-fail-discards it rather than authenticating
|
|
121
|
-
* — the request falls through with no identity, surfacing
|
|
122
|
-
* `credential_type_required` on a daemon-gated action (matching the Rust
|
|
123
|
-
* spine's `None`). Sent over a no-Origin transport so it lands on the
|
|
124
|
-
* invalid-token path, not the browser-context discard.
|
|
125
|
-
*/
|
|
126
|
-
const INVALID_DAEMON_TOKEN_VALUE = 'not-a-valid-daemon-token';
|
|
127
|
-
/**
|
|
128
|
-
* The `wrong_daemon` principal's token: well-shaped (43 base64url characters),
|
|
129
|
-
* so it passes the shape precheck and is refused by the compare — never the
|
|
130
|
-
* server's, whose tokens are random.
|
|
131
|
-
*/
|
|
132
|
-
const WRONG_DAEMON_TOKEN_VALUE = 'A'.repeat(43);
|
|
133
|
-
/**
|
|
134
|
-
* The `unknown_bearer` principal's token: well-shaped (the prefix and 43
|
|
135
|
-
* base64url characters), so it costs the lookup no row answers.
|
|
136
|
-
*/
|
|
137
|
-
const UNKNOWN_BEARER_TOKEN_VALUE = `${API_TOKEN_PREFIX}${'A'.repeat(43)}`;
|
|
138
|
-
if (!is_daemon_token_shaped(WRONG_DAEMON_TOKEN_VALUE)) {
|
|
139
|
-
throw new Error('conformance: WRONG_DAEMON_TOKEN_VALUE must be daemon-token-shaped');
|
|
140
|
-
}
|
|
141
|
-
if (!is_api_token_shaped(UNKNOWN_BEARER_TOKEN_VALUE)) {
|
|
142
|
-
throw new Error('conformance: UNKNOWN_BEARER_TOKEN_VALUE must be api-token-shaped');
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* The keeper's session cookie with its MAC corrupted: the first character of
|
|
146
|
-
* the signature (after the last `.`) changed, so the signature keeps its
|
|
147
|
-
* shape and the keyring refuses it on the compare, not the shape check.
|
|
148
|
-
*/
|
|
149
|
-
const tamper_session_cookie = (cookie) => {
|
|
150
|
-
const dot = cookie.lastIndexOf('.');
|
|
151
|
-
const first = cookie[dot + 1];
|
|
152
|
-
if (dot === -1 || first === undefined) {
|
|
153
|
-
throw new Error(`conformance: principal 'tampered_cookie' found no signed session cookie`);
|
|
154
|
-
}
|
|
155
|
-
return `${cookie.slice(0, dot + 1)}${first === 'A' ? 'B' : 'A'}${cookie.slice(dot + 2)}`;
|
|
156
|
-
};
|
|
157
|
-
/** A dead bearer presented alone: no cookie, no `Origin`, so the token is looked up. */
|
|
158
|
-
const as_lone_bearer = (fixture, token) => ({
|
|
159
|
-
transport: fixture.fresh_transport({ origin: null }),
|
|
160
|
-
headers: { authorization: `Bearer ${token}` },
|
|
161
|
-
suppress_default_origin: true
|
|
162
|
-
});
|
|
163
|
-
/**
|
|
164
|
-
* Mint the `scoped_token` principal's narrowed bearer token over the
|
|
165
|
-
* production `account_token_create` path.
|
|
166
|
-
*
|
|
167
|
-
* Minted rather than seeded, and minted *here* rather than in a case. The
|
|
168
|
-
* seed stays `full` because `_testing_reset`'s api token backs every other
|
|
169
|
-
* bearer principal, and a case that minted its own credential would be the
|
|
170
|
-
* setup-DSL trap the case schema exists to avoid.
|
|
171
|
-
*
|
|
172
|
-
* `account_token_create` is session-only, so this runs over the keeper's
|
|
173
|
-
* session — which also makes the mint itself a live assertion that a narrowed
|
|
174
|
-
* scope is *accepted* at the mint boundary, not merely stored.
|
|
175
|
-
*/
|
|
176
|
-
const mint_scoped_token = async (fixture, resolved_rpc_endpoints) => {
|
|
177
|
-
const found = find_rpc_action(resolved_rpc_endpoints, account_token_create_action_spec.method);
|
|
178
|
-
if (!found) {
|
|
179
|
-
throw new Error(`conformance: principal 'scoped_token' needs '${account_token_create_action_spec.method}' ` +
|
|
180
|
-
`on the surface to mint its narrowed token, but the method is not registered on ` +
|
|
181
|
-
`rpc_endpoints.`);
|
|
182
|
-
}
|
|
183
|
-
return mint_narrowed_api_token({
|
|
184
|
-
app: fixture.transport,
|
|
185
|
-
rpc_path: found.path,
|
|
186
|
-
session_headers: fixture.create_session_headers(),
|
|
187
|
-
methods: [SCOPED_TOKEN_ADMITTED_METHOD],
|
|
188
|
-
name: 'conformance scoped token'
|
|
189
|
-
});
|
|
190
|
-
};
|
|
191
|
-
/**
|
|
192
|
-
* Map a `ConformancePrincipal` onto the transport + headers it
|
|
193
|
-
* authenticates with, reading exclusively from the per-test `TestFixture`.
|
|
194
|
-
*
|
|
195
|
-
* The always-available principals resolve from fixture accessors (the dead
|
|
196
|
-
* credentials that need a server-side state — a revoked session or token, an
|
|
197
|
-
* expired token — from the fixture's `mint_*` seams); `role_holder` /
|
|
198
|
-
* `wrong_role` read a seeded `extra_accounts` entry named via
|
|
199
|
-
* `options.principals` (throws a clear setup error when unconfigured);
|
|
200
|
-
* `scoped_token` mints its narrowed credential over the production path.
|
|
201
|
-
* Also used outside the table by suites that send a principal's requests
|
|
202
|
-
* themselves (`describe_rpc_adversarial_cross_tests`).
|
|
203
|
-
*
|
|
204
|
-
* @param fixture - the per-test fixture
|
|
205
|
-
* @param as - the principal
|
|
206
|
-
* @param principals - usernames for `role_holder` / `wrong_role`
|
|
207
|
-
* @param resolved_rpc_endpoints - the endpoints `scoped_token` mints through
|
|
208
|
-
* @returns the transport and headers the principal sends with
|
|
209
|
-
*/
|
|
210
|
-
export const resolve_conformance_principal = async (fixture, as, principals, resolved_rpc_endpoints = []) => {
|
|
211
|
-
switch (as) {
|
|
212
|
-
case 'keeper':
|
|
213
|
-
// Keeper carries its session cookie via `create_session_headers`
|
|
214
|
-
// (in-process the transport is stateless; cross-process the jar
|
|
215
|
-
// also holds it — the explicit header is the same value).
|
|
216
|
-
return {
|
|
217
|
-
transport: fixture.transport,
|
|
218
|
-
headers: fixture.create_session_headers(),
|
|
219
|
-
actor_id: fixture.actor.id
|
|
220
|
-
};
|
|
221
|
-
case 'daemon':
|
|
222
|
-
// Daemon-token is a non-browser credential — empty jar + no Origin.
|
|
223
|
-
return {
|
|
224
|
-
transport: fixture.fresh_transport({ origin: null }),
|
|
225
|
-
headers: fixture.create_daemon_token_headers(),
|
|
226
|
-
suppress_default_origin: true,
|
|
227
|
-
actor_id: fixture.actor.id
|
|
228
|
-
};
|
|
229
|
-
case 'invalid_daemon':
|
|
230
|
-
// A malformed `X-Daemon-Token` carried ALONGSIDE the keeper's session
|
|
231
|
-
// cookie, over a non-browser (no-Origin) transport. The invalid daemon
|
|
232
|
-
// token is soft-fail-discarded (matching the Rust spine's `None`), so
|
|
233
|
-
// auth falls through to the session leg: the request authenticates as
|
|
234
|
-
// the keeper-via-session (clearing `require_auth`), then the daemon-gated
|
|
235
|
-
// action's credential-type gate refuses the session credential →
|
|
236
|
-
// `403 credential_type_required`. No-Origin keeps the daemon token on
|
|
237
|
-
// the invalid-token path, NOT the browser-context discard. Without the
|
|
238
|
-
// base credential this would 401 (anonymous) — the session is what makes
|
|
239
|
-
// the *credential-type* gate, not the auth gate, the refusing layer.
|
|
240
|
-
return {
|
|
241
|
-
transport: fixture.fresh_transport({ origin: null }),
|
|
242
|
-
headers: fixture.create_session_headers({
|
|
243
|
-
[DAEMON_TOKEN_HEADER]: INVALID_DAEMON_TOKEN_VALUE
|
|
244
|
-
}),
|
|
245
|
-
suppress_default_origin: true,
|
|
246
|
-
actor_id: fixture.actor.id
|
|
247
|
-
};
|
|
248
|
-
case 'daemon_browser':
|
|
249
|
-
// A VALID `X-Daemon-Token` carried in a browser context (default Origin
|
|
250
|
-
// present) ALONGSIDE the keeper's session cookie. The daemon-token
|
|
251
|
-
// middleware discards a header-bearing daemon token as browser context
|
|
252
|
-
// (mirroring the bearer guard + the Rust spine's `is_browser_context`),
|
|
253
|
-
// so the valid token is dropped and auth falls through to the session
|
|
254
|
-
// leg → keeper-via-session → a daemon-gated action refuses the session
|
|
255
|
-
// credential with `credential_type_required`. Origin is NOT suppressed —
|
|
256
|
-
// its presence is the browser-context signal under test. Unlike the
|
|
257
|
-
// `daemon` principal (no Origin → token honored → reaches the 400 confirm
|
|
258
|
-
// guard), the 403 here proves the valid token was discarded, not honored.
|
|
259
|
-
return {
|
|
260
|
-
transport: fixture.transport,
|
|
261
|
-
headers: fixture.create_session_headers(fixture.create_daemon_token_headers()),
|
|
262
|
-
actor_id: fixture.actor.id
|
|
263
|
-
};
|
|
264
|
-
case 'token':
|
|
265
|
-
// Bearer is discarded in a browser context — empty jar + no Origin.
|
|
266
|
-
return {
|
|
267
|
-
transport: fixture.fresh_transport({ origin: null }),
|
|
268
|
-
headers: fixture.create_bearer_headers(),
|
|
269
|
-
suppress_default_origin: true,
|
|
270
|
-
actor_id: fixture.actor.id
|
|
271
|
-
};
|
|
272
|
-
case 'bearer_browser':
|
|
273
|
-
// A VALID bearer api-token in a browser context (default Origin
|
|
274
|
-
// present), fresh jar so no session rides alongside. The bearer
|
|
275
|
-
// middleware discards a header-bearing token as browser context
|
|
276
|
-
// (mirroring the daemon guard + the Rust spine's `is_browser_context`),
|
|
277
|
-
// so the request arrives anonymous → an authed action 401s. Origin is
|
|
278
|
-
// NOT suppressed (its presence is the browser-context signal) — the
|
|
279
|
-
// inverse of the `token` principal, which suppresses it so the same
|
|
280
|
-
// token is honored. The 401 proves the valid token was discarded, not
|
|
281
|
-
// honored (a non-discarding leg would authenticate → 200).
|
|
282
|
-
return {
|
|
283
|
-
transport: fixture.fresh_transport(),
|
|
284
|
-
headers: fixture.create_bearer_headers()
|
|
285
|
-
};
|
|
286
|
-
case 'malformed_bearer': {
|
|
287
|
-
// The keeper's valid token minus its last character — prefixed, one char
|
|
288
|
-
// short — over the same no-Origin, empty-jar transport as `token`, so the
|
|
289
|
-
// shape precheck (not the browser-context discard) is what refuses it.
|
|
290
|
-
const valid = fixture.create_bearer_headers().authorization;
|
|
291
|
-
if (!valid)
|
|
292
|
-
throw new Error(`conformance: principal 'malformed_bearer' found no bearer header`);
|
|
293
|
-
return {
|
|
294
|
-
transport: fixture.fresh_transport({ origin: null }),
|
|
295
|
-
headers: { authorization: valid.slice(0, -1) },
|
|
296
|
-
suppress_default_origin: true
|
|
297
|
-
};
|
|
298
|
-
}
|
|
299
|
-
case 'scoped_token': {
|
|
300
|
-
// A narrowed bearer, otherwise identical to `token` — empty jar + no
|
|
301
|
-
// Origin, so the credential is honored rather than browser-discarded
|
|
302
|
-
// and the scope gate is what any denial comes from.
|
|
303
|
-
const token = await mint_scoped_token(fixture, resolved_rpc_endpoints);
|
|
304
|
-
return {
|
|
305
|
-
transport: fixture.fresh_transport({ origin: null }),
|
|
306
|
-
headers: { authorization: `Bearer ${token}` },
|
|
307
|
-
suppress_default_origin: true,
|
|
308
|
-
actor_id: fixture.actor.id
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
|
-
case 'anonymous':
|
|
312
|
-
// Fresh jar so the keeper cookie (cross-process) can't leak in.
|
|
313
|
-
return { transport: fixture.fresh_transport(), headers: {} };
|
|
314
|
-
case 'fresh_non_admin': {
|
|
315
|
-
const account = await fixture.create_account();
|
|
316
|
-
return {
|
|
317
|
-
transport: fixture.fresh_transport(),
|
|
318
|
-
headers: account.create_session_headers(),
|
|
319
|
-
actor_id: account.actor.id
|
|
320
|
-
};
|
|
321
|
-
}
|
|
322
|
-
case 'expired_session': {
|
|
323
|
-
// The keeper presented via an expired server-side session — fresh
|
|
324
|
-
// jar so only the (expired) cookie this seam returns is sent. The
|
|
325
|
-
// minted cookie payload is valid; the backdated `auth_session` row
|
|
326
|
-
// is what the DB-row expiry gate refuses.
|
|
327
|
-
const cookie = await fixture.mint_expired_session();
|
|
328
|
-
return {
|
|
329
|
-
transport: fixture.fresh_transport(),
|
|
330
|
-
headers: { cookie },
|
|
331
|
-
actor_id: fixture.actor.id
|
|
332
|
-
};
|
|
333
|
-
}
|
|
334
|
-
case 'tampered_cookie': {
|
|
335
|
-
// fresh jar, so the tampered cookie is the only one sent
|
|
336
|
-
const { cookie } = fixture.create_session_headers();
|
|
337
|
-
if (!cookie)
|
|
338
|
-
throw new Error(`conformance: principal 'tampered_cookie' found no cookie`);
|
|
339
|
-
return {
|
|
340
|
-
transport: fixture.fresh_transport(),
|
|
341
|
-
headers: { cookie: tamper_session_cookie(cookie) }
|
|
342
|
-
};
|
|
343
|
-
}
|
|
344
|
-
case 'wrong_daemon':
|
|
345
|
-
// no Origin, so the token reaches the compare, not the browser-context discard
|
|
346
|
-
return {
|
|
347
|
-
transport: fixture.fresh_transport({ origin: null }),
|
|
348
|
-
headers: { [DAEMON_TOKEN_HEADER]: WRONG_DAEMON_TOKEN_VALUE },
|
|
349
|
-
suppress_default_origin: true
|
|
350
|
-
};
|
|
351
|
-
case 'unknown_bearer':
|
|
352
|
-
return as_lone_bearer(fixture, UNKNOWN_BEARER_TOKEN_VALUE);
|
|
353
|
-
case 'revoked_session':
|
|
354
|
-
return {
|
|
355
|
-
transport: fixture.fresh_transport(),
|
|
356
|
-
headers: { cookie: await fixture.mint_revoked_session() }
|
|
357
|
-
};
|
|
358
|
-
case 'revoked_token':
|
|
359
|
-
return as_lone_bearer(fixture, await fixture.mint_revoked_token());
|
|
360
|
-
case 'expired_token':
|
|
361
|
-
return as_lone_bearer(fixture, await fixture.mint_expired_token());
|
|
362
|
-
case 'role_holder':
|
|
363
|
-
case 'wrong_role': {
|
|
364
|
-
const username = principals?.[as];
|
|
365
|
-
if (!username) {
|
|
366
|
-
throw new Error(`conformance: principal '${as}' requires options.principals.${as} naming a seeded ` +
|
|
367
|
-
`extra_accounts username (declare the account at setup via extra_accounts).`);
|
|
368
|
-
}
|
|
369
|
-
const extra = fixture.extra_accounts[username];
|
|
370
|
-
if (!extra) {
|
|
371
|
-
throw new Error(`conformance: extra_accounts['${username}'] not seeded for principal '${as}' — ` +
|
|
372
|
-
`declare it in the suite's extra_accounts option.`);
|
|
373
|
-
}
|
|
374
|
-
return {
|
|
375
|
-
transport: fixture.fresh_transport(),
|
|
376
|
-
headers: extra.create_session_headers(),
|
|
377
|
-
actor_id: extra.actor.id
|
|
378
|
-
};
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
};
|
|
382
114
|
/** Assert each expected field deep-equals the corresponding response field. */
|
|
383
115
|
const assert_fields = (actual, fields, label) => {
|
|
384
116
|
assert.ok(actual !== null && typeof actual === 'object', `${label}: expected an object to read fields from, got ${JSON.stringify(actual)}`);
|