diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_init.py | 44 |
1 files changed, 44 insertions, 0 deletions
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() |
