39 lines
1.4 KiB
Python
39 lines
1.4 KiB
Python
#!/usr/bin/env python3
|
|
"""Local orchestration guard tests; no Docker, credentials, or SSH access."""
|
|
from pathlib import Path
|
|
import subprocess
|
|
import sys
|
|
import unittest
|
|
from unittest.mock import patch
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "deploy"))
|
|
import vm_passive_test as vm
|
|
|
|
|
|
class OrchestrationTests(unittest.TestCase):
|
|
def test_require_fails_closed(self):
|
|
vm.require(True, "valid")
|
|
with self.assertRaisesRegex(RuntimeError, "blocked"):
|
|
vm.require(False, "blocked")
|
|
|
|
def test_failed_command_does_not_echo_private_diagnostics(self):
|
|
result = subprocess.CompletedProcess(["tool"], 1, b"PRIVATE STDOUT", b"PRIVATE STDERR")
|
|
with patch.object(vm.subprocess, "run", return_value=result):
|
|
with self.assertRaises(RuntimeError) as error:
|
|
vm.execute(["tool"])
|
|
self.assertNotIn("PRIVATE", str(error.exception))
|
|
|
|
def test_remote_code_uses_stdin_not_shell_interpolation(self):
|
|
code = "print('literal $(not_a_shell_command)')"
|
|
with patch.object(vm, "execute", return_value=b"ok") as execute:
|
|
result = vm.remote_python(["ssh", "-T"], "test-target", {"TEST": "value"}, code)
|
|
self.assertEqual(result, b"ok")
|
|
execute.assert_called_once_with(
|
|
["ssh", "-T", "test-target", "python3 -"],
|
|
env={"TEST": "value"}, input=code.encode(),
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|