@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
|
@@ -20,6 +20,12 @@ import '../assert_dev_env.js';
|
|
|
20
20
|
* - **already decided → 400** `invalid_request` with reason
|
|
21
21
|
* `role_grant_offer_terminal` — a decline or retract after an accept, a
|
|
22
22
|
* second decline, a second retract, and either one after the other.
|
|
23
|
+
* - **a re-offer refreshes the pending offer.** The grantor offering the same
|
|
24
|
+
* role to the same account while its offer is pending answers that offer —
|
|
25
|
+
* the same id, its `message` the new one, and its `to_actor_id` the new
|
|
26
|
+
* request's: naming the recipient's actor narrows it, naming none widens it
|
|
27
|
+
* back — and the inbox still holds the one offer. Once the offer is decided,
|
|
28
|
+
* a re-offer is a new offer.
|
|
23
29
|
* - **a decided offer can't be accepted.** An accept after a decline or a
|
|
24
30
|
* retract is `role_grant_offer_terminal` and grants nothing — the
|
|
25
31
|
* recipient holds no grant of the role and the offer reads back unaccepted.
|
|
@@ -66,7 +72,7 @@ import '../assert_dev_env.js';
|
|
|
66
72
|
*/
|
|
67
73
|
import { assert, describe, test } from 'vitest';
|
|
68
74
|
import { rpc_call } from '../rpc_helpers.js';
|
|
69
|
-
import { ERROR_CANNOT_REVOKE_KEEPER_ADMIN, ERROR_ROLE_GRANT_OFFER_ACTOR_ACCOUNT_MISMATCH, ERROR_ROLE_GRANT_OFFER_NOT_AUTHORIZED, ERROR_ROLE_GRANT_OFFER_NOT_FOUND, ERROR_ROLE_GRANT_OFFER_SELF_TARGET, ERROR_ROLE_GRANT_OFFER_TERMINAL, RoleGrantOfferDeclineOutput, RoleGrantOfferHistoryOutput, RoleGrantOfferRetractOutput } from '../../auth/role_grant_offer_action_specs.js';
|
|
75
|
+
import { ERROR_CANNOT_REVOKE_KEEPER_ADMIN, ERROR_ROLE_GRANT_OFFER_ACTOR_ACCOUNT_MISMATCH, ERROR_ROLE_GRANT_OFFER_NOT_AUTHORIZED, ERROR_ROLE_GRANT_OFFER_NOT_FOUND, ERROR_ROLE_GRANT_OFFER_SELF_TARGET, ERROR_ROLE_GRANT_OFFER_TERMINAL, RoleGrantOfferCreateOutput, RoleGrantOfferDeclineOutput, RoleGrantOfferHistoryOutput, RoleGrantOfferListOutput, RoleGrantOfferRetractOutput } from '../../auth/role_grant_offer_action_specs.js';
|
|
70
76
|
import { AdminAccountListOutput } from '../../auth/admin_action_specs.js';
|
|
71
77
|
import { ROLE_ADMIN } from '../../auth/role_schema.js';
|
|
72
78
|
import { expect_output } from './cross_rpc.js';
|
|
@@ -115,6 +121,32 @@ export const describe_role_grant_offer_lifecycle_cross_tests = (options) => {
|
|
|
115
121
|
const { offers } = listed.result;
|
|
116
122
|
return offers.some((offer) => offer.id === offer_id);
|
|
117
123
|
};
|
|
124
|
+
describe('a re-offer refreshes the pending offer', () => {
|
|
125
|
+
test("a re-offer while pending answers the same offer, its actor narrowed and widened; after a decline it's a new offer", async () => {
|
|
126
|
+
const fixture = await setup_test();
|
|
127
|
+
const recipient = await fixture.create_account({ username: 'lifecycle_reoffer' });
|
|
128
|
+
const recipient_headers = recipient.create_session_headers();
|
|
129
|
+
const grantor_headers = fixture.create_session_headers();
|
|
130
|
+
const offer = async (params) => expect_output(await rpc(fixture, 'role_grant_offer_create', { to_account_id: recipient.account.id, role, ...params }, grantor_headers), RoleGrantOfferCreateOutput).offer;
|
|
131
|
+
const first = await offer({ message: 'first' });
|
|
132
|
+
assert.strictEqual(first.to_actor_id, null);
|
|
133
|
+
const narrowed = await offer({ to_actor_id: recipient.actor.id, message: 'narrowed' });
|
|
134
|
+
assert.strictEqual(narrowed.id, first.id, 'a re-offer while pending is the same offer');
|
|
135
|
+
assert.strictEqual(narrowed.to_actor_id, recipient.actor.id, 'naming the actor narrows it');
|
|
136
|
+
assert.strictEqual(narrowed.message, 'narrowed');
|
|
137
|
+
const widened = await offer({ message: 'widened' });
|
|
138
|
+
assert.strictEqual(widened.id, first.id);
|
|
139
|
+
assert.strictEqual(widened.to_actor_id, null, 'naming no actor widens it back');
|
|
140
|
+
assert.strictEqual(widened.message, 'widened');
|
|
141
|
+
// the inbox holds the one offer, as the last re-offer left it
|
|
142
|
+
const { offers } = expect_output(await rpc(fixture, 'role_grant_offer_list', {}, recipient_headers), RoleGrantOfferListOutput);
|
|
143
|
+
assert.deepStrictEqual(offers.map(({ id, to_actor_id, message }) => ({ id, to_actor_id, message })), [{ id: first.id, to_actor_id: null, message: 'widened' }]);
|
|
144
|
+
assert_ok(await decline(fixture, first.id, recipient_headers), 'decline');
|
|
145
|
+
const after_decline = await offer({ message: 'again' });
|
|
146
|
+
assert.notStrictEqual(after_decline.id, first.id, 'a decided offer is not reopened');
|
|
147
|
+
assert.ok(await is_pending(fixture, recipient, after_decline.id), 'the new offer is pending');
|
|
148
|
+
});
|
|
149
|
+
});
|
|
118
150
|
describe('role_grant_offer decline + retract refusals', () => {
|
|
119
151
|
test('a decline by anyone but the recipient → 404, identical to a missing offer; the offer stays pending', async () => {
|
|
120
152
|
const fixture = await setup_test();
|
|
@@ -32,10 +32,11 @@ export interface RoleGrantOfferNotificationWsTestOptions extends WsEndpointTarge
|
|
|
32
32
|
/**
|
|
33
33
|
* Register the role-grant-offer WS notification suite — cases over a real
|
|
34
34
|
* upgrade, one per server-initiated notification (received / accepted /
|
|
35
|
-
* declined / retracted / revoke, global and scoped, + supersede on
|
|
36
|
-
*
|
|
37
|
-
* lifecycle RPC, and strict-parses the delivered
|
|
38
|
-
* params schema. Gated on `capabilities.ws
|
|
35
|
+
* declined / retracted / revoke, global and scoped, + supersede on the accept,
|
|
36
|
+
* revoke, delete and purge cascades). Each opens every party's socket, drives
|
|
37
|
+
* the lifecycle RPC, and strict-parses the delivered frames against their
|
|
38
|
+
* canonical params schema. Gated on `capabilities.ws`, the removals on
|
|
39
|
+
* `capabilities.account_lifecycle` too.
|
|
39
40
|
*/
|
|
40
41
|
export declare const describe_role_grant_offer_notification_ws_tests: (options: RoleGrantOfferNotificationWsTestOptions) => void;
|
|
41
42
|
//# sourceMappingURL=role_grant_offer_notification_ws.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"role_grant_offer_notification_ws.d.ts","sourceRoot":"","sources":["../../../src/lib/testing/cross_backend/role_grant_offer_notification_ws.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"role_grant_offer_notification_ws.d.ts","sourceRoot":"","sources":["../../../src/lib/testing/cross_backend/role_grant_offer_notification_ws.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAuG9B,OAAO,EAAE,KAAK,mBAAmB,EAAW,MAAM,mBAAmB,CAAC;AAOtE,OAAO,KAAK,EAAE,SAAS,EAAe,MAAM,YAAY,CAAC;AAEzD,OAAO,EAAmB,KAAK,gBAAgB,EAAyB,MAAM,kBAAkB,CAAC;AAwBjG,2EAA2E;AAC3E,MAAM,WAAW,uCAAwC,SAAQ,gBAAgB;IAChF,8EAA8E;IAC9E,QAAQ,CAAC,UAAU,EAAE,SAAS,CAAC;IAC/B,uEAAuE;IACvE,QAAQ,CAAC,YAAY,EAAE,mBAAmB,CAAC;IAC3C;;;;;;OAMG;IACH,QAAQ,CAAC,iBAAiB,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACnD;;;;OAIG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B;;;;OAIG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACpC;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,+CAA+C,GAC3D,SAAS,uCAAuC,KAC9C,IA4qBF,CAAC"}
|
|
@@ -12,14 +12,19 @@ import '../assert_dev_env.js';
|
|
|
12
12
|
* - `role_grant_revoked` (flat, omits `revoked_by`) → revokee (active grant
|
|
13
13
|
* revoked by the `role_grant_revoke` action), for a global grant and a
|
|
14
14
|
* scoped one unless `scope_kind` is `null`
|
|
15
|
-
* - `role_grant_offer_supersede` → each
|
|
16
|
-
*
|
|
17
|
-
*
|
|
15
|
+
* - `role_grant_offer_supersede` → each live party of an offer a cascade ended:
|
|
16
|
+
* an accept's siblings' grantors (`reason: 'sibling_accepted'`, the
|
|
17
|
+
* recipient being the caller), both parties of every offer a revoke ends
|
|
18
|
+
* (`reason: 'role_grant_revoked'` — the revokee's incoming siblings and its
|
|
19
|
+
* own outgoing offers), and the other party of every offer an account
|
|
20
|
+
* removal ends (`reason: 'account_deleted'`, delete and purge — gated on
|
|
21
|
+
* `capabilities.account_lifecycle` too; the removed account's socket closes
|
|
22
|
+
* and hears none of it)
|
|
18
23
|
*
|
|
19
24
|
* These exercise only spine primitives (accounts, role-grants, offers, WS
|
|
20
25
|
* notifications) — zero consumer domain — so the suite lives here and runs
|
|
21
|
-
* against any backend that
|
|
22
|
-
*
|
|
26
|
+
* against any backend that mounts the standard RPC actions and a WS endpoint
|
|
27
|
+
* their notifications reach: fuz_app's own spine self-tests
|
|
23
28
|
* (`testing_spine_server` + the Rust `testing_spine_stub`) and downstream
|
|
24
29
|
* twin-impl consumers (the fuz_forge Deno/Hono + Rust `fuz_forge_server`
|
|
25
30
|
* backends) alike.
|
|
@@ -35,7 +40,10 @@ import '../assert_dev_env.js';
|
|
|
35
40
|
* but the answers to its own requests, behind a `heartbeat` barrier on its
|
|
36
41
|
* socket (`assert_bystander_heard_nothing` says why the barrier makes the
|
|
37
42
|
* silence meaningful). A fan-out that reached past its target account fails
|
|
38
|
-
* there.
|
|
43
|
+
* there. The target is held the same way, behind a barrier of its own: its
|
|
44
|
+
* socket heard exactly the notifications the case addressed to it, each once,
|
|
45
|
+
* in order — so a backend delivering one twice (a registry reached through
|
|
46
|
+
* two paths) fails, which the frame's own `wait_for` can't see.
|
|
39
47
|
*
|
|
40
48
|
* Sends are queued on the post-commit drain (handler-emit, not audit-derived),
|
|
41
49
|
* so a frame may land a beat after the RPC resolves — `WsClient.wait_for` polls
|
|
@@ -47,11 +55,12 @@ import '../assert_dev_env.js';
|
|
|
47
55
|
* guard), and accept stays idempotent on the role_grant while still superseding
|
|
48
56
|
* pending siblings. Gated on `capabilities.ws`.
|
|
49
57
|
*
|
|
50
|
-
* The revoke
|
|
58
|
+
* The revoke cases revoke the revokee's only `ROLE_ADMIN` grant. On an endpoint
|
|
51
59
|
* gated on that role (`ws_required_roles`) the revokee's socket loses its
|
|
52
60
|
* access by the same revoke: it is closed with `WS_CLOSE_PERMISSION_REVOKED`,
|
|
53
|
-
* and
|
|
54
|
-
* so the
|
|
61
|
+
* and its notifications may or may not reach it first (nothing orders the
|
|
62
|
+
* two), so the cases assert the close there — and at most the start of what it
|
|
63
|
+
* would have heard, in order — and the frames on an ungated endpoint.
|
|
55
64
|
*
|
|
56
65
|
* Cross-process only: `create_admitted_ws_transport` needs a real bound socket, so wire
|
|
57
66
|
* it from a `*.cross.test.ts` file, never an in-process setup. Authed cookies
|
|
@@ -64,23 +73,38 @@ import { assert, describe } from 'vitest';
|
|
|
64
73
|
import { parse_or_throw } from '@fuzdev/fuz_schema/schema.ts';
|
|
65
74
|
import { rpc_call } from '../rpc_helpers.js';
|
|
66
75
|
import { WS_ADMISSION_PROBE_ID } from '../transports/ws_transport.js';
|
|
67
|
-
import { is_notification_with, is_response_for } from '../transports/ws_client.js';
|
|
76
|
+
import { is_notification, is_notification_with, is_response_for } from '../transports/ws_client.js';
|
|
68
77
|
import { ROLE_ADMIN, is_builtin_role } from '../../auth/role_schema.js';
|
|
69
78
|
import { WS_CLOSE_PERMISSION_REVOKED, WS_CLOSE_PERMISSION_REVOKED_REASON } from '../../actions/transports.js';
|
|
70
79
|
import { ROLE_GRANT_OFFER_RECEIVED_NOTIFICATION_METHOD, ROLE_GRANT_OFFER_ACCEPTED_NOTIFICATION_METHOD, ROLE_GRANT_OFFER_DECLINED_NOTIFICATION_METHOD, ROLE_GRANT_OFFER_RETRACTED_NOTIFICATION_METHOD, ROLE_GRANT_OFFER_SUPERSEDE_NOTIFICATION_METHOD, ROLE_GRANT_REVOKED_NOTIFICATION_METHOD, RoleGrantOfferReceivedParams, RoleGrantOfferAcceptedParams, RoleGrantOfferDeclinedParams, RoleGrantOfferRetractedParams, RoleGrantOfferSupersedeParams, RoleGrantRevokedParams } from '../../auth/role_grant_offer_notifications.js';
|
|
71
80
|
import { test_if } from './capabilities.js';
|
|
72
81
|
import { create_active_role_grant, create_pending_role_grant_offer } from './role_grant_cross_helpers.js';
|
|
82
|
+
import { cross_account_purge } from './revocation_drivers.js';
|
|
73
83
|
import { SPINE_PARTICIPANT_ROLE, SPINE_RPC_PATH } from './spine_surface_constants.js';
|
|
74
84
|
import { open_session_ws } from './ws_endpoint.js';
|
|
75
85
|
/** The request id the bystander's barrier `heartbeat` goes out under. */
|
|
76
86
|
const BYSTANDER_BARRIER_ID = 'bystander_barrier';
|
|
87
|
+
/** The request id the target's barrier `heartbeat` goes out under. */
|
|
88
|
+
const TARGET_BARRIER_ID = 'target_barrier';
|
|
89
|
+
/**
|
|
90
|
+
* Name each frame a socket received but the answers to its admission probe and
|
|
91
|
+
* its barrier: a notification by its method, anything else as its JSON, so an
|
|
92
|
+
* unexpected response shows in the assertion's diff.
|
|
93
|
+
*/
|
|
94
|
+
const to_heard_frames = (ws) => ws.messages
|
|
95
|
+
.filter((msg) => !is_response_for(WS_ADMISSION_PROBE_ID)(msg) && !is_response_for(TARGET_BARRIER_ID)(msg))
|
|
96
|
+
.map((msg) => {
|
|
97
|
+
const method = msg?.method;
|
|
98
|
+
return typeof method === 'string' ? method : JSON.stringify(msg);
|
|
99
|
+
});
|
|
77
100
|
/**
|
|
78
101
|
* Register the role-grant-offer WS notification suite — cases over a real
|
|
79
102
|
* upgrade, one per server-initiated notification (received / accepted /
|
|
80
|
-
* declined / retracted / revoke, global and scoped, + supersede on
|
|
81
|
-
*
|
|
82
|
-
* lifecycle RPC, and strict-parses the delivered
|
|
83
|
-
* params schema. Gated on `capabilities.ws
|
|
103
|
+
* declined / retracted / revoke, global and scoped, + supersede on the accept,
|
|
104
|
+
* revoke, delete and purge cascades). Each opens every party's socket, drives
|
|
105
|
+
* the lifecycle RPC, and strict-parses the delivered frames against their
|
|
106
|
+
* canonical params schema. Gated on `capabilities.ws`, the removals on
|
|
107
|
+
* `capabilities.account_lifecycle` too.
|
|
84
108
|
*/
|
|
85
109
|
export const describe_role_grant_offer_notification_ws_tests = (options) => {
|
|
86
110
|
const { setup_test, capabilities, ws_required_roles = [] } = options;
|
|
@@ -131,7 +155,8 @@ export const describe_role_grant_offer_notification_ws_tests = (options) => {
|
|
|
131
155
|
* frame can be written while the pass is still pushing — a window the
|
|
132
156
|
* barrier's round trip outlasts in practice. Either way the check covers
|
|
133
157
|
* every pass of the drain, not just the one that reached the target: TS
|
|
134
|
-
*
|
|
158
|
+
* calls every queued send in one synchronous loop
|
|
159
|
+
* (`flush_post_commit_effects`), and `PostCommitEffects::drain_all` joins
|
|
135
160
|
* effects whose notify futures push synchronously, so every pass
|
|
136
161
|
* completes in the drain's first poll.
|
|
137
162
|
*/
|
|
@@ -140,6 +165,34 @@ export const describe_role_grant_offer_notification_ws_tests = (options) => {
|
|
|
140
165
|
const strays = bystander_ws.messages.filter((msg) => !is_response_for(WS_ADMISSION_PROBE_ID)(msg) && !is_response_for(BYSTANDER_BARRIER_ID)(msg));
|
|
141
166
|
assert.deepStrictEqual(strays, [], 'a bystander socket received frames addressed to others');
|
|
142
167
|
};
|
|
168
|
+
/**
|
|
169
|
+
* Assert the targeted socket heard exactly `expected` — the notifications
|
|
170
|
+
* the case addressed to it, in order, each once — and nothing else but the
|
|
171
|
+
* answers to its own requests. Called once the targeted frame has landed,
|
|
172
|
+
* behind a `heartbeat` barrier on the target's own socket, which makes the
|
|
173
|
+
* absence of a second copy a finding for the reason
|
|
174
|
+
* `assert_bystander_heard_nothing` gives: a fan-out queues every copy it
|
|
175
|
+
* sends in the pass that sent the first, ahead of the barrier's response.
|
|
176
|
+
*/
|
|
177
|
+
const assert_target_heard_exactly = async (target_ws, expected) => {
|
|
178
|
+
await target_ws.request(TARGET_BARRIER_ID, 'heartbeat', {}, 5000);
|
|
179
|
+
assert.deepStrictEqual(to_heard_frames(target_ws), expected, 'the target socket did not hear exactly the notifications addressed to it, each once');
|
|
180
|
+
};
|
|
181
|
+
/**
|
|
182
|
+
* Wait for the `role_grant_offer_supersede` frame of `offer_id` on `ws` and
|
|
183
|
+
* strict-parse its params against the canonical wire schema.
|
|
184
|
+
*/
|
|
185
|
+
const wait_for_supersede = async (ws, offer_id) => {
|
|
186
|
+
const frame = await ws.wait_for(is_notification_with(ROLE_GRANT_OFFER_SUPERSEDE_NOTIFICATION_METHOD, (p) => p.offer.id === offer_id), 5000);
|
|
187
|
+
const params = parse_or_throw(RoleGrantOfferSupersedeParams, frame.params);
|
|
188
|
+
assert.strictEqual(params.offer.id, offer_id);
|
|
189
|
+
assert.isNotNull(params.offer.superseded_at);
|
|
190
|
+
return params;
|
|
191
|
+
};
|
|
192
|
+
/** The offer ids of the supersede frames `ws` heard, in order. */
|
|
193
|
+
const supersede_offer_ids = (ws) => ws.messages
|
|
194
|
+
.filter(is_notification(ROLE_GRANT_OFFER_SUPERSEDE_NOTIFICATION_METHOD))
|
|
195
|
+
.map((msg) => msg.params.offer.id);
|
|
143
196
|
/** Drive a JSON-RPC call over the fixture's HTTP transport. */
|
|
144
197
|
const rpc = (fixture, method, params, headers) => rpc_call({ app: fixture.transport, path: SPINE_RPC_PATH, method, params, headers });
|
|
145
198
|
/** A fresh pending `ROLE_ADMIN` offer, from the keeper unless a grantor is given. */
|
|
@@ -171,6 +224,9 @@ export const describe_role_grant_offer_notification_ws_tests = (options) => {
|
|
|
171
224
|
const params = parse_or_throw(RoleGrantOfferReceivedParams, frame.params);
|
|
172
225
|
assert.strictEqual(params.offer.to_account_id, recipient.account.id);
|
|
173
226
|
assert.strictEqual(params.offer.role, ROLE_ADMIN);
|
|
227
|
+
await assert_target_heard_exactly(recipient_ws, [
|
|
228
|
+
ROLE_GRANT_OFFER_RECEIVED_NOTIFICATION_METHOD
|
|
229
|
+
]);
|
|
174
230
|
await assert_bystander_heard_nothing(bystander_ws);
|
|
175
231
|
}
|
|
176
232
|
finally {
|
|
@@ -196,6 +252,9 @@ export const describe_role_grant_offer_notification_ws_tests = (options) => {
|
|
|
196
252
|
const params = parse_or_throw(RoleGrantOfferAcceptedParams, frame.params);
|
|
197
253
|
assert.strictEqual(params.offer.id, offer.id);
|
|
198
254
|
assert.isNotNull(params.offer.accepted_at);
|
|
255
|
+
await assert_target_heard_exactly(grantor, [
|
|
256
|
+
ROLE_GRANT_OFFER_ACCEPTED_NOTIFICATION_METHOD
|
|
257
|
+
]);
|
|
199
258
|
await assert_bystander_heard_nothing(bystander_ws);
|
|
200
259
|
}
|
|
201
260
|
finally {
|
|
@@ -221,6 +280,9 @@ export const describe_role_grant_offer_notification_ws_tests = (options) => {
|
|
|
221
280
|
assert.strictEqual(params.offer.id, offer.id);
|
|
222
281
|
// Decline reason rides inside the offer row, not a sibling field.
|
|
223
282
|
assert.strictEqual(params.offer.decline_reason, 'no thanks');
|
|
283
|
+
await assert_target_heard_exactly(grantor, [
|
|
284
|
+
ROLE_GRANT_OFFER_DECLINED_NOTIFICATION_METHOD
|
|
285
|
+
]);
|
|
224
286
|
await assert_bystander_heard_nothing(bystander_ws);
|
|
225
287
|
}
|
|
226
288
|
finally {
|
|
@@ -247,6 +309,11 @@ export const describe_role_grant_offer_notification_ws_tests = (options) => {
|
|
|
247
309
|
assert.strictEqual(params.offer.id, offer.id);
|
|
248
310
|
assert.strictEqual(params.offer.to_account_id, recipient.account.id);
|
|
249
311
|
assert.isNotNull(params.offer.retracted_at);
|
|
312
|
+
// the offer's create, made with the socket open, notified it first
|
|
313
|
+
await assert_target_heard_exactly(recipient_ws, [
|
|
314
|
+
ROLE_GRANT_OFFER_RECEIVED_NOTIFICATION_METHOD,
|
|
315
|
+
ROLE_GRANT_OFFER_RETRACTED_NOTIFICATION_METHOD
|
|
316
|
+
]);
|
|
250
317
|
await assert_bystander_heard_nothing(bystander_ws);
|
|
251
318
|
}
|
|
252
319
|
finally {
|
|
@@ -294,10 +361,14 @@ export const describe_role_grant_offer_notification_ws_tests = (options) => {
|
|
|
294
361
|
const early = revokee_ws.messages.find(is_revoke_frame);
|
|
295
362
|
if (early)
|
|
296
363
|
assert_flat_revoke(early);
|
|
364
|
+
// a closed socket takes no barrier: what reached it ahead of the
|
|
365
|
+
// close is the notification once, or nothing
|
|
366
|
+
assert.deepStrictEqual(to_heard_frames(revokee_ws), early ? [ROLE_GRANT_REVOKED_NOTIFICATION_METHOD] : [], 'the gated socket heard more than the one notification before its close');
|
|
297
367
|
await assert_bystander_heard_nothing(bystander_ws);
|
|
298
368
|
return;
|
|
299
369
|
}
|
|
300
370
|
assert_flat_revoke(await revokee_ws.wait_for(is_revoke_frame, 5000));
|
|
371
|
+
await assert_target_heard_exactly(revokee_ws, [ROLE_GRANT_REVOKED_NOTIFICATION_METHOD]);
|
|
301
372
|
await assert_bystander_heard_nothing(bystander_ws);
|
|
302
373
|
}
|
|
303
374
|
finally {
|
|
@@ -329,6 +400,7 @@ export const describe_role_grant_offer_notification_ws_tests = (options) => {
|
|
|
329
400
|
assert.strictEqual(params.scope_kind, scope_kind);
|
|
330
401
|
assert.strictEqual(params.scope_id, scope_id);
|
|
331
402
|
assert.strictEqual(params.reason, null);
|
|
403
|
+
await assert_target_heard_exactly(revokee_ws, [ROLE_GRANT_REVOKED_NOTIFICATION_METHOD]);
|
|
332
404
|
await assert_bystander_heard_nothing(bystander_ws);
|
|
333
405
|
}
|
|
334
406
|
finally {
|
|
@@ -364,6 +436,9 @@ export const describe_role_grant_offer_notification_ws_tests = (options) => {
|
|
|
364
436
|
// cause_id points at the accepted sibling (grantor 2's offer).
|
|
365
437
|
assert.strictEqual(params.cause_id, grantor2_offer.id);
|
|
366
438
|
assert.isNotNull(params.offer.superseded_at);
|
|
439
|
+
await assert_target_heard_exactly(grantor1_ws, [
|
|
440
|
+
ROLE_GRANT_OFFER_SUPERSEDE_NOTIFICATION_METHOD
|
|
441
|
+
]);
|
|
367
442
|
await assert_bystander_heard_nothing(bystander_ws);
|
|
368
443
|
}
|
|
369
444
|
finally {
|
|
@@ -374,39 +449,117 @@ export const describe_role_grant_offer_notification_ws_tests = (options) => {
|
|
|
374
449
|
await bystander_ws.close();
|
|
375
450
|
}
|
|
376
451
|
});
|
|
377
|
-
test_if(capabilities.ws,
|
|
452
|
+
test_if(capabilities.ws, "revoke supersedes the revokee's pending offers both ways and notifies both parties of each", async () => {
|
|
378
453
|
const fixture = await setup_test();
|
|
379
454
|
const grantor = await fixture.create_account({ roles: [ROLE_ADMIN] });
|
|
380
455
|
const revokee = await fixture.create_account({ roles: [ROLE_ADMIN] });
|
|
456
|
+
const recipient = await fixture.create_account({ roles: [ROLE_ADMIN] });
|
|
381
457
|
const role_grant_id = await create_active_role_grant(fixture, revokee, {
|
|
382
458
|
rpc_path: SPINE_RPC_PATH
|
|
383
459
|
});
|
|
384
|
-
// A
|
|
385
|
-
// the revoke
|
|
460
|
+
// A pending sibling for the revoked grant's (account, role), and an
|
|
461
|
+
// offer the revokee made — the revoke's two cascades, in that order.
|
|
386
462
|
const sibling_offer = await create_pending_offer(fixture, revokee.account.id, grantor.create_session_headers());
|
|
387
|
-
|
|
463
|
+
const outgoing_offer = await create_pending_offer(fixture, recipient.account.id, revokee.create_session_headers());
|
|
388
464
|
const bystander_ws = await open_bystander(fixture);
|
|
465
|
+
const grantor_ws = await open_ws(grantor);
|
|
466
|
+
const revokee_ws = await open_ws(revokee);
|
|
467
|
+
const recipient_ws = await open_ws(recipient);
|
|
389
468
|
try {
|
|
390
|
-
const
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
const frame = await grantor_ws.wait_for(is_notification_with(ROLE_GRANT_OFFER_SUPERSEDE_NOTIFICATION_METHOD, (p) => p.offer.id === sibling_offer.id), 5000);
|
|
395
|
-
const params = parse_or_throw(RoleGrantOfferSupersedeParams, frame.params);
|
|
396
|
-
assert.strictEqual(params.offer.id, sibling_offer.id);
|
|
469
|
+
const revoked = await rpc(fixture, 'role_grant_revoke', { actor_id: revokee.actor.id, role_grant_id }, fixture.create_session_headers());
|
|
470
|
+
assert.isTrue(revoked.ok, `revoke failed: ${JSON.stringify(revoked)}`);
|
|
471
|
+
const assert_supersede = async (ws, offer_id) => {
|
|
472
|
+
const params = await wait_for_supersede(ws, offer_id);
|
|
397
473
|
assert.strictEqual(params.reason, 'role_grant_revoked');
|
|
398
474
|
// cause_id points at the revoked role_grant.
|
|
399
475
|
assert.strictEqual(params.cause_id, role_grant_id);
|
|
400
|
-
|
|
401
|
-
|
|
476
|
+
};
|
|
477
|
+
// the sibling's grantor and the outgoing offer's recipient
|
|
478
|
+
await assert_supersede(grantor_ws, sibling_offer.id);
|
|
479
|
+
await assert_target_heard_exactly(grantor_ws, [
|
|
480
|
+
ROLE_GRANT_OFFER_SUPERSEDE_NOTIFICATION_METHOD
|
|
481
|
+
]);
|
|
482
|
+
await assert_supersede(recipient_ws, outgoing_offer.id);
|
|
483
|
+
await assert_target_heard_exactly(recipient_ws, [
|
|
484
|
+
ROLE_GRANT_OFFER_SUPERSEDE_NOTIFICATION_METHOD
|
|
485
|
+
]);
|
|
486
|
+
// the revokee is the sibling's recipient and the outgoing offer's
|
|
487
|
+
// grantor: the revoke, then the two offers in the cascade's order
|
|
488
|
+
const revokee_heard = [
|
|
489
|
+
ROLE_GRANT_REVOKED_NOTIFICATION_METHOD,
|
|
490
|
+
ROLE_GRANT_OFFER_SUPERSEDE_NOTIFICATION_METHOD,
|
|
491
|
+
ROLE_GRANT_OFFER_SUPERSEDE_NOTIFICATION_METHOD
|
|
492
|
+
];
|
|
493
|
+
if (revoke_closes_the_socket) {
|
|
494
|
+
// the gated socket closes with the revoke, hearing at most the
|
|
495
|
+
// start of what it would have heard, in order
|
|
496
|
+
const closed = await revokee_ws.wait_for_close(5000);
|
|
497
|
+
assert.ok(closed, 'the gated socket did not close after the revoke');
|
|
498
|
+
assert.strictEqual(revokee_ws.close_code, WS_CLOSE_PERMISSION_REVOKED);
|
|
499
|
+
const heard = to_heard_frames(revokee_ws);
|
|
500
|
+
assert.deepStrictEqual(heard, revokee_heard.slice(0, heard.length));
|
|
402
501
|
}
|
|
403
|
-
|
|
404
|
-
await
|
|
502
|
+
else {
|
|
503
|
+
await assert_supersede(revokee_ws, outgoing_offer.id);
|
|
504
|
+
await assert_target_heard_exactly(revokee_ws, revokee_heard);
|
|
505
|
+
assert.deepStrictEqual(supersede_offer_ids(revokee_ws), [sibling_offer.id, outgoing_offer.id], "the revokee hears the sibling's supersede, then its own offer's");
|
|
405
506
|
}
|
|
507
|
+
await assert_bystander_heard_nothing(bystander_ws);
|
|
406
508
|
}
|
|
407
509
|
finally {
|
|
510
|
+
await Promise.all([recipient_ws.close(), revokee_ws.close(), grantor_ws.close()]);
|
|
408
511
|
await bystander_ws.close();
|
|
409
512
|
}
|
|
410
513
|
});
|
|
514
|
+
/**
|
|
515
|
+
* The account removals: `remove` ends `removed`'s account, whose pending
|
|
516
|
+
* offers both ways are superseded with `reason: 'account_deleted'`, the
|
|
517
|
+
* account as the grantor's cause and its actor as the recipient's. Each
|
|
518
|
+
* offer's other party hears it once; the removed account's socket closes
|
|
519
|
+
* and hears none of it.
|
|
520
|
+
*/
|
|
521
|
+
const removal_case = async (remove) => {
|
|
522
|
+
const fixture = await setup_test();
|
|
523
|
+
const removed = await fixture.create_account({ roles: [ROLE_ADMIN] });
|
|
524
|
+
const recipient = await fixture.create_account({ roles: [ROLE_ADMIN] });
|
|
525
|
+
const grantor = await fixture.create_account({ roles: [ROLE_ADMIN] });
|
|
526
|
+
const outgoing_offer = await create_pending_offer(fixture, recipient.account.id, removed.create_session_headers());
|
|
527
|
+
const incoming_offer = await create_pending_offer(fixture, removed.account.id, grantor.create_session_headers());
|
|
528
|
+
const bystander_ws = await open_bystander(fixture);
|
|
529
|
+
const removed_ws = await open_ws(removed);
|
|
530
|
+
const recipient_ws = await open_ws(recipient);
|
|
531
|
+
const grantor_ws = await open_ws(grantor);
|
|
532
|
+
try {
|
|
533
|
+
await remove(fixture, removed);
|
|
534
|
+
// the recipient is sent the grantor's actor, an id it already holds —
|
|
535
|
+
// never the removed account's id; the grantor is sent the removed
|
|
536
|
+
// account, its offer's `to_account_id`
|
|
537
|
+
for (const [ws, offer_id, cause_id] of [
|
|
538
|
+
[recipient_ws, outgoing_offer.id, removed.actor.id],
|
|
539
|
+
[grantor_ws, incoming_offer.id, removed.account.id]
|
|
540
|
+
]) {
|
|
541
|
+
const params = await wait_for_supersede(ws, offer_id);
|
|
542
|
+
assert.strictEqual(params.reason, 'account_deleted');
|
|
543
|
+
assert.strictEqual(params.cause_id, cause_id);
|
|
544
|
+
await assert_target_heard_exactly(ws, [ROLE_GRANT_OFFER_SUPERSEDE_NOTIFICATION_METHOD]);
|
|
545
|
+
}
|
|
546
|
+
const closed = await removed_ws.wait_for_close(5000);
|
|
547
|
+
assert.ok(closed, "the removed account's socket did not close");
|
|
548
|
+
// binds only on a spine that delivers a frame queued ahead of the close;
|
|
549
|
+
// one whose close drops it passes either way, so the spine's own fan-out
|
|
550
|
+
// tests are what hold a send to the removed account out
|
|
551
|
+
assert.deepStrictEqual(to_heard_frames(removed_ws), [], "the removed account's socket heard a notification before its close");
|
|
552
|
+
await assert_bystander_heard_nothing(bystander_ws);
|
|
553
|
+
}
|
|
554
|
+
finally {
|
|
555
|
+
await Promise.all([grantor_ws.close(), recipient_ws.close(), removed_ws.close()]);
|
|
556
|
+
await bystander_ws.close();
|
|
557
|
+
}
|
|
558
|
+
};
|
|
559
|
+
test_if(capabilities.ws && capabilities.account_lifecycle, "delete supersedes the account's pending offers both ways and notifies each other party", () => removal_case(async (fixture, removed) => {
|
|
560
|
+
const deleted = await rpc(fixture, 'account_delete', { account_id: removed.account.id }, fixture.create_session_headers());
|
|
561
|
+
assert.isTrue(deleted.ok, `delete failed: ${JSON.stringify(deleted)}`);
|
|
562
|
+
}));
|
|
563
|
+
test_if(capabilities.ws && capabilities.account_lifecycle, "purge supersedes the account's pending offers both ways and notifies each other party", () => removal_case((fixture, removed) => cross_account_purge(fixture, SPINE_RPC_PATH, removed.account.id)));
|
|
411
564
|
});
|
|
412
565
|
};
|
|
@@ -64,10 +64,10 @@ export const describe_role_grant_participation_cross_tests = (options) => {
|
|
|
64
64
|
test(`admin assigns the ${role} app-role to a fresh account (idempotent)`, async () => {
|
|
65
65
|
const fixture = await setup_test();
|
|
66
66
|
const recipient = await fixture.create_account({ username: 'participation_assignee' });
|
|
67
|
-
// The keeper holds ROLE_ADMIN (seeded
|
|
68
|
-
// clears the dispatcher admin gate; `participant` is
|
|
69
|
-
// it clears the grant-path gate; the recipient is
|
|
70
|
-
// target actor resolves without `to_actor_id`.
|
|
67
|
+
// The keeper holds ROLE_ADMIN (seeded by default, as a production
|
|
68
|
+
// bootstrap), so it clears the dispatcher admin gate; `participant` is
|
|
69
|
+
// admin-grantable, so it clears the grant-path gate; the recipient is
|
|
70
|
+
// single-actor, so the target actor resolves without `to_actor_id`.
|
|
71
71
|
const first = await rpc(fixture.transport, 'role_grant_assign', { to_account_id: recipient.account.id, role }, fixture.create_session_headers());
|
|
72
72
|
assert.ok(first.ok, `assign must succeed: ${JSON.stringify(first)}`);
|
|
73
73
|
const assigned = first.result;
|
|
@@ -79,7 +79,7 @@ import { PROTOCOL_ACTION_METHODS } from '../../actions/action_codegen.js';
|
|
|
79
79
|
import { TESTING_METHOD_PREFIX } from '../surface_invariants.js';
|
|
80
80
|
import { create_rpc_post_init } from '../rpc_helpers.js';
|
|
81
81
|
import { assert_rpc_envelope_refusal, create_rpc_envelope_cases, generate_rpc_params_test_cases, to_rpc_envelope_request } from '../rpc_envelope_cases.js';
|
|
82
|
-
import { resolve_conformance_principal } from './
|
|
82
|
+
import { resolve_conformance_principal } from './conformance_principal.js';
|
|
83
83
|
import { SPINE_RPC_PATH } from './spine_surface_constants.js';
|
|
84
84
|
import { xfail_until } from './xfail.js';
|
|
85
85
|
import { expected_invalid_reason } from '../adversarial_input_cases.js';
|
|
@@ -25,8 +25,8 @@ export interface SessionCapCrossTestOptions {
|
|
|
25
25
|
readonly ws?: WsEndpointTarget;
|
|
26
26
|
/**
|
|
27
27
|
* Whether the `ws` endpoint mounts the self-service account actions
|
|
28
|
-
* (`capabilities.ws_account_actions`),
|
|
29
|
-
* over a socket
|
|
28
|
+
* (`capabilities.ws_account_actions`), for the case that lists the
|
|
29
|
+
* sessions over a socket; `false` (the default) skips it.
|
|
30
30
|
*/
|
|
31
31
|
readonly ws_account_actions?: boolean;
|
|
32
32
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session_cap.d.ts","sourceRoot":"","sources":["../../../src/lib/testing/cross_backend/session_cap.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"session_cap.d.ts","sourceRoot":"","sources":["../../../src/lib/testing/cross_backend/session_cap.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AA+E9B,OAAO,KAAK,EAAE,SAAS,EAAe,MAAM,YAAY,CAAC;AAOzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,gDAAgD;AAChD,MAAM,WAAW,0BAA0B;IAC1C,2EAA2E;IAC3E,QAAQ,CAAC,UAAU,EAAE,SAAS,CAAC;IAC/B;;;;OAIG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,2DAA2D;IAC3D,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,qEAAqE;IACrE,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,mFAAmF;IACnF,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B;;;;OAIG;IACH,QAAQ,CAAC,EAAE,CAAC,EAAE,gBAAgB,CAAC;IAC/B;;;;OAIG;IACH,QAAQ,CAAC,kBAAkB,CAAC,EAAE,OAAO,CAAC;IACtC;;;;;OAKG;IACH,QAAQ,CAAC,gBAAgB,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CAClD;AAED,eAAO,MAAM,gCAAgC,GAAI,SAAS,0BAA0B,KAAG,IAkStF,CAAC"}
|
|
@@ -31,6 +31,14 @@ import '../assert_dev_env.js';
|
|
|
31
31
|
* committed, and leave a socket on a session it kept open and dispatching. A
|
|
32
32
|
* spine that only deletes the row leaves the socket running on a dead
|
|
33
33
|
* session; one that closes the account's sockets drops the kept one.
|
|
34
|
+
* - **concurrent logins at the cap all succeed** and leave the account at
|
|
35
|
+
* exactly the cap. The logins of one account take turns on its row lock, so
|
|
36
|
+
* each evicts against a count holding the ones before it; without that, two
|
|
37
|
+
* logins each count without the other's row and both commit above the cap,
|
|
38
|
+
* or deadlock in their evictions and answer 500. The burst can only show the
|
|
39
|
+
* race when it happens: the exact pin — a login waiting on another's
|
|
40
|
+
* uncommitted mint — is each spine's own real-Postgres test (and a backend
|
|
41
|
+
* on a one-connection engine serializes the burst whatever it locks).
|
|
34
42
|
*
|
|
35
43
|
* **Why `max_sessions + 1` logins and not `max_sessions`.** The starting session
|
|
36
44
|
* count isn't zero and isn't guaranteed equal across impls — `create_account`
|
|
@@ -50,11 +58,6 @@ import '../assert_dev_env.js';
|
|
|
50
58
|
* fourth `Set-Cookie` parser — reading the raw header is `cookie_attributes.ts`'s
|
|
51
59
|
* job, and this case only needs "does this login still authenticate".
|
|
52
60
|
*
|
|
53
|
-
* What it does **not** pin: concurrent creators. Two simultaneous logins can
|
|
54
|
-
* each evict against a stale count under Read Committed and both commit above
|
|
55
|
-
* the cap — see `query_session_enforce_limit`'s race note. That needs a
|
|
56
|
-
* barrier-based test against one backend, not a parity case.
|
|
57
|
-
*
|
|
58
61
|
* @module
|
|
59
62
|
*/
|
|
60
63
|
import { describe, test, assert } from 'vitest';
|
|
@@ -86,6 +89,15 @@ export const describe_session_cap_cross_tests = (options) => {
|
|
|
86
89
|
// a refused login past the cap is the defect, not a test fault
|
|
87
90
|
label: `${label} (the cap evicts, it never refuses)`
|
|
88
91
|
});
|
|
92
|
+
/** `account_session_list` on a transport: the listed ids, and those marked current. */
|
|
93
|
+
const list_on = async (transport, headers, label) => {
|
|
94
|
+
const { sessions } = expect_output(await cross_rpc_call(transport, rpc_path, 'account_session_list', undefined, headers), SessionListOutput);
|
|
95
|
+
assert.ok(sessions.length > 0, `${label}: the account lists its sessions`);
|
|
96
|
+
return {
|
|
97
|
+
ids: sessions.map((s) => s.id).sort(),
|
|
98
|
+
current: sessions.filter((s) => s.is_current).map((s) => s.id)
|
|
99
|
+
};
|
|
100
|
+
};
|
|
89
101
|
describe('per-account session cap parity', () => {
|
|
90
102
|
test(`logging in ${max_sessions + 1} times evicts the oldest session (the newest ${max_sessions} resolve, the first does not)`, async () => {
|
|
91
103
|
const fixture = await setup_test();
|
|
@@ -118,6 +130,24 @@ export const describe_session_cap_cross_tests = (options) => {
|
|
|
118
130
|
const { sessions: listed } = expect_output(await cross_rpc_call(newest[newest.length - 1], rpc_path, 'account_session_list', undefined, {}), SessionListOutput);
|
|
119
131
|
assert.strictEqual(listed.length, max_sessions, `the account must hold exactly ${max_sessions} sessions after the cap evicts`);
|
|
120
132
|
});
|
|
133
|
+
test(`${max_sessions * 3} concurrent logins all succeed and leave exactly ${max_sessions} sessions`, async () => {
|
|
134
|
+
const fixture = await setup_test();
|
|
135
|
+
await fixture.create_account({ username, password_value: DEFAULT_TEST_PASSWORD });
|
|
136
|
+
const burst = max_sessions * 3;
|
|
137
|
+
// each asserts its own 200 — a login lost to an eviction deadlock is a 500
|
|
138
|
+
const sessions = await Promise.all(Array.from({ length: burst }, (_, i) => login(fixture, `concurrent login ${i + 1}/${burst}`)));
|
|
139
|
+
let listed = null;
|
|
140
|
+
for (const transport of sessions) {
|
|
141
|
+
const result = await cross_rpc_call(transport, rpc_path, 'account_session_list', undefined, {});
|
|
142
|
+
// an evicted login's transport is the anonymous caller
|
|
143
|
+
if (!result.ok)
|
|
144
|
+
continue;
|
|
145
|
+
listed = expect_output(result, SessionListOutput).sessions.length;
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
assert.strictEqual(listed, max_sessions, `the account must hold exactly ${max_sessions} sessions after a concurrent burst — ` +
|
|
149
|
+
'each login evicting against the sessions committed before it');
|
|
150
|
+
});
|
|
121
151
|
test("the session list marks the caller's own session current, and none for a bearer or daemon token", async () => {
|
|
122
152
|
const fixture = await setup_test();
|
|
123
153
|
const account = await fixture.create_account({
|
|
@@ -127,15 +157,6 @@ export const describe_session_cap_cross_tests = (options) => {
|
|
|
127
157
|
});
|
|
128
158
|
const first = await login(fixture, 'the first login');
|
|
129
159
|
const second = await login(fixture, 'the second login');
|
|
130
|
-
/** `account_session_list` on a transport: the listed ids, and those marked current. */
|
|
131
|
-
const list_on = async (transport, headers, label) => {
|
|
132
|
-
const { sessions } = expect_output(await cross_rpc_call(transport, rpc_path, 'account_session_list', undefined, headers), SessionListOutput);
|
|
133
|
-
assert.ok(sessions.length > 0, `${label}: the account lists its sessions`);
|
|
134
|
-
return {
|
|
135
|
-
ids: sessions.map((s) => s.id).sort(),
|
|
136
|
-
current: sessions.filter((s) => s.is_current).map((s) => s.id)
|
|
137
|
-
};
|
|
138
|
-
};
|
|
139
160
|
const on_first = await list_on(first, {}, 'the first login');
|
|
140
161
|
const on_second = await list_on(second, {}, 'the second login');
|
|
141
162
|
assert.strictEqual(on_first.current.length, 1, 'the first login sees exactly one current session');
|
|
@@ -154,8 +175,19 @@ export const describe_session_cap_cross_tests = (options) => {
|
|
|
154
175
|
const on_daemon_with_cookie = await list_on(fixture.fresh_transport({ origin: null }), fixture.create_daemon_token_headers(fixture.create_session_headers()), 'a daemon-token caller sending a session cookie');
|
|
155
176
|
assert.deepStrictEqual(on_daemon_with_cookie.ids, on_keeper.ids);
|
|
156
177
|
assert.deepStrictEqual(on_daemon_with_cookie.current, [], 'a daemon token authenticated the request, not the cookie beside it');
|
|
157
|
-
|
|
158
|
-
|
|
178
|
+
});
|
|
179
|
+
test_if(ws !== undefined && ws_account_actions, "the session list over a socket marks the socket's own session current", async () => {
|
|
180
|
+
assert.ok(ws !== undefined);
|
|
181
|
+
const fixture = await setup_test();
|
|
182
|
+
await fixture.create_account({
|
|
183
|
+
username,
|
|
184
|
+
password_value: DEFAULT_TEST_PASSWORD,
|
|
185
|
+
roles: [...ws_account_roles]
|
|
186
|
+
});
|
|
187
|
+
const first = await login(fixture, 'the first login');
|
|
188
|
+
await login(fixture, 'the second login');
|
|
189
|
+
const on_first = await list_on(first, {}, 'the first login');
|
|
190
|
+
assert.strictEqual(on_first.current.length, 1, 'the first login sees exactly one current session');
|
|
159
191
|
const client = await create_ws_transport({
|
|
160
192
|
base_url: ws.base_url,
|
|
161
193
|
ws_path: ws.ws_path,
|