Merge lp:~deryck/launchpad/email-update-login-stuck-1036267 into lp:launchpad

Proposed by Deryck Hodge
Status: Merged
Approved by: Deryck Hodge
Approved revision: no longer in the source branch.
Merged at revision: 15799
Proposed branch: lp:~deryck/launchpad/email-update-login-stuck-1036267
Merge into: lp:launchpad
Diff against target: 87 lines (+34/-4)
2 files modified
lib/lp/services/webapp/login.py (+14/-3)
lib/lp/services/webapp/tests/test_login.py (+20/-1)
To merge this branch: bzr merge lp:~deryck/launchpad/email-update-login-stuck-1036267
Reviewer Review Type Date Requested Status
Deryck Hodge (community) Approve
Review via email: mp+119381@code.launchpad.net

Commit message

The code for requiring re-authentication when editing emails was only partially merged. This completes the merge to have fully working re-auth when editing emails.

Description of the change

This change has already landed once, been reverted, and partially landed again. This branch is to complete the merge of the work I did to force re-authentication when editing email addresses. I'm self reviewing since it's all been reviewed twice now, but the merge was messed up somehow.

To post a comment you must log in.
Revision history for this message
Deryck Hodge (deryck) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/services/webapp/login.py'
2--- lib/lp/services/webapp/login.py 2012-08-10 18:16:36 +0000
3+++ lib/lp/services/webapp/login.py 2012-08-13 16:30:41 +0000
4@@ -16,7 +16,10 @@
5 FAILURE,
6 SUCCESS,
7 )
8-from openid.extensions import sreg
9+from openid.extensions import (
10+ pape,
11+ sreg,
12+ )
13 from openid.fetchers import (
14 setDefaultFetcher,
15 Urllib2Fetcher,
16@@ -168,7 +171,10 @@
17 return Consumer(session, openid_store)
18
19 def render(self):
20- if self.account is not None:
21+ # Reauthentication is called for by a query string parameter.
22+ reauth_qs = self.request.query_string_params.get('reauth', ['0'])
23+ do_reauth = int(reauth_qs[0])
24+ if self.account is not None and not do_reauth:
25 return AlreadyLoggedInView(self.context, self.request)()
26
27 # Allow unauthenticated users to have sessions for the OpenID
28@@ -189,6 +195,11 @@
29 self.openid_request.addExtension(
30 sreg.SRegRequest(required=['email', 'fullname']))
31
32+ # Force the Open ID handshake to re-authenticate, using
33+ # pape extension's max_auth_age, if the URL indicates it.
34+ if do_reauth:
35+ self.openid_request.addExtension(pape.Request(max_auth_age=0))
36+
37 assert not self.openid_request.shouldSendRedirect(), (
38 "Our fixed OpenID server should not need us to redirect.")
39 # Once the user authenticates with the OpenID provider they will be
40@@ -216,7 +227,7 @@
41 def starting_url(self):
42 starting_url = self.request.getURL(1)
43 query_string = "&".join([arg for arg in self.form_args])
44- if query_string:
45+ if query_string and query_string != 'reauth=1':
46 starting_url += "?%s" % query_string
47 return starting_url
48
49
50=== modified file 'lib/lp/services/webapp/tests/test_login.py'
51--- lib/lp/services/webapp/tests/test_login.py 2012-08-08 13:41:05 +0000
52+++ lib/lp/services/webapp/tests/test_login.py 2012-08-13 16:30:41 +0000
53@@ -28,7 +28,10 @@
54 FAILURE,
55 SUCCESS,
56 )
57-from openid.extensions import sreg
58+from openid.extensions import (
59+ pape,
60+ sreg,
61+ )
62 from openid.yadis.discover import DiscoveryFailure
63 from testtools.matchers import Contains
64 from zope.component import getUtility
65@@ -731,6 +734,22 @@
66 self.assertEquals(sorted(sreg_extension.required),
67 sorted(sreg_extension.allRequestedFields()))
68
69+ def test_pape_extension_added_with_reauth_query(self):
70+ # We can signal that a request should be reauthenticated via
71+ # a reauth URL parameter, which should add PAPE extension's
72+ # max_auth_age paramter.
73+ request = LaunchpadTestRequest(QUERY_STRING='reauth=1')
74+ # This is a hack to make the request.getURL(1) call issued by the view
75+ # not raise an IndexError.
76+ request._app_names = ['foo']
77+ view = StubbedOpenIDLogin(object(), request)
78+ view()
79+ extensions = view.openid_request.extensions
80+ self.assertIsNot(None, extensions)
81+ pape_extension = extensions[1]
82+ self.assertIsInstance(pape_extension, pape.Request)
83+ self.assertEqual(0, pape_extension.max_auth_age)
84+
85 def test_logs_to_timeline(self):
86 # Beginning an OpenID association makes an HTTP request to the
87 # OP, so it's a potentially long action. It is logged to the