aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_init.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/test_init.py b/tests/test_init.py
index 46b1a26..4f2042c 100644
--- a/tests/test_init.py
+++ b/tests/test_init.py
@@ -321,3 +321,30 @@ class TestWriteGuard(unittest.TestCase):
if __name__ == "__main__":
unittest.main()
+
+
+class TestRepeatedInit(unittest.TestCase):
+ """build()'s own preamble and footer must not accrete across rewrites.
+
+ Found by hand test, not by the suite: a single rewrite looks fine, and
+ the file still parses, so only the third run makes it obvious. The
+ carried text is build()'s, not the user's, so preserving it duplicated
+ the header once per run.
+ """
+
+ def test_the_preamble_and_footer_survive_four_rewrites_exactly_once(self):
+ answers = {"trusted_relays": ["192.0.2.0/24"], "cases": ""}
+ with tempfile.TemporaryDirectory() as tmp:
+ path = pathlib.Path(tmp) / "config.toml"
+ init.write(path, answers)
+ path.write_text(
+ path.read_text() + '\n[misp]\napi_key = "SECRET"\n'
+ )
+ for _ in range(3):
+ init.write(path, answers, force=True)
+
+ text = path.read_text()
+ self.assertEqual(text.count("# abusectl configuration."), 1)
+ self.assertEqual(text.count("# Later parts of abusectl"), 1)
+ # The unknown section still rides across untouched.
+ self.assertEqual(tomllib.loads(text)["misp"]["api_key"], "SECRET")