node: test fetch from trusted
Adds a test for fetching from trusted delegates. Currently marked as failing. When the fetch is initiated from a client that does not have the repository then it will fetch all namespaces, instead of the trusted set. Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com> X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
parent
1e8f5b2259
commit
7fddc70a57
|
|
@ -1,6 +1,6 @@
|
||||||
use std::{thread, time};
|
use std::{collections::HashSet, thread, time};
|
||||||
|
|
||||||
use radicle::crypto::Signer;
|
use radicle::crypto::{test::signer::MockSigner, Signer};
|
||||||
use radicle::node::{FetchResult, Handle as _};
|
use radicle::node::{FetchResult, Handle as _};
|
||||||
use radicle::storage::{ReadRepository, ReadStorage};
|
use radicle::storage::{ReadRepository, ReadStorage};
|
||||||
use radicle::{assert_matches, rad};
|
use radicle::{assert_matches, rad};
|
||||||
|
|
@ -195,6 +195,62 @@ fn test_replication() {
|
||||||
assert_matches!(alice.storage.repository(acme).unwrap().verify(), Ok(()));
|
assert_matches!(alice.storage.repository(acme).unwrap().verify(), Ok(()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore = "failing"]
|
||||||
|
fn test_fetch_trusted_remotes() {
|
||||||
|
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 signers = Vec::with_capacity(5);
|
||||||
|
{
|
||||||
|
for _ in 0..5 {
|
||||||
|
let signer = MockSigner::default();
|
||||||
|
rad::fork_remote(acme, &alice.id, &signer, &alice.storage).unwrap();
|
||||||
|
signers.push(signer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut alice = alice.spawn(service::Config::default());
|
||||||
|
let mut bob = bob.spawn(service::Config::default());
|
||||||
|
|
||||||
|
alice.connect(&bob);
|
||||||
|
converge([&alice, &bob]);
|
||||||
|
|
||||||
|
let trusted = signers
|
||||||
|
.iter()
|
||||||
|
.map(|s| *s.public_key())
|
||||||
|
.take(2)
|
||||||
|
.collect::<HashSet<_>>();
|
||||||
|
|
||||||
|
assert!(
|
||||||
|
trusted.len() < signers.len(),
|
||||||
|
"Bob is only trusting a subset of peers"
|
||||||
|
);
|
||||||
|
assert!(bob.handle.track_repo(acme, Scope::Trusted).unwrap());
|
||||||
|
for nid in &trusted {
|
||||||
|
assert!(bob.handle.track_node(*nid, None).unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
|
let result = bob.handle.fetch(acme, alice.id).unwrap();
|
||||||
|
assert!(result.is_success());
|
||||||
|
|
||||||
|
log::debug!(target: "test", "Fetch complete with {}", bob.id);
|
||||||
|
|
||||||
|
let bob_repo = bob.storage.repository(acme).unwrap();
|
||||||
|
let bob_remotes = bob_repo
|
||||||
|
.remote_ids()
|
||||||
|
.unwrap()
|
||||||
|
.collect::<Result<HashSet<_>, _>>()
|
||||||
|
.unwrap();
|
||||||
|
// TODO: This fails because we are fetching all namespaces at the moment.
|
||||||
|
assert_eq!(bob_remotes.len(), trusted.len() + 1);
|
||||||
|
assert!(bob_remotes.is_superset(&trusted));
|
||||||
|
assert!(bob_remotes.contains(&alice.id));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_clone() {
|
fn test_clone() {
|
||||||
logger::init(log::Level::Debug);
|
logger::init(log::Level::Debug);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue