New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
imaplib authenticate raises TypeError if authenticator tries to abort #67967
Comments
If the authenticator object passed to the IMAP authenticate method tries to abort the handshake by returning None, TypeError is raised instead of sending the * line to the server. >>> import imaplib
>>> imap = imaplib.IMAP4_SSL('imap.gmail.com')
>>> imap.authenticate(b'PLAIN', lambda x: None)
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
imap.authenticate(b'PLAIN', lambda x: None)
File "C:\Python34\lib\imaplib.py", line 380, in authenticate
typ, dat = self._simple_command('AUTHENTICATE', mech)
File "C:\Python34\lib\imaplib.py", line 1133, in _simple_command
return self._command_complete(name, self._command(name, *args))
File "C:\Python34\lib\imaplib.py", line 940, in _command
self.send(literal)
File "C:\Python34\lib\imaplib.py", line 276, in send
self.sock.sendall(data)
File "C:\Python34\lib\ssl.py", line 723, in sendall
v = self.send(data[count:])
File "C:\Python34\lib\ssl.py", line 684, in send
v = self._sslobj.write(data)
TypeError: 'str' does not support the buffer interface The problem is that _Authenticator.process returns a string instead of bytes in this case. |
Thanks for the report and the patch, Craig. Could you convert your reproducer to a test case? imaplib tests are located in Lib/test/test_imaplib.py. |
New patch is attached. |
The patch looks good to me, except that I think it would be better if the test verified that the '*' response is received by the server (perhaps return OK if we don't get it?) |
Okay, I attached another patch. The new version of the test returns success if the client's response is anything other than the abort line (*\r\n). It fails with the current version of imaplib, fails if I change _Authenticator.process to output a byte-string besides *, and succeeds with the change in the patch. |
Looks good to me, thanks. |
New changeset fe55a36a335b by Robert Collins in branch '3.4': New changeset b6f04b9d8c12 by Robert Collins in branch '3.5': New changeset 0879f2c53289 by Robert Collins in branch 'default': |
Thanks for the patch. Applied to 3.4 through 3.6. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: