Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes bug that caused some payload fields to become invalid #77

Merged
merged 1 commit into from
Oct 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions rollbar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,6 @@ def _report_message(message, level, request, extra_data, payload_data):
}

if extra_data:
#extra_data = _scrub_obj(extra_data)
extra_data = extra_data
data['body']['message'].update(extra_data)

Expand Down Expand Up @@ -1037,7 +1036,6 @@ def _build_werkzeug_request_data(request):

try:
if request.json:
#request_data['body'] = json.dumps(_scrub_obj(request.json))
request_data['body'] = request.json
except Exception:
pass
Expand Down Expand Up @@ -1124,18 +1122,24 @@ def _build_server_data():
return server_data


def _transform(obj):
return transforms.transform(obj, *_transforms)
def _transform(obj, key=None):
return transforms.transform(obj, _transforms, key=key)


def _build_payload(data):
"""
Returns the full payload as a string.
"""

data['body'] = _transform(data['body'], key=('body',))
data['server'] = _transform(data['server'], key=('server',))

if 'request' in data:
data['request'] = _transform(data['request'], key=('request',))

payload = {
'access_token': SETTINGS['access_token'],
'data': _transform(data)
'data': data
}

return json.dumps(payload)
Expand Down
5 changes: 3 additions & 2 deletions rollbar/lib/transforms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ def transform_custom(self, o, key=None):



def transform(obj, *transforms):
def transform(obj, transforms, key=None):
key = key or ()

def do_transforms(type_name, val, key=None, **kw):
for transform in transforms:
Expand Down Expand Up @@ -103,7 +104,7 @@ def default_handler(o, key=None):
'allowed_circular_reference_types': _ALLOWED_CIRCULAR_REFERENCE_TYPES
}

return traverse.traverse(obj, **handlers)
return traverse.traverse(obj, key=key, **handlers)


__all__ = ['transform', 'Transform']
4 changes: 2 additions & 2 deletions rollbar/test/test_scrub_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class ScrubTransformTest(BaseTest):
def _assertScrubbed(self, suffixes, start, expected, redact_char='*', skip_id_check=False):
scrubber = ScrubTransform(suffixes=suffixes, redact_char=redact_char, randomize_len=False)
result = transforms.transform(start, scrubber)
result = transforms.transform(start, [scrubber])

"""
print start
Expand Down Expand Up @@ -145,7 +145,7 @@ def test_circular(self):
ref['circular'] = obj

scrubber = ScrubTransform([])
result = transforms.transform(obj, scrubber)
result = transforms.transform(obj, [scrubber])

self.assertIsNot(result, obj)
self.assertIsNot(result['password'], ref)
Expand Down
6 changes: 3 additions & 3 deletions rollbar/test/test_scruburl_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def _assertScrubbed(self,
scrub_password=scrub_password,
redact_char=redact_char,
randomize_len=False)
result = transforms.transform(start, scrubber)
result = transforms.transform(start, [scrubber])

"""
print(start)
Expand Down Expand Up @@ -124,7 +124,7 @@ def test_scrub_dict_val_isnt_string(self):
}

scrubber = ScrubUrlTransform(suffixes=[('url',)], params_to_scrub=['password'], randomize_len=False)
result = transforms.transform(obj, scrubber)
result = transforms.transform(obj, [scrubber])

expected = copy.deepcopy(obj)
self.assertDictEqual(expected, result)
Expand All @@ -139,7 +139,7 @@ def test_scrub_dict_nested_key_match_with_circular_ref(self):
}

scrubber = ScrubUrlTransform(suffixes=[('url',), ('link',)], params_to_scrub=['password'], randomize_len=False)
result = transforms.transform(obj, scrubber)
result = transforms.transform(obj, [scrubber])

self.assertNotIn('secr3t', result['url'][0]['link'])
self.assertNotIn('secret', result['url'][0]['link'])
Expand Down
10 changes: 5 additions & 5 deletions rollbar/test/test_serializable_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
class SerializableTransformTest(BaseTest):
def _assertSerialized(self, start, expected, whitelist=None, skip_id_check=False):
serializable = SerializableTransform(whitelist_types=whitelist)
result = transforms.transform(start, serializable)
result = transforms.transform(start, [serializable])

"""
#print start
Expand Down Expand Up @@ -88,15 +88,15 @@ def test_encode_NaN(self):
start = float('nan')

serializable = SerializableTransform()
result = transforms.transform(start, serializable)
result = transforms.transform(start, [serializable])

self.assertTrue(math.isnan(result))

def test_encode_Infinity(self):
start = float('inf')

serializable = SerializableTransform()
result = transforms.transform(start, serializable)
result = transforms.transform(start, [serializable])

self.assertTrue(math.isinf(result))

Expand Down Expand Up @@ -184,7 +184,7 @@ def __repr__(self):
start = {'hello': 'world', 'custom': CustomRepr()}

serializable = SerializableTransform(whitelist_types=[CustomRepr])
result = transforms.transform(start, serializable)
result = transforms.transform(start, [serializable])

if python_major_version() < 3:
self.assertEqual(result['custom'], b'hello')
Expand All @@ -199,7 +199,7 @@ def __repr__(self):
start = {'hello': 'world', 'custom': CustomRepr()}

serializable = SerializableTransform(whitelist_types=[CustomRepr])
result = transforms.transform(start, serializable)
result = transforms.transform(start, [serializable])
self.assertRegex(result['custom'], "<class '.*CustomRepr'>")

def test_encode_with_custom_repr_returns_unicode(self):
Expand Down