]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Merged revisions 72868 via svnmerge from
authorR. David Murray <rdmurray@bitdance.com>
Sat, 23 May 2009 21:05:11 +0000 (21:05 +0000)
committerR. David Murray <rdmurray@bitdance.com>
Sat, 23 May 2009 21:05:11 +0000 (21:05 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r72868 | r.david.murray | 2009-05-23 14:49:56 -0400 (Sat, 23 May 2009) | 5 lines

  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.
........

Lib/smtplib.py
Lib/test/test_smtplib.py
Misc/ACKS
Misc/NEWS

index acbbf67194bfe576c2d588db013a870089e795da..b0227031138dcf3d0e7022cd426968c98e3d866f 100755 (executable)
@@ -542,7 +542,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"
index 55e30a8082866f6d66e4f0ce5ac38a74a24e8435..012ab9427eb1bb6f697ffd9d940152cafea1a3d4 100644 (file)
@@ -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):
index 2eadbf45be399f5cc350129bd0a1ff41eb0ba646..ad731505caba03537ee4c6319e0eef0a86823107 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -686,6 +686,7 @@ Paul Swartz
 Thenault Sylvain
 Arfrever Frehtes Taifersar Arahesis
 Geoff Talvola
+Musashi Tamura
 William Tanksley
 Christian Tanzer
 Steven Taschuk
index b43d3b25878055155c08324954406c3c0018f939..bc5b3e9b11d6faf515d84e5d3da8dd41c29cbc37 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -65,6 +65,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #5259: smtplib plain auth login no longer gives a traceback.  Fix
+  by Musashi Tamura, tests by Marcin Bachry.
+
 - Issue #4066: smtplib.SMTP_SSL._get_socket now correctly returns the socket.
   Patch by Farhan Ahmad, test by Marcin Bachry.