use std::time::Duration;
use evalbox_sandbox::{Executor, Plan};
#[test]
#[ignore]
fn test_network_blocked_by_default() {
let output = Executor::run(
Plan::new(["sh", "-c", "curl -s --connect-timeout 2 http://example.com || wget -q -O- --timeout=2 http://example.com"])
.timeout(Duration::from_secs(5)),
)
.expect("Executor should run");
assert!(!output.success(), "Network should be blocked by default");
}
#[test]
#[ignore]
fn test_localhost_blocked() {
let output = Executor::run(
Plan::new(["sh", "-c", "echo test | nc -w1 127.0.0.1 80 2>/dev/null"])
.timeout(Duration::from_secs(5)),
)
.expect("Executor should run");
assert!(!output.success(), "Localhost should not be reachable");
}
#[test]
#[ignore]
fn test_external_dns_blocked() {
let output = Executor::run(
Plan::new([
"sh",
"-c",
"getent hosts randomdomain12345.example.com 2>&1",
])
.timeout(Duration::from_secs(5)),
)
.expect("Executor should run");
let stdout = output.stdout_str();
let stderr = output.stderr_str();
let has_ip = stdout.contains('.') && stdout.chars().any(|c| c.is_ascii_digit());
assert!(
!has_ip || !output.success(),
"External DNS should not resolve. stdout: {stdout}, stderr: {stderr}"
);
}
#[test]
#[ignore]
fn test_network_flag_enabled() {
let output = Executor::run(
Plan::new(["sh", "-c", "echo 'network flag test'"])
.network(true)
.timeout(Duration::from_secs(5)),
)
.expect("Executor should run");
assert!(
output.success(),
"Basic command should work with network enabled"
);
assert!(
output.stdout_str().contains("network flag test"),
"Should see output"
);
}
#[test]
#[ignore]
fn test_loopback_isolated() {
let output = Executor::run(
Plan::new([
"sh",
"-c",
"ip addr show lo 2>/dev/null || ifconfig lo 2>/dev/null",
])
.timeout(Duration::from_secs(5)),
)
.expect("Executor should run");
if output.success() {
let stdout = output.stdout_str();
assert!(
stdout.contains("lo") || stdout.contains("127.0.0.1"),
"Loopback should be visible"
);
}
}