mirror of
https://github.com/python/cpython.git
synced 2026-06-04 16:50:51 +00:00
gh-91099: fix[imaplib]: call Exception with string instance (#31823)
* bpo-46943: fix[imaplib]: call Exception with string instance Adjust the behavior of 'login' to be similar to `authenticate()`, where self.error is called with a str() instance. Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
This commit is contained in:
parent
50fe49c879
commit
29805f00a1
3 changed files with 13 additions and 1 deletions
|
|
@ -712,7 +712,7 @@ def login(self, user, password):
|
|||
"""
|
||||
typ, dat = self._simple_command('LOGIN', user, self._quote(password))
|
||||
if typ != 'OK':
|
||||
raise self.error(dat[-1])
|
||||
raise self.error(dat[-1].decode('UTF-8', 'replace'))
|
||||
self.state = 'AUTH'
|
||||
return typ, dat
|
||||
|
||||
|
|
|
|||
|
|
@ -434,6 +434,16 @@ def cmd_AUTHENTICATE(self, tag, args):
|
|||
r'\[AUTHENTICATIONFAILED\] invalid'):
|
||||
client.authenticate('MYAUTH', lambda x: b'fake')
|
||||
|
||||
def test_invalid_login(self):
|
||||
class MyServer(SimpleIMAPHandler):
|
||||
def cmd_LOGIN(self, tag, args):
|
||||
self.server.logged = args[0]
|
||||
self._send_tagged(tag, 'NO', '[LOGIN] failed')
|
||||
client, _ = self._setup(MyServer)
|
||||
with self.assertRaisesRegex(imaplib.IMAP4.error,
|
||||
r'\[LOGIN\] failed'):
|
||||
client.login('user', 'wrongpass')
|
||||
|
||||
def test_valid_authentication_bytes(self):
|
||||
class MyServer(SimpleIMAPHandler):
|
||||
def cmd_AUTHENTICATE(self, tag, args):
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
:meth:`imaplib.IMAP4.login` now raises exceptions with :class:`str` instead of
|
||||
:class:`bytes`. Patch by Florian Best.
|
||||
Loading…
Add table
Add a link
Reference in a new issue