summaryrefslogtreecommitdiff
path: root/src/mailman/rules/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/mailman/rules/tests')
-rw-r--r--src/mailman/rules/tests/test_administrivia.py51
-rw-r--r--src/mailman/rules/tests/test_banned_address.py24
-rw-r--r--src/mailman/rules/tests/test_emergency.py52
-rw-r--r--src/mailman/rules/tests/test_implicit_dest.py51
-rw-r--r--src/mailman/rules/tests/test_loop.py52
-rw-r--r--src/mailman/rules/tests/test_max_recipients.py53
-rw-r--r--src/mailman/rules/tests/test_max_size.py55
-rw-r--r--src/mailman/rules/tests/test_news_moderation.py53
-rw-r--r--src/mailman/rules/tests/test_no_senders.py5
-rw-r--r--src/mailman/rules/tests/test_no_subject.py9
-rw-r--r--src/mailman/rules/tests/test_suspicious.py13
11 files changed, 415 insertions, 3 deletions
diff --git a/src/mailman/rules/tests/test_administrivia.py b/src/mailman/rules/tests/test_administrivia.py
new file mode 100644
index 000000000..e370a0bf2
--- /dev/null
+++ b/src/mailman/rules/tests/test_administrivia.py
@@ -0,0 +1,51 @@
+# Copyright (C) 2016-2017 by the Free Software Foundation, Inc.
+#
+# This file is part of GNU Mailman.
+#
+# GNU Mailman is free software: you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option)
+# any later version.
+#
+# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
+
+"""Test the `administrivia` rule."""
+
+import unittest
+
+from mailman.app.lifecycle import create_list
+from mailman.rules import administrivia
+from mailman.testing.helpers import specialized_message_from_string as mfs
+from mailman.testing.layers import ConfigLayer
+
+
+class TestAdministrivia(unittest.TestCase):
+ """Test the administrivia rule."""
+
+ layer = ConfigLayer
+
+ def setUp(self):
+ self._mlist = create_list('test@example.com')
+
+ def test_administrivia_returns_reason(self):
+ # Ensure administrivia rule returns a reason.
+ msg = mfs("""\
+From: anne@example.com
+To: test@example.com
+Subject: unsubscribe
+Message-ID: <ant>
+
+A message body.
+""")
+ rule = administrivia.Administrivia()
+ msgdata = {}
+ result = rule.check(self._mlist, msg, msgdata)
+ self.assertTrue(result)
+ self.assertEqual(msgdata['moderation_reasons'],
+ ['Message contains administrivia'])
diff --git a/src/mailman/rules/tests/test_banned_address.py b/src/mailman/rules/tests/test_banned_address.py
index 1ecab5b18..2d73ed3fb 100644
--- a/src/mailman/rules/tests/test_banned_address.py
+++ b/src/mailman/rules/tests/test_banned_address.py
@@ -74,6 +74,30 @@ A message body.
result = rule.check(self._mlist, msg, {})
self.assertTrue(result)
+ def test_rule_returns_reason(self):
+ # Ensure a reason is returned.
+ user_manager = getUtility(IUserManager)
+ anne = user_manager.create_user('anne@example.com')
+ set_preferred(anne)
+ IBanManager(self._mlist).ban('anne@example.com')
+ msg = mfs("""\
+From: anne@example.com
+To: test@example.com
+Subject: A test message
+Message-ID: <ant>
+MIME-Version: 1.0
+
+A message body.
+""")
+ rule = banned_address.BannedAddress()
+ msgdata = {}
+ result = rule.check(self._mlist, msg, msgdata)
+ self.assertTrue(result)
+ self.assertEqual(
+ msgdata['moderation_reasons'],
+ [('Message sender {} is banned from this list',
+ 'anne@example.com')])
+
def test_banned_address_linked_to_user(self):
# Anne is subscribed to a mailing list as a user with her preferred
# address. She also has a secondary address which is banned and which
diff --git a/src/mailman/rules/tests/test_emergency.py b/src/mailman/rules/tests/test_emergency.py
new file mode 100644
index 000000000..529742987
--- /dev/null
+++ b/src/mailman/rules/tests/test_emergency.py
@@ -0,0 +1,52 @@
+# Copyright (C) 2016-2017 by the Free Software Foundation, Inc.
+#
+# This file is part of GNU Mailman.
+#
+# GNU Mailman is free software: you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option)
+# any later version.
+#
+# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
+
+"""Test the `emergency` rule."""
+
+import unittest
+
+from mailman.app.lifecycle import create_list
+from mailman.rules import emergency
+from mailman.testing.helpers import specialized_message_from_string as mfs
+from mailman.testing.layers import ConfigLayer
+
+
+class TestEmergency(unittest.TestCase):
+ """Test the emergency rule."""
+
+ layer = ConfigLayer
+
+ def setUp(self):
+ self._mlist = create_list('test@example.com')
+
+ def test_emergency_returns_reason(self):
+ # Ensure emergency rule returns a reason.
+ msg = mfs("""\
+From: anne@example.com
+To: test@example.com
+Subject: A Subject
+Message-ID: <ant>
+
+A message body.
+""")
+ rule = emergency.Emergency()
+ self._mlist.emergency = True
+ msgdata = {}
+ result = rule.check(self._mlist, msg, msgdata)
+ self.assertTrue(result)
+ self.assertEqual(msgdata['moderation_reasons'],
+ ['Emergency moderation is in effect for this list'])
diff --git a/src/mailman/rules/tests/test_implicit_dest.py b/src/mailman/rules/tests/test_implicit_dest.py
new file mode 100644
index 000000000..aed317f57
--- /dev/null
+++ b/src/mailman/rules/tests/test_implicit_dest.py
@@ -0,0 +1,51 @@
+# Copyright (C) 2016-2017 by the Free Software Foundation, Inc.
+#
+# This file is part of GNU Mailman.
+#
+# GNU Mailman is free software: you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option)
+# any later version.
+#
+# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
+
+"""Test the `implicit_dest` rule."""
+
+import unittest
+
+from mailman.app.lifecycle import create_list
+from mailman.rules import implicit_dest
+from mailman.testing.helpers import specialized_message_from_string as mfs
+from mailman.testing.layers import ConfigLayer
+
+
+class TestImplicitDestination(unittest.TestCase):
+ """Test the implicit_dest rule."""
+
+ layer = ConfigLayer
+
+ def setUp(self):
+ self._mlist = create_list('test@example.com')
+
+ def test_implicit_dest_returns_reason(self):
+ # Ensure implicit_dest rule returns a reason.
+ msg = mfs("""\
+From: anne@example.com
+To: bogus@example.com
+Subject: A Subject
+Message-ID: <ant>
+
+A message body.
+""")
+ rule = implicit_dest.ImplicitDestination()
+ msgdata = {}
+ result = rule.check(self._mlist, msg, msgdata)
+ self.assertTrue(result)
+ self.assertEqual(msgdata['moderation_reasons'],
+ ['Message has implicit destination'])
diff --git a/src/mailman/rules/tests/test_loop.py b/src/mailman/rules/tests/test_loop.py
new file mode 100644
index 000000000..09f9fc905
--- /dev/null
+++ b/src/mailman/rules/tests/test_loop.py
@@ -0,0 +1,52 @@
+# Copyright (C) 2016-2017 by the Free Software Foundation, Inc.
+#
+# This file is part of GNU Mailman.
+#
+# GNU Mailman is free software: you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option)
+# any later version.
+#
+# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
+
+"""Test the `loop` rule."""
+
+import unittest
+
+from mailman.app.lifecycle import create_list
+from mailman.rules import loop
+from mailman.testing.helpers import specialized_message_from_string as mfs
+from mailman.testing.layers import ConfigLayer
+
+
+class TestLoop(unittest.TestCase):
+ """Test the loop rule."""
+
+ layer = ConfigLayer
+
+ def setUp(self):
+ self._mlist = create_list('test@example.com')
+
+ def test_loop_returns_reason(self):
+ # Ensure loop rule returns a reason.
+ msg = mfs("""\
+From: anne@example.com
+To: test@example.com
+Subject: A Subject
+List-Post: test@example.com
+Message-ID: <ant>
+
+A message body.
+""")
+ rule = loop.Loop()
+ msgdata = {}
+ result = rule.check(self._mlist, msg, msgdata)
+ self.assertTrue(result)
+ self.assertEqual(msgdata['moderation_reasons'],
+ ['Message has already been posted to this list'])
diff --git a/src/mailman/rules/tests/test_max_recipients.py b/src/mailman/rules/tests/test_max_recipients.py
new file mode 100644
index 000000000..08663f1e5
--- /dev/null
+++ b/src/mailman/rules/tests/test_max_recipients.py
@@ -0,0 +1,53 @@
+# Copyright (C) 2016-2017 by the Free Software Foundation, Inc.
+#
+# This file is part of GNU Mailman.
+#
+# GNU Mailman is free software: you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option)
+# any later version.
+#
+# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
+
+"""Test the `max_recipients` rule."""
+
+import unittest
+
+from mailman.app.lifecycle import create_list
+from mailman.rules import max_recipients
+from mailman.testing.helpers import specialized_message_from_string as mfs
+from mailman.testing.layers import ConfigLayer
+
+
+class TestMaximumRecipients(unittest.TestCase):
+ """Test the max_recipients rule."""
+
+ layer = ConfigLayer
+
+ def setUp(self):
+ self._mlist = create_list('test@example.com')
+
+ def test_max_recipients_returns_reason(self):
+ # Ensure max_recipients rule returns a reason.
+ msg = mfs("""\
+From: anne@example.com
+To: test@example.com
+Cc: anne@example.com, bill@example.com
+Subject: A Subject
+Message-ID: <ant>
+
+A message body.
+""")
+ rule = max_recipients.MaximumRecipients()
+ self._mlist.max_num_recipients = 2
+ msgdata = {}
+ result = rule.check(self._mlist, msg, msgdata)
+ self.assertTrue(result)
+ self.assertEqual(msgdata['moderation_reasons'],
+ [('Message has more than {} recipients', 2)])
diff --git a/src/mailman/rules/tests/test_max_size.py b/src/mailman/rules/tests/test_max_size.py
new file mode 100644
index 000000000..56b279a6b
--- /dev/null
+++ b/src/mailman/rules/tests/test_max_size.py
@@ -0,0 +1,55 @@
+# Copyright (C) 2016-2017 by the Free Software Foundation, Inc.
+#
+# This file is part of GNU Mailman.
+#
+# GNU Mailman is free software: you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option)
+# any later version.
+#
+# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
+
+"""Test the `max_size` rule."""
+
+import unittest
+
+from mailman.app.lifecycle import create_list
+from mailman.rules import max_size
+from mailman.testing.helpers import specialized_message_from_string as mfs
+from mailman.testing.layers import ConfigLayer
+
+
+class TestMaximumSize(unittest.TestCase):
+ """Test the max_size rule."""
+
+ layer = ConfigLayer
+
+ def setUp(self):
+ self._mlist = create_list('test@example.com')
+
+ def test_max_size_returns_reason(self):
+ # Ensure max_size rule returns a reason.
+ msg = mfs("""\
+From: anne@example.com
+To: test@example.com
+Subject: A Subject
+Message-ID: <ant>
+
+A message body.
+""")
+ rule = max_size.MaximumSize()
+ self._mlist.max_message_size = 1
+ # Fake the size.
+ msg.original_size = 2048
+ msgdata = {}
+ result = rule.check(self._mlist, msg, msgdata)
+ self.assertTrue(result)
+ self.assertEqual(msgdata['moderation_reasons'],
+ [('The message is larger than the {} KB maximum size',
+ 1)])
diff --git a/src/mailman/rules/tests/test_news_moderation.py b/src/mailman/rules/tests/test_news_moderation.py
new file mode 100644
index 000000000..aec9e2b14
--- /dev/null
+++ b/src/mailman/rules/tests/test_news_moderation.py
@@ -0,0 +1,53 @@
+# Copyright (C) 2016-2017 by the Free Software Foundation, Inc.
+#
+# This file is part of GNU Mailman.
+#
+# GNU Mailman is free software: you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option)
+# any later version.
+#
+# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
+
+"""Test the `news_moderation` rule."""
+
+import unittest
+
+from mailman.app.lifecycle import create_list
+from mailman.interfaces.nntp import NewsgroupModeration
+from mailman.rules import news_moderation
+from mailman.testing.helpers import specialized_message_from_string as mfs
+from mailman.testing.layers import ConfigLayer
+
+
+class TestModeratedNewsgroup(unittest.TestCase):
+ """Test the news_moderation rule."""
+
+ layer = ConfigLayer
+
+ def setUp(self):
+ self._mlist = create_list('test@example.com')
+
+ def test_news_moderation_returns_reason(self):
+ # Ensure news_moderation rule returns a reason.
+ msg = mfs("""\
+From: anne@example.com
+To: test@example.com
+Subject: A Subject
+Message-ID: <ant>
+
+A message body.
+""")
+ rule = news_moderation.ModeratedNewsgroup()
+ self._mlist.newsgroup_moderation = NewsgroupModeration.moderated
+ msgdata = {}
+ result = rule.check(self._mlist, msg, msgdata)
+ self.assertTrue(result)
+ self.assertEqual(msgdata['moderation_reasons'],
+ ['Post to a moderated newsgroup gateway'])
diff --git a/src/mailman/rules/tests/test_no_senders.py b/src/mailman/rules/tests/test_no_senders.py
index eb59dfe71..06bda5360 100644
--- a/src/mailman/rules/tests/test_no_senders.py
+++ b/src/mailman/rules/tests/test_no_senders.py
@@ -25,7 +25,7 @@ from mailman.rules import no_senders
from mailman.testing.layers import ConfigLayer
-class TestNoSubject(unittest.TestCase):
+class TestNoSender(unittest.TestCase):
"""Test the no_senders rule."""
layer = ConfigLayer
@@ -39,10 +39,9 @@ class TestNoSubject(unittest.TestCase):
msgdata = {}
result = self._rule.check(self._mlist, msg, msgdata)
self.assertTrue(result)
- self.assertEqual(msgdata['moderation_action'], 'discard')
self.assertEqual(msgdata['moderation_reasons'],
['The message has no valid senders'])
- self.assertEqual(msgdata['moderation_sender'], 'None')
+ self.assertEqual(msgdata['moderation_sender'], 'N/A')
def test_message_has_sender(self):
msg = Message()
diff --git a/src/mailman/rules/tests/test_no_subject.py b/src/mailman/rules/tests/test_no_subject.py
index 0379ea689..e80e2e4eb 100644
--- a/src/mailman/rules/tests/test_no_subject.py
+++ b/src/mailman/rules/tests/test_no_subject.py
@@ -46,3 +46,12 @@ class TestNoSubject(unittest.TestCase):
msg['Subject'] = Header('Test subject')
result = self._rule.check(self._mlist, msg, {})
self.assertFalse(result)
+
+ def test_no_subject_returns_reason(self):
+ msg = Message()
+ msg['Subject'] = Header('')
+ msgdata = {}
+ result = self._rule.check(self._mlist, msg, msgdata)
+ self.assertTrue(result)
+ self.assertEqual(msgdata['moderation_reasons'],
+ ['Message has no subject'])
diff --git a/src/mailman/rules/tests/test_suspicious.py b/src/mailman/rules/tests/test_suspicious.py
index b40292283..4012c89d5 100644
--- a/src/mailman/rules/tests/test_suspicious.py
+++ b/src/mailman/rules/tests/test_suspicious.py
@@ -42,3 +42,16 @@ class TestSuspicious(unittest.TestCase):
self._mlist.bounce_matching_headers = 'from: spam@example.com'
result = self._rule.check(self._mlist, msg, {})
self.assertFalse(result)
+
+ def test_suspicious_returns_reason(self):
+ msg = Message()
+ msg['From'] = Header('spam@example.com')
+ self._mlist.bounce_matching_headers = 'from: spam@example.com'
+ msgdata = {}
+ result = self._rule.check(self._mlist, msg, msgdata)
+ self.assertTrue(result)
+ self.assertEqual(
+ msgdata['moderation_reasons'],
+ [('Header "{}" matched a bounce_matching_header line',
+ 'spam@example.com')]
+ )