diff options
| author | Danilo M. <danix@danix.xyz> | 2026-09-10 16:45:54 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-09-10 16:45:54 +0200 |
| commit | 88d07d352e84b0c32012c6989e8402980e0a3b94 (patch) | |
| tree | b45cdf88fdc6d65ed06f53725dfc3753f0ad27e8 /tests | |
| parent | 44ebca17e307a6c86308f59789f52f98c683e1c2 (diff) | |
| download | abusectl-88d07d352e84b0c32012c6989e8402980e0a3b94.tar.gz abusectl-88d07d352e84b0c32012c6989e8402980e0a3b94.zip | |
feat: read which reporting destinations are configured
Adds DESTINATION_KEYS and two Config fields, destinations and
incomplete, so config.load() reports which of misp/abusedb/urlhaus
have every required key filled with a non-empty string. A half-filled
MISP pair is reported as data via incomplete, never raised: parse and
contacts load this same file and read neither key, and report (task 6)
is the one that will refuse it.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0176FYdVfpzUq8S9jecqQqL6
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_config.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/test_config.py b/tests/test_config.py index 1815993..f62960b 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -281,5 +281,63 @@ class TestConfig(unittest.TestCase): ) +class ConfiguredDestinations(unittest.TestCase): + def _load(self, text): + with tempfile.TemporaryDirectory() as tmp: + path = pathlib.Path(tmp) / "config.toml" + general = '[general]\ntrusted_relays = ["192.0.2.0/24"]\n' + # A bare top-level assignment (no leading "[") is only valid TOML + # before the first table header, so it must precede [general] + # rather than follow it. + combined = text + general if text and not text.startswith("[") \ + else general + text + path.write_text(combined) + return config.load(path) + + def test_no_sections_means_nothing_configured(self): + self.assertEqual(self._load("").destinations, set()) + + def test_a_vendor_with_a_key_is_configured(self): + settings = self._load('[abusedb]\napi_key = "k"\n') + self.assertEqual(settings.destinations, {"abusedb"}) + + def test_a_vendor_section_with_no_key_is_not_configured(self): + # Absent reads as not-configured, which is the whole convention. + self.assertEqual(self._load("[urlhaus]\n").destinations, set()) + + def test_an_empty_key_is_not_configured(self): + # api_key = "" is the trap this file exists to refuse: it reads as + # configured-and-broken and produces an auth error much later. + self.assertEqual(self._load('[urlhaus]\napi_key = ""\n').destinations, + set()) + + def test_misp_needs_both_halves(self): + both = '[misp]\nurl = "https://misp.example.invalid"\napi_key = "k"\n' + self.assertEqual(self._load(both).destinations, {"misp"}) + + def test_half_a_misp_pair_is_reported_separately_not_configured(self): + # Not an exception here: parse and contacts load this same file and + # read neither key. report refuses instead, with a sentence. + settings = self._load('[misp]\nurl = "https://misp.example.invalid"\n') + self.assertEqual(settings.destinations, set()) + self.assertEqual(settings.incomplete, {"misp": "api_key"}) + + def test_the_other_half_is_reported_too(self): + settings = self._load('[misp]\napi_key = "k"\n') + self.assertEqual(settings.destinations, set()) + self.assertEqual(settings.incomplete, {"misp": "url"}) + + def test_a_non_string_key_is_rejected_naming_the_file(self): + with self.assertRaises(ValueError) as caught: + self._load("[abusedb]\napi_key = 42\n") + self.assertIn("abusedb.api_key", str(caught.exception)) + self.assertIn("config.toml", str(caught.exception)) + + def test_a_non_table_section_is_rejected(self): + with self.assertRaises(ValueError) as caught: + self._load('abusedb = "nope"\n') + self.assertIn("abusedb", str(caught.exception)) + + if __name__ == "__main__": unittest.main() |
