aboutsummaryrefslogtreecommitdiffstats
path: root/src/access
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-16 10:38:26 +0000
committertv <tv@krebsco.de>2026-11-16 10:38:26 +0000
commit35ba6d49a673b4f34873486cfd521053c5e27971 (patch)
tree24bb4af815b53a912138b3b828fb78ecaf93140b /src/access
parent8029b408b7e33bfd429c9b0cb2ac5412afda3bcc (diff)
screen: what is at the policy's place found in every map on the way
A node judges what it receives once anything is at the policy's place (`Screening::policed`), as a read shows it. But a read shows the newest of the values written at once at a key, merging maps only where that one is a map: a string written at `_continuum/access` beside the map holding the policy, and newer, hides it. So the policy's place read as empty, a change putting `"signed"` into the hidden policy went unjudged where it came alone, and deleting the string left a strict policy no change was refused for. Whether anything is at the policy's place is asked of every map of each key on the way to it, read or not (`store::held_anywhere`), as `store::by_seq` walks them. A swarm with nothing there is screened as before.
Diffstat (limited to 'src/access')
-rw-r--r--src/access/screen.rs69
1 files changed, 64 insertions, 5 deletions
diff --git a/src/access/screen.rs b/src/access/screen.rs
index 909133b..a57c2fe 100644
--- a/src/access/screen.rs
+++ b/src/access/screen.rs
@@ -145,7 +145,8 @@ impl Screening {
/// Itself for the document `epoch_seq`: emptied if it was another's.
/// Whether `doc` holds anything at the policy's place, a policy known or not or what
- /// reads as none (an envelope holding `null`), or did since this node took it up:
+ /// reads as none (an envelope holding `null`), in any of the maps on the way to it, a
+ /// read showing them or not (`store::held_anywhere`), or did since this node took it up:
/// then what it receives is judged (`apply`), each change by the policy at its
/// dependencies, though the policy is gone or unknown now; changes written under it
/// may still come, and one writing into what reads as none may turn it into a policy.
@@ -153,10 +154,7 @@ impl Screening {
/// a restart: a node that starts with nothing at the policy's place judges as one
/// that never had a policy.
pub(crate) fn policed(&mut self, doc: &Document) -> bool {
- self.policed |= !matches!(
- crate::document::store::read_held(doc, &super::policy::path()),
- Ok(None)
- );
+ self.policed |= crate::document::store::held_anywhere(doc, &super::policy::path());
self.policed
}
@@ -1550,4 +1548,65 @@ mod tests {
);
assert!(Screening::default().policed(&doc));
}
+
+ /// A value at `_continuum/access` written beside the map holding the policy, and read
+ /// as newer, hides it from a read: what is received is judged all the same.
+ #[test]
+ fn policed_where_a_value_beside_hides_the_policy() {
+ let mut doc = Document::new();
+ transact(
+ &mut doc,
+ UnixMillis(1),
+ &Writer {
+ node: "a",
+ user: None,
+ },
+ |doc| store::write_path(doc, &path("_continuum/swarm"), &json!("s")),
+ )
+ .unwrap();
+ let mut beside = doc.clone().with_actor(automerge::ActorId::random());
+ transact(
+ &mut doc,
+ UnixMillis(2),
+ &Writer {
+ node: "a",
+ user: None,
+ },
+ |doc| store::write_path(doc, &path("_continuum/access/policy"), &json!({})),
+ )
+ .unwrap();
+ // Writes enough to be the newer when they meet.
+ for at in 0..8 {
+ transact(
+ &mut beside,
+ UnixMillis(3 + at),
+ &Writer {
+ node: "b",
+ user: None,
+ },
+ |doc| store::write_path(doc, &path("notes/x"), &json!(at)),
+ )
+ .unwrap();
+ }
+ transact(
+ &mut beside,
+ UnixMillis(20),
+ &Writer {
+ node: "b",
+ user: None,
+ },
+ |doc| store::write_path(doc, &path("_continuum/access"), &json!("x")),
+ )
+ .unwrap();
+ doc.merge(&mut beside).unwrap();
+ assert_eq!(
+ store::read_path(&doc, &path("_continuum/access")).unwrap(),
+ Some(json!("x"))
+ );
+ assert_eq!(
+ crate::access::policy::of(&doc),
+ crate::access::policy::Policy::Open
+ );
+ assert!(Screening::default().policed(&doc));
+ }
}