Merge lp:~salgado/launchpad/fix-unicode-error-on-login into lp:launchpad/db-devel

Proposed by Guilherme Salgado
Status: Merged
Merged at revision: not available
Proposed branch: lp:~salgado/launchpad/fix-unicode-error-on-login
Merge into: lp:launchpad/db-devel
Diff against target: 54 lines (+18/-1)
2 files modified
lib/canonical/launchpad/webapp/login.py (+2/-1)
lib/canonical/launchpad/webapp/tests/test_login.py (+16/-0)
To merge this branch: bzr merge lp:~salgado/launchpad/fix-unicode-error-on-login
Reviewer Review Type Date Requested Status
Francis J. Lacoste (community) release-critical Approve
Michael Nelson (community) code Approve
Review via email: mp+20656@code.launchpad.net

Description of the change

Fix OpenIDLogin to not OOPS when the query string has non-ascii chars.

Just utf8-encoding the value before passing it to urllib.urlencode()
seems to do the trick.

To post a comment you must log in.
Revision history for this message
Michael Nelson (michael.nelson) wrote :

I'm not sure why the diff hasn't updated yet, but I checked this locally, and it all looks good. Thanks Guilherme.

review: Approve (code)
Revision history for this message
Guilherme Salgado (salgado) wrote :

http://paste.ubuntu.com/388337/ has the diff, in case it never shows up here.

Revision history for this message
Francis J. Lacoste (flacoste) wrote :

Land it on db-devel.

review: Approve (release-critical)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/canonical/launchpad/webapp/login.py'
2--- lib/canonical/launchpad/webapp/login.py 2010-03-02 15:03:43 +0000
3+++ lib/canonical/launchpad/webapp/login.py 2010-03-04 17:21:54 +0000
4@@ -194,7 +194,8 @@
5 # they started the login process (i.e. the current URL without the
6 # '+login' bit). To do that we encode that URL as a query arg in the
7 # return_to URL passed to the OpenID Provider
8- starting_url = urllib.urlencode([('starting_url', self.starting_url)])
9+ starting_url = urllib.urlencode(
10+ [('starting_url', self.starting_url.encode('utf-8'))])
11 trust_root = allvhosts.configs['mainsite'].rooturl
12 return_to = urlappend(trust_root, '+openid-callback')
13 return_to = "%s?%s" % (return_to, starting_url)
14
15=== modified file 'lib/canonical/launchpad/webapp/tests/test_login.py'
16--- lib/canonical/launchpad/webapp/tests/test_login.py 2010-03-02 15:03:43 +0000
17+++ lib/canonical/launchpad/webapp/tests/test_login.py 2010-03-04 17:21:54 +0000
18@@ -307,6 +307,7 @@
19
20 class FakeOpenIDRequest:
21 extensions = None
22+ return_to = None
23
24 def addExtension(self, extension):
25 if self.extensions is None:
26@@ -318,6 +319,7 @@
27 return False
28
29 def htmlMarkup(self, trust_root, return_to):
30+ self.return_to = return_to
31 return None
32
33
34@@ -334,6 +336,20 @@
35 class TestOpenIDLogin(TestCaseWithFactory):
36 layer = DatabaseFunctionalLayer
37
38+ def test_return_to_with_non_ascii_chars(self):
39+ # Sometimes the +login link will have non-ascii characters in the
40+ # query string, and we need to include those in the return_to URL that
41+ # we pass to the OpenID provider, so we must utf-encode them.
42+ request = LaunchpadTestRequest(
43+ form={'non_ascii_field': 'subproc\xc3\xa9s'})
44+ # This is a hack to make the request.getURL(1) call issued by the view
45+ # not raise an IndexError.
46+ request._app_names = ['foo']
47+ view = StubbedOpenIDLogin(object(), request)
48+ view()
49+ self.assertIn(
50+ 'non_ascii_field%3Dsubproc%C3%A9s', view.openid_request.return_to)
51+
52 def test_sreg_fields(self):
53 # We request the user's email address and Full Name (through the SREG
54 # extension) to the OpenID provider so that we can automatically

Subscribers

People subscribed via source and target branches

to status/vote changes: