~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smtp_connection.py

  • Committer: Vincent Ladeuil
  • Date: 2009-04-27 16:10:10 UTC
  • mto: (4310.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 4311.
  • Revision ID: v.ladeuil+lp@free.fr-20090427161010-7swfzeagf63cpixd
Fix bug #367726 by reverting some default user handling introduced
while fixing bug #256612.

* bzrlib/transport/ssh.py:
(_paramiko_auth): Explicitly use getpass.getuser() as default
user.

* bzrlib/transport/ftp/_gssapi.py:
(GSSAPIFtpTransport._create_connection): Explicitly use
getpass.getuser() as default user.

* bzrlib/transport/ftp/__init__.py:
(FtpTransport._create_connection): Explicitly use
getpass.getuser() as default user.

* bzrlib/tests/test_sftp_transport.py:
(TestUsesAuthConfig.test_sftp_is_none_if_no_config)
(TestUsesAuthConfig.test_sftp_doesnt_prompt_username): Revert to
None as the default user.

* bzrlib/tests/test_remote.py:
(TestRemoteSSHTransportAuthentication): The really offending one:
revert to None as the default user.

* bzrlib/tests/test_config.py:
(TestAuthenticationConfig.test_username_default_no_prompt): Update
test (and some PEP8).

* bzrlib/smtp_connection.py:
(SMTPConnection._authenticate): Revert to None as the default
user.

* bzrlib/plugins/launchpad/account.py:
(_get_auth_user): Revert default value handling.

* bzrlib/config.py:
(AuthenticationConfig.get_user): Fix doc-string. Leave default
value handling to callers.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007, 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
91
91
class TestSMTPConnection(tests.TestCaseInTempDir):
92
92
 
93
93
    def get_connection(self, text, smtp_factory=None):
94
 
        my_config = config.GlobalConfig.from_string(text)
 
94
        my_config = config.GlobalConfig()
 
95
        config_file = StringIO(text)
 
96
        my_config._get_parser(config_file)
95
97
        return smtp_connection.SMTPConnection(my_config,
96
98
                                              _smtp_factory=smtp_factory)
97
99
 
134
136
                                   smtp_factory=factory)
135
137
        self.assertIs(None, conn._smtp_password)
136
138
 
137
 
        ui.ui_factory = ui.CannedInputUIFactory([password])
 
139
        ui.ui_factory = tests.TestUIFactory(stdin=password + '\n',
 
140
                                            stdout=tests.StringIOWrapper())
138
141
        conn._connect()
139
142
        self.assertEqual(password, conn._smtp_password)
 
143
        # stdin should be empty (the provided password have been consumed)
 
144
        self.assertEqual('', ui.ui_factory.stdin.readline())
140
145
 
141
146
    def test_smtp_password_from_auth_config(self):
142
147
        user = 'joe'
158
163
 
159
164
    def test_authenticate_with_byte_strings(self):
160
165
        user = 'joe'
161
 
        unicode_pass = u'h\xECspass'
162
 
        utf8_pass = unicode_pass.encode('utf-8')
 
166
        password = 'h\xC3\xACspass'
163
167
        factory = WideOpenSMTPFactory()
164
168
        conn = self.get_connection(
165
 
            u'[DEFAULT]\nsmtp_username=%s\nsmtp_password=%s\n'
166
 
            % (user, unicode_pass), smtp_factory=factory)
167
 
        self.assertEqual(unicode_pass, conn._smtp_password)
 
169
            '[DEFAULT]\nsmtp_username=%s\nsmtp_password=%s\n'
 
170
            % (user, password), smtp_factory=factory)
 
171
        self.assertEqual(u'h\xECspass', conn._smtp_password)
168
172
        conn._connect()
169
173
        self.assertEqual([('connect', 'localhost'),
170
174
                          ('ehlo',),
171
175
                          ('has_extn', 'starttls'),
172
 
                          ('login', user, utf8_pass)], factory._calls)
 
176
                          ('login', user, password)], factory._calls)
173
177
        smtp_username, smtp_password = factory._calls[-1][1:]
174
178
        self.assertIsInstance(smtp_username, str)
175
179
        self.assertIsInstance(smtp_password, str)