diff --git a/Lib/test/test_smtplib.py b/Lib/test/test_smtplib.py index 81806c9..2fcf382 100644 --- a/Lib/test/test_smtplib.py +++ b/Lib/test/test_smtplib.py @@ -479,6 +479,14 @@ class SMTPSimTests(unittest.TestCase): expected_auth_ok = (235, b'plain auth ok') self.assertEqual(smtp.login(sim_auth[0], sim_auth[1]), expected_auth_ok) + def testAUTH_PLAIN_unicode_user(self): + self.serv.add_feature("AUTH PLAIN") + smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15) + + expected_auth_ok = (235, b'plain auth ok') + self.assertEqual(smtp.login(unicode(sim_auth[0]), sim_auth[1]), expected_auth_ok) + + # SimSMTPChannel doesn't fully support LOGIN or CRAM-MD5 auth because they # require a synchronous read to obtain the credentials...so instead smtpd # sees the credential sent by smtplib's login method as an unknown command, @@ -504,6 +512,25 @@ class SMTPSimTests(unittest.TestCase): if sim_auth_credentials['cram-md5'] not in str(err): raise "expected encoded credentials not found in error message" + def testAUTH_CRAM_MD5_unicode_user(self): + self.serv.add_feature("AUTH CRAM-MD5") + smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15) + try: smtp.login(unicode(sim_auth[0]), sim_auth[1]) + except smtplib.SMTPAuthenticationError as err: + if sim_auth_credentials['cram-md5'] not in str(err): + raise "expected encoded credentials not found in error message" + + def test_unicode_login_fails_gracefully_plain(self): + self.serv.add_feature("AUTH PLAIN") + smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15) + self.assertRaises(UnicodeEncodeError, smtp.login, u'bj\u00F6rn@domain.com', 'somepassword') + + def test_unicode_login_fails_gracefully_auth_cram_md5(self): + self.serv.add_feature("AUTH CRAM-MD5") + smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15) + self.assertRaises(UnicodeEncodeError, smtp.login, u'bj\u00F6rn@domain.com', 'somepassword') + + #TODO: add tests for correct AUTH method fallback now that the #test infrastructure can support it.