From 9a13bd372a79d0c944d06801b1c3c67f8e8b8397 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Thu, 10 Sep 2026 16:56:10 +0200 Subject: feat: render the destination sections at init init.build() can now write [misp], [abusedb] and [urlhaus], the three sections report reads, so a user no longer has to hand-edit the config for them. Follows the [reporter] pattern: a section is emitted only when something was answered for it, never with an empty api_key. A half-answered pair (misp_url given, misp_api_key skipped, or vice versa) is rejected rather than silently written: config.load() would classify it "incomplete" and report would refuse, but only after the user believed setup succeeded. Task 8's prompts are the normal route in, but build() is pure and a caller can hand-build a dict, so this is enforced here too. Also fixes FOOTER, which still promised a single [vendors] table; the spec settled three separate sections and [misp] is no longer "a later part" since this plan builds it. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_0176FYdVfpzUq8S9jecqQqL6 --- tests/test_init.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'tests/test_init.py') diff --git a/tests/test_init.py b/tests/test_init.py index f1b20f8..798ed26 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -319,6 +319,50 @@ class TestWriteGuard(unittest.TestCase): self.assertNotIn("topsecret", summary) +class BuildsDestinationSections(unittest.TestCase): + ANSWERS = {"trusted_relays": ["192.0.2.0/24"]} + + def test_a_misp_pair_is_rendered(self): + text = init.build({**self.ANSWERS, + "misp_url": "https://misp.example.invalid", + "misp_api_key": "k"}) + data = tomllib.loads(text) + self.assertEqual(data["misp"]["url"], "https://misp.example.invalid") + self.assertEqual(data["misp"]["api_key"], "k") + + def test_a_vendor_key_is_rendered(self): + text = init.build({**self.ANSWERS, "abusedb_api_key": "k"}) + self.assertEqual(tomllib.loads(text)["abusedb"]["api_key"], "k") + + def test_a_skipped_destination_is_absent_not_empty(self): + # api_key = "" reads as configured-and-broken. Absent reads as + # not-configured and report can say so plainly. + text = init.build({**self.ANSWERS, "urlhaus_api_key": ""}) + self.assertNotIn("[urlhaus]", text) + self.assertNotIn("urlhaus", tomllib.loads(text)) + + def test_nothing_answered_renders_no_destination_section(self): + data = tomllib.loads(init.build(self.ANSWERS)) + for name in ("misp", "abusedb", "urlhaus"): + self.assertNotIn(name, data) + + def test_the_footer_no_longer_promises_a_vendors_table(self): + # It named [vendors] as one table; the spec settles three sections, + # and a footer describing a shape that never arrives is worse than + # no footer. + self.assertNotIn("[vendors]", init.build(self.ANSWERS)) + + def test_every_rendered_section_parses(self): + text = init.build({**self.ANSWERS, + "misp_url": "https://misp.example.invalid", + "misp_api_key": "k", + "abusedb_api_key": "a", + "urlhaus_api_key": "u"}) + data = tomllib.loads(text) + self.assertEqual(set(data) & {"misp", "abusedb", "urlhaus"}, + {"misp", "abusedb", "urlhaus"}) + + if __name__ == "__main__": unittest.main() -- cgit v1.2.3