#![allow(unused_crate_dependencies)]
use serial_test::serial;
use tempfile;
use volli_server::{
export_profile, import_profile, load_agent_whitelist, load_bind_host, load_coord_whitelist,
load_join_hosts, load_profile_host, save_agent_whitelist, save_bind_host, save_coord_whitelist,
save_join_hosts, save_profile_host,
};
#[test]
#[serial]
fn export_import_roundtrip() {
let dir = tempfile::tempdir().unwrap();
unsafe {
std::env::set_var("VOLLI_CONFIG_DIR", dir.path());
}
save_profile_host("p1", "h").unwrap();
save_bind_host("p1", "b").unwrap();
save_join_hosts(
"p1",
&[volli_server::JoinHostEntry {
coord_id: None,
host: "jh".into(),
tcp_port: None,
quic_port: None,
token: None,
cert: None,
fingerprint: None,
last_ok: None,
last_fail: None,
}],
)
.unwrap();
save_agent_whitelist("p1", &["127.0.0.1/32".into()]).unwrap();
save_coord_whitelist("p1", &["10.0.0.0/8".into()]).unwrap();
let yaml = export_profile("p1").unwrap();
let imported = import_profile(&yaml, Some("p2"), false).unwrap();
assert_eq!(imported, "p2");
assert_eq!(load_profile_host("p2").unwrap().unwrap(), "h");
assert_eq!(load_bind_host("p2").unwrap().unwrap(), "b");
let hosts = load_join_hosts("p2").unwrap();
assert_eq!(hosts.len(), 1);
assert_eq!(hosts[0].host, "jh");
assert_eq!(
load_agent_whitelist("p2").unwrap().unwrap(),
vec!["127.0.0.1/32".to_string()]
);
assert_eq!(
load_coord_whitelist("p2").unwrap().unwrap(),
vec!["10.0.0.0/8".to_string()]
);
unsafe {
std::env::remove_var("VOLLI_CONFIG_DIR");
}
}
#[test]
#[serial]
fn import_force_overwrite() {
let dir = tempfile::tempdir().unwrap();
unsafe {
std::env::set_var("VOLLI_CONFIG_DIR", dir.path());
}
save_profile_host("p1", "h").unwrap();
let yaml = export_profile("p1").unwrap();
assert!(import_profile(&yaml, Some("p1"), false).is_err());
let name = import_profile(&yaml, Some("p1"), true).unwrap();
assert_eq!(name, "p1");
unsafe {
std::env::remove_var("VOLLI_CONFIG_DIR");
}
}