Merge lp:~cjwatson/launchpad/fix-login-discharge-macaroon into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18081
Proposed branch: lp:~cjwatson/launchpad/fix-login-discharge-macaroon
Merge into: lp:launchpad
Diff against target: 85 lines (+33/-15)
2 files modified
lib/lp/services/webapp/templates/login-discharge-macaroon.pt (+27/-15)
lib/lp/services/webapp/tests/test_login.py (+6/-0)
To merge this branch: bzr merge lp:~cjwatson/launchpad/fix-login-discharge-macaroon
Reviewer Review Type Date Requested Status
Celso Providelo (community) Approve
Launchpad code reviewers Pending
Review via email: mp+295925@code.launchpad.net

Commit message

Fix the OpenID callback view to actually work properly when receiving a discharge macaroon.

Description of the change

Fix the OpenID callback view to actually work properly when receiving a discharge macaroon.

It was lacking a submit button, and the JS code to auto-submit it wasn't hooked up quite right. I've done a straight-through test with this on dogfood.

To post a comment you must log in.
Revision history for this message
Celso Providelo (cprov) :
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/templates/login-discharge-macaroon.pt'
2--- lib/lp/services/webapp/templates/login-discharge-macaroon.pt 2016-05-19 02:02:39 +0000
3+++ lib/lp/services/webapp/templates/login-discharge-macaroon.pt 2016-05-27 10:02:12 +0000
4@@ -6,7 +6,23 @@
5 metal:use-macro="view/macro:page/main_only"
6 i18n:domain="launchpad">
7
8- <body onload="document.forms[0].submit();">
9+ <metal:block fill-slot="head_epilogue">
10+ <script type="text/javascript"
11+ tal:content="structure string:
12+ LPJS.use('event', function(Y) {
13+ Y.on('load', function(e) {
14+ var form = document.getElementById('discharge-form');
15+ var elements = form.elements;
16+ for (var i = 0; i < elements.length; i++) {
17+ elements[i].style.display = 'none';
18+ }
19+ form.submit();
20+ });
21+ });">
22+ </script>
23+ </metal:block>
24+
25+ <body>
26 <div class="top-portlet" metal:fill-slot="main">
27 <h1>OpenID transaction in progress</h1>
28
29@@ -15,22 +31,18 @@
30 method="post"
31 enctype="application/x-www-form-urlencoded"
32 accept-charset="UTF-8">
33- <input type="hidden"
34- tal:condition="view/params/discharge_macaroon_action"
35- tal:attributes="name view/params/discharge_macaroon_action"
36- value="1" />
37- <input type="hidden"
38- tal:attributes="name view/params/discharge_macaroon_field;
39- value view/discharge_macaroon_raw" />
40+ <div class="actions">
41+ <input type="hidden"
42+ tal:condition="view/params/discharge_macaroon_action"
43+ tal:attributes="name view/params/discharge_macaroon_action"
44+ value="1" />
45+ <input type="hidden"
46+ tal:attributes="name view/params/discharge_macaroon_field;
47+ value view/discharge_macaroon_raw" />
48+ <input type="submit" value="Continue" />
49+ </div>
50 </form>
51 </div>
52-
53- <script>
54- var elements = document.forms[0].elements;
55- for (var i = 0; i < elements.length; i++) {
56- elements[i].style.display = "none";
57- }
58- </script>
59 </body>
60
61 </html>
62
63=== modified file 'lib/lp/services/webapp/tests/test_login.py'
64--- lib/lp/services/webapp/tests/test_login.py 2016-05-19 02:02:39 +0000
65+++ lib/lp/services/webapp/tests/test_login.py 2016-05-27 10:02:12 +0000
66@@ -512,13 +512,19 @@
67 [dict(tag.attrs) for tag in discharge_form.findAll('input')],
68 MatchesListwise([
69 ContainsDict({
70+ 'type': Equals('hidden'),
71 'name': Equals('field.actions.complete'),
72 'value': Equals('1'),
73 }),
74 ContainsDict({
75+ 'type': Equals('hidden'),
76 'name': Equals('field.discharge_macaroon'),
77 'value': Equals('dummy discharge'),
78 }),
79+ ContainsDict({
80+ 'type': Equals('submit'),
81+ 'value': Equals('Continue'),
82+ }),
83 ]))
84
85 def test_discharge_macaroon_missing(self):