use std::collections::HashSet;
use super::harness::*;
#[test]
fn test_sandbox_deny_builtin() {
let denied: HashSet<String> = std::iter::once("push".to_string()).collect();
let result = run_harn_with_denied(
r"pipeline t(task) {
const xs = [1, 2]
push(xs, 3)
}",
denied,
);
let err = result.unwrap_err();
let msg = format!("{err}");
assert!(
msg.contains("not permitted"),
"expected not permitted, got: {msg}"
);
assert!(
msg.contains("push"),
"expected builtin name in error, got: {msg}"
);
}
#[test]
fn test_sandbox_allowed_builtin_works() {
let denied: HashSet<String> = std::iter::once("push".to_string()).collect();
let result = run_harn_with_denied(r#"pipeline t(task) { log("hello") }"#, denied);
let (output, _) = result.unwrap();
assert_eq!(output.trim(), "[harn] hello");
}
#[test]
fn test_sandbox_empty_denied_set() {
let result = run_harn_with_denied(r#"pipeline t(task) { log("ok") }"#, HashSet::new());
let (output, _) = result.unwrap();
assert_eq!(output.trim(), "[harn] ok");
}
#[test]
fn test_sandbox_propagates_to_spawn() {
let denied: HashSet<String> = std::iter::once("push".to_string()).collect();
let result = run_harn_with_denied(
r"pipeline t(task) {
const handle = spawn {
const xs = [1, 2]
push(xs, 3)
}
await(handle)
}",
denied,
);
let err = result.unwrap_err();
let msg = format!("{err}");
assert!(
msg.contains("not permitted"),
"expected not permitted in spawned VM, got: {msg}"
);
}
#[test]
fn test_sandbox_propagates_to_parallel() {
let denied: HashSet<String> = std::iter::once("push".to_string()).collect();
let result = run_harn_with_denied(
r"pipeline t(task) {
const results = parallel(2) { i ->
const xs = [1, 2]
push(xs, 3)
}
}",
denied,
);
let err = result.unwrap_err();
let msg = format!("{err}");
assert!(
msg.contains("not permitted"),
"expected not permitted in parallel VM, got: {msg}"
);
}