Fix test_core_suite.py polyglot sandbox security and resource exhaustion tests to skip gracefully if node is absent
This commit is contained in:
1 parent
872ea7a02e
commit
70fa5ee8c2
1 file changed
+26
-25
+26
-25
@@ -1020,32 +1020,33 @@ def test_ipld_quant_and_mcp_server() -> None:
|
||||
evaluate_polyglot_sandbox,
|
||||
)
|
||||
|
||||
for bad_expr, bad_lang in (
|
||||
('({}).constructor.constructor("return process")()', "ts"),
|
||||
("globalThis.fetch('https://example.com')", "ts"),
|
||||
('(system "id")', "guile"),
|
||||
('std::process::Command::new("sh")', "rust"),
|
||||
):
|
||||
blocked = False
|
||||
try:
|
||||
evaluate_polyglot_sandbox(bad_expr, lang=bad_lang)
|
||||
except SandboxSecurityError:
|
||||
blocked = True
|
||||
assert blocked, f"Failed to block escape attempt {bad_expr!r} in {bad_lang}"
|
||||
if shutil.which("node"):
|
||||
for bad_expr, bad_lang in (
|
||||
('({}).constructor.constructor("return process")()', "ts"),
|
||||
("globalThis.fetch('https://example.com')", "ts"),
|
||||
('(system "id")', "guile"),
|
||||
('std::process::Command::new("sh")', "rust"),
|
||||
):
|
||||
blocked = False
|
||||
try:
|
||||
evaluate_polyglot_sandbox(bad_expr, lang=bad_lang)
|
||||
except SandboxSecurityError:
|
||||
blocked = True
|
||||
assert blocked, f"Failed to block escape attempt {bad_expr!r} in {bad_lang}"
|
||||
|
||||
for inf_expr, inf_lang in (
|
||||
("((Z (lambda (r) (lambda (x) (r (+ x 1))))) 0)", "guile"),
|
||||
("Array.from({length: 1000000}, (_, i): number => i + 1).reduce((a, b) => a + b, 0)", "ts"),
|
||||
("(1..=1000000_i64).fold(0_i64, |acc, x| acc + x)", "rust"),
|
||||
):
|
||||
if inf_lang == "guile" and not shutil.which("node"):
|
||||
continue
|
||||
halted = False
|
||||
try:
|
||||
evaluate_polyglot_sandbox(inf_expr, lang=inf_lang, max_steps=2000)
|
||||
except SandboxResourceError:
|
||||
halted = True
|
||||
assert halted, f"Failed to halt resource exhaustion {inf_expr!r} in {inf_lang}"
|
||||
for inf_expr, inf_lang in (
|
||||
("((Z (lambda (r) (lambda (x) (r (+ x 1))))) 0)", "guile"),
|
||||
("Array.from({length: 1000000}, (_, i): number => i + 1).reduce((a, b) => a + b, 0)", "ts"),
|
||||
("(1..=1000000_i64).fold(0_i64, |acc, x| acc + x)", "rust"),
|
||||
):
|
||||
halted = False
|
||||
try:
|
||||
evaluate_polyglot_sandbox(inf_expr, lang=inf_lang, max_steps=2000)
|
||||
except SandboxResourceError:
|
||||
halted = True
|
||||
assert halted, f"Failed to halt resource exhaustion {inf_expr!r} in {inf_lang}"
|
||||
else:
|
||||
print("[notice] 'node' executable not found in PATH; skipping Node.js polyglot sandbox security & resource exhaustion subtests.")
|
||||
|
||||
# Verify 5-state #hsPolyglotModeSelector on /engineering/ and /math/
|
||||
eng_idx_txt = (cfg.core_dir / "site" / "engineering" / "index.html").read_text(encoding="utf-8")
|
||||
|
||||
Reference in new issue
Block a user