Merge lp:~abentley/launchpad/invalid-sig into lp:launchpad

Proposed by Aaron Bentley
Status: Merged
Approved by: Gavin Panella
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~abentley/launchpad/invalid-sig
Merge into: lp:launchpad
Diff against target: None lines
To merge this branch: bzr merge lp:~abentley/launchpad/invalid-sig
Reviewer Review Type Date Requested Status
Gavin Panella (community) Approve
Review via email: mp+9667@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Aaron Bentley (abentley) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

= Summary =
Stop handling InvalidSignature as an OOPS, instead handle as user error.

== Proposed fix ==
Implement a new _handle_user_error method, and use it.

== Pre-implementation notes ==
None

== Implementation details ==
Until now, handleIncoming has only had doctests, not unittests.

== Tests ==
bin/test test_incoming -t test_invalid_signature

== Demo and Q/A ==
Send a message with an invalid signature. The resulting error message
should explain what the problem was.

= Launchpad lint =

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

Linting changed files:
  lib/canonical/launchpad/mail/incoming.py
  lib/canonical/launchpad/mail/tests/test_incoming.py
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkp4np4ACgkQ0F+nu1YWqI3JLwCfQvI5Hd/gM/FTz7a7I5yHrDFn
J54AmgLOpZ1v+7r+HQ6ZBQuVRMFktEpJ
=pIUT
-----END PGP SIGNATURE-----

Revision history for this message
Gavin Panella (allenap) wrote :
Download full text (3.9 KiB)

Hi Aaron,

It's a shame the error message isn't even more informative, but I
guess this is outside of your responsibility here, and this branch is
a great improvement over the current situation as it is.

One minor/trivial comment.

Gavin.

> === modified file 'lib/canonical/launchpad/mail/incoming.py'
> --- lib/canonical/launchpad/mail/incoming.py 2009-06-25 05:30:52 +0000
> +++ lib/canonical/launchpad/mail/incoming.py 2009-08-04 20:43:38 +0000
> @@ -177,6 +177,12 @@
> msg)
> trans.commit()
>
> + def _handle_user_error(error, mail):
> + mailbox.delete(mail_id)
> + send_process_error_notification(
> + mail['From'], 'Submit Request Failure', str(error), mail)
> + trans.commit()
> +
> log = getLogger('process-mail')
> mailbox = getUtility(IMailBox)
> log.info("Opening the mail box.")
> @@ -250,10 +256,7 @@
> try:
> principal = authenticateEmail(mail)
> except InvalidSignature, error:
> - _handle_error(
> - "Invalid signature for %s:\n %s" % (mail['From'],
> - str(error)),
> - file_alias_url)
> + _handle_user_error(error, mail)
> continue
> except InactiveAccount:
> _handle_error(
>
> === modified file 'lib/canonical/launchpad/mail/tests/test_incoming.py'
> --- lib/canonical/launchpad/mail/tests/test_incoming.py 2009-06-25 05:30:52 +0000
> +++ lib/canonical/launchpad/mail/tests/test_incoming.py 2009-08-04 20:43:38 +0000
> @@ -5,9 +5,55 @@
>
> from zope.testing.doctest import DocTestSuite
>
> +from canonical.launchpad.mail.incoming import handleMail, MailErrorUtility
> +from canonical.testing import LaunchpadZopelessLayer
> +from lp.testing import TestCaseWithFactory
> +from lp.testing.mail_helpers import pop_notifications
> +from lp.services.mail.sendmail import MailController
> +
> +
> +class TestIncoming(TestCaseWithFactory):
> +
> + layer = LaunchpadZopelessLayer
> +
> + def test_invalid_signature(self):
> + """Invalid signature should not be handled as an OOPs.
> +
> + It should produce a message explaining to the user what went wrong.
> + """
> + person = self.factory.makePerson()
> + email_address = person.preferredemail.email
> + invalid_body = (
> + '-----BEGIN PGP SIGNED MESSAGE-----\n'
> + 'Hash: SHA1\n\n'
> + 'Body\n'
> + '-----BEGIN PGP SIGNATURE-----\n'
> + 'Not a signature.\n'
> + '-----END PGP SIGNATURE-----\n')
> + ctrl = MailController(
> + email_address, '<email address hidden>', 'subject', invalid_body,
> + bulk=False)
> + ctrl.send()
> + error_utility = MailErrorUtility()
> + old_oops = error_utility.getLastOopsReport()
> + handleMail()
> + current_oops = error_utility.getLastOopsReport()
> + if old_oops is None:
> + self.assertIs(None, current_oops)
> + else:
> + self.assertEqual(old_oops...

Read more...

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/canonical/launchpad/mail/incoming.py'
2--- lib/canonical/launchpad/mail/incoming.py 2009-06-25 05:30:52 +0000
3+++ lib/canonical/launchpad/mail/incoming.py 2009-08-04 20:43:38 +0000
4@@ -177,6 +177,12 @@
5 msg)
6 trans.commit()
7
8+ def _handle_user_error(error, mail):
9+ mailbox.delete(mail_id)
10+ send_process_error_notification(
11+ mail['From'], 'Submit Request Failure', str(error), mail)
12+ trans.commit()
13+
14 log = getLogger('process-mail')
15 mailbox = getUtility(IMailBox)
16 log.info("Opening the mail box.")
17@@ -250,10 +256,7 @@
18 try:
19 principal = authenticateEmail(mail)
20 except InvalidSignature, error:
21- _handle_error(
22- "Invalid signature for %s:\n %s" % (mail['From'],
23- str(error)),
24- file_alias_url)
25+ _handle_user_error(error, mail)
26 continue
27 except InactiveAccount:
28 _handle_error(
29
30=== modified file 'lib/canonical/launchpad/mail/tests/test_incoming.py'
31--- lib/canonical/launchpad/mail/tests/test_incoming.py 2009-06-25 05:30:52 +0000
32+++ lib/canonical/launchpad/mail/tests/test_incoming.py 2009-08-04 20:43:38 +0000
33@@ -5,9 +5,55 @@
34
35 from zope.testing.doctest import DocTestSuite
36
37+from canonical.launchpad.mail.incoming import handleMail, MailErrorUtility
38+from canonical.testing import LaunchpadZopelessLayer
39+from lp.testing import TestCaseWithFactory
40+from lp.testing.mail_helpers import pop_notifications
41+from lp.services.mail.sendmail import MailController
42+
43+
44+class TestIncoming(TestCaseWithFactory):
45+
46+ layer = LaunchpadZopelessLayer
47+
48+ def test_invalid_signature(self):
49+ """Invalid signature should not be handled as an OOPs.
50+
51+ It should produce a message explaining to the user what went wrong.
52+ """
53+ person = self.factory.makePerson()
54+ email_address = person.preferredemail.email
55+ invalid_body = (
56+ '-----BEGIN PGP SIGNED MESSAGE-----\n'
57+ 'Hash: SHA1\n\n'
58+ 'Body\n'
59+ '-----BEGIN PGP SIGNATURE-----\n'
60+ 'Not a signature.\n'
61+ '-----END PGP SIGNATURE-----\n')
62+ ctrl = MailController(
63+ email_address, 'to@example.com', 'subject', invalid_body,
64+ bulk=False)
65+ ctrl.send()
66+ error_utility = MailErrorUtility()
67+ old_oops = error_utility.getLastOopsReport()
68+ handleMail()
69+ current_oops = error_utility.getLastOopsReport()
70+ if old_oops is None:
71+ self.assertIs(None, current_oops)
72+ else:
73+ self.assertEqual(old_oops.id, current_oops.id)
74+ (notification,) = pop_notifications()
75+ body = notification.get_payload()[0].get_payload(decode=True)
76+ self.assertIn(
77+ "An error occurred while processing a mail you sent to "
78+ "Launchpad's email\ninterface.\n\n\n"
79+ "Error message:\n\nSignature couldn't be verified: No data",
80+ body)
81+
82
83 def test_suite():
84 suite = unittest.TestSuite()
85+ suite.addTest(unittest.TestLoader().loadTestsFromName(__name__))
86 suite.addTest(DocTestSuite('canonical.launchpad.mail.incoming'))
87 return suite
88