diff options
| author | tv <tv@krebsco.de> | 2026-11-16 02:15:23 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-16 02:15:23 +0000 |
| commit | f37d2941415e12bc435265862e3fbdeec3206bd7 (patch) | |
| tree | 969c552cf8afc59347ec8af221e28d233f3c373f /src | |
| parent | ec96187b9cfa86a0f66208d15c80bacecce42fb3 (diff) | |
state: a strict policy written where none judges, refused before it leaves
Every node refuses a change writing a strict policy where the policy
isn't strict (`rules::turns_strict`), whatever the policy before. But a
node judges its own changes before they leave (`judged_here`) only
under a policy judging every change: in a swarm without one, a strict
policy written through its API was taken there and refused by every
other node, with everything the node built on it.
A change that leaves a policy where there was none to judge it is
judged as every node will judge it, too. A change in a swarm that has no
policy after it is judged by none, as before.
Diffstat (limited to 'src')
| -rw-r--r-- | src/simtest/policy.rs | 24 | ||||
| -rw-r--r-- | src/state/mod.rs | 7 |
2 files changed, 26 insertions, 5 deletions
diff --git a/src/simtest/policy.rs b/src/simtest/policy.rs index 8f89b39..d451497 100644 --- a/src/simtest/policy.rs +++ b/src/simtest/policy.rs @@ -854,8 +854,9 @@ async fn a_refusal_naming_the_root() { } /// A write the API would let through but every node's rules refuse (here: past the -/// API, to a path its user may not write): judged before it leaves, refused, rolled -/// back; what the node writes next goes everywhere. +/// API, to a path its user may not write; and before, where no policy judges, a strict +/// policy): judged before it leaves, refused, rolled back; what the node writes next +/// goes everywhere. #[tokio::test(flavor = "multi_thread", worker_threads = 4)] async fn a_write_every_node_would_refuse() { let sim = Sim::with_identity(79); @@ -870,6 +871,25 @@ async fn a_write_every_node_would_refuse() { &[(path("notes"), &[crate::access::Right::Write][..])], ); write_as(&a, "alice", "_continuum/users/bob", bob).await; + // Where no policy judges, a strict one written, which every node refuses: a swarm + // turns strict only at its start or through a strict remake. + let heads = a.doc.read().await.doc.get_heads(); + let policy = path("_continuum/access/policy"); + let strict = a + .mutate_doc_for( + Some("alice".to_owned()), + Sign::Write { + path: policy.clone(), + asked: false, + }, + move |doc| store::write_path(doc, &policy, &json!({"version": 1, "values": "signed"})), + ) + .await; + assert!( + matches!(strict, Err(store::StoreError::Refused(_))), + "a strict policy written where none judges" + ); + assert_eq!(a.doc.read().await.doc.get_heads(), heads, "rolled back"); write_as( &a, "alice", diff --git a/src/state/mod.rs b/src/state/mod.rs index f7c5266..822f214 100644 --- a/src/state/mod.rs +++ b/src/state/mod.rs @@ -263,8 +263,9 @@ pub(crate) struct CatchUpSource { /// The change just made in `replica` (the one head after `before`), judged by the /// swarm's rules as every node will judge it on receipt (`access::rules`), under a policy -/// judging every change: a write the API let through and the rules refuse would be -/// refused everywhere, with everything built on it. +/// judging every change, or one written where none did (which every node refuses where it +/// turns the swarm strict, `rules::turns_strict`): a write the API let through and the +/// rules refuse would be refused everywhere, with everything built on it. fn judged_here( replica: &crate::document::replica::Replica, before: &[crate::document::ChangeHash], @@ -273,7 +274,7 @@ fn judged_here( // changing the policy is judged too. let enforced = crate::document::at::At::new(&replica.doc, before) .is_some_and(|at| crate::access::policy::of(&at).enforced()); - if !enforced { + if !enforced && crate::access::policy::of(&replica.doc) == crate::access::policy::Policy::Open { return Ok(()); } let after = replica.doc.get_heads(); |
