From 5ccc18f29844b55a43bf8f26dffeb39057477dea Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Fri, 31 Jul 2015 08:59:02 +1200 Subject: [PATCH] Issue #23779: imaplib raises TypeError if authenticator tries to abort. Patch from Craig Holmquist. --- Lib/imaplib.py | 2 +- Lib/test/test_imaplib.py | 19 +++++++++++++++++++ Misc/ACKS | 1 + Misc/NEWS | 3 +++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Lib/imaplib.py b/Lib/imaplib.py index 4d9df55dc3c..eb05dcb4f19 100644 --- a/Lib/imaplib.py +++ b/Lib/imaplib.py @@ -1306,7 +1306,7 @@ class _Authenticator: 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 index b34e652347f..96b4f32316c 100644 --- a/Lib/test/test_imaplib.py +++ b/Lib/test/test_imaplib.py @@ -325,6 +325,25 @@ class BaseThreadedNetworkedTests(unittest.TestCase): 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 index f31249e7025..de33df13785 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -592,6 +592,7 @@ Gerrit Holl Shane Holloway Rune Holm Thomas Holmes +Craig Holmquist Philip Homburg Naofumi Honda Jeffrey Honig diff --git a/Misc/NEWS b/Misc/NEWS index 38bdccba3d4..6798182a990 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -66,6 +66,9 @@ Core and Builtins 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.