aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/access/screen.rs52
1 files changed, 47 insertions, 5 deletions
diff --git a/src/access/screen.rs b/src/access/screen.rs
index 9ca8809..909133b 100644
--- a/src/access/screen.rs
+++ b/src/access/screen.rs
@@ -144,14 +144,19 @@ impl Screening {
}
/// Itself for the document `epoch_seq`: emptied if it was another's.
- /// Whether `doc` holds a policy, known or not, or did since this node took it up:
+ /// 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:
/// 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. Kept across a swap of the document (a drop, a switch, a rejoin,
- /// `of`); not across a restart: a node that starts with no policy in its document
- /// judges as one that never had one.
+ /// may still come, and one writing into what reads as none may turn it into a policy.
+ /// Kept across a swap of the document (a drop, a switch, a rejoin, `of`); not across
+ /// 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!(super::policy::of(doc), super::policy::Policy::Open);
+ self.policed |= !matches!(
+ crate::document::store::read_held(doc, &super::policy::path()),
+ Ok(None)
+ );
self.policed
}
@@ -1508,4 +1513,41 @@ mod tests {
assert!(!crate::access::policy::of(&doc).enforced());
assert!(screening.policed(&doc));
}
+
+ /// What reads as no policy at the policy's place (an envelope holding `null`) has
+ /// what is received judged: a change writing into it may make it a policy, strict
+ /// even, which every node refuses where the policy isn't strict.
+ #[test]
+ fn policed_where_the_policy_reads_as_none() {
+ use base64::{Engine, engine::general_purpose::URL_SAFE_NO_PAD as B64URL};
+ let meta = json!({
+ "swarm": "s",
+ "path": ["_continuum", "access", "policy"],
+ "user": "alice",
+ "at": 0,
+ "seq": 0,
+ "prev": "",
+ });
+ let envelope = format!(
+ "cv2.{}.{}.",
+ B64URL.encode("null"),
+ B64URL.encode(meta.to_string())
+ );
+ let mut doc = Document::new();
+ transact(
+ &mut doc,
+ UnixMillis(1),
+ &Writer {
+ node: "a",
+ user: None,
+ },
+ |doc| store::write_path(doc, &path("_continuum/access/policy"), &json!(envelope)),
+ )
+ .unwrap();
+ assert_eq!(
+ crate::access::policy::of(&doc),
+ crate::access::policy::Policy::Open
+ );
+ assert!(Screening::default().policed(&doc));
+ }
}