Merge lp:~oops-tools-dev/wsgi-oops/sanitize_690604 into lp:wsgi-oops

Proposed by Danny Tamez
Status: Merged
Merged at revision: 54
Proposed branch: lp:~oops-tools-dev/wsgi-oops/sanitize_690604
Merge into: lp:wsgi-oops
Diff against target: 121 lines (+57/-4)
2 files modified
canonical/oops/tests/test_wsgi.py (+49/-0)
canonical/oops/wsgi.py (+8/-4)
To merge this branch: bzr merge lp:~oops-tools-dev/wsgi-oops/sanitize_690604
Reviewer Review Type Date Requested Status
Tim Cole (community) Approve
Review via email: mp+45434@code.launchpad.net

Description of the change

Added optional keyword so meta information can be excluded from the oops report.
Fixed condition involving env var dump-oops and oops.wanted that was preventing oops reports from being generated.

To post a comment you must log in.
Revision history for this message
Tim Cole (tcole) wrote :

Looks reasonable.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'canonical/oops/tests/test_wsgi.py'
2--- canonical/oops/tests/test_wsgi.py 2010-12-21 03:13:00 +0000
3+++ canonical/oops/tests/test_wsgi.py 2011-01-06 19:50:08 +0000
4@@ -15,6 +15,7 @@
5 # along with wsgi-oops. If not, see <http://www.gnu.org/licenses/>.
6
7 """ test for canonical.oops.wsgi """
8+import os
9 import unittest
10
11 from canonical.oops.tests import testcase
12@@ -42,6 +43,54 @@
13 self.assertNotEquals(None, self.oops.id)
14 self.assertFalse(self.oops.wanted)
15
16+ def test_hide_meta_false(self):
17+ """hide_meta is False by default so our query string param will be
18+ captured"""
19+ res = self.testapp.get('?error=forced_error',
20+ status=500,
21+ expect_errors=True)
22+ self.assertNotEquals(None, self.oops.id)
23+ self.assertTrue(self.oops.wanted)
24+ self.assertTrue('metadata' in self.oops.get_dump_data().keys())
25+ meta = self.oops.get_dump_data()['metadata']
26+ self.assertEquals('error=forced_error', meta['QUERY_STRING'])
27+
28+ def test_hide_meta_true(self):
29+ """with hide_meta set to True our query string param will not be
30+ captured"""
31+ self.testapp.app.hide_meta = True
32+ res = self.testapp.get('?error=forced_error',
33+ status=500,
34+ expect_errors=True)
35+ self.assertNotEquals(None, self.oops.id)
36+ self.assertTrue(self.oops.wanted)
37+ self.assertFalse('metadata' in self.oops.get_dump_data().keys())
38+
39+ def test_dump_oops_and_want_oops(self):
40+ """An oops serialization should occur for either dump_oops or want_oops
41+ variables being set"""
42+ # no dump but wanted +1
43+ res = self.testapp.get('?error=forced_error',
44+ status=500,
45+ expect_errors=True)
46+ inner_dir = os.listdir(self.tmp_dir)[0]
47+ reports = os.listdir(os.path.join(self.tmp_dir, inner_dir))
48+ self.assertEqual(1, len(reports))
49+
50+ # dump but not wanted +1
51+ res = self.testapp.get('?ok=all_ok',
52+ status=200,
53+ expect_errors=False,
54+ extra_environ={'dump-oops' : 'whatever'})
55+ reports = os.listdir(os.path.join(self.tmp_dir, inner_dir))
56+ self.assertEqual(2, len(reports))
57+
58+ # neither dump nor wanted +0
59+ res = self.testapp.get('?ok=all_ok',
60+ status=200,
61+ expect_errors=False)
62+ reports = os.listdir(os.path.join(self.tmp_dir, inner_dir))
63+ self.assertEqual(2, len(reports))
64
65 def track_completion(body, on_completion):
66 """Prove that we've been called by adding to the body."""
67
68=== modified file 'canonical/oops/wsgi.py'
69--- canonical/oops/wsgi.py 2010-12-21 00:51:42 +0000
70+++ canonical/oops/wsgi.py 2011-01-06 19:50:08 +0000
71@@ -73,11 +73,12 @@
72 def __init__(self, app, oops_dir,
73 serializer_factory_name=DEFAULT_SERIALIZER_FACTORY,
74 completion_tracker_name=DEFAULT_COMPLETION_TRACKER,
75- debug=False, key="appserver"):
76+ debug=False, key="appserver", hide_meta=False):
77 """
78 Initialise the middleware for oops.
79 """
80 self.app = app
81+ self.hide_meta = hide_meta
82 # Add the oops to the storm tracing
83 remove_tracer_type(OOPSStormTracer)
84 install_tracer(OOPSStormTracer())
85@@ -106,7 +107,8 @@
86 oops.add(OOPSLog(thread_local=True))
87
88 metadata = OOPSMetaData(environ)
89- oops.add(metadata)
90+ if not self.hide_meta:
91+ oops.add(metadata)
92
93 environ['OOPSID'] = oops.assign_id()
94
95@@ -114,7 +116,7 @@
96 """
97 Wrapper for start_response which traps the response code and
98 related exception, if any.
99- """
100+ """
101 status_code = status[0:3]
102
103 metadata["http-code"] = status_code
104@@ -146,6 +148,7 @@
105
106 def on_completion(ex_type, ex_value, ex_tb):
107 """Handle request completion."""
108+ exc_info = None
109 if ex_type is not None:
110 oops.keep()
111 message = "Unhandled WSGI application exception " \
112@@ -154,7 +157,8 @@
113 root_logger.error(message, exc_info=exc_info)
114
115 metadata["request-end"] = time.time()
116- if environ.has_key('dump-oops') and not oops.wanted:
117+
118+ if environ.has_key('dump-oops') or oops.wanted:
119 try:
120 self.serial.dump(oops)
121 except:

Subscribers

People subscribed via source and target branches