mirror of https://github.com/python/cpython.git
Fix for issue 5259: ASCII encode the username and password before passing
it to encode_base64, which requires bytes in py3k. Fix by Musashi Tamura, tests by Marcin Bachry.
This commit is contained in:
parent
dfea192ad4
commit
caa27b7823
|
@ -545,7 +545,8 @@ def encode_cram_md5(challenge, user, password):
|
||||||
return encode_base64(response)
|
return encode_base64(response)
|
||||||
|
|
||||||
def encode_plain(user, password):
|
def encode_plain(user, password):
|
||||||
return encode_base64("\0%s\0%s" % (user, password))
|
s = "\0%s\0%s" % (user, password)
|
||||||
|
return encode_base64(s.encode('ascii'), eol='')
|
||||||
|
|
||||||
|
|
||||||
AUTH_PLAIN = "PLAIN"
|
AUTH_PLAIN = "PLAIN"
|
||||||
|
|
|
@ -284,6 +284,9 @@ def testFailingHELO(self):
|
||||||
'Mrs.C@somewhereesle.com':'Ruth C',
|
'Mrs.C@somewhereesle.com':'Ruth C',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sim_auth = ('Mr.A@somewhere.com', 'somepassword')
|
||||||
|
sim_auth_b64encoded = 'AE1yLkFAc29tZXdoZXJlLmNvbQBzb21lcGFzc3dvcmQ='
|
||||||
|
|
||||||
sim_lists = {'list-1':['Mr.A@somewhere.com','Mrs.C@somewhereesle.com'],
|
sim_lists = {'list-1':['Mr.A@somewhere.com','Mrs.C@somewhereesle.com'],
|
||||||
'list-2':['Ms.B@somewhere.com',],
|
'list-2':['Ms.B@somewhere.com',],
|
||||||
}
|
}
|
||||||
|
@ -296,6 +299,7 @@ def smtp_EHLO(self, arg):
|
||||||
'250-SIZE 20000000\r\n' \
|
'250-SIZE 20000000\r\n' \
|
||||||
'250-STARTTLS\r\n' \
|
'250-STARTTLS\r\n' \
|
||||||
'250-DELIVERBY\r\n' \
|
'250-DELIVERBY\r\n' \
|
||||||
|
'250-AUTH PLAIN\r\n' \
|
||||||
'250 HELP'
|
'250 HELP'
|
||||||
self.push(resp)
|
self.push(resp)
|
||||||
|
|
||||||
|
@ -324,6 +328,16 @@ def smtp_EXPN(self, arg):
|
||||||
else:
|
else:
|
||||||
self.push('550 No access for you!')
|
self.push('550 No access for you!')
|
||||||
|
|
||||||
|
def smtp_AUTH(self, arg):
|
||||||
|
mech, auth = arg.split()
|
||||||
|
if mech.lower() == 'plain':
|
||||||
|
if auth == sim_auth_b64encoded:
|
||||||
|
self.push('235 ok, go ahead')
|
||||||
|
else:
|
||||||
|
self.push('550 No access for you!')
|
||||||
|
else:
|
||||||
|
self.push('504 auth type unimplemented')
|
||||||
|
|
||||||
|
|
||||||
class SimSMTPServer(smtpd.SMTPServer):
|
class SimSMTPServer(smtpd.SMTPServer):
|
||||||
def handle_accept(self):
|
def handle_accept(self):
|
||||||
|
@ -372,6 +386,7 @@ def testEHLO(self):
|
||||||
'size': '20000000',
|
'size': '20000000',
|
||||||
'starttls': '',
|
'starttls': '',
|
||||||
'deliverby': '',
|
'deliverby': '',
|
||||||
|
'auth': ' PLAIN',
|
||||||
'help': '',
|
'help': '',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -412,6 +427,11 @@ def testEXPN(self):
|
||||||
self.assertEqual(smtp.expn(u), expected_unknown)
|
self.assertEqual(smtp.expn(u), expected_unknown)
|
||||||
smtp.quit()
|
smtp.quit()
|
||||||
|
|
||||||
|
def testAUTH(self):
|
||||||
|
smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15)
|
||||||
|
|
||||||
|
expected_auth_ok = (235, b'ok, go ahead')
|
||||||
|
self.assertEqual(smtp.login(sim_auth[0], sim_auth[1]), expected_auth_ok)
|
||||||
|
|
||||||
|
|
||||||
def test_main(verbose=None):
|
def test_main(verbose=None):
|
||||||
|
|
|
@ -710,6 +710,7 @@ Andrew Svetlov
|
||||||
Paul Swartz
|
Paul Swartz
|
||||||
Thenault Sylvain
|
Thenault Sylvain
|
||||||
Geoff Talvola
|
Geoff Talvola
|
||||||
|
Musashi Tamura
|
||||||
William Tanksley
|
William Tanksley
|
||||||
Christian Tanzer
|
Christian Tanzer
|
||||||
Steven Taschuk
|
Steven Taschuk
|
||||||
|
|
|
@ -32,6 +32,9 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #5259: smtplib plain auth login no longer gives a traceback. Fix
|
||||||
|
by Musashi Tamura, tests by Marcin Bachry.
|
||||||
|
|
||||||
- Issue #1983: Fix functions taking or returning a process identifier to use
|
- Issue #1983: Fix functions taking or returning a process identifier to use
|
||||||
the dedicated C type ``pid_t`` instead of a C ``int``. Some platforms have
|
the dedicated C type ``pid_t`` instead of a C ``int``. Some platforms have
|
||||||
a process identifier type wider than the standard C integer type.
|
a process identifier type wider than the standard C integer type.
|
||||||
|
|
Loading…
Reference in New Issue