[Python-checkins] cpython (3.4): Issue #23779: imaplib raises TypeError if authenticator tries to abort.

robert.collins python-checkins at python.org
Thu Jul 30 23:03:46 CEST 2015


https://hg.python.org/cpython/rev/fe55a36a335b
changeset:   97155:fe55a36a335b
branch:      3.4
parent:      97152:6eb4441ed14b
user:        Robert Collins <rbtcollins at hp.com>
date:        Fri Jul 31 08:59:02 2015 +1200
summary:
  Issue #23779: imaplib raises TypeError if authenticator tries to abort.

Patch from Craig Holmquist.

files:
  Lib/imaplib.py           |   2 +-
  Lib/test/test_imaplib.py |  19 +++++++++++++++++++
  Misc/ACKS                |   1 +
  Misc/NEWS                |   3 +++
  4 files changed, 24 insertions(+), 1 deletions(-)


diff --git a/Lib/imaplib.py b/Lib/imaplib.py
--- a/Lib/imaplib.py
+++ b/Lib/imaplib.py
@@ -1306,7 +1306,7 @@
     def process(self, data):
         ret = self.mech(self.decode(data))
         if ret is None:
-            return '*'      # Abort conversation
+            return b'*'     # Abort conversation
         return self.encode(ret)
 
     def encode(self, inp):
diff --git a/Lib/test/test_imaplib.py b/Lib/test/test_imaplib.py
--- a/Lib/test/test_imaplib.py
+++ b/Lib/test/test_imaplib.py
@@ -325,6 +325,25 @@
             self.assertEqual(ret, "OK")
 
 
+
+    @reap_threads
+    def test_aborted_authentication(self):
+
+        class MyServer(SimpleIMAPHandler):
+
+            def cmd_AUTHENTICATE(self, tag, args):
+                self._send_textline('+')
+                self.response = yield
+
+                if self.response == b'*\r\n':
+                    self._send_tagged(tag, 'NO', '[AUTHENTICATIONFAILED] aborted')
+                else:
+                    self._send_tagged(tag, 'OK', 'MYAUTH successful')
+
+        with self.reaped_pair(MyServer) as (server, client):
+            with self.assertRaises(imaplib.IMAP4.error):
+                code, data = client.authenticate('MYAUTH', lambda x: None)
+
     def test_linetoolong(self):
         class TooLongHandler(SimpleIMAPHandler):
             def handle(self):
diff --git a/Misc/ACKS b/Misc/ACKS
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -592,6 +592,7 @@
 Shane Holloway
 Rune Holm
 Thomas Holmes
+Craig Holmquist
 Philip Homburg
 Naofumi Honda
 Jeffrey Honig
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -66,6 +66,9 @@
 Library
 -------
 
+- Issue #23779: imaplib raises TypeError if authenticator tries to abort.
+  Patch from Craig Holmquist.
+
 - Issue #23319: Fix ctypes.BigEndianStructure, swap correctly bytes. Patch
   written by Matthieu Gautier.
 

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list