@stigmer/server 3.27.1 → 3.28.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/authorization/authorizer.d.ts +7 -5
- package/dist/authorization/authorizer.d.ts.map +1 -1
- package/dist/authorization/authorizer.js +7 -5
- package/dist/authorization/authorizer.js.map +1 -1
- package/dist/authorization/derived-tuples.d.ts +3 -1
- package/dist/authorization/derived-tuples.d.ts.map +1 -1
- package/dist/authorization/derived-tuples.js +52 -2
- package/dist/authorization/derived-tuples.js.map +1 -1
- package/dist/authorization/evaluator.d.ts +9 -10
- package/dist/authorization/evaluator.d.ts.map +1 -1
- package/dist/authorization/evaluator.js.map +1 -1
- package/dist/authorization/list-read-scope.d.ts.map +1 -1
- package/dist/authorization/list-read-scope.js +29 -18
- package/dist/authorization/list-read-scope.js.map +1 -1
- package/dist/authorization/model/bindings.d.ts +41 -0
- package/dist/authorization/model/bindings.d.ts.map +1 -0
- package/dist/authorization/model/bindings.js +89 -0
- package/dist/authorization/model/bindings.js.map +1 -0
- package/dist/authorization/model/data/authorization-model.json +3114 -0
- package/dist/authorization/model/default-of.d.ts +2 -2
- package/dist/authorization/model/execution-viewer.d.ts +3 -0
- package/dist/authorization/model/execution-viewer.d.ts.map +1 -0
- package/dist/authorization/model/execution-viewer.js +50 -0
- package/dist/authorization/model/execution-viewer.js.map +1 -0
- package/dist/authorization/model/index.d.ts +33 -21
- package/dist/authorization/model/index.d.ts.map +1 -1
- package/dist/authorization/model/index.js +74 -52
- package/dist/authorization/model/index.js.map +1 -1
- package/dist/authorization/model/openfga-json.d.ts +18 -0
- package/dist/authorization/model/openfga-json.d.ts.map +1 -0
- package/dist/authorization/model/openfga-json.js +266 -0
- package/dist/authorization/model/openfga-json.js.map +1 -0
- package/dist/authorization/model/rewrite.d.ts +39 -67
- package/dist/authorization/model/rewrite.d.ts.map +1 -1
- package/dist/authorization/model/rewrite.js +1 -117
- package/dist/authorization/model/rewrite.js.map +1 -1
- package/dist/authorization/strict-json.d.ts +20 -0
- package/dist/authorization/strict-json.d.ts.map +1 -0
- package/dist/authorization/strict-json.js +45 -0
- package/dist/authorization/strict-json.js.map +1 -0
- package/dist/boot/compose.d.ts.map +1 -1
- package/dist/boot/compose.js +9 -7
- package/dist/boot/compose.js.map +1 -1
- package/dist/boot/list-indexes.d.ts.map +1 -1
- package/dist/boot/list-indexes.js +6 -0
- package/dist/boot/list-indexes.js.map +1 -1
- package/dist/domain/iampolicy/list-index.d.ts +2 -0
- package/dist/domain/iampolicy/list-index.d.ts.map +1 -0
- package/dist/domain/iampolicy/list-index.js +32 -0
- package/dist/domain/iampolicy/list-index.js.map +1 -0
- package/dist/domain/iampolicy/resource-store.d.ts.map +1 -1
- package/dist/domain/iampolicy/resource-store.js +24 -11
- package/dist/domain/iampolicy/resource-store.js.map +1 -1
- package/dist/domain/workflowexecution/list-index.d.ts +1 -1
- package/dist/extensions/list-read-scope.d.ts +20 -3
- package/dist/extensions/list-read-scope.d.ts.map +1 -1
- package/dist/extensions/list-read-scope.js +22 -2
- package/dist/extensions/list-read-scope.js.map +1 -1
- package/dist/index.d.ts +8 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -5
- package/dist/index.js.map +1 -1
- package/package.json +7 -6
- package/src/authorization/README.md +48 -39
- package/src/authorization/__tests__/authorizer.test.ts +5 -14
- package/src/authorization/__tests__/derived-tuples.test.ts +192 -17
- package/src/authorization/__tests__/evaluator.test.ts +53 -160
- package/src/authorization/__tests__/facts.test.ts +5 -11
- package/src/authorization/__tests__/list-read-scope.measure.test.ts +424 -62
- package/src/authorization/__tests__/list-read-scope.test.ts +15 -14
- package/src/authorization/__tests__/organization-directory.test.ts +2 -2
- package/src/authorization/__tests__/store-test-kit.ts +246 -0
- package/src/authorization/__tests__/store-tests.test.ts +91 -223
- package/src/authorization/__tests__/support.ts +30 -2
- package/src/authorization/__tests__/throwaway-model.ts +75 -0
- package/src/authorization/__tests__/wire-permissions.test.ts +141 -107
- package/src/authorization/authorizer.ts +7 -5
- package/src/authorization/derived-tuples.ts +105 -16
- package/src/authorization/evaluator.ts +8 -10
- package/src/authorization/list-read-scope.ts +37 -22
- package/src/authorization/model/__tests__/openfga-json.test.ts +353 -0
- package/src/authorization/model/__tests__/registry.test.ts +102 -276
- package/src/authorization/model/bindings.ts +131 -0
- package/src/authorization/model/data/authorization-model.json +3114 -0
- package/src/authorization/model/default-of.ts +2 -2
- package/src/authorization/model/execution-viewer.ts +56 -0
- package/src/authorization/model/index.ts +81 -72
- package/src/authorization/model/openfga-json.ts +310 -0
- package/src/authorization/model/rewrite.ts +39 -188
- package/src/authorization/strict-json.ts +52 -0
- package/src/boot/__tests__/list-indexes.test.ts +4 -0
- package/src/boot/compose.ts +9 -7
- package/src/boot/list-indexes.ts +6 -0
- package/src/domain/iampolicy/__tests__/resource-store.test.ts +65 -5
- package/src/domain/iampolicy/list-index.ts +33 -0
- package/src/domain/iampolicy/resource-store.ts +24 -11
- package/src/extensions/__tests__/built-in-authorization-composed.test.ts +3 -6
- package/src/extensions/list-read-scope.ts +32 -4
- package/src/index.ts +20 -44
- package/dist/authorization/model/agent.d.ts +0 -2
- package/dist/authorization/model/agent.d.ts.map +0 -1
- package/dist/authorization/model/agent.js +0 -43
- package/dist/authorization/model/agent.js.map +0 -1
- package/dist/authorization/model/agent_channel.d.ts +0 -2
- package/dist/authorization/model/agent_channel.d.ts.map +0 -1
- package/dist/authorization/model/agent_channel.js +0 -39
- package/dist/authorization/model/agent_channel.js.map +0 -1
- package/dist/authorization/model/agent_execution.d.ts +0 -2
- package/dist/authorization/model/agent_execution.d.ts.map +0 -1
- package/dist/authorization/model/agent_execution.js +0 -25
- package/dist/authorization/model/agent_execution.js.map +0 -1
- package/dist/authorization/model/agent_instance.d.ts +0 -2
- package/dist/authorization/model/agent_instance.d.ts.map +0 -1
- package/dist/authorization/model/agent_instance.js +0 -48
- package/dist/authorization/model/agent_instance.js.map +0 -1
- package/dist/authorization/model/agent_share.d.ts +0 -2
- package/dist/authorization/model/agent_share.d.ts.map +0 -1
- package/dist/authorization/model/agent_share.js +0 -29
- package/dist/authorization/model/agent_share.js.map +0 -1
- package/dist/authorization/model/api_key.d.ts +0 -2
- package/dist/authorization/model/api_key.d.ts.map +0 -1
- package/dist/authorization/model/api_key.js +0 -27
- package/dist/authorization/model/api_key.js.map +0 -1
- package/dist/authorization/model/artifact.d.ts +0 -2
- package/dist/authorization/model/artifact.d.ts.map +0 -1
- package/dist/authorization/model/artifact.js +0 -27
- package/dist/authorization/model/artifact.js.map +0 -1
- package/dist/authorization/model/channel_app.d.ts +0 -2
- package/dist/authorization/model/channel_app.d.ts.map +0 -1
- package/dist/authorization/model/channel_app.js +0 -28
- package/dist/authorization/model/channel_app.js.map +0 -1
- package/dist/authorization/model/environment.d.ts +0 -2
- package/dist/authorization/model/environment.d.ts.map +0 -1
- package/dist/authorization/model/environment.js +0 -33
- package/dist/authorization/model/environment.js.map +0 -1
- package/dist/authorization/model/execution_context.d.ts +0 -2
- package/dist/authorization/model/execution_context.d.ts.map +0 -1
- package/dist/authorization/model/execution_context.js +0 -19
- package/dist/authorization/model/execution_context.js.map +0 -1
- package/dist/authorization/model/iam_policy.d.ts +0 -2
- package/dist/authorization/model/iam_policy.d.ts.map +0 -1
- package/dist/authorization/model/iam_policy.js +0 -31
- package/dist/authorization/model/iam_policy.js.map +0 -1
- package/dist/authorization/model/identity_account.d.ts +0 -2
- package/dist/authorization/model/identity_account.d.ts.map +0 -1
- package/dist/authorization/model/identity_account.js +0 -25
- package/dist/authorization/model/identity_account.js.map +0 -1
- package/dist/authorization/model/mcp_server.d.ts +0 -2
- package/dist/authorization/model/mcp_server.d.ts.map +0 -1
- package/dist/authorization/model/mcp_server.js +0 -38
- package/dist/authorization/model/mcp_server.js.map +0 -1
- package/dist/authorization/model/memory.d.ts +0 -2
- package/dist/authorization/model/memory.d.ts.map +0 -1
- package/dist/authorization/model/memory.js +0 -26
- package/dist/authorization/model/memory.js.map +0 -1
- package/dist/authorization/model/oauth_app.d.ts +0 -2
- package/dist/authorization/model/oauth_app.d.ts.map +0 -1
- package/dist/authorization/model/oauth_app.js +0 -31
- package/dist/authorization/model/oauth_app.js.map +0 -1
- package/dist/authorization/model/organization.d.ts +0 -2
- package/dist/authorization/model/organization.d.ts.map +0 -1
- package/dist/authorization/model/organization.js +0 -58
- package/dist/authorization/model/organization.js.map +0 -1
- package/dist/authorization/model/platform_client.d.ts +0 -2
- package/dist/authorization/model/platform_client.d.ts.map +0 -1
- package/dist/authorization/model/platform_client.js +0 -31
- package/dist/authorization/model/platform_client.js.map +0 -1
- package/dist/authorization/model/plugin.d.ts +0 -2
- package/dist/authorization/model/plugin.d.ts.map +0 -1
- package/dist/authorization/model/plugin.js +0 -45
- package/dist/authorization/model/plugin.js.map +0 -1
- package/dist/authorization/model/schedule.d.ts +0 -2
- package/dist/authorization/model/schedule.d.ts.map +0 -1
- package/dist/authorization/model/schedule.js +0 -34
- package/dist/authorization/model/schedule.js.map +0 -1
- package/dist/authorization/model/session.d.ts +0 -2
- package/dist/authorization/model/session.d.ts.map +0 -1
- package/dist/authorization/model/session.js +0 -38
- package/dist/authorization/model/session.js.map +0 -1
- package/dist/authorization/model/skill.d.ts +0 -2
- package/dist/authorization/model/skill.d.ts.map +0 -1
- package/dist/authorization/model/skill.js +0 -39
- package/dist/authorization/model/skill.js.map +0 -1
- package/dist/authorization/model/workflow.d.ts +0 -2
- package/dist/authorization/model/workflow.d.ts.map +0 -1
- package/dist/authorization/model/workflow.js +0 -39
- package/dist/authorization/model/workflow.js.map +0 -1
- package/dist/authorization/model/workflow_execution.d.ts +0 -2
- package/dist/authorization/model/workflow_execution.d.ts.map +0 -1
- package/dist/authorization/model/workflow_execution.js +0 -33
- package/dist/authorization/model/workflow_execution.js.map +0 -1
- package/dist/authorization/model/workflow_instance.d.ts +0 -2
- package/dist/authorization/model/workflow_instance.d.ts.map +0 -1
- package/dist/authorization/model/workflow_instance.js +0 -96
- package/dist/authorization/model/workflow_instance.js.map +0 -1
- package/dist/authorization/store-test-kit.d.ts +0 -62
- package/dist/authorization/store-test-kit.d.ts.map +0 -1
- package/dist/authorization/store-test-kit.js +0 -265
- package/dist/authorization/store-test-kit.js.map +0 -1
- package/src/authorization/__tests__/fixtures/fga/agent-channel-owner.fga.yaml +0 -112
- package/src/authorization/__tests__/fixtures/fga/agent-instance-creation.fga.yaml +0 -177
- package/src/authorization/__tests__/fixtures/fga/agent-share-owner.fga.yaml +0 -109
- package/src/authorization/__tests__/fixtures/fga/artifact-org-and-owner.fga.yaml +0 -128
- package/src/authorization/__tests__/fixtures/fga/blueprint-private-visibility.fga.yaml +0 -318
- package/src/authorization/__tests__/fixtures/fga/channel-app-owner.fga.yaml +0 -125
- package/src/authorization/__tests__/fixtures/fga/channel-participation.fga.yaml +0 -201
- package/src/authorization/__tests__/fixtures/fga/channel-session-visibility.fga.yaml +0 -187
- package/src/authorization/__tests__/fixtures/fga/default-instance-inheritance.fga.yaml +0 -214
- package/src/authorization/__tests__/fixtures/fga/mcp-server-authoring.fga.yaml +0 -129
- package/src/authorization/__tests__/fixtures/fga/memory-subject-only.fga.yaml +0 -72
- package/src/authorization/__tests__/fixtures/fga/org-admin-owner-inheritance.fga.yaml +0 -308
- package/src/authorization/__tests__/fixtures/fga/org-shared-environment.fga.yaml +0 -144
- package/src/authorization/__tests__/fixtures/fga/platform-visibility.fga.yaml +0 -199
- package/src/authorization/__tests__/fixtures/fga/provider-standing-viewer.fga.yaml +0 -40
- package/src/authorization/__tests__/fixtures/fga/reserved-label-writer.fga.yaml +0 -41
- package/src/authorization/__tests__/fixtures/fga/schedule-owner.fga.yaml +0 -113
- package/src/authorization/__tests__/fixtures/fga/schedule-session-visibility.fga.yaml +0 -214
- package/src/authorization/__tests__/fixtures/fga/session-personal-resource.fga.yaml +0 -117
- package/src/authorization/__tests__/fixtures/fga/workflow-execution-sharing.fga.yaml +0 -190
- package/src/authorization/model/agent.ts +0 -64
- package/src/authorization/model/agent_channel.ts +0 -57
- package/src/authorization/model/agent_execution.ts +0 -33
- package/src/authorization/model/agent_instance.ts +0 -66
- package/src/authorization/model/agent_share.ts +0 -40
- package/src/authorization/model/api_key.ts +0 -28
- package/src/authorization/model/artifact.ts +0 -38
- package/src/authorization/model/channel_app.ts +0 -39
- package/src/authorization/model/environment.ts +0 -48
- package/src/authorization/model/execution_context.ts +0 -20
- package/src/authorization/model/iam_policy.ts +0 -42
- package/src/authorization/model/identity_account.ts +0 -26
- package/src/authorization/model/mcp_server.ts +0 -59
- package/src/authorization/model/memory.ts +0 -27
- package/src/authorization/model/oauth_app.ts +0 -43
- package/src/authorization/model/organization.ts +0 -59
- package/src/authorization/model/platform_client.ts +0 -43
- package/src/authorization/model/plugin.ts +0 -66
- package/src/authorization/model/schedule.ts +0 -49
- package/src/authorization/model/session.ts +0 -50
- package/src/authorization/model/skill.ts +0 -60
- package/src/authorization/model/workflow.ts +0 -60
- package/src/authorization/model/workflow_execution.ts +0 -46
- package/src/authorization/model/workflow_instance.ts +0 -125
- package/src/authorization/store-test-kit.ts +0 -395
|
@@ -1,395 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The OpenFGA store-test kit — runs a `.fga.yaml` store test (the format
|
|
3
|
-
* `fga model test` reads: fixture tuples, then named tests with `check`
|
|
4
|
-
* and `list_objects` assertions) against the built-in evaluator, so the
|
|
5
|
-
* cloud's own model tests — written by the model's authors and run
|
|
6
|
-
* against real OpenFGA in the cloud's CI — are the proof that this
|
|
7
|
-
* evaluator answers the same model the same way. Open source runs the
|
|
8
|
-
* kit over pinned copies of those documents (authorization/__tests__/
|
|
9
|
-
* fixtures/fga/); the cloud runs it over the LIVE documents at the
|
|
10
|
-
* re-pin, which is what makes the copies safe to hold.
|
|
11
|
-
*
|
|
12
|
-
* Shape: the port-contract kits' (store/port-contract.ts) — vitest-free,
|
|
13
|
-
* node:assert, cases the consumer's framework iterates — because a
|
|
14
|
-
* composition consumes it through the published barrel and vitest is a
|
|
15
|
-
* devDependency that must not enter the barrel's runtime graph.
|
|
16
|
-
*
|
|
17
|
-
* What is run and what is reported. One case per named test; a case
|
|
18
|
-
* asserts every `check` in the test whose object's kind the model
|
|
19
|
-
* declares, relation by relation, and FAILS on the first disagreement
|
|
20
|
-
* (the message names the check in the document's own words). Assertions
|
|
21
|
-
* the kit does not run are returned as `skipped`, each with its reason,
|
|
22
|
-
* so a consumer pins the list and a document that gains a scenario, or a
|
|
23
|
-
* declaration that lands, is a visible diff and never a quietly smaller
|
|
24
|
-
* proof. Three reasons: a check whose TARGET kind the model does not
|
|
25
|
-
* declare (`undeclared-kind`) and every `list_objects` assertion
|
|
26
|
-
* (`list-objects`, the list scope's proof) are known when the kit is
|
|
27
|
-
* built; the third is known only from the walk. A document may grant
|
|
28
|
-
* through a type the model does not declare — the cloud's platform
|
|
29
|
-
* tenancy reaches people through `identity_provider:<idp>#platform_user`,
|
|
30
|
-
* a kind this edition does not serve — and OpenFGA answers `true` where
|
|
31
|
-
* a model without that type resolves the userset to nobody. The kit runs
|
|
32
|
-
* every assertion over a recording view of the document's tuples, and an
|
|
33
|
-
* assertion whose walk READ a tuple naming an undeclared type is
|
|
34
|
-
* reported as `undeclared-subject-type` (the types named) instead of
|
|
35
|
-
* being asserted, whatever it would have answered: decided from the
|
|
36
|
-
* model and the data, per assertion, so the sibling arms of the same
|
|
37
|
-
* check block still run and a union that is settled before it reaches
|
|
38
|
-
* such a tuple runs too. Over a model that declares every type in the
|
|
39
|
-
* file (the cloud's drift test, built from the live model) nothing is
|
|
40
|
-
* recorded and everything runs — the same kit, no edition branch.
|
|
41
|
-
* `skipped` is therefore complete once every case has run; a consumer
|
|
42
|
-
* pins it after the cases, which is the order a test file declares them.
|
|
43
|
-
*
|
|
44
|
-
* The parser is strict on purpose: an unknown key anywhere is a thrown
|
|
45
|
-
* fault, so a change to the format upstream is loud here rather than
|
|
46
|
-
* half-run. The model declares no condition, so the format's `condition`
|
|
47
|
-
* on a tuple and `context` on a check are among the keys refused: a
|
|
48
|
-
* document that still carries them is written against a model this
|
|
49
|
-
* evaluator does not answer, and saying so beats running it half-blind.
|
|
50
|
-
*/
|
|
51
|
-
import assert from "node:assert/strict";
|
|
52
|
-
|
|
53
|
-
import { checkRelation } from "./evaluator.js";
|
|
54
|
-
import type { Model } from "./model/index.js";
|
|
55
|
-
import type { Person, Subject, Tuple, TupleSource } from "./tuples.js";
|
|
56
|
-
import {
|
|
57
|
-
ACCOUNT_TYPE,
|
|
58
|
-
newInMemoryTupleSource,
|
|
59
|
-
parseObjectRef,
|
|
60
|
-
parseSubject,
|
|
61
|
-
} from "./tuples.js";
|
|
62
|
-
|
|
63
|
-
// ---------------------------------------------------------------------------
|
|
64
|
-
// The document, typed exactly as the cloud's files use the format.
|
|
65
|
-
// ---------------------------------------------------------------------------
|
|
66
|
-
|
|
67
|
-
export interface StoreTestTuple {
|
|
68
|
-
readonly user: string;
|
|
69
|
-
readonly relation: string;
|
|
70
|
-
readonly object: string;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export interface StoreTestCheck {
|
|
74
|
-
readonly user: string;
|
|
75
|
-
readonly object: string;
|
|
76
|
-
readonly assertions: Readonly<Record<string, boolean>>;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export interface StoreTestListObjects {
|
|
80
|
-
readonly user: string;
|
|
81
|
-
readonly type: string;
|
|
82
|
-
readonly assertions: Readonly<Record<string, ReadonlyArray<string>>>;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export interface StoreTest {
|
|
86
|
-
readonly name: string;
|
|
87
|
-
readonly check: ReadonlyArray<StoreTestCheck>;
|
|
88
|
-
readonly list_objects: ReadonlyArray<StoreTestListObjects>;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export interface StoreTestDocument {
|
|
92
|
-
readonly name: string;
|
|
93
|
-
readonly tuples: ReadonlyArray<StoreTestTuple>;
|
|
94
|
-
readonly tests: ReadonlyArray<StoreTest>;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Parses a loaded YAML value into a document, refusing anything the
|
|
99
|
-
* format the cloud's files use does not carry (`sourceName` names the
|
|
100
|
-
* file in every message).
|
|
101
|
-
*/
|
|
102
|
-
export function parseStoreTestDocument(
|
|
103
|
-
value: unknown,
|
|
104
|
-
sourceName: string,
|
|
105
|
-
): StoreTestDocument {
|
|
106
|
-
const root = record(value, sourceName, [
|
|
107
|
-
"name",
|
|
108
|
-
"model_file",
|
|
109
|
-
"tuples",
|
|
110
|
-
"tests",
|
|
111
|
-
]);
|
|
112
|
-
return {
|
|
113
|
-
name: text(root["name"], `${sourceName}: name`),
|
|
114
|
-
tuples: list(root["tuples"], `${sourceName}: tuples`).map((entry, index) =>
|
|
115
|
-
parseTuple(entry, `${sourceName}: tuples[${index}]`),
|
|
116
|
-
),
|
|
117
|
-
tests: list(root["tests"], `${sourceName}: tests`).map((entry, index) =>
|
|
118
|
-
parseTest(entry, `${sourceName}: tests[${index}]`),
|
|
119
|
-
),
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function parseTuple(value: unknown, where: string): StoreTestTuple {
|
|
124
|
-
const entry = record(value, where, ["user", "relation", "object"]);
|
|
125
|
-
return {
|
|
126
|
-
user: text(entry["user"], `${where}.user`),
|
|
127
|
-
relation: text(entry["relation"], `${where}.relation`),
|
|
128
|
-
object: text(entry["object"], `${where}.object`),
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function parseTest(value: unknown, where: string): StoreTest {
|
|
133
|
-
const entry = record(value, where, ["name", "check", "list_objects"]);
|
|
134
|
-
return {
|
|
135
|
-
name: text(entry["name"], `${where}.name`),
|
|
136
|
-
check: optionalList(entry["check"], `${where}.check`).map((item, index) =>
|
|
137
|
-
parseCheck(item, `${where}.check[${index}]`),
|
|
138
|
-
),
|
|
139
|
-
list_objects: optionalList(
|
|
140
|
-
entry["list_objects"],
|
|
141
|
-
`${where}.list_objects`,
|
|
142
|
-
).map((item, index) =>
|
|
143
|
-
parseListObjects(item, `${where}.list_objects[${index}]`),
|
|
144
|
-
),
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
function parseCheck(value: unknown, where: string): StoreTestCheck {
|
|
149
|
-
const entry = record(value, where, ["user", "object", "assertions"]);
|
|
150
|
-
const assertions = record(entry["assertions"], `${where}.assertions`);
|
|
151
|
-
const parsed: Record<string, boolean> = {};
|
|
152
|
-
for (const [relation, expected] of Object.entries(assertions)) {
|
|
153
|
-
if (typeof expected !== "boolean") {
|
|
154
|
-
throw new Error(`${where}.assertions.${relation}: expected a boolean`);
|
|
155
|
-
}
|
|
156
|
-
parsed[relation] = expected;
|
|
157
|
-
}
|
|
158
|
-
return {
|
|
159
|
-
user: text(entry["user"], `${where}.user`),
|
|
160
|
-
object: text(entry["object"], `${where}.object`),
|
|
161
|
-
assertions: parsed,
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function parseListObjects(value: unknown, where: string): StoreTestListObjects {
|
|
166
|
-
const entry = record(value, where, ["user", "type", "assertions"]);
|
|
167
|
-
const assertions = record(entry["assertions"], `${where}.assertions`);
|
|
168
|
-
const parsed: Record<string, ReadonlyArray<string>> = {};
|
|
169
|
-
for (const [relation, expected] of Object.entries(assertions)) {
|
|
170
|
-
parsed[relation] = list(expected, `${where}.assertions.${relation}`).map(
|
|
171
|
-
(item, index) => text(item, `${where}.assertions.${relation}[${index}]`),
|
|
172
|
-
);
|
|
173
|
-
}
|
|
174
|
-
return {
|
|
175
|
-
user: text(entry["user"], `${where}.user`),
|
|
176
|
-
type: text(entry["type"], `${where}.type`),
|
|
177
|
-
assertions: parsed,
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
function record(
|
|
182
|
-
value: unknown,
|
|
183
|
-
where: string,
|
|
184
|
-
allowedKeys?: ReadonlyArray<string>,
|
|
185
|
-
): Record<string, unknown> {
|
|
186
|
-
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
187
|
-
throw new Error(`${where}: expected a mapping`);
|
|
188
|
-
}
|
|
189
|
-
const entry = value as Record<string, unknown>;
|
|
190
|
-
if (allowedKeys !== undefined) {
|
|
191
|
-
for (const key of Object.keys(entry)) {
|
|
192
|
-
if (!allowedKeys.includes(key)) {
|
|
193
|
-
throw new Error(`${where}: unknown key '${key}'`);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
return entry;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
function list(value: unknown, where: string): ReadonlyArray<unknown> {
|
|
201
|
-
if (!Array.isArray(value)) {
|
|
202
|
-
throw new Error(`${where}: expected a list`);
|
|
203
|
-
}
|
|
204
|
-
return value as ReadonlyArray<unknown>;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
function optionalList(value: unknown, where: string): ReadonlyArray<unknown> {
|
|
208
|
-
return value === undefined ? [] : list(value, where);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
function text(value: unknown, where: string): string {
|
|
212
|
-
if (typeof value !== "string") {
|
|
213
|
-
throw new Error(`${where}: expected a string`);
|
|
214
|
-
}
|
|
215
|
-
return value;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
// ---------------------------------------------------------------------------
|
|
219
|
-
// The cases.
|
|
220
|
-
// ---------------------------------------------------------------------------
|
|
221
|
-
|
|
222
|
-
export interface StoreTestCase {
|
|
223
|
-
/** `<document> :: <test name>` — the framework prints it as the test name. */
|
|
224
|
-
readonly name: string;
|
|
225
|
-
run(): Promise<void>;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
export type StoreTestSkipReason =
|
|
229
|
-
| "undeclared-kind"
|
|
230
|
-
| "list-objects"
|
|
231
|
-
| "undeclared-subject-type";
|
|
232
|
-
|
|
233
|
-
/** One assertion (or assertion group) the kit did not run, in the document's words. */
|
|
234
|
-
export interface StoreTestSkip {
|
|
235
|
-
readonly document: string;
|
|
236
|
-
readonly test: string;
|
|
237
|
-
readonly subject: string;
|
|
238
|
-
/** The check's object, or `<type>` for a list_objects assertion. */
|
|
239
|
-
readonly object: string;
|
|
240
|
-
/** The one relation, for a skip decided per assertion; absent for a group. */
|
|
241
|
-
readonly relation?: string;
|
|
242
|
-
readonly reason: StoreTestSkipReason;
|
|
243
|
-
/** For `undeclared-subject-type`: the types the walk read that the model does not declare, sorted. */
|
|
244
|
-
readonly types?: ReadonlyArray<string>;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
export interface StoreTestKit {
|
|
248
|
-
readonly cases: ReadonlyArray<StoreTestCase>;
|
|
249
|
-
/** Complete once every case has run (the module header). */
|
|
250
|
-
readonly skipped: ReadonlyArray<StoreTestSkip>;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* The document's tests as runnable cases over `model`, plus every
|
|
255
|
-
* assertion group the kit does not run.
|
|
256
|
-
*/
|
|
257
|
-
export function storeTestCases(
|
|
258
|
-
document: StoreTestDocument,
|
|
259
|
-
model: Model,
|
|
260
|
-
): StoreTestKit {
|
|
261
|
-
const source = newInMemoryTupleSource(document.tuples.map(tupleOf));
|
|
262
|
-
const skipped: StoreTestSkip[] = [];
|
|
263
|
-
const cases: StoreTestCase[] = [];
|
|
264
|
-
|
|
265
|
-
for (const test of document.tests) {
|
|
266
|
-
const runnable: StoreTestCheck[] = [];
|
|
267
|
-
for (const item of test.check) {
|
|
268
|
-
const object = parseObjectRef(item.object);
|
|
269
|
-
if (model.byType(object.type) === undefined) {
|
|
270
|
-
skipped.push({
|
|
271
|
-
document: document.name,
|
|
272
|
-
test: test.name,
|
|
273
|
-
subject: item.user,
|
|
274
|
-
object: item.object,
|
|
275
|
-
reason: "undeclared-kind",
|
|
276
|
-
});
|
|
277
|
-
} else {
|
|
278
|
-
runnable.push(item);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
for (const item of test.list_objects) {
|
|
282
|
-
skipped.push({
|
|
283
|
-
document: document.name,
|
|
284
|
-
test: test.name,
|
|
285
|
-
subject: item.user,
|
|
286
|
-
object: `<${item.type}>`,
|
|
287
|
-
reason: "list-objects",
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
if (runnable.length === 0) {
|
|
291
|
-
continue;
|
|
292
|
-
}
|
|
293
|
-
cases.push({
|
|
294
|
-
name: `${document.name} :: ${test.name}`,
|
|
295
|
-
async run() {
|
|
296
|
-
for (const item of runnable) {
|
|
297
|
-
const object = parseObjectRef(item.object);
|
|
298
|
-
const person = personOf(item.user);
|
|
299
|
-
for (const [relation, expected] of Object.entries(item.assertions)) {
|
|
300
|
-
const recording = recordUndeclaredTypes(source, model);
|
|
301
|
-
const actual = await checkRelation(
|
|
302
|
-
{ model, source: recording },
|
|
303
|
-
object,
|
|
304
|
-
relation,
|
|
305
|
-
person,
|
|
306
|
-
);
|
|
307
|
-
if (recording.reached.size > 0) {
|
|
308
|
-
skipped.push({
|
|
309
|
-
document: document.name,
|
|
310
|
-
test: test.name,
|
|
311
|
-
subject: item.user,
|
|
312
|
-
object: item.object,
|
|
313
|
-
relation,
|
|
314
|
-
reason: "undeclared-subject-type",
|
|
315
|
-
types: [...recording.reached].sort(),
|
|
316
|
-
});
|
|
317
|
-
continue;
|
|
318
|
-
}
|
|
319
|
-
assert.equal(
|
|
320
|
-
actual,
|
|
321
|
-
expected,
|
|
322
|
-
`${document.name} :: ${test.name}: ${item.user} ${relation} ${item.object} expected ${String(expected)}, got ${String(actual)}`,
|
|
323
|
-
);
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
},
|
|
327
|
-
});
|
|
328
|
-
}
|
|
329
|
-
return { cases, skipped };
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
interface RecordingTupleSource extends TupleSource {
|
|
333
|
-
/** The undeclared types named by the subjects of the tuples the walk read. */
|
|
334
|
-
readonly reached: ReadonlySet<string>;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
/**
|
|
338
|
-
* A view of `inner` that records, for one walk, every subject type the
|
|
339
|
-
* evaluator read that `model` does not declare. A person
|
|
340
|
-
* (`identity_account:<id>`) is a subject the evaluator compares, never a
|
|
341
|
-
* type it resolves, so it is not a "reach" whatever the model declares; a
|
|
342
|
-
* userset or a parent object of an undeclared type is.
|
|
343
|
-
*/
|
|
344
|
-
function recordUndeclaredTypes(
|
|
345
|
-
inner: TupleSource,
|
|
346
|
-
model: Model,
|
|
347
|
-
): RecordingTupleSource {
|
|
348
|
-
const reached = new Set<string>();
|
|
349
|
-
return {
|
|
350
|
-
reached,
|
|
351
|
-
async tuplesOf(object, relation) {
|
|
352
|
-
const tuples = await inner.tuplesOf(object, relation);
|
|
353
|
-
for (const tuple of tuples) {
|
|
354
|
-
const type = resolvedTypeOf(tuple.subject);
|
|
355
|
-
if (type !== undefined && model.byType(type) === undefined) {
|
|
356
|
-
reached.add(type);
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
return tuples;
|
|
360
|
-
},
|
|
361
|
-
};
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
/** The type the evaluator would resolve a subject on, or undefined for a person. */
|
|
365
|
-
function resolvedTypeOf(subject: Subject): string | undefined {
|
|
366
|
-
switch (subject.form) {
|
|
367
|
-
case "object":
|
|
368
|
-
return subject.object.type === ACCOUNT_TYPE
|
|
369
|
-
? undefined
|
|
370
|
-
: subject.object.type;
|
|
371
|
-
case "userset":
|
|
372
|
-
return subject.object.type;
|
|
373
|
-
default: {
|
|
374
|
-
const exhaustive: never = subject;
|
|
375
|
-
throw new Error(`unknown subject form: ${JSON.stringify(exhaustive)}`);
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
function tupleOf(entry: StoreTestTuple): Tuple {
|
|
381
|
-
return {
|
|
382
|
-
object: parseObjectRef(entry.object),
|
|
383
|
-
relation: entry.relation,
|
|
384
|
-
subject: parseSubject(entry.user),
|
|
385
|
-
};
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
/** The document's users are plain accounts; a user of another type is a format the kit does not run. */
|
|
389
|
-
function personOf(user: string): Person {
|
|
390
|
-
const object = parseObjectRef(user);
|
|
391
|
-
if (object.type !== ACCOUNT_TYPE || object.id === "*") {
|
|
392
|
-
throw new Error(`store test users are accounts; got '${user}'`);
|
|
393
|
-
}
|
|
394
|
-
return { accountId: object.id, aliases: new Set([object.id]) };
|
|
395
|
-
}
|