Barry Warsaw pushed to branch coverage at mailman / Mailman Core
Commits:
bf2897a6 by Barry Warsaw at 2017-07-23T08:42:25-05:00
Boost coverage and modernize.
- - - - -
3 changed files:
- src/mailman/rules/docs/suspicious.rst
- src/mailman/rules/suspicious.py
- src/mailman/rules/tests/test_suspicious.py
Changes:
=====================================
src/mailman/rules/docs/suspicious.rst
=====================================
--- a/src/mailman/rules/docs/suspicious.rst
+++ b/src/mailman/rules/docs/suspicious.rst
@@ -6,7 +6,7 @@ Suspicious headers are a way for Mailman to hold messages that
match a
particular regular expression. This mostly historical feature is fairly
confusing to users, and the list attribute that controls this is misnamed.
- >>> mlist = create_list('[email protected]')
+ >>> mlist = create_list('[email protected]')
>>> rule = config.rules['suspicious-header']
>>> print(rule.name)
suspicious-header
@@ -16,9 +16,9 @@ Set the so-called suspicious header configuration variable.
>>> mlist.bounce_matching_headers = 'From: .*person@(blah.)?example.com'
>>> msg = message_from_string("""\
... From: [email protected]
- ... To: [email protected]
+ ... To: [email protected]
... Subject: An implicit message
- ...
+ ...
... """)
>>> rule.check(mlist, msg, {})
True
@@ -28,9 +28,9 @@ This one comes from a ``.org`` address.
>>> msg = message_from_string("""\
... From: [email protected]
- ... To: [email protected]
+ ... To: [email protected]
... Subject: An implicit message
- ...
+ ...
... """)
>>> rule.check(mlist, msg, {})
False
=====================================
src/mailman/rules/suspicious.py
=====================================
--- a/src/mailman/rules/suspicious.py
+++ b/src/mailman/rules/suspicious.py
@@ -60,7 +60,7 @@ def _parse_matching_header_opt(mlist):
# This didn't look like a header line. BAW: should do a
# better job of informing the list admin.
log.error('bad bounce_matching_header line: %s\n%s',
- mlist.display_name, line)
+ mlist.list_id, line)
else:
header = line[:i]
value = line[i+1:].lstrip()
@@ -71,7 +71,7 @@ def _parse_matching_header_opt(mlist):
# job of informing the list admin.
log.error("""\
bad regexp in bounce_matching_header line: %s
-\n%s (cause: %s)""", mlist.display_name, value, error)
+"%s" (cause: %s)""", mlist.list_id, value, error)
else:
all.append((header, cre, line))
return all
=====================================
src/mailman/rules/tests/test_suspicious.py
=====================================
--- a/src/mailman/rules/tests/test_suspicious.py
+++ b/src/mailman/rules/tests/test_suspicious.py
@@ -24,17 +24,24 @@ from email.header import Header
from mailman.app.lifecycle import create_list
from mailman.email.message import Message
from mailman.rules import suspicious
+from mailman.testing.helpers import (
+ LogFileMark, specialized_message_from_string as mfs)
from mailman.testing.layers import ConfigLayer
class TestSuspicious(unittest.TestCase):
- """Test the suspicious rule."""
-
layer = ConfigLayer
+ maxDiff = None
def setUp(self):
- self._mlist = create_list('[email protected]')
+ self._mlist = create_list('[email protected]')
self._rule = suspicious.SuspiciousHeader()
+ self._msg = mfs("""\
+From: [email protected]
+To: [email protected]
+Subject: A message
+
+""")
def test_header_instance(self):
msg = Message()
@@ -42,3 +49,29 @@ class TestSuspicious(unittest.TestCase):
self._mlist.bounce_matching_headers = 'from: [email protected]'
result = self._rule.check(self._mlist, msg, {})
self.assertFalse(result)
+
+ def test_bounce_matching_header_not_a_header(self):
+ mark = LogFileMark('mailman.error')
+ self._mlist.bounce_matching_headers = 'This is not a header'
+ result = self._rule.check(self._mlist, self._msg, {})
+ self.assertFalse(result)
+ log_lines = mark.read().splitlines()
+ self.assertEqual(
+ log_lines[0][-48:],
+ 'bad bounce_matching_header line: ant.example.com')
+ self.assertEqual(
+ log_lines[1][-20:],
+ 'This is not a header')
+
+ def test_bounce_matching_header_not_a_regexp(self):
+ mark = LogFileMark('mailman.error')
+ self._mlist.bounce_matching_headers = 'From: [a-z'
+ result = self._rule.check(self._mlist, self._msg, {})
+ self.assertFalse(result)
+ log_lines = mark.read().splitlines()
+ self.assertEqual(
+ log_lines[0][-58:],
+ 'bad regexp in bounce_matching_header line: ant.example.com')
+ self.assertEqual(
+ log_lines[1][-56:],
+ '"[a-z" (cause: unterminated character set at position 0)')
View it on GitLab:
https://gitlab.com/mailman/mailman/commit/bf2897a6de0dd93f2a0a870ac3059632cc0fc163
---
View it on GitLab:
https://gitlab.com/mailman/mailman/commit/bf2897a6de0dd93f2a0a870ac3059632cc0fc163
You're receiving this email because of your account on gitlab.com.
_______________________________________________
Mailman-checkins mailing list
[email protected]
Unsubscribe:
https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org