fix(auditor): heal on decision-duration drift, not just IP membership/count

This commit is contained in:
patrick committed 2026-02-23 22:20:16 -05:00
1 parent 480eea8095
commit 28267a0cf4
2 files changed
+101 -11

No files matched your search

+36
View File
@@ -1,4 +1,5 @@
import unittest
import datetime
from auditor import FirewallAuditor
@@ -33,6 +34,41 @@ class AuditorDecisionExtractionTests(unittest.TestCase):
self.assertIn(("3.3.3.3", "12h", "manual"), decision_keys)
self.assertEqual(3, len(decision_keys))
def test_reconcile_detects_metadata_drift_for_extended_duration(self):
auditor = FirewallAuditor()
auditor.get_remote_lapi_truth = lambda: {
"1.1.1.1": {"duration": "24h", "until_epoch": None}
}
auditor.get_kernel_state = lambda: {"1.1.1.1": 3 * 3600 * 1000}
is_synced, count, drift = auditor.reconcile()
self.assertFalse(is_synced)
self.assertEqual(1, count)
self.assertEqual("metadata_drift", drift["reason"])
self.assertEqual(1, drift["metadata_drift_count"])
def test_reconcile_uses_until_for_expected_remaining(self):
now_epoch = datetime.datetime.now(datetime.timezone.utc).timestamp()
auditor = FirewallAuditor()
auditor.get_remote_lapi_truth = lambda: {
"2.2.2.2": {
"duration": "4h",
"until_epoch": now_epoch + (24 * 3600),
}
}
auditor.get_kernel_state = lambda: {"2.2.2.2": 2 * 3600 * 1000}
is_synced, _, drift = auditor.reconcile()
self.assertFalse(is_synced)
self.assertEqual("metadata_drift", drift["reason"])
def test_parse_duration_supports_compound_values(self):
auditor = FirewallAuditor()
self.assertEqual(5400, auditor.parse_duration("1h30m"))
self.assertEqual(1209600, auditor.parse_duration("14d"))
if __name__ == "__main__":
unittest.main()