aboutsummaryrefslogtreecommitdiffstats
path: root/src/federation/store/memory.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/federation/store/memory.rs')
-rw-r--r--src/federation/store/memory.rs54
1 files changed, 44 insertions, 10 deletions
diff --git a/src/federation/store/memory.rs b/src/federation/store/memory.rs
index b8035d7..bc0c672 100644
--- a/src/federation/store/memory.rs
+++ b/src/federation/store/memory.rs
@@ -805,6 +805,47 @@ mod tests {
assert_eq!(anew.own(), (own, drops));
}
+ /// Heads for a checkpoint before the store's, or one in another's history: no move
+ /// (`docs/store.md`, Attacks, 25).
+ #[test]
+ fn store_attack_25() {
+ let (mut store, cut, _, first) = cut_at_a_lock();
+ let checkpoint = store.checkpoint().to_vec();
+ store.offer(testfold::cut(&[cut], 2, &[first]));
+ assert_eq!(store.checkpoint(), checkpoint.as_slice());
+ let mut store = self::store();
+ let root = store.id();
+ let one = taken(store.offer(testfold::put(&[root], "a", "1")));
+ let two = taken(store.offer(testfold::put(&[one], "a", "2")));
+ let checkpoint = store.checkpoint().to_vec();
+ store.offer(testfold::cut(&[two], 1, &[one, two]));
+ assert_eq!(store.checkpoint(), checkpoint.as_slice());
+ }
+
+ /// A head brought again after a move: taken as held, and not read anew; so is what
+ /// came before it (`docs/store.md`, Attacks, 26).
+ #[test]
+ fn store_attack_26() {
+ let (mut store, _, lock, first) = cut_at_a_lock();
+ let root = store.id();
+ let second = Id::of(&testfold::put(&[first], "a", "2"));
+ let state = store.state().clone();
+ assert_eq!(store.offer(testfold::lock(&[second], "b")), Offered::Held);
+ assert_eq!(Id::of(&testfold::lock(&[second], "b")), lock);
+ assert_eq!(store.offer(testfold::put(&[root], "a", "1")), Offered::Held);
+ assert!(store.state() == &state);
+ }
+
+ /// An operator has its node drop an event its checkpoint keeps, or one of its heads:
+ /// refused (`docs/store.md`, Attacks, 27).
+ #[test]
+ fn store_attack_27() {
+ let (mut store, _, lock, first) = cut_at_a_lock();
+ let second = Id::of(&testfold::put(&[first], "a", "2"));
+ assert!(store.drop_taken(&[second]).is_err());
+ assert!(store.drop_taken(&[lock]).is_err());
+ }
+
/// Heads leave out what is neither among them, in their history, nor above them.
#[test]
fn heads_leave_out_what_is_beside_them() {
@@ -869,15 +910,6 @@ mod tests {
store.offer(testfold::put(&[root], "c", "1")),
Offered::Refused(Refusal::NotAbove)
);
- // A head brought again is held; so is what came before it.
- assert_eq!(
- store.offer(testfold::lock(
- &[Id::of(&testfold::put(&[first], "a", "2"))],
- "b"
- )),
- Offered::Held
- );
- assert_eq!(store.offer(testfold::put(&[root], "a", "1")), Offered::Held);
}
/// The checkpoint a store builds at heads it holds is the one it moves to there.
@@ -932,8 +964,10 @@ mod tests {
);
}
+ /// A fork's events brought to the store it came from, or the other way: never taken
+ /// (`docs/store.md`, Attacks, 9).
#[test]
- fn a_fork_and_the_store_it_left_take_nothing_of_each_other() {
+ fn store_attack_9() {
let mut store = store();
let root = store.id();
let here = taken(store.offer(testfold::put(&[root], "a", "1")));