@fuzdev/fuz_app 0.157.0 → 0.159.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions/CLAUDE.md +1 -0
- package/dist/actions/compile_action_registry.d.ts +5 -1
- package/dist/actions/compile_action_registry.d.ts.map +1 -1
- package/dist/actions/compile_action_registry.js +8 -1
- package/dist/auth/CLAUDE.md +11 -6
- package/dist/auth/actor_lookup_action_specs.d.ts +184 -40
- package/dist/auth/actor_lookup_action_specs.d.ts.map +1 -1
- package/dist/auth/actor_lookup_action_specs.js +16 -14
- package/dist/auth/actor_search_action_specs.d.ts +180 -40
- package/dist/auth/actor_search_action_specs.d.ts.map +1 -1
- package/dist/auth/actor_search_action_specs.js +12 -15
- package/dist/auth/audit_log_route_schema.d.ts +18 -6
- package/dist/auth/audit_log_route_schema.d.ts.map +1 -1
- package/dist/auth/audit_log_route_schema.js +7 -3
- package/dist/auth/credential_type_schema.d.ts +4 -4
- package/dist/auth/credential_type_schema.d.ts.map +1 -1
- package/dist/auth/credential_type_schema.js +6 -6
- package/dist/auth/grant_path_schema.d.ts +4 -4
- package/dist/auth/grant_path_schema.d.ts.map +1 -1
- package/dist/auth/grant_path_schema.js +6 -6
- package/dist/auth/request_context.js +1 -1
- package/dist/auth/role_grant_offer_action_specs.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_action_specs.js +9 -6
- package/dist/auth/role_grant_offer_ddl.d.ts +5 -4
- package/dist/auth/role_grant_offer_ddl.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_ddl.js +5 -4
- package/dist/auth/role_schema.d.ts +15 -2
- package/dist/auth/role_schema.d.ts.map +1 -1
- package/dist/auth/role_schema.js +17 -4
- package/dist/auth/role_schema_fuz.d.ts +29 -0
- package/dist/auth/role_schema_fuz.d.ts.map +1 -0
- package/dist/auth/role_schema_fuz.js +28 -0
- package/dist/auth/scope_kind_schema.d.ts +22 -15
- package/dist/auth/scope_kind_schema.d.ts.map +1 -1
- package/dist/auth/scope_kind_schema.js +24 -17
- package/dist/auth/self_service_role_action_specs.d.ts +70 -27
- package/dist/auth/self_service_role_action_specs.d.ts.map +1 -1
- package/dist/auth/self_service_role_action_specs.js +16 -14
- package/dist/auth/token_scope.d.ts +3 -2
- package/dist/auth/token_scope.d.ts.map +1 -1
- package/dist/auth/token_scope.js +4 -3
- package/dist/http/CLAUDE.md +19 -6
- package/dist/http/db_routes.d.ts.map +1 -1
- package/dist/http/db_routes.js +8 -3
- package/dist/http/error_schemas.d.ts +5 -2
- package/dist/http/error_schemas.d.ts.map +1 -1
- package/dist/http/route_spec.d.ts +7 -4
- package/dist/http/route_spec.d.ts.map +1 -1
- package/dist/http/route_spec.js +26 -5
- package/dist/http/schema_helpers.d.ts +21 -3
- package/dist/http/schema_helpers.d.ts.map +1 -1
- package/dist/http/schema_helpers.js +34 -4
- package/dist/http/surface.d.ts +2 -0
- package/dist/http/surface.d.ts.map +1 -1
- package/dist/http/surface.js +6 -2
- package/dist/primitive_schemas.d.ts +1 -1
- package/dist/primitive_schemas.d.ts.map +1 -1
- package/dist/primitive_schemas_fuz.d.ts +19 -4
- package/dist/primitive_schemas_fuz.d.ts.map +1 -1
- package/dist/primitive_schemas_fuz.js +22 -4
- package/dist/schema_issues.d.ts +11 -0
- package/dist/schema_issues.d.ts.map +1 -1
- package/dist/schema_issues.js +15 -0
- package/dist/server/serve_fact_route.d.ts.map +1 -1
- package/dist/server/serve_fact_route.js +3 -2
- package/dist/server/surface_route.d.ts.map +1 -1
- package/dist/server/surface_route.js +3 -2
- package/dist/testing/CLAUDE.md +12 -8
- package/dist/testing/cross_backend/role_grant_role_grammar.d.ts.map +1 -1
- package/dist/testing/cross_backend/role_grant_role_grammar.js +94 -6
- package/package.json +1 -1
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
* @module
|
|
9
9
|
*/
|
|
10
10
|
import { z } from 'zod';
|
|
11
|
-
import {
|
|
11
|
+
import { object } from '@fuzdev/fuz_schema/schema.ts';
|
|
12
|
+
import { ActingActor } from '../primitive_schemas_fuz.js';
|
|
12
13
|
import { ROLE_ADMIN } from '../auth/role_schema.js';
|
|
13
14
|
/**
|
|
14
15
|
* Create the admin-only route spec that serves the `AppSurface` as JSON.
|
|
@@ -37,7 +38,7 @@ export const create_surface_route_spec = (options) => ({
|
|
|
37
38
|
},
|
|
38
39
|
handler: (c) => c.json(options.surface),
|
|
39
40
|
description: 'Application surface (routes, middleware, schemas) — admin only',
|
|
40
|
-
query:
|
|
41
|
+
query: object({ acting: ActingActor }),
|
|
41
42
|
input: z.null(),
|
|
42
43
|
output: z.looseObject({
|
|
43
44
|
routes: z.array(z.looseObject({})),
|
package/dist/testing/CLAUDE.md
CHANGED
|
@@ -534,9 +534,7 @@ handler needing real seeded state, a path segment no schema describes. A
|
|
|
534
534
|
route whose params merely carry a format needs no entry: `resolve_valid_path`
|
|
535
535
|
synthesizes a segment the route accepts.
|
|
536
536
|
|
|
537
|
-
Also exported: `describe_adversarial_auth(options)` (group 3 on its own)
|
|
538
|
-
`build_error_schema_lookup(specs, middleware_specs?)` (pre-built
|
|
539
|
-
`Map<string, RouteErrorSchemas>` for per-response validation).
|
|
537
|
+
Also exported: `describe_adversarial_auth(options)` (group 3 on its own).
|
|
540
538
|
|
|
541
539
|
### `adversarial_input.ts` + `adversarial_input_cases.ts` — schema-walk payload generation
|
|
542
540
|
|
|
@@ -2534,19 +2532,25 @@ Cross-process only — the per-surface in-process TS pins live beside each
|
|
|
2534
2532
|
module's own tests (`account_status.test.ts`, `action_rpc.test.ts`,
|
|
2535
2533
|
`serve_fact_route.db.test.ts`);
|
|
2536
2534
|
|
|
2537
|
-
### Grant-verb role grammar parity — `cross_backend/role_grant_role_grammar.ts`
|
|
2535
|
+
### Grant-verb role and scope-kind grammar parity — `cross_backend/role_grant_role_grammar.ts`
|
|
2538
2536
|
|
|
2539
2537
|
`describe_role_grant_role_grammar_cross_tests({setup_test, rpc_path?})` — an
|
|
2540
|
-
off-grammar `role` (uppercase, hyphen, digit, leading or
|
|
2541
|
-
space, empty, or all lowercase and one character past the length
|
|
2538
|
+
off-grammar `role` (uppercase, hyphen, digit, leading, trailing or consecutive
|
|
2539
|
+
underscores, space, empty, or all lowercase and one character past the length
|
|
2540
|
+
cap) on `role_grant_assign` and `role_grant_offer_create` answers
|
|
2542
2541
|
`invalid_params` with no `data.reason`, and after the refusals no
|
|
2543
2542
|
`role_grant_create` / `role_grant_offer_create` audit row carries one of those
|
|
2544
2543
|
strings. The control — an on-grammar role no registry holds, refused past
|
|
2545
2544
|
validation with `role_not_web_grantable` — keeps the audit read from being
|
|
2546
2545
|
vacuous, and the same refusal for a role exactly at the length cap pins that
|
|
2547
|
-
boundary.
|
|
2546
|
+
boundary. An off-grammar `scope_kind` with its `scope_id` (the same grammar
|
|
2547
|
+
and cap, `ScopeKindName`, among them `'GLOBAL'` with the all-zeros uuid, the
|
|
2548
|
+
partial unique indexes' key for a global grant) is refused the same way and
|
|
2549
|
+
recorded in no row; with an unregistered role, on-grammar ones (one at the cap)
|
|
2550
|
+
are refused past validation with the verb's not-grantable reason. Exists
|
|
2551
|
+
because the action-manifest parity gate captures no param
|
|
2548
2552
|
schemas while the Rust spine parses params by hand, and the grant verbs write
|
|
2549
|
-
the role they refuse into their failure rows. Ungated; cross-process only (it
|
|
2553
|
+
the role and `scope_kind` they refuse into their failure rows. Ungated; cross-process only (it
|
|
2550
2554
|
reads the audit log behind `_testing_drain_effects`).
|
|
2551
2555
|
|
|
2552
2556
|
### API-token lifetime parity — `cross_backend/token_lifetime.ts`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"role_grant_role_grammar.d.ts","sourceRoot":"../src/lib/","sources":["../../../src/lib/testing/cross_backend/role_grant_role_grammar.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"role_grant_role_grammar.d.ts","sourceRoot":"../src/lib/","sources":["../../../src/lib/testing/cross_backend/role_grant_role_grammar.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAiD9B,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAG3D,8EAA8E;AAC9E,MAAM,MAAM,oCAAoC,GAAG,wBAAwB,CAAC;AAoE5E,eAAO,MAAM,4CAA4C,GACxD,SAAS,oCAAoC,KAC3C,IAqKF,CAAC"}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import '../assert_dev_env.js';
|
|
2
2
|
/**
|
|
3
|
-
* Cross-backend parity suite for an **off-grammar `role`** on
|
|
3
|
+
* Cross-backend parity suite for an **off-grammar `role` or `scope_kind`** on
|
|
4
|
+
* the grant verbs.
|
|
4
5
|
*
|
|
5
6
|
* `role_grant_assign` and `role_grant_offer_create` declare `role` as
|
|
6
|
-
* `RoleName` (lowercase letters and underscores, no leading or
|
|
7
|
-
*
|
|
8
|
-
* validation — JSON-RPC `invalid_params`, with no
|
|
9
|
-
* no audit row: a role is caller-chosen text until
|
|
10
|
-
* the grant verbs record the role they refuse in
|
|
7
|
+
* `RoleName` (lowercase letters and underscores, no leading, trailing or
|
|
8
|
+
* consecutive underscores, at most 64 characters). A role string outside that
|
|
9
|
+
* grammar is refused at input validation — JSON-RPC `invalid_params`, with no
|
|
10
|
+
* `data.reason` — and writes no audit row: a role is caller-chosen text until
|
|
11
|
+
* it passes the grammar, and the grant verbs record the role they refuse in
|
|
12
|
+
* their failure rows.
|
|
11
13
|
*
|
|
12
14
|
* - **refused at validation** — each off-grammar role, on each verb, answers
|
|
13
15
|
* `invalid_params` with no reason, so the refusal is the input schema's and
|
|
@@ -19,6 +21,13 @@ import '../assert_dev_env.js';
|
|
|
19
21
|
* on-grammar role no registry holds is refused past validation with
|
|
20
22
|
* `role_not_web_grantable`, the refusal a failure row records — as is one
|
|
21
23
|
* exactly at the length cap, which pins the boundary.
|
|
24
|
+
* - **`scope_kind` too** — `scope_kind` is a `ScopeKindName`, the same grammar
|
|
25
|
+
* and cap, so an off-grammar one with its `scope_id` is refused the same way
|
|
26
|
+
* and recorded in no row. Among them is `'GLOBAL'` with the all-zeros
|
|
27
|
+
* uuid, the partial unique indexes' key for a global grant, which a spine
|
|
28
|
+
* letting it through would answer with a 500 on an actor already holding
|
|
29
|
+
* the role globally. The role is on the grammar and held by no registry, so
|
|
30
|
+
* a `scope_kind` let through is refused past validation with a reason.
|
|
22
31
|
*
|
|
23
32
|
* Exists because the action-manifest parity gate captures no param schemas
|
|
24
33
|
* while the Rust spine parses params by hand — a spine that let an off-grammar
|
|
@@ -30,6 +39,7 @@ import '../assert_dev_env.js';
|
|
|
30
39
|
* @module
|
|
31
40
|
*/
|
|
32
41
|
import { assert, describe, test } from 'vitest';
|
|
42
|
+
import { ERROR_ROLE_GRANT_OFFER_ROLE_NOT_GRANTABLE } from '../../auth/role_grant_offer_action_specs.js';
|
|
33
43
|
import { ERROR_ROLE_NOT_WEB_GRANTABLE } from '../../http/error_schemas.js';
|
|
34
44
|
import { JSONRPC_ERROR_CODES } from '../../http/jsonrpc_errors.js';
|
|
35
45
|
import { list_audit_events } from './audit_cross_helpers.js';
|
|
@@ -52,13 +62,41 @@ const OFF_GRAMMAR_ROLES = [
|
|
|
52
62
|
'role1', // digit
|
|
53
63
|
'_role', // leading underscore
|
|
54
64
|
'role_', // trailing underscore
|
|
65
|
+
'role__name', // a run of two underscores
|
|
66
|
+
'role___name', // a run of three
|
|
55
67
|
'role name', // space
|
|
56
68
|
'', // empty
|
|
57
69
|
OVER_LENGTH_ROLE // on the alphabet, one past the length cap
|
|
58
70
|
];
|
|
59
71
|
/** On the grammar, held by no registry. */
|
|
60
72
|
const UNREGISTERED_ROLE = 'not_a_registered_role';
|
|
73
|
+
/**
|
|
74
|
+
* The longest scope kind the grammar admits — an independent copy of the
|
|
75
|
+
* producers' `SCOPE_KIND_LENGTH_MAX`.
|
|
76
|
+
*/
|
|
77
|
+
const SCOPE_KIND_LENGTH_MAX = 64;
|
|
78
|
+
/** Each breaks one rule of the `ScopeKindName` grammar. */
|
|
79
|
+
const OFF_GRAMMAR_SCOPE_KINDS = [
|
|
80
|
+
'GLOBAL', // the partial unique indexes' token for a global grant
|
|
81
|
+
'Classroom', // uppercase
|
|
82
|
+
'a__b', // a run of two underscores
|
|
83
|
+
'_a', // leading underscore
|
|
84
|
+
'a_', // trailing underscore
|
|
85
|
+
'a1', // digit
|
|
86
|
+
'', // empty
|
|
87
|
+
'a'.repeat(SCOPE_KIND_LENGTH_MAX + 1) // on the alphabet, one past the length cap
|
|
88
|
+
];
|
|
89
|
+
/** On the grammar, the second exactly at the length cap. */
|
|
90
|
+
const ON_GRAMMAR_SCOPE_KINDS = [
|
|
91
|
+
'classroom',
|
|
92
|
+
'a'.repeat(SCOPE_KIND_LENGTH_MAX)
|
|
93
|
+
];
|
|
61
94
|
const GRANT_METHODS = ['role_grant_assign', 'role_grant_offer_create'];
|
|
95
|
+
/** What each grant verb refuses an unregistered role with, past validation. */
|
|
96
|
+
const NOT_GRANTABLE_REASONS = {
|
|
97
|
+
role_grant_assign: ERROR_ROLE_NOT_WEB_GRANTABLE,
|
|
98
|
+
role_grant_offer_create: ERROR_ROLE_GRANT_OFFER_ROLE_NOT_GRANTABLE
|
|
99
|
+
};
|
|
62
100
|
/** The audit event types the grant verbs write. */
|
|
63
101
|
const GRANT_EVENT_TYPES = ['role_grant_create', 'role_grant_offer_create'];
|
|
64
102
|
export const describe_role_grant_role_grammar_cross_tests = (options) => {
|
|
@@ -111,4 +149,54 @@ export const describe_role_grant_role_grammar_cross_tests = (options) => {
|
|
|
111
149
|
}
|
|
112
150
|
});
|
|
113
151
|
});
|
|
152
|
+
describe('grant verbs refuse an off-grammar scope_kind at validation', () => {
|
|
153
|
+
const scoped = (scope_kind) => ({
|
|
154
|
+
to_account_id: NIL_UUID,
|
|
155
|
+
role: UNREGISTERED_ROLE,
|
|
156
|
+
scope_kind,
|
|
157
|
+
scope_id: NIL_UUID
|
|
158
|
+
});
|
|
159
|
+
for (const method of GRANT_METHODS) {
|
|
160
|
+
test(`${method}: an off-grammar scope_kind is invalid_params with no reason`, async () => {
|
|
161
|
+
const fixture = await setup_test();
|
|
162
|
+
const t = fixture.fresh_transport();
|
|
163
|
+
for (const scope_kind of OFF_GRAMMAR_SCOPE_KINDS) {
|
|
164
|
+
const res = await cross_rpc_call(t, rpc_path, method, scoped(scope_kind), fixture.create_session_headers());
|
|
165
|
+
const label = `${method} scope_kind=${JSON.stringify(scope_kind)}`;
|
|
166
|
+
assert.strictEqual(res.ok, false, `${label}: expected a refusal`);
|
|
167
|
+
assert.strictEqual(res.error?.code, JSONRPC_ERROR_CODES.invalid_params, label);
|
|
168
|
+
// a validation refusal, not the grant-path one an unregistered role gets
|
|
169
|
+
assert.strictEqual(error_reason(res), undefined, `${label}: no data.reason`);
|
|
170
|
+
}
|
|
171
|
+
// on the grammar, the same call reaches the grant-path gate
|
|
172
|
+
for (const scope_kind of ON_GRAMMAR_SCOPE_KINDS) {
|
|
173
|
+
const res = await cross_rpc_call(t, rpc_path, method, scoped(scope_kind), fixture.create_session_headers());
|
|
174
|
+
assert.strictEqual(error_reason(res), NOT_GRANTABLE_REASONS[method], `${method} scope_kind=${JSON.stringify(scope_kind)}: passes validation`);
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
test('an off-grammar scope_kind writes no audit row', async () => {
|
|
179
|
+
const fixture = await setup_test();
|
|
180
|
+
const t = fixture.fresh_transport();
|
|
181
|
+
const session = fixture.create_session_headers();
|
|
182
|
+
for (const method of GRANT_METHODS) {
|
|
183
|
+
for (const scope_kind of [...OFF_GRAMMAR_SCOPE_KINDS, ...ON_GRAMMAR_SCOPE_KINDS]) {
|
|
184
|
+
await cross_rpc_call(t, rpc_path, method, scoped(scope_kind), session);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
for (const event_type of GRANT_EVENT_TYPES) {
|
|
188
|
+
const events = await list_audit_events(fixture, { event_type }, rpc_path);
|
|
189
|
+
const scope_kinds = events.map((event) => event.metadata?.scope_kind);
|
|
190
|
+
for (const scope_kind of scope_kinds) {
|
|
191
|
+
assert.ok(typeof scope_kind !== 'string' || !OFF_GRAMMAR_SCOPE_KINDS.includes(scope_kind), `${event_type}: an audit row records the off-grammar scope_kind ${JSON.stringify(scope_kind)}`);
|
|
192
|
+
}
|
|
193
|
+
if (event_type === 'role_grant_create') {
|
|
194
|
+
// the on-grammar refusals' failure rows are in the same read, so it is not vacuous
|
|
195
|
+
for (const scope_kind of ON_GRAMMAR_SCOPE_KINDS) {
|
|
196
|
+
assert.ok(scope_kinds.includes(scope_kind), `the scope_kind=${JSON.stringify(scope_kind)} refusal wrote its failure row`);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
});
|
|
114
202
|
};
|