summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mailman/rules/dmarc.py11
-rw-r--r--src/mailman/rules/tests/data/org_domain.txt2
-rw-r--r--src/mailman/rules/tests/test_dmarc.py12
3 files changed, 19 insertions, 6 deletions
diff --git a/src/mailman/rules/dmarc.py b/src/mailman/rules/dmarc.py
index 122aefe7b..8180211bc 100644
--- a/src/mailman/rules/dmarc.py
+++ b/src/mailman/rules/dmarc.py
@@ -102,12 +102,13 @@ def ensure_current_suffix_list():
return cached_copy_path
-def parse_suffix_list():
+def parse_suffix_list(filename=None):
# Parse the suffix list into a per process cache.
- cached_copy_path = ensure_current_suffix_list()
+ if filename is None:
+ filename = ensure_current_suffix_list()
# At this point the cached copy must exist and is as valid as possible.
# Read and return the contents as a UTF-8 string.
- with open(cached_copy_path, 'r', encoding='utf-8') as fp:
+ with open(filename, 'r', encoding='utf-8') as fp:
for line in fp:
if not line.strip() or line.startswith('//'):
continue
@@ -121,8 +122,8 @@ def parse_suffix_list():
else:
exception = False
parts.reverse()
- k = DOT.join(parts)
- suffix_cache[k] = exception
+ key = DOT.join(parts)
+ suffix_cache[key] = exception
def _get_dom(d, l):
diff --git a/src/mailman/rules/tests/data/org_domain.txt b/src/mailman/rules/tests/data/org_domain.txt
index 4e6f7816e..e10db8a32 100644
--- a/src/mailman/rules/tests/data/org_domain.txt
+++ b/src/mailman/rules/tests/data/org_domain.txt
@@ -17,7 +17,7 @@ org
!city.kobe.jp
// A line with a trailing comment for testing
-co.uk some nonesence
+co.uk some nonsense
// A line with leading white space (ignored)
example.biz
diff --git a/src/mailman/rules/tests/test_dmarc.py b/src/mailman/rules/tests/test_dmarc.py
index df5127895..7748343eb 100644
--- a/src/mailman/rules/tests/test_dmarc.py
+++ b/src/mailman/rules/tests/test_dmarc.py
@@ -173,6 +173,18 @@ To: ant@example.com
'anne@example.info (_dmarc.example.info). '
'Abstract base class shared by all dnspython exceptions.\n')
+ def test_parser(self):
+ data_file = resource_filename(
+ 'mailman.rules.tests.data', 'org_domain.txt')
+ dmarc.parse_suffix_list(data_file)
+ # There is no entry for example.biz because that line starts with
+ # whitespace.
+ self.assertNotIn('biz.example', self.cache)
+ # The file had !city.kobe.jp so the flag says there's an exception.
+ self.assertTrue(self.cache['jp.kobe.city'])
+ # The file had *.kobe.jp so there's no exception.
+ self.assertFalse(self.cache['jp.kobe.*'])
+
# New in Python 3.5.
try: