diff options
| author | Barry Warsaw | 2011-01-02 23:52:22 -0500 |
|---|---|---|
| committer | Barry Warsaw | 2011-01-02 23:52:22 -0500 |
| commit | 5d0d6a5afa34c61630a6442006e9ff2b87fb0c8d (patch) | |
| tree | 6296162e7f68e2af68f7ed8ab9ccc7f1394ec084 /src/mailman/testing/mta.py | |
| parent | 1b8c94f4ad4730b3251c9efd667db27245105b6c (diff) | |
| download | mailman-5d0d6a5afa34c61630a6442006e9ff2b87fb0c8d.tar.gz mailman-5d0d6a5afa34c61630a6442006e9ff2b87fb0c8d.tar.zst mailman-5d0d6a5afa34c61630a6442006e9ff2b87fb0c8d.zip | |
LP: #490044 - Support SMTP AUTH.
Added smtp_user and smtp_pass options to the [mta] section to support logging
into the SMTP server. All the underlying support is in Python's smtplib.
Diffstat (limited to '')
| -rw-r--r-- | src/mailman/testing/mta.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/mailman/testing/mta.py b/src/mailman/testing/mta.py index f44143972..8fae233fa 100644 --- a/src/mailman/testing/mta.py +++ b/src/mailman/testing/mta.py @@ -59,11 +59,31 @@ class FakeMTA: class StatisticsChannel(Channel): """A channel that can answers to the fake STAT command.""" + def smtp_EHLO(self, arg): + if not arg: + self.push(b'501 Syntax: HELO hostname') + return + if self._SMTPChannel__greeting: + self.push(b'503 Duplicate HELO/EHLO') + else: + self._SMTPChannel__greeting = arg + self.push(b'250-%s' % self._SMTPChannel__fqdn) + self.push(b'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') + def smtp_AUTH(self, arg): + """Record that the AUTH occurred.""" + if arg == 'PLAIN AHRlc3R1c2VyAHRlc3RwYXNz': + # testuser:testpass + self.push(b'235 Ok') + self._server.send_auth(arg) + else: + self.push(b'571 Bad authentication') + def smtp_RCPT(self, arg): """For testing, sometimes cause a non-25x response.""" code = self._server.next_error('rcpt') @@ -103,6 +123,7 @@ class ConnectionCountingServer(QueueServer): """ QueueServer.__init__(self, host, port, queue) self._connection_count = 0 + self.last_auth = None # The out-of-band queue is where the server sends statistics to the # controller upon request. self._oob_queue = oob_queue @@ -152,6 +173,10 @@ class ConnectionCountingServer(QueueServer): self._connection_count -= 1 self._oob_queue.put(self._connection_count) + def send_auth(self, arg): + """Echo back the authentication data.""" + self._oob_queue.put(arg) + class ConnectionCountingController(QueueController): @@ -187,6 +212,10 @@ class ConnectionCountingController(QueueController): # seconds. Let that propagate. return self.oob_queue.get(block=True, timeout=10) + def get_authentication_credentials(self): + """Retrieve the last authentication credentials.""" + return self.oob_queue.get(block=True, timeout=10) + @property def messages(self): """Return all the messages received by the SMTP server.""" @@ -196,3 +225,7 @@ class ConnectionCountingController(QueueController): def clear(self): """Clear all the messages from the queue.""" list(self) + + def reset(self): + smtpd = self._connect() + smtpd.docmd(b'RSET') |
