From 65e9d86e48e3fd182882ceb54b9b8b1ff475369d Mon Sep 17 00:00:00 2001 From: tv Date: Mon, 16 Nov 2026 22:47:30 +0000 Subject: store: a test per attack row marked unit Each row of `docs/store.md`, Attacks, marked unit has its test, `store_attack_`: where it is judged (`access::holding`, `access::token`), where the store held in memory meets it (`federation::store::memory`), and where a node reads its store from its document (`federation::held`). Tests that checked a row already take its name; a check reads the doc's rows and fails on a unit row without its test, but for rows 21 and 22, which the remakes bring. --- src/access/holding.rs | 106 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 83 insertions(+), 23 deletions(-) (limited to 'src/access/holding.rs') diff --git a/src/access/holding.rs b/src/access/holding.rs index 631b36a..3ff3e3e 100644 --- a/src/access/holding.rs +++ b/src/access/holding.rs @@ -184,26 +184,6 @@ mod tests { }], }; assert!(judge(&at, &again, "federation").is_err()); - // At another key, or too large: refused. - let mut doc = swarm(); - assert!( - judged(&mut doc, "node-a", |doc| put( - doc, - &Id::of(b"else").to_string(), - &event - )) - .is_err() - ); - let mut doc = swarm(); - let large = vec![b' '; crate::federation::event::LARGEST + 1]; - assert!( - judged(&mut doc, "node-a", |doc| put( - doc, - &Id::of(&large).to_string(), - &large - )) - .is_err() - ); // A string, not bytes: refused. let mut doc = swarm(); assert!( @@ -214,8 +194,9 @@ mod tests { ); } + /// An event deleted, or replaced: refused. #[test] - fn nothing_deletes_or_replaces_an_event() { + fn store_attack_4() { let root = Id::of(ROOT).to_string(); let mut doc = swarm(); assert!( @@ -228,8 +209,10 @@ mod tests { assert!(judged(&mut doc, "node-a", |doc| put(doc, &root, b"other bytes")).is_err()); } + /// A node writing another node's entry, or under `_continuum` where it may not: + /// refused; its own entry it writes. #[test] - fn a_node_writes_its_own_entry_and_nothing_else() { + fn store_attack_18() { let entry = |node: &str| meta::path(&[meta::MEMBERS, node]); let mut doc = swarm(); assert_eq!( @@ -245,7 +228,7 @@ mod tests { .is_err() ); for closed in [ - vec!["config".to_owned()], + meta::path(&["else"]), meta::path(&[meta::USERS, "alice"]), meta::path(&[meta::SWARM]), meta::path(&[meta::NEIGHBOURS]), @@ -289,4 +272,81 @@ mod tests { .is_err() ); } + + // The store's attack rows (`docs/store.md`, Attacks) judged here. + + /// A change writing outside `_continuum/events` and the protocol data listed: refused. + #[test] + fn store_attack_1() { + let mut doc = swarm(); + assert!( + judged(&mut doc, "node-a", |doc| store::write_path( + doc, + &["config".to_owned()], + &json!(1) + )) + .is_err() + ); + } + + /// An event at a key its bytes don't hash to: refused. + #[test] + fn store_attack_2() { + let mut doc = swarm(); + assert!( + judged(&mut doc, "node-a", |doc| put( + doc, + &Id::of(b"else").to_string(), + b"an event" + )) + .is_err() + ); + } + + /// A change by a node that isn't a member, brought by one that is: taken, as nothing + /// here asks who is a member. + #[test] + fn store_attack_7() { + let event = b"an event".to_vec(); + let mut doc = swarm(); + assert_eq!( + judged(&mut doc, "a-node-no-party-lists", |doc| put( + doc, + &Id::of(&event).to_string(), + &event + )), + Ok(()) + ); + } + + /// A decision or abort written by a node not its coordinator: refused, as a swarm + /// holding a store takes no remake records. + #[test] + fn store_attack_14() { + for part in ["decision", "abortRequested"] { + let mut doc = swarm(); + assert!( + judged(&mut doc, "node-a", |doc| { + store::write_path(doc, &meta::path(&[meta::REMAKES, "r", part]), &json!({})) + }) + .is_err() + ); + } + } + + /// An event larger than the fold allows, put by a change: refused, by the change's own + /// bytes. + #[test] + fn store_attack_32() { + let large = vec![b' '; crate::federation::event::LARGEST + 1]; + let mut doc = swarm(); + assert!( + judged(&mut doc, "node-a", |doc| put( + doc, + &Id::of(&large).to_string(), + &large + )) + .is_err() + ); + } } -- cgit v1.3.1