aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-09-08 13:57:11 +0200
committerDanilo M. <danix@danix.xyz>2026-09-08 13:57:11 +0200
commit0f5b1e38f448b554b13e6f6189cb8b7fbd22a95e (patch)
treeaf7e3f662353ef06ad2429948a42ddd0467d811a /tests
parentb491b772b9f68c0c61a62597a972b6cc7848466e (diff)
downloadabusectl-0f5b1e38f448b554b13e6f6189cb8b7fbd22a95e.tar.gz
abusectl-0f5b1e38f448b554b13e6f6189cb8b7fbd22a95e.zip
fix: reject non-list relays and empty cases values
An empty cases string resolved to Path("") = cwd, scattering evidence wherever the command happened to run. A string trusted_relays (easy to hand-write without brackets) iterated as characters, failing on '1' with an error naming nothing findable in the file. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KphFXTc2QajxXsHWyvGJ4R
Diffstat (limited to 'tests')
-rw-r--r--tests/test_config.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/test_config.py b/tests/test_config.py
index c0a9ac4..6fa8619 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -76,6 +76,35 @@ class TestConfig(unittest.TestCase):
config.load(path)
self.assertNotIsInstance(caught.exception, config.NotConfigured)
+ def test_an_empty_cases_value_falls_back_to_the_default(self):
+ # Empty is the same as absent, per this module's own rule: writing
+ # Path("") would put evidence in whatever directory the command
+ # happened to run from.
+ path = self._write(
+ '[general]\ntrusted_relays = ["192.0.2.0/24"]\ncases = ""\n'
+ )
+ self.assertEqual(config.load(path).cases, config.DEFAULT_CASES)
+
+ def test_a_whitespace_cases_value_falls_back_to_the_default(self):
+ path = self._write(
+ '[general]\ntrusted_relays = ["192.0.2.0/24"]\ncases = " "\n'
+ )
+ self.assertEqual(config.load(path).cases, config.DEFAULT_CASES)
+
+ def test_a_string_trusted_relays_is_rejected_clearly(self):
+ # Easy to write by hand without the brackets. Iterating the string
+ # validates single characters and reports an error naming nothing
+ # the user can find in their file.
+ path = self._write('[general]\ntrusted_relays = "192.0.2.0/24"\n')
+ with self.assertRaises(ValueError) as caught:
+ config.load(path)
+ self.assertIn("must be a list", str(caught.exception))
+
+ def test_a_relay_entry_that_is_not_a_string_is_rejected_clearly(self):
+ path = self._write("[general]\ntrusted_relays = [42]\n")
+ with self.assertRaises(ValueError):
+ config.load(path)
+
def test_the_config_path_follows_xdg_config_home(self):
with mock.patch.dict(os.environ, {"XDG_CONFIG_HOME": "/tmp/xdg-probe"}):
self.assertEqual(