mirror of https://github.com/django/django.git
Fixed #19134 -- Allowed closing smtp backend when the server is stopped
Thanks Sebastian Noack for the report and the initial patch.
This commit is contained in:
parent
84ea85fb90
commit
1b3f832ab7
|
@ -63,9 +63,10 @@ class EmailBackend(BaseEmailBackend):
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
self.connection.quit()
|
self.connection.quit()
|
||||||
except socket.sslerror:
|
except (socket.sslerror, smtplib.SMTPServerDisconnected):
|
||||||
# This happens when calling quit() on a TLS connection
|
# This happens when calling quit() on a TLS connection
|
||||||
# sometimes.
|
# sometimes, or when the connection was already disconnected
|
||||||
|
# by the server.
|
||||||
self.connection.close()
|
self.connection.close()
|
||||||
except:
|
except:
|
||||||
if self.fail_silently:
|
if self.fail_silently:
|
||||||
|
|
|
@ -659,7 +659,7 @@ class FakeSMTPServer(smtpd.SMTPServer, threading.Thread):
|
||||||
asyncore.close_all()
|
asyncore.close_all()
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
assert self.active
|
if self.active:
|
||||||
self.active = False
|
self.active = False
|
||||||
self.join()
|
self.join()
|
||||||
|
|
||||||
|
@ -715,3 +715,16 @@ class SMTPBackendTests(BaseEmailBackendTests, TestCase):
|
||||||
backend = smtp.EmailBackend(username='', password='')
|
backend = smtp.EmailBackend(username='', password='')
|
||||||
self.assertEqual(backend.username, '')
|
self.assertEqual(backend.username, '')
|
||||||
self.assertEqual(backend.password, '')
|
self.assertEqual(backend.password, '')
|
||||||
|
|
||||||
|
def test_server_stopped(self):
|
||||||
|
"""
|
||||||
|
Test that closing the backend while the SMTP server is stopped doesn't
|
||||||
|
raise an exception.
|
||||||
|
"""
|
||||||
|
backend = smtp.EmailBackend(username='', password='')
|
||||||
|
backend.open()
|
||||||
|
self.server.stop()
|
||||||
|
try:
|
||||||
|
backend.close()
|
||||||
|
except Exception as e:
|
||||||
|
self.fail("close() unexpectedly raised an exception: %s" % e)
|
||||||
|
|
Loading…
Reference in New Issue