Merge lp:~thumper/launchpad/process-email-oops-on-person-adaptation into lp:launchpad

Proposed by Tim Penhey
Status: Merged
Approved by: Robert Collins
Approved revision: no longer in the source branch.
Merged at revision: 12520
Proposed branch: lp:~thumper/launchpad/process-email-oops-on-person-adaptation
Merge into: lp:launchpad
Diff against target: 76 lines (+25/-4)
3 files modified
lib/lp/services/mail/incoming.py (+8/-3)
lib/lp/services/mail/tests/test_incoming.py (+14/-0)
lib/lp/testing/factory.py (+3/-1)
To merge this branch: bzr merge lp:~thumper/launchpad/process-email-oops-on-person-adaptation
Reviewer Review Type Date Requested Status
Robert Collins (community) Approve
William Grant code* Approve
Review via email: mp+51992@code.launchpad.net

Commit message

[r=lifeless,wgrant][bug=728132] Fix OOPS generated when adapting accounts to IPerson when there is no linked person.

Description of the change

I found this while looking through the process mail log file.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) wrote :

Looks good, as long as you s/principle/principal/.

review: Approve (code*)
Revision history for this message
Robert Collins (lifeless) wrote :

@wgrant agreed.

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/mail/incoming.py'
2--- lib/lp/services/mail/incoming.py 2010-12-14 03:48:06 +0000
3+++ lib/lp/services/mail/incoming.py 2011-03-03 02:32:47 +0000
4@@ -1,4 +1,4 @@
5-# Copyright 2009-2010 Canonical Ltd. This software is licensed under the
6+# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
7 # GNU Affero General Public License version 3 (see the file LICENSE).
8
9 """Functions dealing with mails coming into Launchpad."""
10@@ -186,9 +186,14 @@
11 # Check that sender is registered in Launchpad and the email is signed.
12 if principal is None:
13 setupInteraction(authutil.unauthenticatedPrincipal())
14- return
15+ return None
16
17- person = IPerson(principal)
18+ # People with accounts but no related person will have a principal, but
19+ # the person adaptation will fail.
20+ person = IPerson(principal, None)
21+ if person is None:
22+ setupInteraction(authutil.unauthenticatedPrincipal())
23+ return None
24
25 if person.account_status != AccountStatus.ACTIVE:
26 raise InactiveAccount(
27
28=== modified file 'lib/lp/services/mail/tests/test_incoming.py'
29--- lib/lp/services/mail/tests/test_incoming.py 2010-12-01 06:15:29 +0000
30+++ lib/lp/services/mail/tests/test_incoming.py 2011-03-03 02:32:47 +0000
31@@ -6,6 +6,7 @@
32 import os
33 import unittest
34
35+from testtools.matchers import Is
36 import transaction
37 from zope.security.management import setSecurityPolicy
38
39@@ -104,6 +105,19 @@
40 authenticateEmail,
41 msg, fail_all_timestamps)
42
43+ def test_unknown_email(self):
44+ # An unknown email address returns no principal.
45+ unknown = 'random-unknown@example.com'
46+ mail = self.factory.makeSignedMessage(email_address=unknown)
47+ self.assertThat(authenticateEmail(mail), Is(None))
48+
49+ def test_accounts_without_person(self):
50+ # An account without a person should be the same as an unknown email.
51+ email = 'non-person@example.com'
52+ self.factory.makeAccount(email=email)
53+ mail = self.factory.makeSignedMessage(email_address=email)
54+ self.assertThat(authenticateEmail(mail), Is(None))
55+
56
57 def setUp(test):
58 test._old_policy = setSecurityPolicy(LaunchpadSecurityPolicy)
59
60=== modified file 'lib/lp/testing/factory.py'
61--- lib/lp/testing/factory.py 2011-03-02 17:48:28 +0000
62+++ lib/lp/testing/factory.py 2011-03-03 02:32:47 +0000
63@@ -502,10 +502,12 @@
64 pocket)
65 return ProxyFactory(location)
66
67- def makeAccount(self, displayname, email=None, password=None,
68+ def makeAccount(self, displayname=None, email=None, password=None,
69 status=AccountStatus.ACTIVE,
70 rationale=AccountCreationRationale.UNKNOWN):
71 """Create and return a new Account."""
72+ if displayname is None:
73+ displayname = self.getUniqueString('displayname')
74 account = getUtility(IAccountSet).new(
75 rationale, displayname, password=password)
76 removeSecurityProxy(account).status = status