68 lines
2.3 KiB
Python
68 lines
2.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Small, dependency-free fitness/ACL checks for Stage 1."""
|
|
import json
|
|
import re
|
|
import unittest
|
|
import urllib.error
|
|
import urllib.request
|
|
from pathlib import Path
|
|
|
|
BASE = "http://127.0.0.1:9160"
|
|
ROOT = Path("/root/buryan-infra")
|
|
|
|
|
|
def get(path, headers=None):
|
|
req = urllib.request.Request(BASE + path, headers=headers or {})
|
|
with urllib.request.urlopen(req, timeout=10) as r:
|
|
return r.status, r.read().decode()
|
|
|
|
|
|
class AuditAccess(unittest.TestCase):
|
|
def test_health(self):
|
|
code, _ = get("/health")
|
|
self.assertEqual(code, 200)
|
|
|
|
def test_tracker_api(self):
|
|
code, body = get("/api/audit")
|
|
self.assertEqual(code, 200)
|
|
data = json.loads(body)
|
|
self.assertGreaterEqual(len(data.get("sprint") or []), 30)
|
|
self.assertTrue(any(x.get("requires_user") for x in data.get("sprint") or []))
|
|
|
|
def test_other_email_denied(self):
|
|
with self.assertRaises(urllib.error.HTTPError) as ctx:
|
|
get("/", {"X-Audit-Gateway": "1", "X-Audit-User": "other@example.com"})
|
|
self.assertEqual(ctx.exception.code, 403)
|
|
|
|
def test_roman_allowed(self):
|
|
code, _ = get("/", {"X-Audit-Gateway": "1", "X-Audit-User": "maloyakapg@gmail.com"})
|
|
self.assertEqual(code, 200)
|
|
|
|
|
|
class ArchitectureFiles(unittest.TestCase):
|
|
def test_required_docs(self):
|
|
required = [
|
|
"docs/architecture/README.md",
|
|
"docs/architecture/FULL-ARCHITECTURE.md",
|
|
"docs/architecture/SPRINT-TRACKER.md",
|
|
"docs/architecture/DECISIONS/ADR-004-media-first.md",
|
|
"docs/architecture/CONTRACTS/media-api.yaml",
|
|
"docs/admin/ADMIN-GUIDE.md",
|
|
"docs/user/USER-GUIDE.md",
|
|
]
|
|
for p in required:
|
|
self.assertTrue((ROOT / p).is_file(), p)
|
|
|
|
def test_no_key_patterns_in_docs(self):
|
|
pat = re.compile(r"(sk-[A-Za-z0-9]{20,}|ghp_[A-Za-z0-9]{20,}|AIza[0-9A-Za-z_-]{20,})")
|
|
bad = []
|
|
for p in (ROOT / "docs").rglob("*"):
|
|
if p.is_file() and p.suffix.lower() in (".md", ".txt", ".yaml", ".yml", ".json"):
|
|
if pat.search(p.read_text(errors="ignore")):
|
|
bad.append(str(p))
|
|
self.assertEqual(bad, [])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main(verbosity=2)
|