#![allow(unused_crate_dependencies)]
#![allow(unused_extern_crates)]
use serial_test::serial;
use std::time::Duration;
#[tokio::test]
#[serial]
async fn default_profile_bootstrap() {
let base = tempfile::TempDir::new().unwrap();
unsafe {
std::env::set_var("VOLLI_CONFIG_DIR", base.path());
}
let prof_dir = volli_server::secret_dir(Some("default"));
volli_server::bootstrap_keypair(Some(&prof_dir)).unwrap();
volli_server::save_profile_host("default", "127.0.0.1").unwrap();
volli_server::save_bind_host("default", "127.0.0.1").unwrap();
let (_c, _k, _fp) = volli_server::load_or_generate_cert(None, None, Some(&prof_dir)).unwrap();
volli_server::save_join_hosts("default", &[]).unwrap();
let cfg = volli_server::ServerConfigOpts {
tcp_port: 0,
quic_port: 0,
secret_dir: Some(prof_dir.to_string_lossy().to_string()),
..Default::default()
};
let handle = tokio::spawn(volli_server::run(cfg, None, false));
tokio::time::sleep(Duration::from_millis(50)).await;
handle.abort();
assert!(prof_dir.join("coord_sk").exists());
let hosts = volli_server::load_join_hosts("default").unwrap();
assert!(hosts.is_empty());
unsafe {
std::env::remove_var("VOLLI_CONFIG_DIR");
}
}
#[tokio::test]
#[serial]
async fn second_profile_bootstrap() {
let base = tempfile::TempDir::new().unwrap();
unsafe {
std::env::set_var("VOLLI_CONFIG_DIR", base.path());
}
let ddir = volli_server::secret_dir(Some("default"));
volli_server::bootstrap_keypair(Some(&ddir)).unwrap();
volli_server::save_profile_host("default", "127.0.0.1").unwrap();
volli_server::save_bind_host("default", "127.0.0.1").unwrap();
volli_server::load_or_generate_cert(None, None, Some(&ddir)).unwrap();
let cfg1 = volli_server::ServerConfigOpts {
tcp_port: 0,
quic_port: 0,
secret_dir: Some(ddir.to_string_lossy().to_string()),
..Default::default()
};
let h1 = tokio::spawn(volli_server::run(cfg1, None, false));
tokio::time::sleep(Duration::from_millis(20)).await;
h1.abort();
let prof_dir = volli_server::secret_dir(Some("p2"));
volli_server::bootstrap_keypair(Some(&prof_dir)).unwrap();
volli_server::save_profile_host("p2", "127.0.0.1").unwrap();
volli_server::save_bind_host("p2", "127.0.0.1").unwrap();
let (_c2, _k2, _fp2) =
volli_server::load_or_generate_cert(None, None, Some(&prof_dir)).unwrap();
volli_server::save_join_hosts("p2", &[]).unwrap();
let cfg2 = volli_server::ServerConfigOpts {
tcp_port: 0,
quic_port: 0,
secret_dir: Some(prof_dir.to_string_lossy().to_string()),
profile: "p2".into(),
..Default::default()
};
let h2 = tokio::spawn(volli_server::run(cfg2, None, false));
tokio::time::sleep(Duration::from_millis(50)).await;
h2.abort();
assert!(prof_dir.join("coord_sk").exists());
let hosts = volli_server::load_join_hosts("p2").unwrap();
assert!(hosts.is_empty());
unsafe {
std::env::remove_var("VOLLI_CONFIG_DIR");
}
}