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
1=== modified file 'lib/canonical/launchpad/webapp/errorlog.py'
2--- lib/canonical/launchpad/webapp/errorlog.py 2011-05-20 04:48:41 +0000
3+++ lib/canonical/launchpad/webapp/errorlog.py 2011-06-07 21:24:40 +0000
4@@ -377,7 +377,12 @@
5 return True
6 if strtype in self._ignored_exceptions_for_offsite_referer:
7 if request is not None:
8- referer = request.get('HTTP_REFERER', '')
9+ referer = request.get('HTTP_REFERER')
10+ # If there is no referrer then we can't tell if this exception
11+ # should be ignored or not, so we'll be conservative and
12+ # ignore it.
13+ if referer is None:
14+ return True
15 referer_parts = urlparse.urlparse(referer)
16 root_parts = urlparse.urlparse(
17 allvhosts.configs['mainsite'].rooturl)
18
19=== modified file 'lib/canonical/launchpad/webapp/tests/test_errorlog.py'
20--- lib/canonical/launchpad/webapp/tests/test_errorlog.py 2011-05-19 21:01:54 +0000
21+++ lib/canonical/launchpad/webapp/tests/test_errorlog.py 2011-06-07 21:24:40 +0000
22@@ -967,5 +967,29 @@
23 self.assertIs(None, self.error_utility.getLastOopsReport())
24
25
26+class Test404Oops(testtools.TestCase):
27+
28+ def test_offsite_404_ignored(self):
29+ # A request originating from another site that generates a NotFound
30+ # (404) is ignored (i.e., no OOPS is logged).
31+ utility = ErrorReportingUtility()
32+ request = dict(HTTP_REFERER='example.com')
33+ self.assertTrue(utility._isIgnoredException('NotFound', request))
34+
35+ def test_onsite_404_not_ignored(self):
36+ # A request originating from a local site that generates a NotFound
37+ # (404) produces an OOPS.
38+ utility = ErrorReportingUtility()
39+ request = dict(HTTP_REFERER='canonical.com')
40+ self.assertTrue(utility._isIgnoredException('NotFound', request))
41+
42+ def test_404_without_referer_is_ignored(self):
43+ # If a 404 is generated and there is no HTTP referer, we don't produce
44+ # an OOPS.
45+ utility = ErrorReportingUtility()
46+ request = dict()
47+ self.assertTrue(utility._isIgnoredException('NotFound', request))
48+
49+
50 def test_suite():
51 return unittest.TestLoader().loadTestsFromName(__name__)