summaryrefslogtreecommitdiff
path: root/src/mailman/runners/tests
diff options
context:
space:
mode:
authorBarry Warsaw2012-03-13 21:03:01 -0700
committerBarry Warsaw2012-03-13 21:03:01 -0700
commit80ac803cb2816dde0503671fd117ed134680de53 (patch)
treeed2d40855f6b45dedf421a7a98bd83d95b6e3b40 /src/mailman/runners/tests
parent07685642934fe934098927a9a9d20c17080f3dab (diff)
downloadmailman-80ac803cb2816dde0503671fd117ed134680de53.tar.gz
mailman-80ac803cb2816dde0503671fd117ed134680de53.tar.zst
mailman-80ac803cb2816dde0503671fd117ed134680de53.zip
* The LMTP server now requires that the incoming message have a `Message-ID`,
otherwise it rejects the message with a 550 error. Also, the LMTP server adds the `X-Message-ID-Hash` header automatically. The `inject` cli command will also add the `X-Message-ID-Hash` header, but it will craft a `Message-ID` header first if one is missing from the injected text. Also, `inject` will always set the correct value for the `original_size` attribute on the message object, instead of trusting a possibly incorrect value if it's already set. The individual `IArchiver` implementations no longer set the `X-Message-ID-Hash` header.
Diffstat (limited to 'src/mailman/runners/tests')
-rw-r--r--src/mailman/runners/tests/test_confirm.py6
-rw-r--r--src/mailman/runners/tests/test_lmtp.py98
2 files changed, 101 insertions, 3 deletions
diff --git a/src/mailman/runners/tests/test_confirm.py b/src/mailman/runners/tests/test_confirm.py
index 34a2af523..ea972c17f 100644
--- a/src/mailman/runners/tests/test_confirm.py
+++ b/src/mailman/runners/tests/test_confirm.py
@@ -155,7 +155,7 @@ Franziskanerstra=C3=9Fe
self.assertEqual(address.email, 'anne@example.org')
messages = get_queue_messages('virgin')
self.assertEqual(len(messages), 1)
- self.assertEqual(messages[0].msgdata['recipients'],
+ self.assertEqual(messages[0].msgdata['recipients'],
set(['anne@example.org']))
def test_confirm_with_no_command_in_utf8_body(self):
@@ -188,7 +188,7 @@ Franziskanerstra=C3=9Fe
self.assertEqual(address.email, 'anne@example.org')
messages = get_queue_messages('virgin')
self.assertEqual(len(messages), 1)
- self.assertEqual(messages[0].msgdata['recipients'],
+ self.assertEqual(messages[0].msgdata['recipients'],
set(['anne@example.org']))
def test_double_confirmation(self):
@@ -259,5 +259,5 @@ From: Anne Person <anne@example.org>
messages = get_queue_messages('virgin', sort_on='subject')
self.assertEqual(len(messages), 2)
message = messages[1].msg
- self.assertEqual(str(message['subject']),
+ self.assertEqual(str(message['subject']),
'Welcome to the "Test" mailing list')
diff --git a/src/mailman/runners/tests/test_lmtp.py b/src/mailman/runners/tests/test_lmtp.py
new file mode 100644
index 000000000..2c4defe59
--- /dev/null
+++ b/src/mailman/runners/tests/test_lmtp.py
@@ -0,0 +1,98 @@
+# Copyright (C) 2012 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/>.
+
+"""Tests for the LMTP server."""
+
+from __future__ import absolute_import, print_function, unicode_literals
+
+__metaclass__ = type
+__all__ = [
+ 'TestLMTP',
+ ]
+
+
+import smtplib
+import unittest
+
+from mailman.app.lifecycle import create_list
+from mailman.config import config
+from mailman.testing.helpers import get_lmtp_client, get_queue_messages
+from mailman.testing.layers import LMTPLayer
+
+
+
+class TestLMTP(unittest.TestCase):
+ """Test various aspects of the LMTP server."""
+
+ layer = LMTPLayer
+
+ def setUp(self):
+ self._mlist = create_list('test@example.com')
+ config.db.commit()
+ self._lmtp = get_lmtp_client(quiet=True)
+ self._lmtp.lhlo('remote.example.org')
+
+ def tearDown(self):
+ self._lmtp.close()
+
+ def test_message_id_required(self):
+ # The message is rejected if it does not have a Message-ID header.
+ try:
+ self._lmtp.sendmail('anne@example.com', ['test@example.com'], """\
+From: anne@example.com
+To: test@example.com
+Subject: This has no Message-ID header
+
+""")
+ except smtplib.SMTPDataError as error:
+ pass
+ else:
+ raise AssertionError('SMTPDataError expected')
+ # LMTP returns a 550: Requested action not taken: mailbox unavailable
+ # (e.g., mailbox not found, no access, or command rejected for policy
+ # reasons)
+ self.assertEqual(error.smtp_code, 550)
+ self.assertEqual(error.smtp_error, 'No Message-ID header provided')
+
+ def test_message_id_hash_is_added(self):
+ self._lmtp.sendmail('anne@example.com', ['test@example.com'], """\
+From: anne@example.com
+To: test@example.com
+Message-ID: <ant>
+Subject: This has a Message-ID but no X-Message-ID-Hash
+
+""")
+ messages = get_queue_messages('in')
+ self.assertEqual(len(messages), 1)
+ self.assertEqual(messages[0].msg['x-message-id-hash'],
+ 'MS6QLWERIJLGCRF44J7USBFDELMNT2BW')
+
+ def test_original_message_id_hash_is_overwritten(self):
+ self._lmtp.sendmail('anne@example.com', ['test@example.com'], """\
+From: anne@example.com
+To: test@example.com
+Message-ID: <ant>
+X-Message-ID-Hash: IGNOREME
+Subject: This has a Message-ID but no X-Message-ID-Hash
+
+""")
+ messages = get_queue_messages('in')
+ self.assertEqual(len(messages), 1)
+ all_headers = messages[0].msg.get_all('x-message-id-hash')
+ self.assertEqual(len(all_headers), 1)
+ self.assertEqual(messages[0].msg['x-message-id-hash'],
+ 'MS6QLWERIJLGCRF44J7USBFDELMNT2BW')