feat(auditor): add startup enforcement sanity check and dedupe set-mismatch warnings
This commit is contained in:
1 parent
389f310f24
commit
c698d01c40
3 files changed
+92
-4
No files matched your search
@@ -284,6 +284,45 @@ class AuditorDecisionExtractionTests(unittest.TestCase):
|
||||
|
||||
self.assertEqual({"1.1.1.1": 1000.0}, kernel_state)
|
||||
|
||||
@patch("auditor.subprocess.run")
|
||||
def test_startup_check_warns_when_configured_sets_have_no_overlap(self, run_mock):
|
||||
auditor = FirewallAuditor(
|
||||
targets=[("ip", "crowdsec")],
|
||||
managed_sets=["missing-set-name"],
|
||||
)
|
||||
run_mock.return_value = subprocess.CompletedProcess(
|
||||
args=[],
|
||||
returncode=0,
|
||||
stdout=json.dumps(
|
||||
{"nftables": [{"set": {"name": "crowdsec-blacklists-cscli"}}]}
|
||||
),
|
||||
)
|
||||
|
||||
with self.assertLogs(level="WARNING") as logs:
|
||||
auditor.log_enforcement_startup_state()
|
||||
|
||||
self.assertTrue(
|
||||
any("Configured enforcement sets not found" in msg for msg in logs.output)
|
||||
)
|
||||
|
||||
@patch("auditor.subprocess.run")
|
||||
@patch("auditor.logging.warning")
|
||||
def test_startup_check_no_warning_when_overlap_exists(self, warning_mock, run_mock):
|
||||
auditor = FirewallAuditor(
|
||||
targets=[("ip", "crowdsec")],
|
||||
managed_sets=["crowdsec-blacklists-cscli"],
|
||||
)
|
||||
run_mock.return_value = subprocess.CompletedProcess(
|
||||
args=[],
|
||||
returncode=0,
|
||||
stdout=json.dumps(
|
||||
{"nftables": [{"set": {"name": "crowdsec-blacklists-cscli"}}]}
|
||||
),
|
||||
)
|
||||
|
||||
auditor.log_enforcement_startup_state()
|
||||
warning_mock.assert_not_called()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user