lair_keystore_api 0.7.1

secret lair private keystore API library
Documentation
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() {
    // Lair config should use an absolute path for 'connection_url'
    // when passed an relative path for 'lair_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() {
    // Lair config should use an absolute path for 'connection_url'
    // when passed an absolute path for 'lair_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));
}