Skip to content

Commit

Permalink
[3.2.x] Refs #27131 -- Removed SMTPBackendTests.test_server_login().
Browse files Browse the repository at this point in the history
test_server_login() was a regression test for a crash when passing
Unicode strings to SMTP server using CRAM-MD5 method on Python 2.
Python 2 is no longer supported and test_server_login() passes even
without FakeSMTPChannel.smtp_AUTH() because
smtplib.SMTPAuthenticationError is raised when AUTH is not implemented.
Backport of cdad96e from main
  • Loading branch information
felixxm committed Oct 14, 2021
1 parent 1128291 commit 137a989
Showing 1 changed file with 1 addition and 38 deletions.
39 changes: 1 addition & 38 deletions tests/mail/tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import asyncore
import base64
import mimetypes
import os
import shutil
Expand All @@ -13,7 +12,7 @@
from email.utils import parseaddr
from io import StringIO
from pathlib import Path
from smtplib import SMTP, SMTPAuthenticationError, SMTPException
from smtplib import SMTP, SMTPException
from ssl import SSLError
from unittest import mock

Expand Down Expand Up @@ -1321,15 +1320,6 @@ def collect_incoming_data(self, data):
# cares whether the connection attempt was made.
pass

def smtp_AUTH(self, arg):
if arg == 'CRAM-MD5':
# This is only the first part of the login process. But it's enough
# for our tests.
challenge = base64.b64encode(b'somerandomstring13579')
self.push('334 %s' % challenge.decode())
else:
self.push('502 Error: login "%s" not implemented' % arg)


class FakeSMTPServer(smtpd.SMTPServer, threading.Thread):
"""
Expand Down Expand Up @@ -1392,20 +1382,6 @@ def stop(self):
self.join()


class FakeAUTHSMTPConnection(SMTP):
"""
A SMTP connection pretending support for the AUTH command. It does not, but
at least this can allow testing the first part of the AUTH process.
"""

def ehlo(self, name=''):
response = SMTP.ehlo(self, name=name)
self.esmtp_features.update({
'auth': 'CRAM-MD5 PLAIN LOGIN',
})
return response


class SMTPBackendTestsBase(SimpleTestCase):

@classmethod
Expand Down Expand Up @@ -1496,19 +1472,6 @@ def test_reopen_connection(self):
backend.connection = mock.Mock(spec=object())
self.assertIs(backend.open(), False)

def test_server_login(self):
"""
Even if the Python SMTP server doesn't support authentication, the
login process starts and the appropriate exception is raised.
"""
class CustomEmailBackend(smtp.EmailBackend):
connection_class = FakeAUTHSMTPConnection

backend = CustomEmailBackend(username='username', password='password')
with self.assertRaises(SMTPAuthenticationError):
with backend:
pass

@override_settings(EMAIL_USE_TLS=True)
def test_email_tls_use_settings(self):
backend = smtp.EmailBackend()
Expand Down

0 comments on commit 137a989

Please sign in to comment.