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

Proposed by Vincent Ladeuil
Status: Merged
Approved by: Martin Packman
Approved revision: no longer in the source branch.
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) Approve
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.
Revision history for this message
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
Revision history for this message
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
=== modified file 'bzrlib/tests/test_ui.py'
--- bzrlib/tests/test_ui.py 2012-08-02 11:45:26 +0000
+++ bzrlib/tests/test_ui.py 2012-09-17 09:14:28 +0000
@@ -97,28 +97,20 @@
97 pb.finished()97 pb.finished()
9898
99 def test_text_factory_utf8_password(self):99 def test_text_factory_utf8_password(self):
100 """Test an utf8 password.100 """Test an utf8 password."""
101101 ui = _mod_ui_text.TextUIFactory(None, None, None)
102 We can't predict what encoding users will have for stdin, so we force102 ui.stdin = tests.StringIOWrapper(u'baz\u1234'.encode('utf8'))
103 it to utf8 to test that we transport the password correctly.103 ui.stdout = tests.StringIOWrapper()
104 """104 ui.stderr = tests.StringIOWrapper()
105 ui = self.make_test_ui_factory(u'baz\u1234'.encode('utf8'))
106 ui.stderr.encoding = ui.stdout.encoding = ui.stdin.encoding = 'utf8'105 ui.stderr.encoding = ui.stdout.encoding = ui.stdin.encoding = 'utf8'
107 pb = ui.nested_progress_bar()106 pb = ui.nested_progress_bar()
108 try:107 password = ui.get_password(u'Hello \u1234 %(user)s', user=u'some\u1234')
109 password = self.apply_redirected(ui.stdin, ui.stdout, ui.stderr,108 self.assertEqual(u'baz\u1234', password)
110 ui.get_password,109 self.assertEqual(u'Hello \u1234 some\u1234: ',
111 u'Hello \u1234 %(user)s',110 ui.stderr.getvalue().decode('utf8'))
112 user=u'some\u1234')111 # stdin and stdout should be empty
113 # We use StringIO objects, we need to decode them112 self.assertEqual('', ui.stdin.readline())
114 self.assertEqual(u'baz\u1234', password.decode('utf8'))113 self.assertEqual('', ui.stdout.getvalue())
115 self.assertEqual(u'Hello \u1234 some\u1234: ',
116 ui.stderr.getvalue().decode('utf8'))
117 # stdin and stdout should be empty
118 self.assertEqual('', ui.stdin.readline())
119 self.assertEqual('', ui.stdout.readline())
120 finally:
121 pb.finished()
122114
123 def test_text_ui_get_boolean(self):115 def test_text_ui_get_boolean(self):
124 stdin = tests.StringIOWrapper("y\n" # True116 stdin = tests.StringIOWrapper("y\n" # True
@@ -270,36 +262,30 @@
270 pb.finished()262 pb.finished()
271263
272 def test_text_ui_getusername(self):264 def test_text_ui_getusername(self):
273 factory = _mod_ui_text.TextUIFactory(None, None, None)265 ui = _mod_ui_text.TextUIFactory(None, None, None)
274 factory.stdin = tests.StringIOWrapper("someuser\n\n")266 ui.stdin = tests.StringIOWrapper('someuser\n\n')
275 factory.stdout = tests.StringIOWrapper()267 ui.stdout = tests.StringIOWrapper()
276 factory.stderr = tests.StringIOWrapper()268 ui.stderr = tests.StringIOWrapper()
277 factory.stdout.encoding = "utf8"269 ui.stdout.encoding = 'utf8'
278 # there is no output from the base factory270 self.assertEqual('someuser',
279 self.assertEqual("someuser",271 ui.get_username(u'Hello %(host)s', host='some'))
280 factory.get_username(u'Hello %(host)s', host='some'))272 self.assertEquals('Hello some: ', ui.stderr.getvalue())
281 self.assertEquals("Hello some: ", factory.stderr.getvalue())273 self.assertEquals('', ui.stdout.getvalue())
282 self.assertEquals('', factory.stdout.getvalue())274 self.assertEqual('', ui.get_username(u"Gebruiker"))
283 self.assertEqual("", factory.get_username(u"Gebruiker"))
284 # stdin should be empty275 # stdin should be empty
285 self.assertEqual('', factory.stdin.readline())276 self.assertEqual('', ui.stdin.readline())
286277
287 def test_text_ui_getusername_utf8(self):278 def test_text_ui_getusername_utf8(self):
288 ui = tests.TestUIFactory(stdin=u'someuser\u1234'.encode('utf8'),279 ui = _mod_ui_text.TextUIFactory(None, None, None)
289 stdout=tests.StringIOWrapper(),280 ui.stdin = tests.StringIOWrapper(u'someuser\u1234'.encode('utf8'))
290 stderr=tests.StringIOWrapper())281 ui.stdout = tests.StringIOWrapper()
282 ui.stderr = tests.StringIOWrapper()
291 ui.stderr.encoding = ui.stdout.encoding = ui.stdin.encoding = "utf8"283 ui.stderr.encoding = ui.stdout.encoding = ui.stdin.encoding = "utf8"
292 pb = ui.nested_progress_bar()284 username = ui.get_username(u'Hello %(host)s', host=u'some\u1234')
293 try:285 self.assertEquals(u"someuser\u1234", username)
294 # there is no output from the base factory286 self.assertEquals(u"Hello some\u1234: ",
295 username = self.apply_redirected(ui.stdin, ui.stdout, ui.stderr,287 ui.stderr.getvalue().decode("utf8"))
296 ui.get_username, u'Hello\u1234 %(host)s', host=u'some\u1234')288 self.assertEquals('', ui.stdout.getvalue())
297 self.assertEquals(u"someuser\u1234", username.decode('utf8'))
298 self.assertEquals(u"Hello\u1234 some\u1234: ",
299 ui.stderr.getvalue().decode("utf8"))
300 self.assertEquals('', ui.stdout.getvalue())
301 finally:
302 pb.finished()
303289
304 def test_quietness(self):290 def test_quietness(self):
305 self.overrideEnv('BZR_PROGRESS_BAR', 'text')291 self.overrideEnv('BZR_PROGRESS_BAR', 'text')
306292
=== modified file 'bzrlib/ui/text.py'
--- bzrlib/ui/text.py 2012-04-30 10:44:04 +0000
+++ bzrlib/ui/text.py 2012-09-17 09:14:28 +0000
@@ -231,8 +231,11 @@
231 password = self.stdin.readline()231 password = self.stdin.readline()
232 if not password:232 if not password:
233 password = None233 password = None
234 elif password[-1] == '\n':234 else:
235 password = password[:-1]235 password = password.decode(self.stdin.encoding)
236
237 if password[-1] == '\n':
238 password = password[:-1]
236 return password239 return password
237240
238 def get_password(self, prompt=u'', **kwargs):241 def get_password(self, prompt=u'', **kwargs):
@@ -266,8 +269,10 @@
266 username = self.stdin.readline()269 username = self.stdin.readline()
267 if not username:270 if not username:
268 username = None271 username = None
269 elif username[-1] == '\n':272 else:
270 username = username[:-1]273 username = username.decode(self.stdin.encoding)
274 if username[-1] == '\n':
275 username = username[:-1]
271 return username276 return username
272277
273 def make_progress_view(self):278 def make_progress_view(self):
274279
=== modified file 'doc/en/release-notes/bzr-2.6.txt'
--- doc/en/release-notes/bzr-2.6.txt 2012-09-14 17:22:35 +0000
+++ doc/en/release-notes/bzr-2.6.txt 2012-09-17 09:14:28 +0000
@@ -49,6 +49,9 @@
49 and would be ignored.49 and would be ignored.
50 (Haw Loeung, #932515)50 (Haw Loeung, #932515)
5151
52* ``Authentication.Config`` now always returns unicode user names and passwords.
53 (Vincent Ladeuil, #514301)
54
52* Warn when ``--show-base`` is used for ``pull`` in a treeless branch55* Warn when ``--show-base`` is used for ``pull`` in a treeless branch
53 instead of failing. It's useless but harmless. (Vincent Ladeuil, #1022160)56 instead of failing. It's useless but harmless. (Vincent Ladeuil, #1022160)
5457