From 821a6b6c08440dc7fdce85a03889c9843283c26d Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Mon, 6 Mar 2023 15:11:41 +0000 Subject: [PATCH] node: test do not fetch from owned refs To ensure the behaviour of ignoring references that are owned by the local peer a test case is added. The case has two peers: alice and bob, where alice creates a new repository. bob fetches to be up-to-date with alice. alice, in turn, creates an issue and fetches from bob -- which should be successful. If the refspec: ^refs/namespaces//* was not in place, her fetch from bob would fail since the signed references would not be a fast-forward. Signed-off-by: Fintan Halpenny X-Clacks-Overhead: GNU Terry Pratchett --- radicle-node/src/test/environment.rs | 14 +++++++++++++- radicle-node/src/tests/e2e.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/radicle-node/src/test/environment.rs b/radicle-node/src/test/environment.rs index 35775e20..9c93fab8 100644 --- a/radicle-node/src/test/environment.rs +++ b/radicle-node/src/test/environment.rs @@ -9,6 +9,8 @@ use std::{ use crossbeam_channel as chan; +use radicle::cob; +use radicle::cob::issue; use radicle::crypto::ssh::{keystore::MemorySigner, Keystore}; use radicle::crypto::test::signer::MockSigner; use radicle::crypto::{KeyPair, Seed, Signer}; @@ -19,7 +21,7 @@ use radicle::node::Handle as _; use radicle::profile::Home; use radicle::profile::Profile; use radicle::rad; -use radicle::storage::ReadStorage; +use radicle::storage::ReadStorage as _; use radicle::test::fixtures; use radicle::Storage; @@ -234,6 +236,16 @@ impl NodeHandle { } Ok(()) } + + /// Create an [`issue::Issue`] in the `NodeHandle`'s storage. + pub fn issue(&self, rid: Id, title: &str, desc: &str) -> cob::ObjectId { + let repo = self.storage.repository(rid).unwrap(); + let mut issues = issue::Issues::open(&repo).unwrap(); + *issues + .create(title, desc, &[], &[], &self.signer) + .unwrap() + .id() + } } impl Node { diff --git a/radicle-node/src/tests/e2e.rs b/radicle-node/src/tests/e2e.rs index f795107e..6d2e3a04 100644 --- a/radicle-node/src/tests/e2e.rs +++ b/radicle-node/src/tests/e2e.rs @@ -195,6 +195,33 @@ fn test_replication() { assert_matches!(alice.storage.repository(acme).unwrap().verify(), Ok(())); } +#[test] +fn test_dont_fetch_owned_refs() { + 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]); + + assert!(bob.handle.track_repo(acme, Scope::Trusted).unwrap()); + + let result = bob.handle.fetch(acme, alice.id).unwrap(); + assert!(result.is_success()); + + log::debug!(target: "test", "Fetch complete with {}", bob.id); + + alice.issue(acme, "Don't fetch self", "Use ^"); + let result = alice.handle.fetch(acme, bob.id).unwrap(); + assert!(result.is_success()) +} + #[test] #[ignore = "failing"] fn test_fetch_trusted_remotes() {