mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2026-09-14 18:56:52 +00:00
ProxMenux modifies the host: it rewrites configuration files, installs packages, enables services. Until now nobody could say afterwards what had changed, and showing the script does not answer that question — a four-hundred-line function may alter two values, and the reader has no way to know which two. This adds the two halves of an answer. The change journal records what ProxMenux does as it does it. Eleven bash primitives capture the previous state, apply the change and record it in the same step, writing to a spool that the Monitor reads back. One hundred and thirteen functions across twenty-five scripts are instrumented, covering post-install, shared storage, security tooling, container conversions, disk operations and the PVE 8 to 9 upgrade path. The page shows the difference — rotate 7 becoming rotate 14 — and never the script. Restore and backup scripts are deliberately left out: a restore puts the host back to a state some other script already recorded. The Audit and reports page answers the other half: what state is this host in, regardless of who put it there. Forty-three checks across seven areas read the host and classify each result as critical, warning, observation, conformant, unverified or not applicable, with the evidence they read attached to each one. A declared policy lets the reader say what this particular host is expected to do — which guests must have a backup, which storages are essential — so the report judges the host against its own intent rather than a generic template. An inventory records the hardware, network and guest topology behind those readings, a comparison shows what moved between two runs, and six report profiles produce a printable document scoped to what the reader needs. Everything is available in the eight supported languages. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
65 lines
2.9 KiB
Python
65 lines
2.9 KiB
Python
"""Policy endpoint contracts; authentication and storage are isolated fixtures."""
|
|
import importlib
|
|
from pathlib import Path
|
|
import sys
|
|
import tempfile
|
|
import types
|
|
import unittest
|
|
from unittest.mock import patch
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "AppImage/scripts"))
|
|
from flask import Flask
|
|
import audit_policy as policy
|
|
import audit_store as store
|
|
|
|
|
|
class PolicyApiTests(unittest.TestCase):
|
|
def setUp(self):
|
|
temp = tempfile.TemporaryDirectory()
|
|
self.addCleanup(temp.cleanup)
|
|
self.path = Path(temp.name) / "policy.json"
|
|
original_load, original_save = policy.load, policy.save
|
|
for patcher in (
|
|
patch.object(policy, "load", side_effect=lambda *args: original_load(self.path)),
|
|
patch.object(policy, "save", side_effect=lambda raw, **kw: original_save(raw, self.path, **kw)),
|
|
patch.object(store, "DB_PATH", Path(temp.name) / "audit.db"),
|
|
patch.object(store, "_schema_ready", False),
|
|
):
|
|
patcher.start(); self.addCleanup(patcher.stop)
|
|
auth = types.ModuleType("auth_manager")
|
|
auth.load_auth_config = lambda: {"enabled": True}
|
|
auth.verify_token = lambda token: "fixture"
|
|
middleware = types.ModuleType("jwt_middleware")
|
|
middleware.require_auth = lambda f: f
|
|
middleware.require_admin_scope = lambda f: f
|
|
with patch.dict(sys.modules, auth_manager=auth, jwt_middleware=middleware):
|
|
sys.modules.pop("flask_audit_routes", None)
|
|
routes = importlib.import_module("flask_audit_routes")
|
|
self.addCleanup(lambda: sys.modules.pop("flask_audit_routes", None))
|
|
app = Flask(__name__)
|
|
app.register_blueprint(routes.audit_bp)
|
|
self.client = app.test_client()
|
|
|
|
def test_revision_and_conflict_contract(self):
|
|
first = self.client.get("/api/audit/policy").json
|
|
self.assertEqual(first["summary"]["revision"], "missing")
|
|
self.assertEqual(self.client.put("/api/audit/policy", json={}).status_code, 428)
|
|
payload = {"expected_revision": "missing", "defaults": {"backup": "required"}}
|
|
response = self.client.put("/api/audit/policy", json=payload)
|
|
self.assertEqual(response.status_code, 200)
|
|
self.assertEqual(self.client.put("/api/audit/policy", json=payload).status_code, 409)
|
|
self.assertEqual(self.client.get("/api/audit/policy").json["policy"]["defaults"]["backup"], "required")
|
|
|
|
def test_validation_error_is_not_silent_success(self):
|
|
bad = {"expected_revision": "missing", "thresholds": {"storage_usage_percent": True}}
|
|
self.assertEqual(self.client.put("/api/audit/policy", json=bad).status_code, 400)
|
|
self.assertFalse(self.path.exists())
|
|
|
|
def test_invalid_file_does_not_open_empty_editor(self):
|
|
self.path.write_text("invalid json")
|
|
self.assertEqual(self.client.get("/api/audit/policy").status_code, 422)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|