use adk_sandbox::{ProcessBackend, SandboxBackend};
#[test]
fn a_backend_without_an_enforcer_claims_no_filesystem_isolation() {
let caps = ProcessBackend::default().capabilities();
assert!(!caps.enforced_limits.filesystem_write_isolation);
assert!(!caps.enforced_limits.filesystem_read_isolation);
assert!(
caps.enforced_limits.environment_isolation,
"the environment is cleared even without an enforcer"
);
assert!(caps.enforced_limits.timeout);
}
#[cfg(all(feature = "sandbox-macos", target_os = "macos"))]
#[test]
fn the_macos_profile_denies_writes_but_not_reads() {
use adk_sandbox::sandbox::macos::MacOsEnforcer;
use adk_sandbox::{SandboxEnforcer, SandboxPolicyBuilder};
let enforcer = MacOsEnforcer::new();
if enforcer.probe().is_err() {
return;
}
let dir = tempfile::tempdir().unwrap();
let policy = SandboxPolicyBuilder::new().allow_read_write(dir.path()).build();
let profile = enforcer
.wrap_command(std::ffi::OsStr::new("/bin/echo"), &[], &policy)
.expect("wrapping must succeed on macOS");
let rendered = profile
.args
.iter()
.map(|arg| arg.to_string_lossy().to_string())
.collect::<Vec<_>>()
.join(" ");
assert!(
rendered.contains("file-write") || rendered.contains("deny default"),
"the profile must restrict writes: {rendered}"
);
assert!(
!rendered.contains("(deny file-read*)"),
"if a blanket read denial is added, update the reported read-isolation capability"
);
}