static PRESEAL_TEST_LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(());
#[test]
fn a_cached_secret_survives_its_path_becoming_unreachable() {
let _preseal_guard = PRESEAL_TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner());
let dir = tempfile::tempdir().unwrap();
let path = dir.path().join("provider.key");
std::fs::write(&path, "sk-test-value").unwrap();
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;
std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o600)).unwrap();
}
let r = SecretRef::File(path.clone());
cache_before_seal(&r).expect("resolves while the path is reachable");
std::fs::remove_file(&path).unwrap();
use secrecy::ExposeSecret;
let got = r
.resolve_blocking()
.expect("cached value must still resolve");
assert_eq!(got.expose_secret(), "sk-test-value");
}
#[test]
fn an_uncached_secret_fails_when_its_path_is_unreachable() {
let dir = tempfile::tempdir().unwrap();
let path = dir.path().join("uncached.key");
std::fs::write(&path, "sk-other-value").unwrap();
let r = SecretRef::File(path.clone());
std::fs::remove_file(&path).unwrap();
assert!(
r.resolve_blocking().is_err(),
"an uncached ref must not resolve once its path is gone"
);
}
#[test]
fn preseal_cached_lookup_does_not_touch_the_backend() {
let _preseal_guard = PRESEAL_TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner());
let r = SecretRef::Keychain {
service: "mur-agent-test-nonexistent".into(),
account: "no-such-agent/NO_SUCH_KEY".into(),
};
assert!(r.resolve_preseal_cached().is_none());
let dir = tempfile::tempdir().unwrap();
let path = dir.path().join("agent.key");
std::fs::write(&path, "sk-agent").unwrap();
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;
std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o600)).unwrap();
}
let f = SecretRef::File(path.clone());
cache_before_seal(&f).unwrap();
std::fs::remove_file(&path).unwrap();
use secrecy::ExposeSecret;
let got = f.resolve_preseal_cached().expect("cached hit");
assert_eq!(got.expose_secret(), "sk-agent");
}
#[test]
fn caching_the_same_ref_twice_stores_one_entry() {
let _preseal_guard = PRESEAL_TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner());
let dir = tempfile::tempdir().unwrap();
let path = dir.path().join("dup.key");
std::fs::write(&path, "v").unwrap();
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;
std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o600)).unwrap();
}
let r = SecretRef::File(path);
let before = preseal_cached_count();
cache_before_seal(&r).unwrap();
cache_before_seal(&r).unwrap();
assert_eq!(preseal_cached_count(), before + 1);
}
use super::*;
#[test]
fn resolve_blocking_env_and_missing() {
let mut env = crate::test_env::EnvGuard::set([("MUR_TEST_SECRET_BLOCKING", "s3cret")]);
let r: SecretRef = "env:MUR_TEST_SECRET_BLOCKING".parse().unwrap();
assert_eq!(r.resolve_to_string_blocking().as_deref(), Some("s3cret"));
env.unset_var("MUR_TEST_SECRET_BLOCKING");
assert!(r.resolve_blocking().is_err());
}
#[tokio::test]
async fn resolve_blocking_inside_current_thread_runtime_does_not_panic() {
let _env = crate::test_env::EnvGuard::set([("MUR_TEST_SECRET_CT_RT", "s3cret")]);
let r: SecretRef = "env:MUR_TEST_SECRET_CT_RT".parse().unwrap();
assert_eq!(r.resolve_to_string_blocking().as_deref(), Some("s3cret"));
}