use std::time::Duration;
use evalbox_sandbox::{Executor, Plan};
#[test]
#[ignore]
fn test_cannot_read_etc_shadow() {
let output = Executor::run(Plan::new(["cat", "/etc/shadow"]).timeout(Duration::from_secs(5)))
.expect("Executor should run");
assert!(!output.success(), "/etc/shadow should not be readable");
let stderr = output.stderr_str();
assert!(
stderr.contains("No such file") || stderr.contains("Permission denied"),
"Expected 'No such file' or 'Permission denied', got: {stderr}"
);
}
#[test]
#[ignore]
fn test_cannot_write_etc_passwd() {
let output = Executor::run(
Plan::new(["sh", "-c", "echo 'hacked:x:0:0::/:/bin/sh' >> /etc/passwd"])
.timeout(Duration::from_secs(5)),
)
.expect("Executor should run");
assert!(!output.success(), "/etc/passwd should not be writable");
}
#[test]
#[ignore]
fn test_cannot_access_root_home() {
let output = Executor::run(Plan::new(["ls", "/root"]).timeout(Duration::from_secs(5)))
.expect("Executor should run");
assert!(!output.success(), "/root should not be accessible");
}
#[test]
#[ignore]
fn test_work_dir_is_writable() {
let output = Executor::run(
Plan::new([
"sh",
"-c",
"echo 'test content' > ./test.txt && cat ./test.txt",
])
.timeout(Duration::from_secs(5)),
)
.expect("Executor should run");
assert!(
output.success(),
"Should be able to write to CWD (work dir)"
);
assert_eq!(output.stdout_str().trim(), "test content");
}
#[test]
#[ignore]
fn test_tmp_is_writable() {
let output = Executor::run(
Plan::new([
"sh",
"-c",
"echo 'temp data' > ../tmp/test.txt && cat ../tmp/test.txt",
])
.timeout(Duration::from_secs(5)),
)
.expect("Executor should run");
assert!(
output.success(),
"Should be able to write to workspace tmp (../tmp)"
);
assert_eq!(output.stdout_str().trim(), "temp data");
}
#[test]
#[ignore]
fn test_path_traversal_blocked() {
let output =
Executor::run(Plan::new(["cat", "../../../etc/shadow"]).timeout(Duration::from_secs(5)))
.expect("Executor should run");
assert!(
!output.success(),
"Path traversal to /etc/shadow should be blocked by Landlock"
);
}
#[test]
#[ignore]
fn test_symlink_escape_blocked() {
let output = Executor::run(
Plan::new(["sh", "-c", "ln -s /etc/shadow ./shadow && cat ./shadow"])
.timeout(Duration::from_secs(5)),
)
.expect("Executor should run");
assert!(!output.success(), "Symlink escape should be blocked");
}
#[test]
#[ignore]
fn test_proc_self_exe_safe() {
let output =
Executor::run(Plan::new(["readlink", "/proc/self/exe"]).timeout(Duration::from_secs(5)))
.expect("Executor should run");
assert!(
output.exit_code.is_some(),
"/proc/self/exe readlink should complete without crashing"
);
}