From f78e010c556d5dcc1b43378c746df2f617a33b32 Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Wed, 29 Mar 2023 15:54:12 +0100 Subject: [PATCH] node: e2e test simulating a peer migrating their key Previously, if a peer created a project which was replicated and then moved to another setup, ultimately deleting that project, then they would not be able to fetch it again since their remote namespace would be excluded from the fetch. This test confirms that a peer can remove their project and clone it again from a peer that has replicated the project. This is simulated by directly removing the project directory in the test and fetching the project from the other peer. Signed-off-by: Fintan Halpenny X-Clacks-Overhead: GNU Terry Pratchett --- radicle-node/src/tests/e2e.rs | 50 +++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/radicle-node/src/tests/e2e.rs b/radicle-node/src/tests/e2e.rs index 2ab3853c..323014ab 100644 --- a/radicle-node/src/tests/e2e.rs +++ b/radicle-node/src/tests/e2e.rs @@ -195,6 +195,56 @@ fn test_replication() { assert_matches!(alice.storage.repository(acme).unwrap().verify(), Ok(())); } +#[test] +fn test_migrated_clone() { + logger::init(log::Level::Debug); + + let tmp = tempfile::tempdir().unwrap(); + let mut alice = Node::init(tmp.path()); + let bob = Node::init(tmp.path()); + let acme = alice.project("acme", ""); + + let mut alice = alice.spawn(service::Config::default()); + let mut bob = bob.spawn(service::Config::default()); + + alice.connect(&bob); + converge([&alice, &bob]); + + let tracked = bob.handle.track_repo(acme, Scope::All).unwrap(); + assert!(tracked); + + let result = bob.handle.fetch(acme, alice.id).unwrap(); + assert!(result.is_success()); + + log::debug!(target: "test", "Fetch complete with {}", alice.id); + + // Simulate alice deleting the project and cloning it again + { + let path = alice.storage.path().join(acme.canonical()); + std::fs::remove_dir_all(path).unwrap(); + } + assert!(!alice.storage.contains(&acme).unwrap()); + let result = alice.handle.fetch(acme, bob.id).unwrap(); + assert!(result.is_success()); + + let alice_repo = alice.storage.repository(acme).unwrap(); + let bob_repo = bob.storage.repository(acme).unwrap(); + + let alice_refs = alice_repo + .references() + .unwrap() + .collect::, _>>() + .unwrap(); + let bob_refs = bob_repo + .references() + .unwrap() + .collect::, _>>() + .unwrap(); + + assert_eq!(alice_refs, bob_refs); + assert_matches!(alice.storage.repository(acme).unwrap().verify(), Ok(())); +} + #[test] fn test_dont_fetch_owned_refs() { logger::init(log::Level::Debug);