diff options
Diffstat (limited to 'src/access/screen.rs')
| -rw-r--r-- | src/access/screen.rs | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/access/screen.rs b/src/access/screen.rs index b616238..9ca8809 100644 --- a/src/access/screen.rs +++ b/src/access/screen.rs @@ -1064,7 +1064,8 @@ mod tests { } /// Under a strict policy, two signed values written one after the other at the same - /// path, received in one batch: both taken, the second judged with the first in. + /// path, received in one batch: both taken, the second judged with the first in. And + /// the first put back beside the second changes nothing. #[test] fn successive_signed_values_in_one_batch() { use crate::access::{envelope, sshsig}; @@ -1094,18 +1095,20 @@ mod tests { write(&mut theirs, "a", None, "_continuum/members/a", json!({})); let sealed = |prev: &str, value: serde_json::Value| { let payload = envelope::Payload { + value, swarm: "s".to_owned(), path: path("config"), - value, user: "alice".to_owned(), at: 1, + seq: u64::from(!prev.is_empty()), prev: prev.to_owned(), }; - let bytes = serde_json::to_vec(&payload).unwrap(); + let bytes = payload.signed(); envelope::seal(&bytes, &sshsig::sign(&key, envelope::NAMESPACE, &bytes)).unwrap() }; let first = sealed("", json!(1)); let second = sealed(&envelope::digest(Some(&first)), json!(2)); + let before = theirs.get_heads(); write(&mut theirs, "a", Some("alice"), "config", json!(first)); write(&mut theirs, "a", Some("alice"), "config", json!(second)); @@ -1117,6 +1120,25 @@ mod tests { store::read_path(&ours, &path("config")).unwrap(), Some(json!(second)) ); + + // The first put there again, by a change that saw neither: taken, as nothing + // was there at its history, and held beside the second, which stays the value + // (its `seq` is higher), whatever the order of the operations. + let mut side = theirs.fork_at(&before).unwrap(); + write(&mut side, "a", Some("alice"), "config", json!(first)); + theirs.merge(&mut side).unwrap(); + let mut ours = Document::new(); + let screened = screen(&mut ours, received(&theirs, &[]), &mut Waiting::default()); + let why: Vec<&str> = screened.refused.iter().map(|r| r.why.as_str()).collect(); + assert!(why.is_empty(), "{why:?}"); + assert_eq!( + store::read_candidates(&ours, &path("config")).unwrap(), + [json!(second), json!(first)] + ); + assert_eq!( + store::read_path(&ours, &path("config")).unwrap(), + Some(json!(second)) + ); } /// A refused change offered again: refused by its hash, not judged or kept again, |
