Merge lp:~gz/bzr-svn/unicode_password_prompt_1076386 into lp:bzr-svn

Proposed by Martin Packman
Status: Merged
Merged at revision: 4196
Proposed branch: lp:~gz/bzr-svn/unicode_password_prompt_1076386
Merge into: lp:bzr-svn
Diff against target: 93 lines (+55/-1)
4 files modified
NEWS (+3/-0)
auth.py (+1/-1)
tests/__init__.py (+1/-0)
tests/test_auth.py (+50/-0)
To merge this branch: bzr merge lp:~gz/bzr-svn/unicode_password_prompt_1076386
Reviewer Review Type Date Requested Status
Jelmer Vernooij (community) code Approve
Review via email: mp+133518@code.launchpad.net

Description of the change

Fix prompting for passwords against newer bzr versions which have become strict about ui-level strings actually being unicode rather than bytestrings. Core bzr should possibly make allowances for old plugins that are lax about this, but since at least 2.2 TextUIFactory.prompt has tried to encode the string using the terminal encoding, which would blow up with non-ascii bytestrings.

The branch also adds a new tests.test_auth module as the current auth module seems to be untested at present.

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

Looks good, please land. :-) Can you add an entry in NEWS as well?

review: Approve (code)
4198. By Martin Packman

Add NEWS

Revision history for this message
Martin Packman (gz) wrote :

News added. I don't have push rights to lp:bzr-svn though, do you have some other means of landing?

Revision history for this message
Jelmer Vernooij (jelmer) wrote :

On Fri, 2012-11-09 at 12:08 +0000, Martin Packman wrote:
> News added. I don't have push rights to lp:bzr-svn though, do you have some other means of landing?
You're now a member of ~bzr-svn. Have fun. (-:

Cheers,

Jelmer

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2012-06-28 11:09:23 +0000
3+++ NEWS 2012-11-09 12:05:26 +0000
4@@ -5,6 +5,9 @@
5 * Support show_base argument to ``WorkingTree.pull``.
6 (Jelmer Vernooij, #1018797)
7
8+ * Use unicode string for password prompt fixing ValueError
9+ with newer bzr versions. (Martin Packman, #1076386)
10+
11 bzr-svn 1.2.2 2012-04-16
12
13 BUG FIXES
14
15=== modified file 'auth.py'
16--- auth.py 2012-03-08 17:52:35 +0000
17+++ auth.py 2012-11-09 12:05:26 +0000
18@@ -77,7 +77,7 @@
19 host=self.host, path=self.path, realm=realm, ask=True)
20 password = self.get_password(self.scheme, host=self.host,
21 path=self.path, user=username,
22- realm=realm, prompt="%s %s password" % (realm, username))
23+ realm=realm, prompt=u"%s %s password" % (realm, username))
24 if type(password) == unicode:
25 password = password.encode('utf-8')
26 return (username.encode("utf-8"), password, False)
27
28=== modified file 'tests/__init__.py'
29--- tests/__init__.py 2011-11-14 14:53:05 +0000
30+++ tests/__init__.py 2012-11-09 12:05:26 +0000
31@@ -227,6 +227,7 @@
32 suite = TestSuite()
33
34 testmod_names = [
35+ 'test_auth',
36 'test_branch',
37 'test_branchprops',
38 'test_cache',
39
40=== added file 'tests/test_auth.py'
41--- tests/test_auth.py 1970-01-01 00:00:00 +0000
42+++ tests/test_auth.py 2012-11-09 12:05:26 +0000
43@@ -0,0 +1,50 @@
44+# Copyright (C) 2012 Martin Packman <martin.packman@canonical.com>
45+
46+# This program is free software; you can redistribute it and/or modify
47+# it under the terms of the GNU General Public License as published by
48+# the Free Software Foundation; either version 2 of the License, or
49+# (at your option) any later version.
50+
51+# This program is distributed in the hope that it will be useful,
52+# but WITHOUT ANY WARRANTY; without even the implied warranty of
53+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
54+# GNU General Public License for more details.
55+
56+# You should have received a copy of the GNU General Public License
57+# along with this program; if not, write to the Free Software
58+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
59+
60+"""Tests for authentication module"""
61+
62+from bzrlib import (
63+ tests,
64+ ui,
65+ )
66+from bzrlib.plugins.svn.auth import (
67+ SubversionAuthenticationConfig,
68+ )
69+
70+
71+class TestSubversionAuthenticationConfig(tests.TestCase):
72+ """Subversion specific authentication.conf handling tests"""
73+
74+ def override_ui(self, stdin):
75+ stdout = tests.StringIOWrapper()
76+ stderr = tests.StringIOWrapper()
77+ ui.ui_factory = tests.TestUIFactory(stdin=stdin, stdout=stdout,
78+ stderr=stderr)
79+ return stdout, stderr
80+
81+ def test_get_svn_simple(self):
82+ username, password = "a-user", "a-secret"
83+ realm = "REALM" # what does this mean in the context of svn?
84+ stdout, stderr = self.override_ui(password + "\n")
85+ conf = SubversionAuthenticationConfig("svn", username, None, None)
86+ got_user, got_pass, _ = conf.get_svn_simple(realm, username, True)
87+ self.assertIsInstance(got_user, str)
88+ self.assertEquals(username, got_user)
89+ self.assertIsInstance(got_pass, str)
90+ self.assertEquals(password, got_pass)
91+ self.assertEquals("%s %s password: " % (realm, username),
92+ stderr.getvalue())
93+ self.assertEquals("", stdout.getvalue())

Subscribers

People subscribed via source and target branches

to status/vote changes: