summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2021-10-14 11:36:51 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-10-14 11:38:27 +0200
commit137a9899d7965432fc24cf6fc0331e333316a1dd (patch)
treea001f7e1ef406c7f9f15b91da58d125fbbe0cb4a
parent1128291650bfa1fe6c0594726d48587e6894ba11 (diff)
[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 cdad96e6330cd31185f7496aaf8eb316f2773d6d from main
-rw-r--r--tests/mail/tests.py39
1 files changed, 1 insertions, 38 deletions
diff --git a/tests/mail/tests.py b/tests/mail/tests.py
index 475e204b32..e62a9edc84 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
@@ -1321,15 +1320,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):
"""
@@ -1392,20 +1382,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
@@ -1496,19 +1472,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()