use hc_seed_bundle::dependencies::sodoken;
use lair_keystore_api::prelude::*;
use std::sync::{Arc, Mutex};
use std::{env::current_dir, path::PathBuf};
use tempfile::TempDir;
#[cfg(not(windows))]
#[tokio::test(flavor = "multi_thread")]
async fn lair_config_connection_url_relative_root() {
let passphrase = Arc::new(Mutex::new(sodoken::LockedArray::from(
b"passphrase".to_vec(),
)));
let dir = TempDir::with_prefix_in("example", ".").unwrap();
let mut relative_lair_root = PathBuf::from(".");
relative_lair_root.push(dir.path().components().last().unwrap());
let config = hc_seed_bundle::PwHashLimits::Minimum
.with_exec(|| {
LairServerConfigInner::new(relative_lair_root, passphrase.clone())
})
.await
.unwrap();
let mut expected_path = current_dir().unwrap();
expected_path.push(dir.path().components().last().unwrap());
let expected_path_str = expected_path.to_str().unwrap();
assert!(config.connection_url.as_str().contains(expected_path_str));
}
#[cfg(not(windows))]
#[tokio::test(flavor = "multi_thread")]
async fn lair_config_connection_url_absolute_root() {
let passphrase = Arc::new(Mutex::new(sodoken::LockedArray::from(
b"passphrase".to_vec(),
)));
let dir = TempDir::with_prefix_in("example", ".").unwrap();
let mut absolute_lair_root = current_dir().unwrap();
absolute_lair_root.push(dir.path().components().last().unwrap());
let config = hc_seed_bundle::PwHashLimits::Minimum
.with_exec(|| {
LairServerConfigInner::new(
absolute_lair_root.clone(),
passphrase.clone(),
)
})
.await
.unwrap();
let mut expected_path = current_dir().unwrap();
expected_path.push(dir.path().components().last().unwrap());
let expected_path_str = expected_path.to_str().unwrap();
assert!(config.connection_url.as_str().contains(expected_path_str));
}