56 lines
1.7 KiB
Rust
56 lines
1.7 KiB
Rust
use super::*;
|
|
|
|
fn parent(pairs: &[(&str, &str)]) -> Vec<(String, String)> {
|
|
pairs
|
|
.iter()
|
|
.map(|(k, v)| (k.to_string(), v.to_string()))
|
|
.collect()
|
|
}
|
|
|
|
#[test]
|
|
fn copy_parent_env_retains_every_var() {
|
|
let sandbox_env = copy_parent_env(&parent(&[("GH_TOKEN", "secret"), ("XDG_SEAT", "seat0")]));
|
|
assert_eq!(sandbox_env.get("GH_TOKEN").unwrap(), "secret");
|
|
assert_eq!(sandbox_env.get("XDG_SEAT").unwrap(), "seat0");
|
|
}
|
|
|
|
#[test]
|
|
fn whitelist_retains_allowed_var() {
|
|
let sandbox_env = apply_whitelist(&parent(&[("TERM", "xterm")]));
|
|
assert_eq!(sandbox_env.get("TERM").unwrap(), "xterm");
|
|
}
|
|
|
|
#[test]
|
|
fn whitelist_removes_unlisted_var() {
|
|
let sandbox_env = apply_whitelist(&parent(&[("SOME_RANDOM_NOISE_VAR", "leak")]));
|
|
assert!(sandbox_env.is_empty());
|
|
}
|
|
|
|
#[test]
|
|
fn blacklist_removes_secret_var() {
|
|
let sandbox_env = apply_blacklist(&parent(&[("GH_TOKEN", "secret"), ("MY_NICE_VAR", "hello")]));
|
|
assert!(!sandbox_env.contains_key("GH_TOKEN"));
|
|
assert_eq!(sandbox_env.get("MY_NICE_VAR").unwrap(), "hello");
|
|
}
|
|
|
|
#[test]
|
|
fn blacklist_carves_out_vendor_prefix() {
|
|
let sandbox_env = apply_blacklist(&parent(&[("ANTHROPIC_API_KEY", "key")]));
|
|
assert_eq!(sandbox_env.get("ANTHROPIC_API_KEY").unwrap(), "key");
|
|
}
|
|
|
|
#[test]
|
|
fn find_parent_value_returns_present_value() {
|
|
let parent_env = parent(&[("XDG_RUNTIME_DIR", "/run/user/1000")]);
|
|
assert_eq!(
|
|
find_parent_value(&parent_env, "XDG_RUNTIME_DIR").unwrap(),
|
|
"/run/user/1000"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn find_parent_value_returns_none_for_absent_key() {
|
|
let parent_env = parent(&[("HOME", "/home/me")]);
|
|
assert!(find_parent_value(&parent_env, "XDG_RUNTIME_DIR").is_none());
|
|
}
|