Skip to content

Commit 137a989

Browse files
committed
[3.2.x] Refs #27131 -- Removed SMTPBackendTests.test_server_login().
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
1 parent 1128291 commit 137a989

File tree

1 file changed

+1
-38
lines changed

1 file changed

+1
-38
lines changed

tests/mail/tests.py

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import asyncore
2-
import base64
32
import mimetypes
43
import os
54
import shutil
@@ -13,7 +12,7 @@
1312
from email.utils import parseaddr
1413
from io import StringIO
1514
from pathlib import Path
16-
from smtplib import SMTP, SMTPAuthenticationError, SMTPException
15+
from smtplib import SMTP, SMTPException
1716
from ssl import SSLError
1817
from unittest import mock
1918

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

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

13341324
class FakeSMTPServer(smtpd.SMTPServer, threading.Thread):
13351325
"""
@@ -1392,20 +1382,6 @@ def stop(self):
13921382
self.join()
13931383

13941384

1395-
class FakeAUTHSMTPConnection(SMTP):
1396-
"""
1397-
A SMTP connection pretending support for the AUTH command. It does not, but
1398-
at least this can allow testing the first part of the AUTH process.
1399-
"""
1400-
1401-
def ehlo(self, name=''):
1402-
response = SMTP.ehlo(self, name=name)
1403-
self.esmtp_features.update({
1404-
'auth': 'CRAM-MD5 PLAIN LOGIN',
1405-
})
1406-
return response
1407-
1408-
14091385
class SMTPBackendTestsBase(SimpleTestCase):
14101386

14111387
@classmethod
@@ -1496,19 +1472,6 @@ def test_reopen_connection(self):
14961472
backend.connection = mock.Mock(spec=object())
14971473
self.assertIs(backend.open(), False)
14981474

1499-
def test_server_login(self):
1500-
"""
1501-
Even if the Python SMTP server doesn't support authentication, the
1502-
login process starts and the appropriate exception is raised.
1503-
"""
1504-
class CustomEmailBackend(smtp.EmailBackend):
1505-
connection_class = FakeAUTHSMTPConnection
1506-
1507-
backend = CustomEmailBackend(username='username', password='password')
1508-
with self.assertRaises(SMTPAuthenticationError):
1509-
with backend:
1510-
pass
1511-
15121475
@override_settings(EMAIL_USE_TLS=True)
15131476
def test_email_tls_use_settings(self):
15141477
backend = smtp.EmailBackend()

0 commit comments

Comments
 (0)