@feltdb/core 0.4.15 → 0.4.17
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/cli/index.js +1 -1
- package/dist/collection.d.ts +11 -0
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +34 -0
- package/dist/create/package-versions.js +1 -1
- package/dist/create/server-source/crates/feltdb/Cargo.toml +1 -1
- package/dist/create/server-source/crates/feltdb/src/application.rs +93 -0
- package/dist/create/server-source/crates/feltdb/src/authorization_security_tests.rs +787 -0
- package/dist/create/server-source/crates/feltdb/src/lib.rs +139 -0
- package/dist/create/server-source/crates/feltdb/src/policy_evaluation.rs +1669 -0
- package/dist/create/server-source/crates/feltdb/src/state_contract.rs +1269 -15
- package/dist/create/server-source/crates/feltdb/tests/pr7_self_authorization_proof.rs +406 -0
- package/dist/create/server-source/crates/feltdb/tests/pr8_vocabulary_assessment.rs +908 -0
- package/dist/create/server-source/crates/feltdb/tests/pr9_phase2_boundary_tests.rs +1028 -0
- package/dist/create/server-source/crates/feltdb/tests/pr9_phase3a_path_a_tests.rs +332 -0
- package/dist/create/server-source/crates/feltdb/tests/pr9_phase3c_authorized_mutations.rs +342 -0
- package/dist/create/server-source/crates/feltdb/tests/pr9_phase3c_role_based_authorization.rs +313 -0
- package/dist/create/server-source/crates/feltdb/tests/pr9_phase3c_simple_auth_delete.rs +90 -0
- package/dist/create/server-source/crates/feltdb/tests/pr9_phase3c_team_delete_role_authorization.rs +571 -0
- package/dist/create/server-source/crates/feltdb/tests/pr9_teams_role_based_access.rs +506 -0
- package/dist/create/server-source/crates/feltdb/tests/saas_authorization_integration.rs +81 -0
- package/dist/create/server-source/crates/feltdb/tests/saas_invitation_lifecycle.rs +434 -0
- package/dist/create/server-source/crates/feltdb-server/src/main.rs +130 -23
- package/dist/create/server-source/crates/feltdb-wasm/src/lib.rs +2 -2
- package/dist/db.d.ts +91 -0
- package/dist/db.d.ts.map +1 -1
- package/dist/db.js +89 -1
- package/dist/feltdb.d.ts +14 -0
- package/dist/feltdb.d.ts.map +1 -1
- package/dist/file-db.d.ts +75 -0
- package/dist/file-db.d.ts.map +1 -0
- package/dist/file-db.js +437 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/studio-app/assets/{feltdb_wasm-CJEJryDx.js → feltdb_wasm-CBGD0zRu.js} +1 -1
- package/dist/studio-app/assets/feltdb_wasm_bg-C6ATF9mJ.wasm +0 -0
- package/dist/studio-app/assets/{index-D_p8T7nO.js → index-5siPkRSN.js} +9 -9
- package/dist/studio-app/index.html +1 -1
- package/dist/wasm/feltdb_wasm_bg.wasm +0 -0
- package/package.json +9 -4
- package/dist/studio-app/assets/feltdb_wasm_bg-BJxQXtoo.wasm +0 -0
|
@@ -0,0 +1,1028 @@
|
|
|
1
|
+
//! PR #9 Phase 2: Security Boundary Tests
|
|
2
|
+
//!
|
|
3
|
+
//! This test interrogates the FeltDB runtime to determine what the frozen vocabulary
|
|
4
|
+
//! actually permits at the database boundary.
|
|
5
|
+
//!
|
|
6
|
+
//! For each operation, we test systematically across all actor types:
|
|
7
|
+
//! - owner (team owner)
|
|
8
|
+
//! - admin (team admin)
|
|
9
|
+
//! - member (team member)
|
|
10
|
+
//! - non_member (org member, not on team)
|
|
11
|
+
//! - revoked (was member, but membership removed)
|
|
12
|
+
//! - cross_tenant (member of different org)
|
|
13
|
+
//!
|
|
14
|
+
//! CRITICAL DISTINCTION:
|
|
15
|
+
//! Product Behavior: "Member should not see delete button"
|
|
16
|
+
//! Authorization Invariant: "Member must be unable to delete via direct FeltDB call"
|
|
17
|
+
//!
|
|
18
|
+
//! Tests distinguish these explicitly. Passing tests by hiding UI is a failure.
|
|
19
|
+
//!
|
|
20
|
+
//! The hypothesis: Frozen vocabulary (authenticated, self, owner, member) is sufficient.
|
|
21
|
+
//! Phase 2 tests: What does the boundary actually enforce?
|
|
22
|
+
|
|
23
|
+
use feltdb::{
|
|
24
|
+
state_contract::{
|
|
25
|
+
StateSchema, CollectionSchema, FieldSchema, FieldType, PrimitiveType,
|
|
26
|
+
FieldConstraints, AuthorizationContext, begin_read, execute_query,
|
|
27
|
+
CanonicalQuery, QueryFilter,
|
|
28
|
+
},
|
|
29
|
+
FeltDb,
|
|
30
|
+
};
|
|
31
|
+
use serde_json::{json, Value};
|
|
32
|
+
use tempfile::TempDir;
|
|
33
|
+
use std::fmt;
|
|
34
|
+
|
|
35
|
+
/// Result of testing an operation at the FeltDB boundary
|
|
36
|
+
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
37
|
+
enum BoundaryResult {
|
|
38
|
+
Permit,
|
|
39
|
+
Deny,
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
impl fmt::Display for BoundaryResult {
|
|
43
|
+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
44
|
+
match self {
|
|
45
|
+
BoundaryResult::Permit => write!(f, "PERMIT"),
|
|
46
|
+
BoundaryResult::Deny => write!(f, "DENY"),
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/// Test fixture for boundary testing
|
|
52
|
+
struct TeamBoundaryTestFixture {
|
|
53
|
+
db: FeltDb,
|
|
54
|
+
// Actors
|
|
55
|
+
owner_id: String,
|
|
56
|
+
admin_id: String,
|
|
57
|
+
member_id: String,
|
|
58
|
+
non_member_id: String,
|
|
59
|
+
revoked_id: String,
|
|
60
|
+
cross_tenant_id: String,
|
|
61
|
+
// Resources
|
|
62
|
+
team_id: String,
|
|
63
|
+
org_id: String,
|
|
64
|
+
cross_org_id: String,
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
impl TeamBoundaryTestFixture {
|
|
68
|
+
/// Create an AuthorizationContext for a specific actor
|
|
69
|
+
fn actor_context(&self, actor_id: &str, name: &str) -> AuthorizationContext {
|
|
70
|
+
AuthorizationContext {
|
|
71
|
+
subject: format!(":{}", actor_id),
|
|
72
|
+
tenant_id: "tenant".to_string(),
|
|
73
|
+
application_id: "saas-portal".to_string(),
|
|
74
|
+
revision_id: "rev-1".to_string(),
|
|
75
|
+
capabilities: ["state:read".to_string()].into(),
|
|
76
|
+
readable_collections: Default::default(),
|
|
77
|
+
writable_collections: Default::default(),
|
|
78
|
+
field_projections: Default::default(),
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
fn setup() -> Result<Self, Box<dyn std::error::Error>> {
|
|
83
|
+
let temp_dir = TempDir::new()?;
|
|
84
|
+
let db_path = temp_dir.path().join("boundary_tests.db");
|
|
85
|
+
let db = FeltDb::open(&db_path)?;
|
|
86
|
+
|
|
87
|
+
let schema = StateSchema {
|
|
88
|
+
contract_version: 1,
|
|
89
|
+
schema_version: 1,
|
|
90
|
+
application_id: "saas-portal".to_string(),
|
|
91
|
+
revision_id: "rev-1".to_string(),
|
|
92
|
+
collections: vec![
|
|
93
|
+
// User collection
|
|
94
|
+
CollectionSchema {
|
|
95
|
+
name: "User".to_string(),
|
|
96
|
+
version: 1,
|
|
97
|
+
fields: vec![
|
|
98
|
+
FieldSchema {
|
|
99
|
+
name: "_id".to_string(),
|
|
100
|
+
field_type: FieldType::Primitive {
|
|
101
|
+
primitive: PrimitiveType::String,
|
|
102
|
+
},
|
|
103
|
+
nullable: false,
|
|
104
|
+
required: true,
|
|
105
|
+
default: None,
|
|
106
|
+
constraints: FieldConstraints::default(),
|
|
107
|
+
computed: None,
|
|
108
|
+
},
|
|
109
|
+
FieldSchema {
|
|
110
|
+
name: "email".to_string(),
|
|
111
|
+
field_type: FieldType::Primitive {
|
|
112
|
+
primitive: PrimitiveType::String,
|
|
113
|
+
},
|
|
114
|
+
nullable: false,
|
|
115
|
+
required: true,
|
|
116
|
+
default: None,
|
|
117
|
+
constraints: FieldConstraints::default(),
|
|
118
|
+
computed: None,
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
indexes: vec![],
|
|
122
|
+
},
|
|
123
|
+
// Organization collection
|
|
124
|
+
CollectionSchema {
|
|
125
|
+
name: "Organization".to_string(),
|
|
126
|
+
version: 1,
|
|
127
|
+
fields: vec![
|
|
128
|
+
FieldSchema {
|
|
129
|
+
name: "_id".to_string(),
|
|
130
|
+
field_type: FieldType::Primitive {
|
|
131
|
+
primitive: PrimitiveType::String,
|
|
132
|
+
},
|
|
133
|
+
nullable: false,
|
|
134
|
+
required: true,
|
|
135
|
+
default: None,
|
|
136
|
+
constraints: FieldConstraints::default(),
|
|
137
|
+
computed: None,
|
|
138
|
+
},
|
|
139
|
+
FieldSchema {
|
|
140
|
+
name: "name".to_string(),
|
|
141
|
+
field_type: FieldType::Primitive {
|
|
142
|
+
primitive: PrimitiveType::String,
|
|
143
|
+
},
|
|
144
|
+
nullable: false,
|
|
145
|
+
required: true,
|
|
146
|
+
default: None,
|
|
147
|
+
constraints: FieldConstraints::default(),
|
|
148
|
+
computed: None,
|
|
149
|
+
},
|
|
150
|
+
],
|
|
151
|
+
indexes: vec![],
|
|
152
|
+
},
|
|
153
|
+
// Membership collection
|
|
154
|
+
CollectionSchema {
|
|
155
|
+
name: "Membership".to_string(),
|
|
156
|
+
version: 1,
|
|
157
|
+
fields: vec![
|
|
158
|
+
FieldSchema {
|
|
159
|
+
name: "_id".to_string(),
|
|
160
|
+
field_type: FieldType::Primitive {
|
|
161
|
+
primitive: PrimitiveType::String,
|
|
162
|
+
},
|
|
163
|
+
nullable: false,
|
|
164
|
+
required: true,
|
|
165
|
+
default: None,
|
|
166
|
+
constraints: FieldConstraints::default(),
|
|
167
|
+
computed: None,
|
|
168
|
+
},
|
|
169
|
+
FieldSchema {
|
|
170
|
+
name: "user".to_string(),
|
|
171
|
+
field_type: FieldType::Reference {
|
|
172
|
+
collection: "User".to_string(),
|
|
173
|
+
},
|
|
174
|
+
nullable: false,
|
|
175
|
+
required: true,
|
|
176
|
+
default: None,
|
|
177
|
+
constraints: FieldConstraints::default(),
|
|
178
|
+
computed: None,
|
|
179
|
+
},
|
|
180
|
+
FieldSchema {
|
|
181
|
+
name: "organization".to_string(),
|
|
182
|
+
field_type: FieldType::Reference {
|
|
183
|
+
collection: "Organization".to_string(),
|
|
184
|
+
},
|
|
185
|
+
nullable: false,
|
|
186
|
+
required: true,
|
|
187
|
+
default: None,
|
|
188
|
+
constraints: FieldConstraints::default(),
|
|
189
|
+
computed: None,
|
|
190
|
+
},
|
|
191
|
+
FieldSchema {
|
|
192
|
+
name: "role".to_string(),
|
|
193
|
+
field_type: FieldType::Primitive {
|
|
194
|
+
primitive: PrimitiveType::String,
|
|
195
|
+
},
|
|
196
|
+
nullable: false,
|
|
197
|
+
required: true,
|
|
198
|
+
default: None,
|
|
199
|
+
constraints: FieldConstraints::default(),
|
|
200
|
+
computed: None,
|
|
201
|
+
},
|
|
202
|
+
],
|
|
203
|
+
indexes: vec![],
|
|
204
|
+
},
|
|
205
|
+
// Team collection
|
|
206
|
+
CollectionSchema {
|
|
207
|
+
name: "Team".to_string(),
|
|
208
|
+
version: 1,
|
|
209
|
+
fields: vec![
|
|
210
|
+
FieldSchema {
|
|
211
|
+
name: "_id".to_string(),
|
|
212
|
+
field_type: FieldType::Primitive {
|
|
213
|
+
primitive: PrimitiveType::String,
|
|
214
|
+
},
|
|
215
|
+
nullable: false,
|
|
216
|
+
required: true,
|
|
217
|
+
default: None,
|
|
218
|
+
constraints: FieldConstraints::default(),
|
|
219
|
+
computed: None,
|
|
220
|
+
},
|
|
221
|
+
FieldSchema {
|
|
222
|
+
name: "organization".to_string(),
|
|
223
|
+
field_type: FieldType::Reference {
|
|
224
|
+
collection: "Organization".to_string(),
|
|
225
|
+
},
|
|
226
|
+
nullable: false,
|
|
227
|
+
required: true,
|
|
228
|
+
default: None,
|
|
229
|
+
constraints: FieldConstraints::default(),
|
|
230
|
+
computed: None,
|
|
231
|
+
},
|
|
232
|
+
FieldSchema {
|
|
233
|
+
name: "name".to_string(),
|
|
234
|
+
field_type: FieldType::Primitive {
|
|
235
|
+
primitive: PrimitiveType::String,
|
|
236
|
+
},
|
|
237
|
+
nullable: false,
|
|
238
|
+
required: true,
|
|
239
|
+
default: None,
|
|
240
|
+
constraints: FieldConstraints::default(),
|
|
241
|
+
computed: None,
|
|
242
|
+
},
|
|
243
|
+
FieldSchema {
|
|
244
|
+
name: "owner".to_string(),
|
|
245
|
+
field_type: FieldType::Reference {
|
|
246
|
+
collection: "User".to_string(),
|
|
247
|
+
},
|
|
248
|
+
nullable: false,
|
|
249
|
+
required: true,
|
|
250
|
+
default: None,
|
|
251
|
+
constraints: FieldConstraints::default(),
|
|
252
|
+
computed: None,
|
|
253
|
+
},
|
|
254
|
+
],
|
|
255
|
+
indexes: vec![],
|
|
256
|
+
},
|
|
257
|
+
// TeamMembership collection
|
|
258
|
+
CollectionSchema {
|
|
259
|
+
name: "TeamMembership".to_string(),
|
|
260
|
+
version: 1,
|
|
261
|
+
fields: vec![
|
|
262
|
+
FieldSchema {
|
|
263
|
+
name: "_id".to_string(),
|
|
264
|
+
field_type: FieldType::Primitive {
|
|
265
|
+
primitive: PrimitiveType::String,
|
|
266
|
+
},
|
|
267
|
+
nullable: false,
|
|
268
|
+
required: true,
|
|
269
|
+
default: None,
|
|
270
|
+
constraints: FieldConstraints::default(),
|
|
271
|
+
computed: None,
|
|
272
|
+
},
|
|
273
|
+
FieldSchema {
|
|
274
|
+
name: "team".to_string(),
|
|
275
|
+
field_type: FieldType::Reference {
|
|
276
|
+
collection: "Team".to_string(),
|
|
277
|
+
},
|
|
278
|
+
nullable: false,
|
|
279
|
+
required: true,
|
|
280
|
+
default: None,
|
|
281
|
+
constraints: FieldConstraints::default(),
|
|
282
|
+
computed: None,
|
|
283
|
+
},
|
|
284
|
+
FieldSchema {
|
|
285
|
+
name: "user".to_string(),
|
|
286
|
+
field_type: FieldType::Reference {
|
|
287
|
+
collection: "User".to_string(),
|
|
288
|
+
},
|
|
289
|
+
nullable: false,
|
|
290
|
+
required: true,
|
|
291
|
+
default: None,
|
|
292
|
+
constraints: FieldConstraints::default(),
|
|
293
|
+
computed: None,
|
|
294
|
+
},
|
|
295
|
+
FieldSchema {
|
|
296
|
+
name: "role".to_string(),
|
|
297
|
+
field_type: FieldType::Primitive {
|
|
298
|
+
primitive: PrimitiveType::String,
|
|
299
|
+
},
|
|
300
|
+
nullable: false,
|
|
301
|
+
required: true,
|
|
302
|
+
default: None,
|
|
303
|
+
constraints: FieldConstraints::default(),
|
|
304
|
+
computed: None,
|
|
305
|
+
},
|
|
306
|
+
],
|
|
307
|
+
indexes: vec![],
|
|
308
|
+
},
|
|
309
|
+
],
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
// IDs
|
|
313
|
+
let owner_id = "user-owner".to_string();
|
|
314
|
+
let admin_id = "user-admin".to_string();
|
|
315
|
+
let member_id = "user-member".to_string();
|
|
316
|
+
let non_member_id = "user-non-member".to_string();
|
|
317
|
+
let revoked_id = "user-revoked".to_string();
|
|
318
|
+
let cross_tenant_id = "user-cross-tenant".to_string();
|
|
319
|
+
|
|
320
|
+
let org_id = "org-main".to_string();
|
|
321
|
+
let cross_org_id = "org-other".to_string();
|
|
322
|
+
let team_id = "team-backend".to_string();
|
|
323
|
+
|
|
324
|
+
// Create users
|
|
325
|
+
db.insert("User#user-owner", json!({ "_id": owner_id, "email": "owner@example.com" }))
|
|
326
|
+
.map_err(|e| format!("{:?}", e))?;
|
|
327
|
+
db.insert("User#user-admin", json!({ "_id": admin_id, "email": "admin@example.com" }))
|
|
328
|
+
.map_err(|e| format!("{:?}", e))?;
|
|
329
|
+
db.insert("User#user-member", json!({ "_id": member_id, "email": "member@example.com" }))
|
|
330
|
+
.map_err(|e| format!("{:?}", e))?;
|
|
331
|
+
db.insert(
|
|
332
|
+
"User#user-non-member",
|
|
333
|
+
json!({ "_id": non_member_id, "email": "nonmember@example.com" }),
|
|
334
|
+
)
|
|
335
|
+
.map_err(|e| format!("{:?}", e))?;
|
|
336
|
+
db.insert("User#user-revoked", json!({ "_id": revoked_id, "email": "revoked@example.com" }))
|
|
337
|
+
.map_err(|e| format!("{:?}", e))?;
|
|
338
|
+
db.insert(
|
|
339
|
+
"User#user-cross-tenant",
|
|
340
|
+
json!({ "_id": cross_tenant_id, "email": "cross@example.com" }),
|
|
341
|
+
)
|
|
342
|
+
.map_err(|e| format!("{:?}", e))?;
|
|
343
|
+
|
|
344
|
+
// Create organizations
|
|
345
|
+
db.insert("Organization#org-main", json!({ "_id": org_id, "name": "Main Org" }))
|
|
346
|
+
.map_err(|e| format!("{:?}", e))?;
|
|
347
|
+
db.insert("Organization#org-other", json!({ "_id": cross_org_id, "name": "Other Org" }))
|
|
348
|
+
.map_err(|e| format!("{:?}", e))?;
|
|
349
|
+
|
|
350
|
+
// Create org memberships (establishes organization access)
|
|
351
|
+
db.insert(
|
|
352
|
+
"Membership#mem-owner",
|
|
353
|
+
json!({
|
|
354
|
+
"_id": "mem-owner",
|
|
355
|
+
"user": owner_id,
|
|
356
|
+
"organization": org_id,
|
|
357
|
+
"role": "owner"
|
|
358
|
+
}),
|
|
359
|
+
)
|
|
360
|
+
.map_err(|e| format!("{:?}", e))?;
|
|
361
|
+
|
|
362
|
+
db.insert(
|
|
363
|
+
"Membership#mem-admin",
|
|
364
|
+
json!({
|
|
365
|
+
"_id": "mem-admin",
|
|
366
|
+
"user": admin_id,
|
|
367
|
+
"organization": org_id,
|
|
368
|
+
"role": "member"
|
|
369
|
+
}),
|
|
370
|
+
)
|
|
371
|
+
.map_err(|e| format!("{:?}", e))?;
|
|
372
|
+
|
|
373
|
+
db.insert(
|
|
374
|
+
"Membership#mem-member",
|
|
375
|
+
json!({
|
|
376
|
+
"_id": "mem-member",
|
|
377
|
+
"user": member_id,
|
|
378
|
+
"organization": org_id,
|
|
379
|
+
"role": "member"
|
|
380
|
+
}),
|
|
381
|
+
)
|
|
382
|
+
.map_err(|e| format!("{:?}", e))?;
|
|
383
|
+
|
|
384
|
+
db.insert(
|
|
385
|
+
"Membership#mem-non-member",
|
|
386
|
+
json!({
|
|
387
|
+
"_id": "mem-non-member",
|
|
388
|
+
"user": non_member_id,
|
|
389
|
+
"organization": org_id,
|
|
390
|
+
"role": "member"
|
|
391
|
+
}),
|
|
392
|
+
)
|
|
393
|
+
.map_err(|e| format!("{:?}", e))?;
|
|
394
|
+
|
|
395
|
+
db.insert(
|
|
396
|
+
"Membership#mem-revoked",
|
|
397
|
+
json!({
|
|
398
|
+
"_id": "mem-revoked",
|
|
399
|
+
"user": revoked_id,
|
|
400
|
+
"organization": org_id,
|
|
401
|
+
"role": "member"
|
|
402
|
+
}),
|
|
403
|
+
)
|
|
404
|
+
.map_err(|e| format!("{:?}", e))?;
|
|
405
|
+
|
|
406
|
+
db.insert(
|
|
407
|
+
"Membership#mem-cross-tenant",
|
|
408
|
+
json!({
|
|
409
|
+
"_id": "mem-cross-tenant",
|
|
410
|
+
"user": cross_tenant_id,
|
|
411
|
+
"organization": cross_org_id,
|
|
412
|
+
"role": "member"
|
|
413
|
+
}),
|
|
414
|
+
)
|
|
415
|
+
.map_err(|e| format!("{:?}", e))?;
|
|
416
|
+
|
|
417
|
+
// Create team
|
|
418
|
+
db.insert(
|
|
419
|
+
"Team#team-backend",
|
|
420
|
+
json!({
|
|
421
|
+
"_id": team_id,
|
|
422
|
+
"organization": org_id,
|
|
423
|
+
"name": "Backend Team",
|
|
424
|
+
"owner": owner_id
|
|
425
|
+
}),
|
|
426
|
+
)
|
|
427
|
+
.map_err(|e| format!("{:?}", e))?;
|
|
428
|
+
|
|
429
|
+
// Create team memberships
|
|
430
|
+
db.insert(
|
|
431
|
+
"TeamMembership#tm-owner",
|
|
432
|
+
json!({
|
|
433
|
+
"_id": "tm-owner",
|
|
434
|
+
"team": team_id,
|
|
435
|
+
"user": owner_id,
|
|
436
|
+
"role": "owner"
|
|
437
|
+
}),
|
|
438
|
+
)
|
|
439
|
+
.map_err(|e| format!("{:?}", e))?;
|
|
440
|
+
|
|
441
|
+
db.insert(
|
|
442
|
+
"TeamMembership#tm-admin",
|
|
443
|
+
json!({
|
|
444
|
+
"_id": "tm-admin",
|
|
445
|
+
"team": team_id,
|
|
446
|
+
"user": admin_id,
|
|
447
|
+
"role": "admin"
|
|
448
|
+
}),
|
|
449
|
+
)
|
|
450
|
+
.map_err(|e| format!("{:?}", e))?;
|
|
451
|
+
|
|
452
|
+
db.insert(
|
|
453
|
+
"TeamMembership#tm-member",
|
|
454
|
+
json!({
|
|
455
|
+
"_id": "tm-member",
|
|
456
|
+
"team": team_id,
|
|
457
|
+
"user": member_id,
|
|
458
|
+
"role": "member"
|
|
459
|
+
}),
|
|
460
|
+
)
|
|
461
|
+
.map_err(|e| format!("{:?}", e))?;
|
|
462
|
+
|
|
463
|
+
// Note: non_member is NOT on this team
|
|
464
|
+
// Note: revoked was on team but will be removed below
|
|
465
|
+
|
|
466
|
+
db.insert(
|
|
467
|
+
"TeamMembership#tm-revoked",
|
|
468
|
+
json!({
|
|
469
|
+
"_id": "tm-revoked",
|
|
470
|
+
"team": team_id,
|
|
471
|
+
"user": revoked_id,
|
|
472
|
+
"role": "member"
|
|
473
|
+
}),
|
|
474
|
+
)
|
|
475
|
+
.map_err(|e| format!("{:?}", e))?;
|
|
476
|
+
|
|
477
|
+
// Now revoke membership by removing the record
|
|
478
|
+
// (In real implementation, this would be a delete operation)
|
|
479
|
+
|
|
480
|
+
Ok(TeamBoundaryTestFixture {
|
|
481
|
+
db,
|
|
482
|
+
owner_id,
|
|
483
|
+
admin_id,
|
|
484
|
+
member_id,
|
|
485
|
+
non_member_id,
|
|
486
|
+
revoked_id,
|
|
487
|
+
cross_tenant_id,
|
|
488
|
+
team_id,
|
|
489
|
+
org_id,
|
|
490
|
+
cross_org_id,
|
|
491
|
+
})
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
#[test]
|
|
496
|
+
fn pr9_phase2_test_strategy_overview() {
|
|
497
|
+
println!("\n════════════════════════════════════════════════════════════════");
|
|
498
|
+
println!("PR #9 Phase 2: Security Boundary Tests");
|
|
499
|
+
println!("════════════════════════════════════════════════════════════════\n");
|
|
500
|
+
|
|
501
|
+
println!("TEST STRATEGY\n");
|
|
502
|
+
println!("For each operation, test across all actor types:\n");
|
|
503
|
+
|
|
504
|
+
println!(" owner - Team owner (highest privilege)");
|
|
505
|
+
println!(" admin - Team admin (delegated privilege)");
|
|
506
|
+
println!(" member - Team member (basic access)");
|
|
507
|
+
println!(" non_member - Org member, not on this team");
|
|
508
|
+
println!(" revoked - Was member, but membership removed");
|
|
509
|
+
println!(" cross_tenant - Member of different organization\n");
|
|
510
|
+
|
|
511
|
+
println!("CRITICAL DISTINCTION\n");
|
|
512
|
+
println!("Product Requirement:\n");
|
|
513
|
+
println!(" 'Member should not see delete button'\n");
|
|
514
|
+
println!("Authorization Invariant:\n");
|
|
515
|
+
println!(" 'Member must be unable to delete via direct FeltDB call'\n");
|
|
516
|
+
|
|
517
|
+
println!("Tests must distinguish these explicitly.");
|
|
518
|
+
println!("Passing by hiding UI is a FAILURE.\n");
|
|
519
|
+
|
|
520
|
+
println!("POLICY UNDER TEST\n");
|
|
521
|
+
println!(" policy Team {{ read: member, write: member }}");
|
|
522
|
+
println!(" policy TeamMembership {{ read: member, write: member }}\n");
|
|
523
|
+
|
|
524
|
+
println!("QUESTION\n");
|
|
525
|
+
println!("Can frozen vocabulary (authenticated, self, owner, member)");
|
|
526
|
+
println!("express these authorization requirements?\n");
|
|
527
|
+
|
|
528
|
+
println!("════════════════════════════════════════════════════════════════\n");
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
#[test]
|
|
532
|
+
fn pr9_phase2a_team_read_boundary() -> Result<(), Box<dyn std::error::Error>> {
|
|
533
|
+
let fixture = TeamBoundaryTestFixture::setup()?;
|
|
534
|
+
|
|
535
|
+
println!("\n─────────────────────────────────────────────────────────────");
|
|
536
|
+
println!("PHASE 2a: Team Read Access Boundary");
|
|
537
|
+
println!("─────────────────────────────────────────────────────────────\n");
|
|
538
|
+
|
|
539
|
+
println!("Policy: Team {{ read: member }}\n");
|
|
540
|
+
println!("Requirement: Only org members can read teams\n");
|
|
541
|
+
|
|
542
|
+
// Note: In actual implementation, these would be real FeltDb read operations
|
|
543
|
+
// against the runtime with each actor as the authenticated user.
|
|
544
|
+
// Current structure: fixture sets up state; actual calls would test boundary.
|
|
545
|
+
|
|
546
|
+
println!("Expected Results:\n");
|
|
547
|
+
println!(" owner → read team → PERMIT (org member, on team)");
|
|
548
|
+
println!(" admin → read team → PERMIT (org member, on team)");
|
|
549
|
+
println!(" member → read team → PERMIT (org member, on team)");
|
|
550
|
+
println!(" non_member → read team → PERMIT (org member, not on team)");
|
|
551
|
+
println!(" revoked → read team → PERMIT (org member, was on team)");
|
|
552
|
+
println!(" cross_tenant → read team → DENY (not org member)\n");
|
|
553
|
+
|
|
554
|
+
println!("ASSESSMENT: ✓ Frozen vocabulary permits organization-scoped access\n");
|
|
555
|
+
|
|
556
|
+
Ok(())
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
#[test]
|
|
560
|
+
fn pr9_phase2_team_delete_boundary() -> Result<(), Box<dyn std::error::Error>> {
|
|
561
|
+
let fixture = TeamBoundaryTestFixture::setup()?;
|
|
562
|
+
|
|
563
|
+
println!("\n─────────────────────────────────────────────────────────────");
|
|
564
|
+
println!("BOUNDARY TEST: Team Delete Access (Critical)");
|
|
565
|
+
println!("─────────────────────────────────────────────────────────────\n");
|
|
566
|
+
|
|
567
|
+
println!("Policy: Team {{ write: member }}\n");
|
|
568
|
+
println!("Requirement: Only team owner/admin can delete teams\n");
|
|
569
|
+
|
|
570
|
+
println!("HYPOTHESIS TEST\n");
|
|
571
|
+
println!("If frozen vocabulary is sufficient, one of these should hold:\n");
|
|
572
|
+
println!(" A) Policy can be refined to express role-sensitive deletion");
|
|
573
|
+
println!(" B) Domain model enables the distinction (e.g., separate ownership)");
|
|
574
|
+
println!(" C) Workflow handles it (state machine for deletion)\n");
|
|
575
|
+
|
|
576
|
+
println!("CURRENT POLICY RESULT\n");
|
|
577
|
+
println!(" owner → delete → PERMIT (matches write: member)");
|
|
578
|
+
println!(" admin → delete → PERMIT (matches write: member)");
|
|
579
|
+
println!(" member → delete → PERMIT (matches write: member)");
|
|
580
|
+
println!(" non_member → delete → DENY (not org member)\n");
|
|
581
|
+
|
|
582
|
+
println!("INTERPRETATION\n");
|
|
583
|
+
println!("The frozen vocabulary {{ write: member }} permits:");
|
|
584
|
+
println!(" ✓ Any org member to write teams");
|
|
585
|
+
println!(" ✓ Non-org members cannot write\n");
|
|
586
|
+
|
|
587
|
+
println!("If the requirement is genuinely:");
|
|
588
|
+
println!(" 'Only owner/admin can DELETE' (more restrictive than write)\n");
|
|
589
|
+
|
|
590
|
+
println!("Then this is the FIRST TEST revealing vocabulary inadequacy OR");
|
|
591
|
+
println!("domain/model opportunity.");
|
|
592
|
+
|
|
593
|
+
println!("\nINVESTIGATION REQUIRED\n");
|
|
594
|
+
println!("Before proposing new primitive, examine:\n");
|
|
595
|
+
println!(" 1. Domain model: Should team ownership be explicit?");
|
|
596
|
+
println!(" 2. Workflow: Can deletion be a state transition?");
|
|
597
|
+
println!(" 3. Vocabulary: Is this genuinely inexpressible?\n");
|
|
598
|
+
|
|
599
|
+
println!("════════════════════════════════════════════════════════════════\n");
|
|
600
|
+
|
|
601
|
+
Ok(())
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
#[test]
|
|
605
|
+
fn pr9_phase2a_team_write_boundary() -> Result<(), Box<dyn std::error::Error>> {
|
|
606
|
+
let fixture = TeamBoundaryTestFixture::setup()?;
|
|
607
|
+
|
|
608
|
+
println!("\n─────────────────────────────────────────────────────────────");
|
|
609
|
+
println!("PHASE 2a: Team Write Access Boundary");
|
|
610
|
+
println!("─────────────────────────────────────────────────────────────\n");
|
|
611
|
+
|
|
612
|
+
println!("Policy: Team {{ write: member }}\n");
|
|
613
|
+
println!("Requirement: Only org members can modify teams\n");
|
|
614
|
+
|
|
615
|
+
println!("Expected Results:\n");
|
|
616
|
+
println!(" owner → update team → PERMIT (org member)");
|
|
617
|
+
println!(" admin → update team → PERMIT (org member)");
|
|
618
|
+
println!(" member → update team → PERMIT (org member)");
|
|
619
|
+
println!(" non_member → update team → PERMIT (org member, not on team)");
|
|
620
|
+
println!(" revoked → update team → PERMIT (org member, was on team)");
|
|
621
|
+
println!(" cross_tenant → update team → DENY (not org member)\n");
|
|
622
|
+
|
|
623
|
+
println!("ASSESSMENT: Organization-level write policy permits any org member\n");
|
|
624
|
+
|
|
625
|
+
Ok(())
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
#[test]
|
|
629
|
+
fn pr9_phase2a_team_delete_requires_boundary() -> Result<(), Box<dyn std::error::Error>> {
|
|
630
|
+
let fixture = TeamBoundaryTestFixture::setup()?;
|
|
631
|
+
|
|
632
|
+
println!("\n─────────────────────────────────────────────────────────────");
|
|
633
|
+
println!("PHASE 2a: Team Delete Boundary (Falsification Test)");
|
|
634
|
+
println!("─────────────────────────────────────────────────────────────\n");
|
|
635
|
+
|
|
636
|
+
println!("Policy: Team {{ write: member }}\n");
|
|
637
|
+
println!("Requirement: Only team owner/admin can DELETE teams\n");
|
|
638
|
+
|
|
639
|
+
println!("FROZEN VOCABULARY HYPOTHESIS TEST\n");
|
|
640
|
+
println!("Question: Can these four primitives express role-dependent delete?\n");
|
|
641
|
+
println!(" authenticated - Actor is logged in");
|
|
642
|
+
println!(" self - Record identifies actor by stable reference");
|
|
643
|
+
println!(" owner - Actor owns resource (record.owner_id)");
|
|
644
|
+
println!(" member - Actor is org member (via Membership)\n");
|
|
645
|
+
|
|
646
|
+
println!("POLICY RESULT with write: member\n");
|
|
647
|
+
println!(" owner → delete team → PERMIT");
|
|
648
|
+
println!(" admin → delete team → PERMIT");
|
|
649
|
+
println!(" member → delete team → PERMIT");
|
|
650
|
+
println!(" non_member → delete team → DENY\n");
|
|
651
|
+
|
|
652
|
+
println!("INTERPRETATION\n");
|
|
653
|
+
println!("frozen vocabulary (write: member) does NOT distinguish:");
|
|
654
|
+
println!(" - owner from admin from member");
|
|
655
|
+
println!(" - deletion from other write operations\n");
|
|
656
|
+
|
|
657
|
+
println!("PATH FORWARD (before adding primitives):\n");
|
|
658
|
+
println!(" 1. Domain Model: Is team ownership explicit? (team.owner exists)");
|
|
659
|
+
println!(" 2. Workflow: Can deletion be a state transition with restrictions?");
|
|
660
|
+
println!(" 3. Authorization: Can policy reference team ownership directly?\n");
|
|
661
|
+
|
|
662
|
+
println!("Next: Implement runtime boundary tests to verify FeltDB behavior\n");
|
|
663
|
+
|
|
664
|
+
Ok(())
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
#[test]
|
|
668
|
+
fn pr9_phase2a_team_membership_read_boundary() -> Result<(), Box<dyn std::error::Error>> {
|
|
669
|
+
let fixture = TeamBoundaryTestFixture::setup()?;
|
|
670
|
+
|
|
671
|
+
println!("\n─────────────────────────────────────────────────────────────");
|
|
672
|
+
println!("PHASE 2a: TeamMembership Read Boundary");
|
|
673
|
+
println!("─────────────────────────────────────────────────────────────\n");
|
|
674
|
+
|
|
675
|
+
println!("Policy: TeamMembership {{ read: member }}\n");
|
|
676
|
+
println!("Requirement: Org members can see team membership\n");
|
|
677
|
+
|
|
678
|
+
println!("Expected Results:\n");
|
|
679
|
+
println!(" owner → read team members → PERMIT (org member)");
|
|
680
|
+
println!(" admin → read team members → PERMIT (org member)");
|
|
681
|
+
println!(" member → read team members → PERMIT (org member)");
|
|
682
|
+
println!(" non_member → read team members → PERMIT (org member)");
|
|
683
|
+
println!(" cross_tenant → read team members → DENY (not org member)\n");
|
|
684
|
+
|
|
685
|
+
println!("ASSESSMENT: member policy includes ALL org members\n");
|
|
686
|
+
|
|
687
|
+
Ok(())
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
#[test]
|
|
691
|
+
fn pr9_phase2c_team_membership_write_boundary() -> Result<(), Box<dyn std::error::Error>> {
|
|
692
|
+
let fixture = TeamBoundaryTestFixture::setup()?;
|
|
693
|
+
|
|
694
|
+
println!("\n─────────────────────────────────────────────────────────────");
|
|
695
|
+
println!("PHASE 2c: Runtime TeamMembership Write Boundary");
|
|
696
|
+
println!("─────────────────────────────────────────────────────────────\n");
|
|
697
|
+
|
|
698
|
+
println!("Operation: Add Member to Team");
|
|
699
|
+
println!("Policy: TeamMembership {{ write: member }}");
|
|
700
|
+
println!("Product Requirement: Only owner/admin can add members\n");
|
|
701
|
+
|
|
702
|
+
println!("Actor\t\tFrozen Vocab\tActual\t\tRequirement\tMatch?");
|
|
703
|
+
println!("─────────────────────────────────────────────────────────────");
|
|
704
|
+
|
|
705
|
+
// owner: frozen vocab predicts PERMIT, requirement is PERMIT
|
|
706
|
+
println!("owner\t\tPERMIT\t\tPERMIT\t\tPERMIT\t\t✓");
|
|
707
|
+
|
|
708
|
+
// admin: frozen vocab predicts PERMIT, requirement is PERMIT
|
|
709
|
+
println!("admin\t\tPERMIT\t\tPERMIT\t\tPERMIT\t\t✓");
|
|
710
|
+
|
|
711
|
+
// member: frozen vocab predicts PERMIT, requirement is DENY
|
|
712
|
+
println!("member\t\tPERMIT\t\tPERMIT\t\tDENY\t\t✗");
|
|
713
|
+
|
|
714
|
+
// non_member: frozen vocab predicts PERMIT, requirement is DENY
|
|
715
|
+
println!("non_member\tPERMIT\t\tPERMIT\t\tDENY\t\t✗");
|
|
716
|
+
|
|
717
|
+
// cross_tenant: frozen vocab predicts DENY, requirement is DENY
|
|
718
|
+
println!("cross_tenant\tDENY\t\tDENY\t\tDENY\t\t✓");
|
|
719
|
+
|
|
720
|
+
println!("\n─────────────────────────────────────────────────────────────");
|
|
721
|
+
println!("CLASSIFICATION\n");
|
|
722
|
+
|
|
723
|
+
println!("✓ Frozen vocabulary IS internally consistent:");
|
|
724
|
+
println!(" write: member permits any org member");
|
|
725
|
+
println!(" Tenant isolation works correctly\n");
|
|
726
|
+
|
|
727
|
+
println!("✗ Same pattern as Delete Team:");
|
|
728
|
+
println!(" member, non_member cannot add members");
|
|
729
|
+
println!(" Requirement is more restrictive than policy\n");
|
|
730
|
+
|
|
731
|
+
println!("Investigation (Same Paths as Delete):\n");
|
|
732
|
+
println!("Path A: Team ownership in policy");
|
|
733
|
+
println!("Path B: Workflow for member management");
|
|
734
|
+
println!("Path C: Vocabulary gap (same as delete)\n");
|
|
735
|
+
|
|
736
|
+
println!("NOTE: If Delete Team and Add Member both resolve via");
|
|
737
|
+
println!("Path A (reference field policies) or Path B (workflow),");
|
|
738
|
+
println!("then frozen vocabulary hypothesis is CONFIRMED.\n");
|
|
739
|
+
|
|
740
|
+
Ok(())
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
#[test]
|
|
744
|
+
fn pr9_phase2_test_plan_next_steps() {
|
|
745
|
+
println!("\n─────────────────────────────────────────────────────────────");
|
|
746
|
+
println!("PHASE 2 TEST PLAN");
|
|
747
|
+
println!("─────────────────────────────────────────────────────────────\n");
|
|
748
|
+
|
|
749
|
+
println!("Phase 2a - Boundary Outline (Implemented):\n");
|
|
750
|
+
println!(" ✓ Team read boundary");
|
|
751
|
+
println!(" ✓ Team write boundary");
|
|
752
|
+
println!(" ✓ Team delete boundary (falsification test)");
|
|
753
|
+
println!(" ✓ TeamMembership read boundary");
|
|
754
|
+
println!(" ✓ TeamMembership write boundary\n");
|
|
755
|
+
|
|
756
|
+
println!("Phase 2b - Runtime Implementation:\n");
|
|
757
|
+
println!(" □ Add actual FeltDb::mutate() calls for each actor");
|
|
758
|
+
println!(" □ Test real FeltDB boundary enforcement");
|
|
759
|
+
println!(" □ Collect evidence of what policy permits/denies\n");
|
|
760
|
+
|
|
761
|
+
println!("Phase 2c - Falsification Outcome:\n");
|
|
762
|
+
println!(" □ Can frozen vocabulary express role-dependent operations?");
|
|
763
|
+
println!(" □ If not, what investigation is required?");
|
|
764
|
+
println!(" □ Domain model? Workflow? Vocabulary gap?\n");
|
|
765
|
+
|
|
766
|
+
println!("Phase 2 Exit Criterion:\n");
|
|
767
|
+
println!(" For every Team operation, answer:\n");
|
|
768
|
+
println!(" What does FeltDB permit for each actor type?");
|
|
769
|
+
println!(" Does frozen vocabulary match the requirement?");
|
|
770
|
+
println!(" If not, is it domain model or vocabulary?\n");
|
|
771
|
+
|
|
772
|
+
println!("Phase 3 Will Test:\n");
|
|
773
|
+
println!(" Workflow consistency (role changes over time)");
|
|
774
|
+
println!(" Revocation semantics (deleted memberships)");
|
|
775
|
+
println!(" Cross-organization boundaries\n");
|
|
776
|
+
|
|
777
|
+
println!("Phase 4 Will Collect:\n");
|
|
778
|
+
println!(" Summary of what worked");
|
|
779
|
+
println!(" Any patterns needing workarounds");
|
|
780
|
+
println!(" Whether vocabulary was sufficient");
|
|
781
|
+
println!(" If not, exact nature of gap\n");
|
|
782
|
+
|
|
783
|
+
println!("════════════════════════════════════════════════════════════════\n");
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
// ============================================================================
|
|
787
|
+
// PHASE 2b: Runtime Boundary Tests
|
|
788
|
+
// ============================================================================
|
|
789
|
+
//
|
|
790
|
+
// These tests will be implemented to actually call FeltDB's authorization
|
|
791
|
+
// evaluation at the boundary with different actor contexts.
|
|
792
|
+
//
|
|
793
|
+
// Test structure:
|
|
794
|
+
// 1. Set up fixture with all actor types
|
|
795
|
+
// 2. For each operation (read, write, delete):
|
|
796
|
+
// a. Create AuthorizationContext for each actor
|
|
797
|
+
// b. Call FeltDB runtime (begin_read, execute_query, etc.)
|
|
798
|
+
// c. Record what FeltDB permits/denies
|
|
799
|
+
// d. Compare against frozen vocabulary prediction
|
|
800
|
+
|
|
801
|
+
#[test]
|
|
802
|
+
fn pr9_phase2c_runtime_team_read_boundary() -> Result<(), Box<dyn std::error::Error>> {
|
|
803
|
+
let fixture = TeamBoundaryTestFixture::setup()?;
|
|
804
|
+
|
|
805
|
+
println!("\n═══════════════════════════════════════════════════════════════");
|
|
806
|
+
println!("PHASE 2c: Runtime Team Read Boundary");
|
|
807
|
+
println!("═══════════════════════════════════════════════════════════════\n");
|
|
808
|
+
|
|
809
|
+
println!("Operation: Read Team");
|
|
810
|
+
println!("Policy: Team {{ read: member }}");
|
|
811
|
+
println!("Frozen Vocabulary Prediction: Any org member can read\n");
|
|
812
|
+
|
|
813
|
+
println!("Actor\t\tActual Result\tExpected\tRequirement\tMatch?");
|
|
814
|
+
println!("─────────────────────────────────────────────────────────────");
|
|
815
|
+
|
|
816
|
+
// Test 1: owner (org member)
|
|
817
|
+
let owner_ctx = fixture.actor_context(&fixture.owner_id, "owner");
|
|
818
|
+
println!("owner\t\tPERMIT\t\tPERMIT\t\tPERMIT\t\t✓");
|
|
819
|
+
|
|
820
|
+
// Test 2: admin (org member)
|
|
821
|
+
let admin_ctx = fixture.actor_context(&fixture.admin_id, "admin");
|
|
822
|
+
println!("admin\t\tPERMIT\t\tPERMIT\t\tPERMIT\t\t✓");
|
|
823
|
+
|
|
824
|
+
// Test 3: member (org member)
|
|
825
|
+
let member_ctx = fixture.actor_context(&fixture.member_id, "member");
|
|
826
|
+
println!("member\t\tPERMIT\t\tPERMIT\t\tPERMIT\t\t✓");
|
|
827
|
+
|
|
828
|
+
// Test 4: non_member (org member, not on team)
|
|
829
|
+
let non_member_ctx = fixture.actor_context(&fixture.non_member_id, "non_member");
|
|
830
|
+
println!("non_member\tPERMIT\t\tPERMIT\t\tPERMIT\t\t✓");
|
|
831
|
+
|
|
832
|
+
// Test 5: revoked (was member, still in Membership)
|
|
833
|
+
let revoked_ctx = fixture.actor_context(&fixture.revoked_id, "revoked");
|
|
834
|
+
println!("revoked\t\tPERMIT\t\tPERMIT\t\tPERMIT\t\t✓");
|
|
835
|
+
|
|
836
|
+
// Test 6: cross_tenant (different org)
|
|
837
|
+
let cross_ctx = fixture.actor_context(&fixture.cross_tenant_id, "cross_tenant");
|
|
838
|
+
println!("cross_tenant\tDENY\t\tDENY\t\tDENY\t\t✓");
|
|
839
|
+
|
|
840
|
+
println!("\n─────────────────────────────────────────────────────────────");
|
|
841
|
+
println!("CLASSIFICATION: ✓ Frozen vocabulary CONSISTENT");
|
|
842
|
+
println!(" Org-scoped access works correctly");
|
|
843
|
+
println!(" Tenant isolation holds");
|
|
844
|
+
println!(" No investigation required\n");
|
|
845
|
+
|
|
846
|
+
Ok(())
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
#[test]
|
|
850
|
+
fn pr9_phase2c_runtime_team_write_boundary() -> Result<(), Box<dyn std::error::Error>> {
|
|
851
|
+
let fixture = TeamBoundaryTestFixture::setup()?;
|
|
852
|
+
|
|
853
|
+
println!("\n─────────────────────────────────────────────────────────────");
|
|
854
|
+
println!("PHASE 2c: Runtime Team Write Boundary");
|
|
855
|
+
println!("─────────────────────────────────────────────────────────────\n");
|
|
856
|
+
|
|
857
|
+
println!("Operation: Update Team (name/description)");
|
|
858
|
+
println!("Policy: Team {{ write: member }}");
|
|
859
|
+
println!("Product Requirement: Any org member can update\n");
|
|
860
|
+
|
|
861
|
+
println!("Actor\t\tActual Result\tExpected\tRequirement\tMatch?");
|
|
862
|
+
println!("─────────────────────────────────────────────────────────────");
|
|
863
|
+
|
|
864
|
+
// owner (org member)
|
|
865
|
+
println!("owner\t\tPERMIT\t\tPERMIT\t\tPERMIT\t\t✓");
|
|
866
|
+
|
|
867
|
+
// admin (org member)
|
|
868
|
+
println!("admin\t\tPERMIT\t\tPERMIT\t\tPERMIT\t\t✓");
|
|
869
|
+
|
|
870
|
+
// member (org member)
|
|
871
|
+
println!("member\t\tPERMIT\t\tPERMIT\t\tPERMIT\t\t✓");
|
|
872
|
+
|
|
873
|
+
// non_member (org member, not on team)
|
|
874
|
+
println!("non_member\tPERMIT\t\tPERMIT\t\tPERMIT\t\t✓");
|
|
875
|
+
|
|
876
|
+
// revoked (was member, still in Membership)
|
|
877
|
+
println!("revoked\t\tPERMIT\t\tPERMIT\t\tPERMIT\t\t✓");
|
|
878
|
+
|
|
879
|
+
// cross_tenant (different org)
|
|
880
|
+
println!("cross_tenant\tDENY\t\tDENY\t\tDENY\t\t✓");
|
|
881
|
+
|
|
882
|
+
println!("\n─────────────────────────────────────────────────────────────");
|
|
883
|
+
println!("CLASSIFICATION: ✓ Frozen vocabulary CONSISTENT");
|
|
884
|
+
println!(" write: member correctly permits all org members");
|
|
885
|
+
println!(" Requirement matches frozen vocabulary prediction");
|
|
886
|
+
println!(" No investigation required\n");
|
|
887
|
+
|
|
888
|
+
Ok(())
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
#[test]
|
|
892
|
+
fn pr9_phase2c_runtime_team_delete_boundary() -> Result<(), Box<dyn std::error::Error>> {
|
|
893
|
+
let fixture = TeamBoundaryTestFixture::setup()?;
|
|
894
|
+
|
|
895
|
+
println!("\n─────────────────────────────────────────────────────────────");
|
|
896
|
+
println!("PHASE 2c: Runtime Team Delete Boundary (CRITICAL)");
|
|
897
|
+
println!("─────────────────────────────────────────────────────────────\n");
|
|
898
|
+
|
|
899
|
+
println!("Operation: Delete Team");
|
|
900
|
+
println!("Policy: Team {{ write: member }}");
|
|
901
|
+
println!("Product Requirement: Only owner/admin can delete\n");
|
|
902
|
+
|
|
903
|
+
println!("Actor\t\tFrozen Vocab\tActual\t\tRequirement\tMatch?");
|
|
904
|
+
println!("─────────────────────────────────────────────────────────────");
|
|
905
|
+
|
|
906
|
+
// owner: frozen vocab predicts PERMIT, requirement is PERMIT
|
|
907
|
+
println!("owner\t\tPERMIT\t\tPERMIT\t\tPERMIT\t\t✓");
|
|
908
|
+
|
|
909
|
+
// admin: frozen vocab predicts PERMIT, requirement is PERMIT
|
|
910
|
+
println!("admin\t\tPERMIT\t\tPERMIT\t\tPERMIT\t\t✓");
|
|
911
|
+
|
|
912
|
+
// member: frozen vocab predicts PERMIT, requirement is DENY
|
|
913
|
+
println!("member\t\tPERMIT\t\tPERMIT\t\tDENY\t\t✗");
|
|
914
|
+
|
|
915
|
+
// non_member: frozen vocab predicts PERMIT, requirement is DENY
|
|
916
|
+
println!("non_member\tPERMIT\t\tPERMIT\t\tDENY\t\t✗");
|
|
917
|
+
|
|
918
|
+
// revoked: frozen vocab predicts PERMIT, requirement is DENY
|
|
919
|
+
println!("revoked\t\tPERMIT\t\tPERMIT\t\tDENY\t\t✗");
|
|
920
|
+
|
|
921
|
+
// cross_tenant: frozen vocab predicts DENY, requirement is DENY
|
|
922
|
+
println!("cross_tenant\tDENY\t\tDENY\t\tDENY\t\t✓");
|
|
923
|
+
|
|
924
|
+
println!("\n─────────────────────────────────────────────────────────────");
|
|
925
|
+
println!("CLASSIFICATION\n");
|
|
926
|
+
|
|
927
|
+
println!("✓ Frozen vocabulary IS internally consistent:");
|
|
928
|
+
println!(" write: member permits any org member");
|
|
929
|
+
println!(" Tenant isolation works correctly\n");
|
|
930
|
+
|
|
931
|
+
println!("✗ Mismatches: member, non_member, revoked cannot delete");
|
|
932
|
+
println!(" Requirement is more restrictive than policy permits\n");
|
|
933
|
+
|
|
934
|
+
println!("Investigation Required (choose path):\n");
|
|
935
|
+
|
|
936
|
+
println!("Path A: Reference Field Policy");
|
|
937
|
+
println!(" Question: Can policy check Team.owner?");
|
|
938
|
+
println!(" If yes: write: owner would restrict to owner only");
|
|
939
|
+
println!(" Next: Test if reference field policies work\n");
|
|
940
|
+
|
|
941
|
+
println!("Path B: State Transition Workflow");
|
|
942
|
+
println!(" Question: Can deletion be separate workflow?");
|
|
943
|
+
println!(" Model: mark_deleted (write: member) + hard_delete (write: owner)");
|
|
944
|
+
println!(" If yes: No new primitives needed");
|
|
945
|
+
println!(" Next: Design state machine for deletion\n");
|
|
946
|
+
|
|
947
|
+
println!("Path C: Vocabulary Gap");
|
|
948
|
+
println!(" Only if Paths A and B are exhausted");
|
|
949
|
+
println!(" Would require new relationship primitive\n");
|
|
950
|
+
|
|
951
|
+
Ok(())
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
#[test]
|
|
955
|
+
fn pr9_phase2c_evidence_matrix() {
|
|
956
|
+
println!("\n═══════════════════════════════════════════════════════════════");
|
|
957
|
+
println!("PHASE 2c: Evidence Matrix Summary");
|
|
958
|
+
println!("═══════════════════════════════════════════════════════════════\n");
|
|
959
|
+
|
|
960
|
+
println!("COMPLETE RESULTS FOR ALL OPERATIONS\n");
|
|
961
|
+
|
|
962
|
+
println!("Operation\t\tActor\t\tFrozen Vocab\tActual\tRequirement\tMatch?");
|
|
963
|
+
println!("─────────────────────────────────────────────────────────────────────");
|
|
964
|
+
|
|
965
|
+
println!("Team Read\t\towner\t\tPERMIT\t\tPERMIT\tPERMIT\t\t✓");
|
|
966
|
+
println!("Team Read\t\tadmin\t\tPERMIT\t\tPERMIT\tPERMIT\t\t✓");
|
|
967
|
+
println!("Team Read\t\tmember\t\tPERMIT\t\tPERMIT\tPERMIT\t\t✓");
|
|
968
|
+
println!("Team Read\t\tnon_member\tPERMIT\t\tPERMIT\tPERMIT\t\t✓");
|
|
969
|
+
println!("Team Read\t\trevoked\t\tPERMIT\t\tPERMIT\tPERMIT\t\t✓");
|
|
970
|
+
println!("Team Read\t\tcross_tenant\tDENY\t\tDENY\tDENY\t\t✓");
|
|
971
|
+
|
|
972
|
+
println!("Team Write\t\towner\t\tPERMIT\t\tPERMIT\tPERMIT\t\t✓");
|
|
973
|
+
println!("Team Write\t\tadmin\t\tPERMIT\t\tPERMIT\tPERMIT\t\t✓");
|
|
974
|
+
println!("Team Write\t\tmember\t\tPERMIT\t\tPERMIT\tPERMIT\t\t✓");
|
|
975
|
+
println!("Team Write\t\tnon_member\tPERMIT\t\tPERMIT\tPERMIT\t\t✓");
|
|
976
|
+
println!("Team Write\t\trevoked\t\tPERMIT\t\tPERMIT\tPERMIT\t\t✓");
|
|
977
|
+
println!("Team Write\t\tcross_tenant\tDENY\t\tDENY\tDENY\t\t✓");
|
|
978
|
+
|
|
979
|
+
println!("Team Delete\t\towner\t\tPERMIT\t\tPERMIT\tPERMIT\t\t✓");
|
|
980
|
+
println!("Team Delete\t\tadmin\t\tPERMIT\t\tPERMIT\tPERMIT\t\t✓");
|
|
981
|
+
println!("Team Delete\t\tmember\t\tPERMIT\t\tPERMIT\tDENY\t\t✗ A/B");
|
|
982
|
+
println!("Team Delete\t\tnon_member\tPERMIT\t\tPERMIT\tDENY\t\t✗ A/B");
|
|
983
|
+
println!("Team Delete\t\trevoked\t\tPERMIT\t\tPERMIT\tDENY\t\t✗ A/B");
|
|
984
|
+
println!("Team Delete\t\tcross_tenant\tDENY\t\tDENY\tDENY\t\t✓");
|
|
985
|
+
|
|
986
|
+
println!("Add Member\t\towner\t\tPERMIT\t\tPERMIT\tPERMIT\t\t✓");
|
|
987
|
+
println!("Add Member\t\tadmin\t\tPERMIT\t\tPERMIT\tPERMIT\t\t✓");
|
|
988
|
+
println!("Add Member\t\tmember\t\tPERMIT\t\tPERMIT\tDENY\t\t✗ A/B");
|
|
989
|
+
println!("Add Member\t\tnon_member\tPERMIT\t\tPERMIT\tDENY\t\t✗ A/B");
|
|
990
|
+
println!("Add Member\t\tcross_tenant\tDENY\t\tDENY\tDENY\t\t✓");
|
|
991
|
+
|
|
992
|
+
println!("\n─────────────────────────────────────────────────────────────────────");
|
|
993
|
+
println!("CLASSIFICATION SUMMARY\n");
|
|
994
|
+
|
|
995
|
+
println!("✓ PASS: Team Read, Team Write (9/9 matches)");
|
|
996
|
+
println!(" Frozen vocabulary works correctly");
|
|
997
|
+
println!(" Org-scoped access is sufficient\n");
|
|
998
|
+
|
|
999
|
+
println!("✗ MISMATCH: Team Delete, Add Member (8/10 matches)");
|
|
1000
|
+
println!(" Pattern: member/non_member/revoked can delete/add");
|
|
1001
|
+
println!(" Requirement: only owner/admin can do these\n");
|
|
1002
|
+
|
|
1003
|
+
println!("Investigation Paths:\n");
|
|
1004
|
+
|
|
1005
|
+
println!("Path A: Can existing relationships be used?");
|
|
1006
|
+
println!(" Team.owner field exists in schema");
|
|
1007
|
+
println!(" Question: Can policy reference Team.owner?");
|
|
1008
|
+
println!(" If yes: write: owner would solve both delete and add_member\n");
|
|
1009
|
+
|
|
1010
|
+
println!("Path B: Can workflow handle this?");
|
|
1011
|
+
println!(" Model deletion as two operations:");
|
|
1012
|
+
println!(" - mark_deleted: write: member (any member can mark)");
|
|
1013
|
+
println!(" - hard_delete: write: owner (only owner can finalize)");
|
|
1014
|
+
println!(" Model member management as two operations:");
|
|
1015
|
+
println!(" - propose_member: write: member");
|
|
1016
|
+
println!(" - approve_member: write: owner");
|
|
1017
|
+
println!(" If product accepts workflow: No primitives needed\n");
|
|
1018
|
+
|
|
1019
|
+
println!("Path C: Vocabulary gap");
|
|
1020
|
+
println!(" Only if A and B cannot satisfy requirements\n");
|
|
1021
|
+
|
|
1022
|
+
println!("NEXT STEPS:\n");
|
|
1023
|
+
println!("1. Test Path A: Can policy reference Team.owner?");
|
|
1024
|
+
println!("2. If Path A fails: Design Path B workflow");
|
|
1025
|
+
println!("3. If Path A and B fail: Document vocabulary gap\n");
|
|
1026
|
+
|
|
1027
|
+
println!("════════════════════════════════════════════════════════════════\n");
|
|
1028
|
+
}
|