Rev 4203: (James Henstridge) Insure that byte strings are passed to SMTP.login() in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Wed Mar 25 18:43:37 GMT 2009
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 4203
revision-id: pqm at pqm.ubuntu.com-20090325184331-1up3t0gh14ttr5zm
parent: pqm at pqm.ubuntu.com-20090325042012-23a6pm0mraw7g2kg
parent: james at jamesh.id.au-20090325054124-y7v92dpwnhh28szg
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2009-03-25 18:43:31 +0000
message:
(James Henstridge) Insure that byte strings are passed to SMTP.login()
modified:
bzrlib/smtp_connection.py smtp_connection.py-20070618204456-nu6wag1ste4biuk2-1
bzrlib/tests/test_smtp_connection.py test_smtp_connection-20070618204509-wuyxc0r0ztrecv7e-1
------------------------------------------------------------
revno: 4147.1.3
revision-id: james at jamesh.id.au-20090325054124-y7v92dpwnhh28szg
parent: james at jamesh.id.au-20090324072923-4l42qpdtur9nqsc5
committer: James Henstridge <james at jamesh.id.au>
branch nick: bzr.bug-338261
timestamp: Wed 2009-03-25 14:41:24 +0900
message:
Switch to using osutils.safe_utf8() as suggested by Vincent. Also
remove a few unused imports.
modified:
bzrlib/smtp_connection.py smtp_connection.py-20070618204456-nu6wag1ste4biuk2-1
bzrlib/tests/test_smtp_connection.py test_smtp_connection-20070618204509-wuyxc0r0ztrecv7e-1
------------------------------------------------------------
revno: 4147.1.2
revision-id: james at jamesh.id.au-20090324072923-4l42qpdtur9nqsc5
parent: james at jamesh.id.au-20090316072459-b26rgmv3lln2j8he
committer: James Henstridge <james at jamesh.id.au>
branch nick: bzr.bug-338261
timestamp: Tue 2009-03-24 16:29:23 +0900
message:
Encode usernames and passwords as UTF-8 rather than ASCII. While
CRAM-MD5 gives no guidance on encodings, other authentication methods
(e.g. SASL PLAIN) do.
modified:
bzrlib/smtp_connection.py smtp_connection.py-20070618204456-nu6wag1ste4biuk2-1
bzrlib/tests/test_smtp_connection.py test_smtp_connection-20070618204509-wuyxc0r0ztrecv7e-1
------------------------------------------------------------
revno: 4147.1.1
revision-id: james at jamesh.id.au-20090316072459-b26rgmv3lln2j8he
parent: pqm at pqm.ubuntu.com-20090316041621-taek91nogxt42bfy
committer: James Henstridge <james at jamesh.id.au>
branch nick: bzr.bug-338261
timestamp: Mon 2009-03-16 16:24:59 +0900
message:
Ensure that byte strings are passed to SMTP.login(), as passing unicode
does not make sense and breaks in Python 2.6.
modified:
bzrlib/smtp_connection.py smtp_connection.py-20070618204456-nu6wag1ste4biuk2-1
bzrlib/tests/test_smtp_connection.py test_smtp_connection-20070618204509-wuyxc0r0ztrecv7e-1
=== modified file 'bzrlib/smtp_connection.py'
--- a/bzrlib/smtp_connection.py 2009-03-23 14:59:43 +0000
+++ b/bzrlib/smtp_connection.py 2009-03-25 18:43:31 +0000
@@ -23,7 +23,7 @@
from bzrlib import (
config,
- ui,
+ osutils,
)
from bzrlib.errors import (
NoDestinationAddress,
@@ -111,7 +111,14 @@
self._smtp_password = auth.get_password(
'smtp', self._smtp_server, self._smtp_username)
- self._connection.login(self._smtp_username, self._smtp_password)
+ # smtplib requires that the username and password be byte
+ # strings. The CRAM-MD5 spec doesn't give any guidance on
+ # encodings, but the SASL PLAIN spec says UTF-8, so that's
+ # what we'll use.
+ username = osutils.safe_utf8(self._smtp_username)
+ password = osutils.safe_utf8(self._smtp_password)
+
+ self._connection.login(username, password)
@staticmethod
def get_message_addresses(message):
=== modified file 'bzrlib/tests/test_smtp_connection.py'
--- a/bzrlib/tests/test_smtp_connection.py 2009-03-23 14:59:43 +0000
+++ b/bzrlib/tests/test_smtp_connection.py 2009-03-25 18:43:31 +0000
@@ -19,7 +19,6 @@
import errno
import smtplib
import socket
-import sys
from bzrlib import (
config,
@@ -86,7 +85,7 @@
"""A fake smtp server that implements login by accepting anybody."""
def login(self, user, password):
- pass
+ self._calls.append(('login', user, password))
class TestSMTPConnection(tests.TestCaseInTempDir):
@@ -162,6 +161,23 @@
conn._connect()
self.assertEqual(password, conn._smtp_password)
+ def test_authenticate_with_byte_strings(self):
+ user = 'joe'
+ password = 'h\xC3\xACspass'
+ factory = WideOpenSMTPFactory()
+ conn = self.get_connection(
+ '[DEFAULT]\nsmtp_username=%s\nsmtp_password=%s\n'
+ % (user, password), smtp_factory=factory)
+ self.assertEqual(u'h\xECspass', conn._smtp_password)
+ conn._connect()
+ self.assertEqual([('connect', 'localhost'),
+ ('ehlo',),
+ ('has_extn', 'starttls'),
+ ('login', user, password)], factory._calls)
+ smtp_username, smtp_password = factory._calls[-1][1:]
+ self.assertIsInstance(smtp_username, str)
+ self.assertIsInstance(smtp_password, str)
+
def test_create_connection(self):
factory = StubSMTPFactory()
conn = self.get_connection('', smtp_factory=factory)
More information about the bazaar-commits
mailing list