Merge lp:~bac/launchpad/bug-520476 into lp:launchpad

Proposed by Brad Crittenden
Status: Merged
Approved by: Curtis Hovey
Approved revision: no longer in the source branch.
Merged at revision: 10904
Proposed branch: lp:~bac/launchpad/bug-520476
Merge into: lp:launchpad
Diff against target: 69 lines (+20/-12)
2 files modified
lib/lp/registry/browser/person.py (+9/-5)
lib/lp/registry/browser/tests/gpg-views.txt (+11/-7)
To merge this branch: bzr merge lp:~bac/launchpad/bug-520476
Reviewer Review Type Date Requested Status
Curtis Hovey (community) code Approve
Review via email: mp+25713@code.launchpad.net

Commit message

Throw and UnexpectedFormData exception when +editpgpkeys has no action.

Description of the change

= Summary =

Somehow (dumb browser, network fart, who knows?) the +editpgpkeys form
has been submitted with the form action set to None, which causes the
call to getattr to fail. Add defensive programming to not allow that to
happen and produce a better failure.

== Proposed fix ==

Remove the test for non-None before throwing UnexpectedFormData.

== Pre-implementation notes ==

Talk with Curtis.

== Implementation details ==

As above.

== Tests ==

bin/test -vvt gpg-views.txt

== Demo and Q/A ==

= Launchpad lint =

Checking for conflicts. and issues in doctests and templates.
Running jslint, xmllint, pyflakes, and pylint.
Using normal rules.

Linting changed files:
  lib/lp/registry/browser/tests/gpg-views.txt
  lib/lp/registry/browser/person.py

== Pylint notices ==

lib/lp/registry/browser/person.py
    1944: [C0301] Line too long (83/78)

Pre-existing lint problem. Will fix before submitting.

To post a comment you must log in.
Revision history for this message
Curtis Hovey (sinzui) wrote :

Thanks for doing this. As we discussed, the root cause was probably on the client, which is still an oops, but one that the client needs to address, not us.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/registry/browser/person.py'
2--- lib/lp/registry/browser/person.py 2010-05-19 17:03:40 +0000
3+++ lib/lp/registry/browser/person.py 2010-05-20 19:00:56 +0000
4@@ -1941,7 +1941,7 @@
5 extra_params=critical_bugs_params)
6
7 def getHighBugsURL(self, distributionsourcepackage):
8- """Return the URL for high importance bugs on distributionsourcepackage."""
9+ """Return URL for high importance bugs on distributionsourcepackage."""
10 high_bugs_params = {
11 'field.status': [], 'field.importance': "High"}
12
13@@ -3658,13 +3658,17 @@
14 IGPGHandler).getURLForKeyInServer(self.fingerprint, public=True)
15
16 def form_action(self):
17- permitted_actions = ['claim_gpg', 'deactivate_gpg',
18- 'remove_gpgtoken', 'reactivate_gpg']
19+ permitted_actions = [
20+ 'claim_gpg',
21+ 'deactivate_gpg',
22+ 'remove_gpgtoken',
23+ 'reactivate_gpg',
24+ ]
25 if self.request.method != "POST":
26 return ''
27 action = self.request.form.get('action')
28- if action and (action not in permitted_actions):
29- raise UnexpectedFormData("Action was not defined")
30+ if action not in permitted_actions:
31+ raise UnexpectedFormData("Action not permitted: %s" % action)
32 getattr(self, action)()
33
34 def claim_gpg(self):
35
36=== modified file 'lib/lp/registry/browser/tests/gpg-views.txt'
37--- lib/lp/registry/browser/tests/gpg-views.txt 2010-03-11 16:09:29 +0000
38+++ lib/lp/registry/browser/tests/gpg-views.txt 2010-05-20 19:00:56 +0000
39@@ -28,10 +28,10 @@
40 >>> revoked = "84D2 05F0 3E1E 6709 6CB5 4E26 2BE8 3793 AACC D97C"
41 >>> expired = "ECA5 B797 586F 2E27 381A 16CF DE6C 9167 046C 6D63"
42
43- >>> def post_fingerprint(fingerprint):
44+ >>> def post_fingerprint(fingerprint, action='claim_gpg'):
45 ... request = LaunchpadTestRequest(form={
46 ... 'fingerprint': fingerprint,
47- ... 'action': 'claim_gpg',
48+ ... 'action': action,
49 ... 'import': 'Import Key'})
50 ... request.method = "POST"
51 ... view = getMultiAdapter((sample_user, request), name="+editpgpkeys")
52@@ -128,8 +128,12 @@
53 >>> view.context.pending_gpg_keys
54 []
55
56-
57-And knock the server out, finally:
58-
59- >>> z.tearDown()
60-
61+In some unknown way, the action sent to the form can be None (see bug 520476).
62+
63+ >>> view = post_fingerprint(good_fingerprint, action=None)
64+ Traceback (most recent call last):
65+ ...
66+ UnexpectedFormData: Action not permitted: None
67+
68+Tear down the key server.
69+ >>> z.tearDown()