use super::tests::linux_policy_with_workspace_ops;
use super::*;
#[test]
fn a_loopback_grant_admits_sockets_only_where_a_namespace_bounds_them() {
let mut policy = linux_policy_with_workspace_ops(&["read_text"]);
policy.side_effect_level = Some("process_exec".to_string());
assert!(
!allowed_syscalls(&policy).contains(&libc::SYS_socket),
"the premise is that this policy admits no socket calls before the grant",
);
policy.process_sandbox.allow_tcp_loopback = true;
policy.process_sandbox.netns_launcher_path = Some("/opt/example/launch".to_string());
let granted = allowed_syscalls(&policy);
for syscall in [
libc::SYS_socket,
libc::SYS_bind,
libc::SYS_listen,
libc::SYS_connect,
libc::SYS_accept,
] {
assert!(
granted.contains(&syscall),
"a loopback grant must admit the calls a loopback client needs",
);
}
let mut unnamespaced = policy;
unnamespaced.process_sandbox.netns_launcher_path = None;
resolve_netns_launcher(&unnamespaced)
.expect_err("a loopback grant with no namespace helper must be refused, never widened");
}