Merge lp:~vila/bzr/514301-auth-config-unicode into lp:bzr

Proposed by Vincent Ladeuil on 2012-09-17
Status: Merged
Approved by: Martin Packman on 2012-10-10
Approved revision: 6560
Merged at revision: 6568
Proposed branch: lp:~vila/bzr/514301-auth-config-unicode
Merge into: lp:bzr
Diff against target: 145 lines (+44/-50)
3 files modified
bzrlib/tests/test_ui.py (+32/-46)
bzrlib/ui/text.py (+9/-4)
doc/en/release-notes/bzr-2.6.txt (+3/-0)
To merge this branch: bzr merge lp:~vila/bzr/514301-auth-config-unicode
Reviewer Review Type Date Requested Status
Martin Packman (community) 2012-09-17 Approve on 2012-10-10
Review via email: mp+124627@code.launchpad.net

Commit message

AuthConfig alwaus return user/password as unicode.

Description of the change

This fixes bug #514301 by always returning unicode username/password when
typed by the user (using stdin encoding).

I cleaned up the tests where we enforced the wrong behaviour (let ui
returned encoded strings (including ascii) instead of unicode).

To post a comment you must log in.
Martin Packman (gz) wrote :

Looks good.

We'll get the ui object doing the right thing with unicode, one method at a time...

review: Approve
Vincent Ladeuil (vila) wrote :

sent to pqm by email

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzrlib/tests/test_ui.py'
2--- bzrlib/tests/test_ui.py 2012-08-02 11:45:26 +0000
3+++ bzrlib/tests/test_ui.py 2012-09-17 09:14:28 +0000
4@@ -97,28 +97,20 @@
5 pb.finished()
6
7 def test_text_factory_utf8_password(self):
8- """Test an utf8 password.
9-
10- We can't predict what encoding users will have for stdin, so we force
11- it to utf8 to test that we transport the password correctly.
12- """
13- ui = self.make_test_ui_factory(u'baz\u1234'.encode('utf8'))
14+ """Test an utf8 password."""
15+ ui = _mod_ui_text.TextUIFactory(None, None, None)
16+ ui.stdin = tests.StringIOWrapper(u'baz\u1234'.encode('utf8'))
17+ ui.stdout = tests.StringIOWrapper()
18+ ui.stderr = tests.StringIOWrapper()
19 ui.stderr.encoding = ui.stdout.encoding = ui.stdin.encoding = 'utf8'
20 pb = ui.nested_progress_bar()
21- try:
22- password = self.apply_redirected(ui.stdin, ui.stdout, ui.stderr,
23- ui.get_password,
24- u'Hello \u1234 %(user)s',
25- user=u'some\u1234')
26- # We use StringIO objects, we need to decode them
27- self.assertEqual(u'baz\u1234', password.decode('utf8'))
28- self.assertEqual(u'Hello \u1234 some\u1234: ',
29- ui.stderr.getvalue().decode('utf8'))
30- # stdin and stdout should be empty
31- self.assertEqual('', ui.stdin.readline())
32- self.assertEqual('', ui.stdout.readline())
33- finally:
34- pb.finished()
35+ password = ui.get_password(u'Hello \u1234 %(user)s', user=u'some\u1234')
36+ self.assertEqual(u'baz\u1234', password)
37+ self.assertEqual(u'Hello \u1234 some\u1234: ',
38+ ui.stderr.getvalue().decode('utf8'))
39+ # stdin and stdout should be empty
40+ self.assertEqual('', ui.stdin.readline())
41+ self.assertEqual('', ui.stdout.getvalue())
42
43 def test_text_ui_get_boolean(self):
44 stdin = tests.StringIOWrapper("y\n" # True
45@@ -270,36 +262,30 @@
46 pb.finished()
47
48 def test_text_ui_getusername(self):
49- factory = _mod_ui_text.TextUIFactory(None, None, None)
50- factory.stdin = tests.StringIOWrapper("someuser\n\n")
51- factory.stdout = tests.StringIOWrapper()
52- factory.stderr = tests.StringIOWrapper()
53- factory.stdout.encoding = "utf8"
54- # there is no output from the base factory
55- self.assertEqual("someuser",
56- factory.get_username(u'Hello %(host)s', host='some'))
57- self.assertEquals("Hello some: ", factory.stderr.getvalue())
58- self.assertEquals('', factory.stdout.getvalue())
59- self.assertEqual("", factory.get_username(u"Gebruiker"))
60+ ui = _mod_ui_text.TextUIFactory(None, None, None)
61+ ui.stdin = tests.StringIOWrapper('someuser\n\n')
62+ ui.stdout = tests.StringIOWrapper()
63+ ui.stderr = tests.StringIOWrapper()
64+ ui.stdout.encoding = 'utf8'
65+ self.assertEqual('someuser',
66+ ui.get_username(u'Hello %(host)s', host='some'))
67+ self.assertEquals('Hello some: ', ui.stderr.getvalue())
68+ self.assertEquals('', ui.stdout.getvalue())
69+ self.assertEqual('', ui.get_username(u"Gebruiker"))
70 # stdin should be empty
71- self.assertEqual('', factory.stdin.readline())
72+ self.assertEqual('', ui.stdin.readline())
73
74 def test_text_ui_getusername_utf8(self):
75- ui = tests.TestUIFactory(stdin=u'someuser\u1234'.encode('utf8'),
76- stdout=tests.StringIOWrapper(),
77- stderr=tests.StringIOWrapper())
78+ ui = _mod_ui_text.TextUIFactory(None, None, None)
79+ ui.stdin = tests.StringIOWrapper(u'someuser\u1234'.encode('utf8'))
80+ ui.stdout = tests.StringIOWrapper()
81+ ui.stderr = tests.StringIOWrapper()
82 ui.stderr.encoding = ui.stdout.encoding = ui.stdin.encoding = "utf8"
83- pb = ui.nested_progress_bar()
84- try:
85- # there is no output from the base factory
86- username = self.apply_redirected(ui.stdin, ui.stdout, ui.stderr,
87- ui.get_username, u'Hello\u1234 %(host)s', host=u'some\u1234')
88- self.assertEquals(u"someuser\u1234", username.decode('utf8'))
89- self.assertEquals(u"Hello\u1234 some\u1234: ",
90- ui.stderr.getvalue().decode("utf8"))
91- self.assertEquals('', ui.stdout.getvalue())
92- finally:
93- pb.finished()
94+ username = ui.get_username(u'Hello %(host)s', host=u'some\u1234')
95+ self.assertEquals(u"someuser\u1234", username)
96+ self.assertEquals(u"Hello some\u1234: ",
97+ ui.stderr.getvalue().decode("utf8"))
98+ self.assertEquals('', ui.stdout.getvalue())
99
100 def test_quietness(self):
101 self.overrideEnv('BZR_PROGRESS_BAR', 'text')
102
103=== modified file 'bzrlib/ui/text.py'
104--- bzrlib/ui/text.py 2012-04-30 10:44:04 +0000
105+++ bzrlib/ui/text.py 2012-09-17 09:14:28 +0000
106@@ -231,8 +231,11 @@
107 password = self.stdin.readline()
108 if not password:
109 password = None
110- elif password[-1] == '\n':
111- password = password[:-1]
112+ else:
113+ password = password.decode(self.stdin.encoding)
114+
115+ if password[-1] == '\n':
116+ password = password[:-1]
117 return password
118
119 def get_password(self, prompt=u'', **kwargs):
120@@ -266,8 +269,10 @@
121 username = self.stdin.readline()
122 if not username:
123 username = None
124- elif username[-1] == '\n':
125- username = username[:-1]
126+ else:
127+ username = username.decode(self.stdin.encoding)
128+ if username[-1] == '\n':
129+ username = username[:-1]
130 return username
131
132 def make_progress_view(self):
133
134=== modified file 'doc/en/release-notes/bzr-2.6.txt'
135--- doc/en/release-notes/bzr-2.6.txt 2012-09-14 17:22:35 +0000
136+++ doc/en/release-notes/bzr-2.6.txt 2012-09-17 09:14:28 +0000
137@@ -49,6 +49,9 @@
138 and would be ignored.
139 (Haw Loeung, #932515)
140
141+* ``Authentication.Config`` now always returns unicode user names and passwords.
142+ (Vincent Ladeuil, #514301)
143+
144 * Warn when ``--show-base`` is used for ``pull`` in a treeless branch
145 instead of failing. It's useless but harmless. (Vincent Ladeuil, #1022160)
146