From 8ab95364b5182fd702478289f98b01d16a21016e Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Thu, 14 Oct 2021 11:36:51 +0200 Subject: [PATCH] [4.0.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 cdad96e6330cd31185f7496aaf8eb316f2773d6d from main --- tests/mail/tests.py | 39 +-------------------------------------- 1 file changed, 1 insertion(+), 38 deletions(-) diff --git a/tests/mail/tests.py b/tests/mail/tests.py index 30f8252e0a..b9b3e452d5 100644 --- a/tests/mail/tests.py +++ b/tests/mail/tests.py @@ -1,5 +1,4 @@ import asyncore -import base64 import mimetypes import os import shutil @@ -13,7 +12,7 @@ from email.mime.text import MIMEText 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 @@ -1347,15 +1346,6 @@ class FakeSMTPChannel(smtpd.SMTPChannel): # 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): """ @@ -1418,20 +1408,6 @@ class FakeSMTPServer(smtpd.SMTPServer, threading.Thread): 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 @@ -1518,19 +1494,6 @@ class SMTPBackendTests(BaseEmailBackendTests, SMTPBackendTestsBase): 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()