[3.8] bpo-27820: Fix AUTH LOGIN logic in smtplib.SMTP (GH-24118) (#24… · python/cpython@8cadc2c (original) (raw)
`@@ -733,7 +733,7 @@ def found_terminator(self):
`
733
733
`except ResponseException as e:
`
734
734
`self.smtp_state = self.COMMAND
`
735
735
`self.push('%s %s' % (e.smtp_code, e.smtp_error))
`
736
``
`-
return
`
``
736
`+
return
`
737
737
`super().found_terminator()
`
738
738
``
739
739
``
`@@ -799,6 +799,11 @@ def _auth_login(self, arg=None):
`
799
799
`self._authenticated(self._auth_login_user, password == sim_auth[1])
`
800
800
`del self._auth_login_user
`
801
801
``
``
802
`+
def _auth_buggy(self, arg=None):
`
``
803
`+
This AUTH mechanism will 'trap' client in a neverending 334
`
``
804
`+
base64 encoded 'BuGgYbUgGy'
`
``
805
`+
self.push('334 QnVHZ1liVWdHeQ==')
`
``
806
+
802
807
`def _auth_cram_md5(self, arg=None):
`
803
808
`if arg is None:
`
804
809
`self.push('334 {}'.format(sim_cram_md5_challenge))
`
`@@ -1011,6 +1016,39 @@ def testAUTH_LOGIN(self):
`
1011
1016
`self.assertEqual(resp, (235, b'Authentication Succeeded'))
`
1012
1017
`smtp.close()
`
1013
1018
``
``
1019
`+
def testAUTH_LOGIN_initial_response_ok(self):
`
``
1020
`+
self.serv.add_feature("AUTH LOGIN")
`
``
1021
`+
with smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15) as smtp:
`
``
1022
`+
smtp.user, smtp.password = sim_auth
`
``
1023
`+
smtp.ehlo("test_auth_login")
`
``
1024
`+
resp = smtp.auth("LOGIN", smtp.auth_login, initial_response_ok=True)
`
``
1025
`+
self.assertEqual(resp, (235, b'Authentication Succeeded'))
`
``
1026
+
``
1027
`+
def testAUTH_LOGIN_initial_response_notok(self):
`
``
1028
`+
self.serv.add_feature("AUTH LOGIN")
`
``
1029
`+
with smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15) as smtp:
`
``
1030
`+
smtp.user, smtp.password = sim_auth
`
``
1031
`+
smtp.ehlo("test_auth_login")
`
``
1032
`+
resp = smtp.auth("LOGIN", smtp.auth_login, initial_response_ok=False)
`
``
1033
`+
self.assertEqual(resp, (235, b'Authentication Succeeded'))
`
``
1034
+
``
1035
`+
def testAUTH_BUGGY(self):
`
``
1036
`+
self.serv.add_feature("AUTH BUGGY")
`
``
1037
+
``
1038
`+
def auth_buggy(challenge=None):
`
``
1039
`+
self.assertEqual(b"BuGgYbUgGy", challenge)
`
``
1040
`+
return "\0"
`
``
1041
+
``
1042
`+
smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15)
`
``
1043
`+
try:
`
``
1044
`+
smtp.user, smtp.password = sim_auth
`
``
1045
`+
smtp.ehlo("test_auth_buggy")
`
``
1046
`+
expect = r"^Server AUTH mechanism infinite loop.*"
`
``
1047
`+
with self.assertRaisesRegex(smtplib.SMTPException, expect) as cm:
`
``
1048
`+
smtp.auth("BUGGY", auth_buggy, initial_response_ok=False)
`
``
1049
`+
finally:
`
``
1050
`+
smtp.close()
`
``
1051
+
1014
1052
`@requires_hashdigest('md5')
`
1015
1053
`def testAUTH_CRAM_MD5(self):
`
1016
1054
`self.serv.add_feature("AUTH CRAM-MD5")
`