Files
CosmicClash/server/security/test_compose_manifests.py
T
2026-09-04 17:07:13 +01:00

63 lines
2.7 KiB
Python

from pathlib import Path
import unittest
ROOT = Path(__file__).parents[2]
class ComposeManifestTest(unittest.TestCase):
def test_allocated_fixture_is_independent_of_legacy_smoke(self):
allocated = (ROOT / "compose.allocated-smoke.yml").read_text()
legacy = (ROOT / "compose.phase6-smoke.yml").read_text()
self.assertIn("target: testkit-api", allocated)
self.assertIn("target: game-server", allocated)
self.assertIn("--drain-url=http://127.0.0.1:7780/drain", allocated)
self.assertIn("--allocated-mode", allocated)
self.assertIn('"18080:8080"', allocated)
self.assertNotIn("compose.phase6-smoke.yml", allocated)
self.assertNotIn("18080:8080", legacy)
self.assertNotIn("max-matches", allocated)
def test_allocated_runner_checks_durable_retry_and_shutdown(self):
runner = (ROOT / "scripts/verify_allocated_compose.sh").read_text()
allocated = (ROOT / "compose.allocated-smoke.yml").read_text()
for marker in (
"/v1/servers/compose-server-0001/result",
"compose-result-key-123456",
"result_receipts",
"/v1/servers/compose-server-0001/shutdown",
"SERVER_SHUTDOWN",
"/v1/session/steam",
"compose-queue-key-123456",
"/v1/queue/compose-queue-ticket/heartbeat",
"/v1/proposals/$proposal_id/accept",
"compose-match-ticket-",
"down --volumes --remove-orphans",
):
self.assertIn(marker, runner)
self.assertIn("target: matcher", allocated)
self.assertIn("target: allocator", allocated)
self.assertIn("agones-provider", allocated)
def test_chaos_fixture_has_real_maintenance_and_restart_boundary(self):
chaos = (ROOT / "compose.chaos-smoke.yml").read_text()
runner = (ROOT / "scripts/verify_chaos_recovery.sh").read_text()
self.assertIn("target: maintenance", chaos)
self.assertIn("restart control-plane", runner)
self.assertIn("stalled-allocation:", runner)
self.assertIn("down --volumes --remove-orphans", runner)
def test_kind_runner_uses_strict_allocation_response_validation(self):
runner = (ROOT / "scripts/verify_kind_agones.sh").read_text()
self.assertIn("verify_agones_allocation_response.py", runner)
self.assertNotIn("p.get(\"port\", 0) > 0", runner)
def test_kind_runner_bounds_agones_extensions_ephemeral_storage(self):
runner = (ROOT / "scripts/verify_kind_agones.sh").read_text()
self.assertIn("agones.extensions.resources.requests.ephemeral-storage=128Mi", runner)
self.assertIn("agones.extensions.resources.limits.ephemeral-storage=512Mi", runner)
if __name__ == "__main__":
unittest.main()