|
| 1 | +"""Automated security, dependency floor, and third-party license contract tests for DevCenter.""" |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +import re |
| 6 | +from pathlib import Path |
| 7 | + |
| 8 | +ROOT = Path(__file__).resolve().parents[1] |
| 9 | + |
| 10 | + |
| 11 | +def test_dependency_vulnerability_floors() -> None: |
| 12 | + """Verify requirements.txt and pyproject.toml enforce patched dependency floors against CVEs.""" |
| 13 | + req_file = ROOT / "requirements.txt" |
| 14 | + assert req_file.is_file(), "requirements.txt must exist" |
| 15 | + req_text = req_file.read_text(encoding="utf-8") |
| 16 | + |
| 17 | + # Pillow >= 12.3.0 floor resolves CVEs/GHSAs (GHSA-4x4j-2g7c-83w6, GHSA-45hq-cxwh-f6vc) |
| 18 | + assert re.search(r"^Pillow\s*>=\s*12\.3\.0", req_text, re.MULTILINE), ( |
| 19 | + "requirements.txt must enforce Pillow>=12.3.0 floor" |
| 20 | + ) |
| 21 | + assert re.search(r"^keyring\s*>=\s*25\.0\.0", req_text, re.MULTILINE), ( |
| 22 | + "requirements.txt must enforce keyring>=25.0.0 floor" |
| 23 | + ) |
| 24 | + |
| 25 | + pyproject_file = ROOT / "pyproject.toml" |
| 26 | + assert pyproject_file.is_file(), "pyproject.toml must exist" |
| 27 | + pyproject_text = pyproject_file.read_text(encoding="utf-8") |
| 28 | + |
| 29 | + # PEP 621 dependencies section |
| 30 | + assert "dependencies = [" in pyproject_text, "pyproject.toml must define project.dependencies" |
| 31 | + assert "Pillow>=12.3.0" in pyproject_text, "pyproject.toml must specify Pillow>=12.3.0" |
| 32 | + assert "keyring>=25.0.0" in pyproject_text, "pyproject.toml must specify keyring>=25.0.0" |
| 33 | + |
| 34 | + # Dev/test optional dependencies floor (pytest >= 9.1.1 protects against CVE-2025-7117 / GHSA-6w46-j5rx-g56g) |
| 35 | + assert "[project.optional-dependencies]" in pyproject_text, "pyproject.toml must define optional-dependencies" |
| 36 | + assert "pytest>=9.1.1" in pyproject_text, "pyproject.toml dev dependencies must require pytest>=9.1.1" |
| 37 | + assert "ruff>=0.9.0" in pyproject_text, "pyproject.toml dev dependencies must require ruff>=0.9.0" |
| 38 | + |
| 39 | + |
| 40 | +def test_third_party_licenses_complete_and_accurate() -> None: |
| 41 | + """Verify THIRD_PARTY_LICENSES.txt comprehensively covers runtime, transitive, build, and test packages.""" |
| 42 | + license_file = ROOT / "THIRD_PARTY_LICENSES.txt" |
| 43 | + assert license_file.is_file(), "THIRD_PARTY_LICENSES.txt must exist" |
| 44 | + content = license_file.read_text(encoding="utf-8") |
| 45 | + |
| 46 | + required_packages = [ |
| 47 | + ("PySide6", "LGPL-3.0-only"), |
| 48 | + ("Pillow", "HPND-sell-variant"), |
| 49 | + ("anthropic", "MIT"), |
| 50 | + ("keyring", "MIT"), |
| 51 | + ("chardet", "LGPL-2.1-or-later"), |
| 52 | + ("ftfy", "Apache-2.0"), |
| 53 | + ("pip-licenses", "MIT"), |
| 54 | + ("watchdog", "Apache-2.0"), |
| 55 | + ("pywin32-ctypes", "BSD-3-Clause"), |
| 56 | + ("jaraco.classes", "MIT"), |
| 57 | + ("jaraco.context", "MIT"), |
| 58 | + ("jaraco.functools", "MIT"), |
| 59 | + ("PyInstaller", "GPL-2.0-or-later WITH Bootloader-exception"), |
| 60 | + ("pyinstaller-hooks-contrib", "Apache-2.0"), |
| 61 | + ("altgraph", "MIT"), |
| 62 | + ("packaging", "Apache-2.0 OR BSD-2-Clause"), |
| 63 | + ("pytest", "MIT"), |
| 64 | + ("pluggy", "MIT"), |
| 65 | + ("iniconfig", "MIT"), |
| 66 | + ("ruff", "MIT OR Apache-2.0"), |
| 67 | + ] |
| 68 | + |
| 69 | + for pkg, spdx in required_packages: |
| 70 | + assert pkg in content, f"Package {pkg} missing from THIRD_PARTY_LICENSES.txt" |
| 71 | + assert spdx in content, f"SPDX identifier {spdx} for {pkg} missing from THIRD_PARTY_LICENSES.txt" |
| 72 | + |
| 73 | + # Ensure structured schema fields exist |
| 74 | + assert "License:" in content, "License: field missing in THIRD_PARTY_LICENSES.txt" |
| 75 | + assert "URL:" in content, "URL: field missing in THIRD_PARTY_LICENSES.txt" |
| 76 | + assert "SPDX:" in content, "SPDX: field missing in THIRD_PARTY_LICENSES.txt" |
| 77 | + assert "Notice:" in content, "Notice: field missing in THIRD_PARTY_LICENSES.txt" |
| 78 | + |
| 79 | + |
| 80 | +def test_gitignore_security_and_multi_host_hardening() -> None: |
| 81 | + """Verify .gitignore blocks private secrets, certificates, and multi-host conflict files.""" |
| 82 | + gitignore_file = ROOT / ".gitignore" |
| 83 | + assert gitignore_file.is_file(), ".gitignore must exist" |
| 84 | + content = gitignore_file.read_text(encoding="utf-8") |
| 85 | + |
| 86 | + # Secrets and certificate protection |
| 87 | + for pat in ["credentials.json", "*.pfx", "*.pem", "*.key", "keyring/", "secrets.*"]: |
| 88 | + assert pat in content, f"Secret pattern {pat} missing in .gitignore" |
| 89 | + |
| 90 | + # Multi-host sync hardening |
| 91 | + for host_pat in ["*-WORKSTATION-LG*", "*-ASUS-GEI*", "*.sync-conflict-*", "*.conflict"]: |
| 92 | + assert host_pat in content, f"Sync conflict pattern {host_pat} missing in .gitignore" |
| 93 | + |
| 94 | + # Multi-agent lock system fail-closed patterns |
| 95 | + for lock_pat in ["LOCK.*", "*.lock", "LOCK*.txt"]: |
| 96 | + assert lock_pat in content, f"Lock pattern {lock_pat} missing in .gitignore" |
| 97 | + |
| 98 | + |
| 99 | +def test_no_hardcoded_user_paths_in_python_code() -> None: |
| 100 | + """Verify no hardcoded personal user profile paths (e.g. C:\\Users\\lukas) exist in active Python source.""" |
| 101 | + disallowed_regex = re.compile(r"""(?i)C:[/\\]Users[/\\](?:lukas|admin|administrator)[/\\]""", re.VERBOSE) |
| 102 | + |
| 103 | + python_files = list(ROOT.glob("*.py")) + list((ROOT / "src").rglob("*.py")) + list((ROOT / "tests").glob("*.py")) |
| 104 | + assert len(python_files) >= 50, f"Expected at least 50 Python files to scan, found {len(python_files)}" |
| 105 | + |
| 106 | + violating_lines = [] |
| 107 | + for py_file in python_files: |
| 108 | + if not py_file.is_file(): |
| 109 | + continue |
| 110 | + try: |
| 111 | + text = py_file.read_text(encoding="utf-8") |
| 112 | + except Exception: |
| 113 | + continue |
| 114 | + for idx, line in enumerate(text.splitlines(), 1): |
| 115 | + if disallowed_regex.search(line): |
| 116 | + violating_lines.append(f"{py_file.name}:{idx}: {line.strip()}") |
| 117 | + |
| 118 | + assert not violating_lines, "Found hardcoded user paths in Python code:\n" + "\n".join(violating_lines) |
| 119 | + |
| 120 | + |
| 121 | +def test_security_policy_sla_and_contacts() -> None: |
| 122 | + """Verify SECURITY.md maintains strict SLA and designated response channels.""" |
| 123 | + sec_file = ROOT / "SECURITY.md" |
| 124 | + assert sec_file.is_file(), "SECURITY.md must exist" |
| 125 | + content = sec_file.read_text(encoding="utf-8") |
| 126 | + |
| 127 | + assert "security@dev-bricks.org" in content, "security@dev-bricks.org missing from SECURITY.md" |
| 128 | + assert "security@open-bricks.org" in content, "security@open-bricks.org missing from SECURITY.md" |
| 129 | + assert "security@ellmos.ai" in content, "security@ellmos.ai missing from SECURITY.md" |
| 130 | + assert "support@lukasgeiger.com" in content, "support@lukasgeiger.com missing from SECURITY.md" |
| 131 | + assert "48" in content, "48h initial acknowledgment SLA missing" |
| 132 | + assert "5" in content, "5-day triage commitment missing" |
| 133 | + assert "Sicherheitsrichtlinie" in content, "German section header missing" |
| 134 | + |
| 135 | + |
| 136 | +if __name__ == "__main__": |
| 137 | + import pytest |
| 138 | + raise SystemExit(pytest.main(["-v", __file__])) |
0 commit comments