ThreeGate/tools/tests/adversarial_tool_request_sh...

53 lines
1.1 KiB
Python

#!/usr/bin/env python3
"""
Adversarial test: ERA Tool Request must reject shell metacharacters.
"""
from __future__ import annotations
import tempfile
from pathlib import Path
from tools.validate_tool_request import validate
DOC = """---
request_type: tool_request
schema_version: 1
request_id: "TR-test-shell-meta"
created_utc: "2026-02-10T00:00:00Z"
requested_by: "core_draft"
approved_by: "operator"
approved_utc: "2026-02-10T00:01:00Z"
purpose: "Test shell meta rejection"
backend: "ERA"
language: "python"
network: "none"
cpu_limit: "1"
memory_limit_mb: 128
time_limit_sec: 5
---
## Command
echo safe && rm -rf /
## Input Files
## Output Expectations
Reject.
## Risk Assessment
High.
"""
def main() -> int:
with tempfile.TemporaryDirectory() as td:
p = Path(td) / "TR.md"
p.write_text(DOC, encoding="utf-8")
res = validate(str(p))
assert not res.ok, "Expected rejection for shell metacharacters"
assert any("metacharacters" in e.lower() for e in res.errors), f"Unexpected errors: {res.errors}"
return 0
if __name__ == "__main__":
raise SystemExit(main())