summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBarry Warsaw2014-12-17 17:37:38 -0500
committerBarry Warsaw2014-12-17 17:37:38 -0500
commit7cb8c33735fee118e65d498b362833c336c3c683 (patch)
treeb2f65b1f164e8bbfb4ad82773584f6ee3dfb736d
parent75ff7330c91c0fb5d5e77fc3c61259e20fca99e8 (diff)
downloadmailman-7cb8c33735fee118e65d498b362833c336c3c683.tar.gz
mailman-7cb8c33735fee118e65d498b362833c336c3c683.tar.zst
mailman-7cb8c33735fee118e65d498b362833c336c3c683.zip
-rw-r--r--src/mailman/mta/docs/authentication.rst2
-rw-r--r--src/mailman/mta/docs/bulk.rst9
-rw-r--r--src/mailman/mta/docs/connection.rst24
-rw-r--r--src/mailman/mta/tests/test_connection.py54
-rw-r--r--src/mailman/runners/lmtp.py10
-rw-r--r--src/mailman/runners/tests/test_lmtp.py2
-rw-r--r--src/mailman/testing/mta.py22
7 files changed, 78 insertions, 45 deletions
diff --git a/src/mailman/mta/docs/authentication.rst b/src/mailman/mta/docs/authentication.rst
index 94cd2c99e..f98c00e1f 100644
--- a/src/mailman/mta/docs/authentication.rst
+++ b/src/mailman/mta/docs/authentication.rst
@@ -60,7 +60,7 @@ But if the user name and password does not match, the connection will fail.
>>> response = bulk.deliver(
... mlist, msg, dict(recipients=['bperson@example.com']))
>>> dump_msgdata(response)
- bperson@example.com: (571, 'Bad authentication')
+ bperson@example.com: (571, b'Bad authentication')
>>> config.pop('auth')
diff --git a/src/mailman/mta/docs/bulk.rst b/src/mailman/mta/docs/bulk.rst
index f2a76229b..cd7873de1 100644
--- a/src/mailman/mta/docs/bulk.rst
+++ b/src/mailman/mta/docs/bulk.rst
@@ -332,7 +332,8 @@ recipients.
>>> failures = bulk.deliver(mlist, msg, msgdata)
>>> for address in sorted(failures):
- ... print(address, failures[address][0], failures[address][1])
+ ... print(address, failures[address][0],
+ ... failures[address][1].decode('ascii'))
aperson@example.org 500 Error: SMTPRecipientsRefused
bperson@example.org 500 Error: SMTPRecipientsRefused
cperson@example.org 500 Error: SMTPRecipientsRefused
@@ -350,7 +351,8 @@ Or there could be some other problem causing an SMTP response failure.
>>> failures = bulk.deliver(mlist, msg, msgdata)
>>> for address in sorted(failures):
- ... print(address, failures[address][0], failures[address][1])
+ ... print(address, failures[address][0],
+ ... failures[address][1].decode('ascii'))
aperson@example.org 450 Error: SMTPResponseException
bperson@example.org 450 Error: SMTPResponseException
cperson@example.org 450 Error: SMTPResponseException
@@ -361,7 +363,8 @@ Or there could be some other problem causing an SMTP response failure.
>>> failures = bulk.deliver(mlist, msg, msgdata)
>>> for address in sorted(failures):
- ... print(address, failures[address][0], failures[address][1])
+ ... print(address, failures[address][0],
+ ... failures[address][1].decode('ascii'))
aperson@example.org 500 Error: SMTPResponseException
bperson@example.org 500 Error: SMTPResponseException
cperson@example.org 500 Error: SMTPResponseException
diff --git a/src/mailman/mta/docs/connection.rst b/src/mailman/mta/docs/connection.rst
index a57a76bb9..f4e0d8107 100644
--- a/src/mailman/mta/docs/connection.rst
+++ b/src/mailman/mta/docs/connection.rst
@@ -75,30 +75,6 @@ will authenticate with the mail server after each new connection.
>>> reset()
>>> config.pop('auth')
-However, a bad user name or password generates an error.
-
- >>> config.push('auth', """
- ... [mta]
- ... smtp_user: baduser
- ... smtp_pass: badpass
- ... """)
-
- >>> connection = Connection(
- ... config.mta.smtp_host, int(config.mta.smtp_port), 0,
- ... config.mta.smtp_user, config.mta.smtp_pass)
- >>> connection.sendmail('anne@example.com', ['bart@example.com'], """\
- ... From: anne@example.com
- ... To: bart@example.com
- ... Subject: aardvarks
- ...
- ... """)
- Traceback (most recent call last):
- ...
- SMTPAuthenticationError: (571, 'Bad authentication')
-
- >>> reset()
- >>> config.pop('auth')
-
Sessions per connection
=======================
diff --git a/src/mailman/mta/tests/test_connection.py b/src/mailman/mta/tests/test_connection.py
new file mode 100644
index 000000000..94b5904b5
--- /dev/null
+++ b/src/mailman/mta/tests/test_connection.py
@@ -0,0 +1,54 @@
+# Copyright (C) 2014 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 MTA connections."""
+
+from __future__ import absolute_import, print_function, unicode_literals
+
+__metaclass__ = type
+__all__ = [
+ 'TestConnection',
+ ]
+
+
+import unittest
+
+from mailman.config import config
+from mailman.mta.connection import Connection
+from mailman.testing.layers import SMTPLayer
+from smtplib import SMTPAuthenticationError
+
+
+
+class TestConnection(unittest.TestCase):
+ layer = SMTPLayer
+
+ def test_authentication_error(self):
+ # Logging in to the MTA with a bad user name and password produces a
+ # 571 Bad Authentication error.
+ with self.assertRaises(SMTPAuthenticationError) as cm:
+ connection = Connection(
+ config.mta.smtp_host, int(config.mta.smtp_port), 0,
+ 'baduser', 'badpass')
+ connection.sendmail('anne@example.com', ['bart@example.com'], """\
+From: anne@example.com
+To: bart@example.com
+Subject: aardvarks
+
+""")
+ self.assertEqual(cm.exception.smtp_code, 571)
+ self.assertEqual(cm.exception.smtp_error, b'Bad authentication')
diff --git a/src/mailman/runners/lmtp.py b/src/mailman/runners/lmtp.py
index daa1e7e1c..2a685f18b 100644
--- a/src/mailman/runners/lmtp.py
+++ b/src/mailman/runners/lmtp.py
@@ -92,11 +92,11 @@ SUBADDRESS_QUEUES = dict(
DASH = '-'
CRLF = '\r\n'
-ERR_451 = b'451 Requested action aborted: error in processing'
-ERR_501 = b'501 Message has defects'
-ERR_502 = b'502 Error: command HELO not implemented'
-ERR_550 = b'550 Requested action not taken: mailbox unavailable'
-ERR_550_MID = b'550 No Message-ID header provided'
+ERR_451 = '451 Requested action aborted: error in processing'
+ERR_501 = '501 Message has defects'
+ERR_502 = '502 Error: command HELO not implemented'
+ERR_550 = '550 Requested action not taken: mailbox unavailable'
+ERR_550_MID = '550 No Message-ID header provided'
# XXX Blech
smtpd.__version__ = 'Python LMTP runner 1.0'
diff --git a/src/mailman/runners/tests/test_lmtp.py b/src/mailman/runners/tests/test_lmtp.py
index ccd27c829..0757ec22d 100644
--- a/src/mailman/runners/tests/test_lmtp.py
+++ b/src/mailman/runners/tests/test_lmtp.py
@@ -67,7 +67,7 @@ Subject: This has no Message-ID header
# reasons)
self.assertEqual(cm.exception.smtp_code, 550)
self.assertEqual(cm.exception.smtp_error,
- 'No Message-ID header provided')
+ b'No Message-ID header provided')
def test_message_id_hash_is_added(self):
self._lmtp.sendmail('anne@example.com', ['test@example.com'], """\
diff --git a/src/mailman/testing/mta.py b/src/mailman/testing/mta.py
index 234540e98..4dd5bc097 100644
--- a/src/mailman/testing/mta.py
+++ b/src/mailman/testing/mta.py
@@ -59,28 +59,28 @@ class StatisticsChannel(Channel):
def smtp_EHLO(self, arg):
if not arg:
- self.push(b'501 Syntax: HELO hostname')
+ self.push('501 Syntax: HELO hostname')
return
if self._SMTPChannel__greeting:
- self.push(b'503 Duplicate HELO/EHLO')
+ self.push('503 Duplicate HELO/EHLO')
else:
self._SMTPChannel__greeting = arg
- self.push(b'250-%s' % self._SMTPChannel__fqdn)
- self.push(b'250 AUTH PLAIN')
+ self.push('250-%s' % self._SMTPChannel__fqdn)
+ self.push('250 AUTH PLAIN')
def smtp_STAT(self, arg):
"""Cause the server to send statistics to its controller."""
self._server.send_statistics()
- self.push(b'250 Ok')
+ self.push('250 Ok')
def smtp_AUTH(self, arg):
"""Record that the AUTH occurred."""
if arg == 'PLAIN AHRlc3R1c2VyAHRlc3RwYXNz':
# testuser:testpass
- self.push(b'235 Ok')
+ self.push('235 Ok')
self._server.send_auth(arg)
else:
- self.push(b'571 Bad authentication')
+ self.push('571 Bad authentication')
def smtp_RCPT(self, arg):
"""For testing, sometimes cause a non-25x response."""
@@ -91,7 +91,7 @@ class StatisticsChannel(Channel):
else:
# The test suite wants this to fail. The message corresponds to
# the exception we expect smtplib.SMTP to raise.
- self.push(b'%d Error: SMTPRecipientsRefused' % code)
+ self.push('%d Error: SMTPRecipientsRefused' % code)
def smtp_MAIL(self, arg):
"""For testing, sometimes cause a non-25x response."""
@@ -102,7 +102,7 @@ class StatisticsChannel(Channel):
else:
# The test suite wants this to fail. The message corresponds to
# the exception we expect smtplib.SMTP to raise.
- self.push(b'%d Error: SMTPResponseException' % code)
+ self.push('%d Error: SMTPResponseException' % code)
@@ -210,7 +210,7 @@ class ConnectionCountingController(QueueController):
:rtype: integer
"""
smtpd = self._connect()
- smtpd.docmd(b'STAT')
+ smtpd.docmd('STAT')
# An Empty exception will occur if the data isn't available in 10
# seconds. Let that propagate.
return self.oob_queue.get(block=True, timeout=10)
@@ -231,4 +231,4 @@ class ConnectionCountingController(QueueController):
def reset(self):
smtpd = self._connect()
- smtpd.docmd(b'RSET')
+ smtpd.docmd('RSET')