Merge lp:~benji/launchpad/bug-719637 into lp:launchpad

Proposed by Benji York
Status: Merged
Approved by: Benji York
Approved revision: no longer in the source branch.
Merged at revision: 13173
Proposed branch: lp:~benji/launchpad/bug-719637
Merge into: lp:launchpad
Diff against target: 51 lines (+30/-1)
2 files modified
lib/canonical/launchpad/webapp/errorlog.py (+6/-1)
lib/canonical/launchpad/webapp/tests/test_errorlog.py (+24/-0)
To merge this branch: bzr merge lp:~benji/launchpad/bug-719637
Reviewer Review Type Date Requested Status
Aaron Bentley (community) Approve
Review via email: mp+63159@code.launchpad.net

Commit message

[r=abentley][bug=719637] fix a variant of 719637 by not generating OOPSes on otherwise ignorable exceptions if there is no referer

Description of the change

Bug 719637 was mostly fixed along with bug 730393. However, a new incarnation of the bug was introduced at that time that caused NotFound (and similar errors) to OOPS if no referer is set. This happens in production (e.g., OOPS-1970CF506). This branch fixes this.

The operative change is the "if" statement added to lib/canonical/launchpad/webapp/errorlog.py.

The new tests exercise the different ways the if can be traversed.

The new tests can be run with

    bin/test -c -m canonical.launchpad.webapp.tests -t Test404Oops

The make lint report is clean.

To post a comment you must log in.
Revision history for this message
Aaron Bentley (abentley) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/canonical/launchpad/webapp/errorlog.py'
--- lib/canonical/launchpad/webapp/errorlog.py 2011-05-20 04:48:41 +0000
+++ lib/canonical/launchpad/webapp/errorlog.py 2011-06-07 21:24:40 +0000
@@ -377,7 +377,12 @@
377 return True377 return True
378 if strtype in self._ignored_exceptions_for_offsite_referer:378 if strtype in self._ignored_exceptions_for_offsite_referer:
379 if request is not None:379 if request is not None:
380 referer = request.get('HTTP_REFERER', '')380 referer = request.get('HTTP_REFERER')
381 # If there is no referrer then we can't tell if this exception
382 # should be ignored or not, so we'll be conservative and
383 # ignore it.
384 if referer is None:
385 return True
381 referer_parts = urlparse.urlparse(referer)386 referer_parts = urlparse.urlparse(referer)
382 root_parts = urlparse.urlparse(387 root_parts = urlparse.urlparse(
383 allvhosts.configs['mainsite'].rooturl)388 allvhosts.configs['mainsite'].rooturl)
384389
=== modified file 'lib/canonical/launchpad/webapp/tests/test_errorlog.py'
--- lib/canonical/launchpad/webapp/tests/test_errorlog.py 2011-05-19 21:01:54 +0000
+++ lib/canonical/launchpad/webapp/tests/test_errorlog.py 2011-06-07 21:24:40 +0000
@@ -967,5 +967,29 @@
967 self.assertIs(None, self.error_utility.getLastOopsReport())967 self.assertIs(None, self.error_utility.getLastOopsReport())
968968
969969
970class Test404Oops(testtools.TestCase):
971
972 def test_offsite_404_ignored(self):
973 # A request originating from another site that generates a NotFound
974 # (404) is ignored (i.e., no OOPS is logged).
975 utility = ErrorReportingUtility()
976 request = dict(HTTP_REFERER='example.com')
977 self.assertTrue(utility._isIgnoredException('NotFound', request))
978
979 def test_onsite_404_not_ignored(self):
980 # A request originating from a local site that generates a NotFound
981 # (404) produces an OOPS.
982 utility = ErrorReportingUtility()
983 request = dict(HTTP_REFERER='canonical.com')
984 self.assertTrue(utility._isIgnoredException('NotFound', request))
985
986 def test_404_without_referer_is_ignored(self):
987 # If a 404 is generated and there is no HTTP referer, we don't produce
988 # an OOPS.
989 utility = ErrorReportingUtility()
990 request = dict()
991 self.assertTrue(utility._isIgnoredException('NotFound', request))
992
993
970def test_suite():994def test_suite():
971 return unittest.TestLoader().loadTestsFromName(__name__)995 return unittest.TestLoader().loadTestsFromName(__name__)