localstack-tesis/tests/test_simulation_guards.py

32 lines
1.4 KiB
Python

"""Las simulaciones abortan sin consentimiento antes de cargar datos o llamar AWS."""
import os
from pathlib import Path
import shutil
import subprocess
import tempfile
import unittest
ROOT = Path(__file__).resolve().parents[1]
class SimulationGuardTest(unittest.TestCase):
def test_all_entrypoints_refuse_execution_by_default(self):
with tempfile.TemporaryDirectory() as tmp:
aws = Path(tmp) / "aws"
marker = Path(tmp) / "called"
aws.write_text('#!/bin/sh\ntouch "' + str(marker) + '"\nexit 97\n')
aws.chmod(0o700)
playbooks = ROOT / "ansible/playbooks/simulations"
for playbook in [*sorted(playbooks.glob("0*.yml")), playbooks / "rollback_cleanup.yml"]:
with self.subTest(playbook=playbook.name):
result = subprocess.run(
[shutil.which("ansible-playbook"), "-i", "localhost,", str(playbook)],
env={**os.environ, "PATH": tmp + os.pathsep + os.environ["PATH"],
"ANSIBLE_CONFIG": str(ROOT / "ansible/ansible.cfg")},
capture_output=True, text=True, timeout=30,
)
self.assertNotEqual(result.returncode, 0)
self.assertIn("Simulacion deshabilitada", result.stdout)
self.assertFalse(marker.exists(), "Se invoco AWS antes de confirmar")