diff options
Diffstat (limited to 'Lib')
-rwxr-xr-x | Lib/smtplib.py | 3 | ||||
-rw-r--r-- | Lib/test/test_smtplib.py | 20 |
2 files changed, 22 insertions, 1 deletions
diff --git a/Lib/smtplib.py b/Lib/smtplib.py index d8d717c..0b2a586 100755 --- a/Lib/smtplib.py +++ b/Lib/smtplib.py @@ -545,7 +545,8 @@ class SMTP: return encode_base64(response) 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" diff --git a/Lib/test/test_smtplib.py b/Lib/test/test_smtplib.py index 55e30a8..012ab94 100644 --- a/Lib/test/test_smtplib.py +++ b/Lib/test/test_smtplib.py @@ -284,6 +284,9 @@ sim_users = {'Mr.A@somewhere.com':'John A', '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'], 'list-2':['Ms.B@somewhere.com',], } @@ -296,6 +299,7 @@ class SimSMTPChannel(smtpd.SMTPChannel): '250-SIZE 20000000\r\n' \ '250-STARTTLS\r\n' \ '250-DELIVERBY\r\n' \ + '250-AUTH PLAIN\r\n' \ '250 HELP' self.push(resp) @@ -324,6 +328,16 @@ class SimSMTPChannel(smtpd.SMTPChannel): else: 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): def handle_accept(self): @@ -372,6 +386,7 @@ class SMTPSimTests(TestCase): 'size': '20000000', 'starttls': '', 'deliverby': '', + 'auth': ' PLAIN', 'help': '', } @@ -412,6 +427,11 @@ class SMTPSimTests(TestCase): self.assertEqual(smtp.expn(u), expected_unknown) 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): |