Skip to content

Commit 78378e8

Browse files
committed
Issue #23779: imaplib raises TypeError if authenticator tries to abort.
Patch from Craig Holmquist.
2 parents 659fcb0 + 5ccc18f commit 78378e8

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

Lib/imaplib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1353,7 +1353,7 @@ def __init__(self, mechinst):
13531353
def process(self, data):
13541354
ret = self.mech(self.decode(data))
13551355
if ret is None:
1356-
return '*' # Abort conversation
1356+
return b'*' # Abort conversation
13571357
return self.encode(ret)
13581358

13591359
def encode(self, inp):

Lib/test/test_imaplib.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,26 @@ def cmd_AUTHENTICATE(self, tag, args):
419419
ret, data = client.login_cram_md5("tim", b"tanstaaftanstaaf")
420420
self.assertEqual(ret, "OK")
421421

422+
423+
@reap_threads
424+
def test_aborted_authentication(self):
425+
426+
class MyServer(SimpleIMAPHandler):
427+
428+
def cmd_AUTHENTICATE(self, tag, args):
429+
self._send_textline('+')
430+
self.response = yield
431+
432+
if self.response == b'*\r\n':
433+
self._send_tagged(tag, 'NO', '[AUTHENTICATIONFAILED] aborted')
434+
else:
435+
self._send_tagged(tag, 'OK', 'MYAUTH successful')
436+
437+
with self.reaped_pair(MyServer) as (server, client):
438+
with self.assertRaises(imaplib.IMAP4.error):
439+
code, data = client.authenticate('MYAUTH', lambda x: None)
440+
441+
422442
def test_linetoolong(self):
423443
class TooLongHandler(SimpleIMAPHandler):
424444
def handle(self):

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,7 @@ Gerrit Holl
603603
Shane Holloway
604604
Rune Holm
605605
Thomas Holmes
606+
Craig Holmquist
606607
Philip Homburg
607608
Naofumi Honda
608609
Jeffrey Honig

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ Core and Builtins
1313
Library
1414
-------
1515

16+
- Issue #23779: imaplib raises TypeError if authenticator tries to abort.
17+
Patch from Craig Holmquist.
18+
1619
- Issue #23319: Fix ctypes.BigEndianStructure, swap correctly bytes. Patch
1720
written by Matthieu Gautier.
1821

0 commit comments

Comments
 (0)