def test_bad_input(self): with self.assertRaises(InterfaceValidationError): Frame.to_python({ 'filename': 1, }) with self.assertRaises(InterfaceValidationError): Frame.to_python({ 'filename': 'foo', 'abs_path': 1, }) with self.assertRaises(InterfaceValidationError): Frame.to_python({ 'function': 1, }) with self.assertRaises(InterfaceValidationError): Frame.to_python({ 'module': 1, }) with self.assertRaises(InterfaceValidationError): Frame.to_python({ 'function': '?', })
def test_context_with_nan(self): self.assertEquals( Frame.to_python({ 'filename': 'x', 'vars': { 'x': float('inf') }, }).vars, {'x': '<inf>'}, ) self.assertEquals( Frame.to_python({ 'filename': 'x', 'vars': { 'x': float('-inf') }, }).vars, {'x': '<-inf>'}, ) self.assertEquals( Frame.to_python({ 'filename': 'x', 'vars': { 'x': float('nan') }, }).vars, {'x': '<nan>'}, )
def test_get_hash_sanitizes_versioned_filenames(self): # This is Ruby specific interface = Frame.to_python( { 'filename': '/data/foo/releases/20140114151955/app/views/foo.html.erb', 'context_line': '<% if @hotels.size > 0 %>', } ) result = interface.get_hash() self.assertEquals( result, [ '/data/foo/releases/<version>/app/views/foo.html.erb', '<% if @hotels.size > 0 %>', ] ) interface = Frame.to_python( { 'filename': '20140114151955/app/views/foo.html.erb', 'context_line': '<% if @hotels.size > 0 %>', } ) result = interface.get_hash() self.assertEquals( result, [ '<version>/app/views/foo.html.erb', '<% if @hotels.size > 0 %>', ] )
def test_get_hash_ignores_filename_if_https(self): interface = Frame.to_python({ 'context_line': 'hello world', 'filename': 'https://foo.com/foo.py', }) result = interface.get_hash() self.assertEquals(result, ['hello world'])
def test_get_hash_sanitizes_erb_templates(self): # This is Ruby specific interface = Frame.to_python( {"filename": "foo.html.erb", "function": "_foo_html_erb__3327151541118998292_70361296749460"} ) result = interface.get_hash() self.assertEquals(result, ["foo.html.erb", "_foo_html_erb__<anon>_<anon>"])
def test_get_hash_with_only_required_vars(self): interface = Frame.to_python({ 'lineno': 1, 'filename': 'foo.py', }) result = interface.get_hash() self.assertEquals(result, ['foo.py', 1])
def test_get_hash_sanitizes_versioned_filenames(self): # This is Ruby specific interface = Frame.to_python( { "filename": "/data/foo/releases/20140114151955/app/views/foo.html.erb", "context_line": "<% if @hotels.size > 0 %>", } ) result = interface.get_hash() self.assertEquals(result, ["/data/foo/releases/<version>/app/views/foo.html.erb", "<% if @hotels.size > 0 %>"]) interface = Frame.to_python( {"filename": "20140114151955/app/views/foo.html.erb", "context_line": "<% if @hotels.size > 0 %>"} ) result = interface.get_hash() self.assertEquals(result, ["<version>/app/views/foo.html.erb", "<% if @hotels.size > 0 %>"])
def test_get_hash_ignores_safari_native_code(self): interface = Frame.to_python({ 'abs_path': '[native code]', 'filename': '[native code]', 'function': 'forEach', }) result = interface.get_hash() self.assertEquals(result, [])
def test_get_hash_uses_function_over_lineno(self): interface = Frame.to_python({ 'lineno': 1, 'filename': 'foo.py', 'function': 'bar' }) result = interface.get_hash() self.assertEquals(result, ['foo.py', 'bar'])
def test_get_hash_uses_module_over_filename(self): interface = Frame.to_python({ 'lineno': 1, 'filename': 'foo.py', 'module': 'foo' }) result = interface.get_hash() self.assertEquals(result, ['foo', 1])
def test_get_hash_sanitizes_block_functions(self): # This is Ruby specific interface = Frame.to_python({ 'filename': 'foo.py', 'function': 'block in _conditional_callback_around_233', }) result = interface.get_hash() self.assertEquals(result, ['foo.py', 'block'])
def test_get_hash_ignores_filename_if_https(self): interface = Frame.to_python({ 'context_line': 'hello world', 'filename': 'https://foo.com/foo.py', 'function': 'test', }) result = interface.get_hash() self.assertEquals(result, ['hello world'])
def test_get_hash_ignores_filename_if_blob(self): interface = Frame.to_python( { 'filename': 'blob:http://example.com/7f7aaadf-a006-4217-9ed5-5fbf8585c6c0', } ) result = interface.get_hash() self.assertEquals(result, [])
def test_compute_hashes_uses_context_line_over_function(self): interface = Frame.to_python({ 'context_line': 'foo bar', 'lineno': 1, 'filename': 'foo.py', 'function': 'bar' }) result = interface.compute_hashes() self.assertEquals(result, [['foo.py', 'foo bar']])
def test_compute_hashes_ignores_filename_if_abs_path_is_http(self): interface = Frame.to_python({ 'context_line': 'hello world', 'abs_path': 'https://foo.com/foo.py', 'function': 'test', 'filename': 'foo.py', }) result = interface.compute_hashes() self.assertEquals(result, [['hello world']])
def test_compute_hashes_ignores_sun_java_generated_methods(self): interface = Frame.to_python({ 'module': 'sun.reflect.GeneratedMethodAccessor12345', 'function': 'invoke', }) result = interface.compute_hashes(platform='java') self.assertEquals(result, [[ 'sun.reflect.GeneratedMethodAccessor', 'invoke', ]])
def test_get_hash_ignores_java8_lambda_function(self): interface = Frame.to_python({ 'module': 'foo.bar.Baz', 'function': 'lambda$work$1', }) result = interface.get_hash() self.assertEquals(result, [ 'foo.bar.Baz', '<function>', ])
def test_compute_hashes_ignores_extra_ENHANCED_clojure_classes(self): interface = Frame.to_python({ 'module': 'sentry_clojure_example.core$_main$fn__1539$fn__1540', 'function': 'invoke' }) result = interface.compute_hashes(platform='java') self.assertEquals(result, [[ 'sentry_clojure_example.core$_main$fn__<auto>$fn__<auto>', 'invoke', ]])
def test_compute_hashes_ignores_java8_lambda_module(self): interface = Frame.to_python({ 'module': 'foo.bar.Baz$$Lambda$40/1673859467', 'function': 'call', }) result = interface.compute_hashes(platform='java') self.assertEquals(result, [[ '<module>', 'call', ]])
def test_get_hash_ignores_sun_java_generated_methods(self): interface = Frame.to_python({ 'module': 'sun.reflect.GeneratedMethodAccessor12345', 'function': 'invoke', }) result = interface.get_hash() self.assertEquals(result, [ 'sun.reflect.GeneratedMethodAccessor', 'invoke', ])
def test_get_hash_ignores_ENHANCED_clojure_classes(self): interface = Frame.to_python({ 'module': 'sentry_clojure_example.core$_main$fn__1539', 'function': 'invoke' }) result = interface.get_hash() self.assertEquals(result, [ 'sentry_clojure_example.core$_main$fn__<auto>', 'invoke', ])
def test_get_hash_ignores_extra_ENHANCED_clojure_classes(self): interface = Frame.to_python({ 'module': 'sentry_clojure_example.core$_main$fn__1539$fn__1540', 'function': 'invoke' }) result = interface.get_hash() self.assertEquals(result, [ 'sentry_clojure_example.core$_main$fn__<auto>$fn__<auto>', 'invoke', ])
def test_get_hash_sanitizes_erb_templates(self): # This is Ruby specific interface = Frame.to_python({ 'filename': 'foo.html.erb', 'function': '_foo_html_erb__3327151541118998292_70361296749460', }) result = interface.get_hash() self.assertEquals(result, [ 'foo.html.erb', '_foo_html_erb__<anon>_<anon>', ])
def test_get_hash_ignores_java8_lambda_module(self): interface = Frame.to_python({ 'module': 'foo.bar.Baz$$Lambda$40/1673859467', 'function': 'call', }) result = interface.get_hash() self.assertEquals(result, [ '<module>', 'call', ])
def test_get_hash_skips_symbol_if_unknown(self): interface = Frame.to_python({ 'module': 'libfoo', 'function': 'main', 'symbol': '?', }) result = interface.get_hash() self.assertEquals(result, [ 'libfoo', 'main', ])
def test_compute_hashes_ignores_sun_java_generated_constructors(self): interface = Frame.to_python({ 'module': 'sun.reflect.GeneratedSerializationConstructorAccessor1', 'function': 'invoke', }) result = interface.compute_hashes(platform='java') self.assertEquals(result, [[ 'sun.reflect.GeneratedSerializationConstructorAccessor<auto>', 'invoke', ]]) interface = Frame.to_python({ 'module': 'sun.reflect.GeneratedConstructorAccessor2', 'function': 'invoke', }) result = interface.compute_hashes(platform='java') self.assertEquals(result, [[ 'sun.reflect.GeneratedConstructorAccessor<auto>', 'invoke', ]])
def test_get_hash_uses_symbol_instead_of_function(self): interface = Frame.to_python({ 'module': 'libfoo', 'function': 'int main()', 'symbol': '_main', }) result = interface.get_hash() self.assertEquals(result, [ 'libfoo', '_main', ])
def test_compute_hashes_uses_symbol_instead_of_function(self): interface = Frame.to_python({ 'module': 'libfoo', 'function': 'int main()', 'symbol': '_main', }) result = interface.compute_hashes() self.assertEquals(result, [[ 'libfoo', '_main', ]])
def test_get_hash_sanitizes_versioned_filenames(self): # This is Ruby specific interface = Frame.to_python({ 'filename': '/data/foo/releases/20140114151955/app/views/foo.html.erb', 'context_line': '<% if @hotels.size > 0 %>', }) result = interface.get_hash() self.assertEquals(result, [ '/data/foo/releases/<version>/app/views/foo.html.erb', '<% if @hotels.size > 0 %>', ]) interface = Frame.to_python({ 'filename': '20140114151955/app/views/foo.html.erb', 'context_line': '<% if @hotels.size > 0 %>', }) result = interface.get_hash() self.assertEquals(result, [ '<version>/app/views/foo.html.erb', '<% if @hotels.size > 0 %>', ])
def test_bad_input(self): assert Frame.to_python({ 'filename': 1, }).filename is None assert Frame.to_python({ 'filename': 'foo', 'abs_path': 1, }).abs_path == 'foo' assert Frame.to_python({ 'function': 1, }).function is None assert Frame.to_python({ 'module': 1, }).module is None assert Frame.to_python({ 'function': '?', }).function is None
def test_get_hash_ignores_ENHANCED_spring_classes(self): interface = Frame.to_python({ 'module': 'invalid.gruml.talkytalkyhub.common.config.' 'JipJipConfig$$EnhancerBySpringCGLIB$$1ebdddb0', 'function': 'jipJipManagementApplication' }) result = interface.get_hash() self.assertEquals(result, [ 'invalid.gruml.talkytalkyhub.common.config.JipJipConfig' '$$EnhancerBySpringCGLIB$$<auto>', 'jipJipManagementApplication', ])
def test_address_normalization(self): interface = Frame.to_python({ 'lineno': 1, 'filename': 'blah.c', 'function': 'main', 'instruction_addr': 123456, 'symbol_addr': '123450', 'image_addr': '0x0', }) assert interface.instruction_addr == '0x1e240' assert interface.symbol_addr == '0x1e23a' assert interface.image_addr == '0x0'
def test_context_with_nan(self): self.assertEquals( Frame.to_python({ 'filename': 'x', 'vars': {'x': float('inf')}, }).vars, {'x': '<inf>'}, ) self.assertEquals( Frame.to_python({ 'filename': 'x', 'vars': {'x': float('-inf')}, }).vars, {'x': '<-inf>'}, ) self.assertEquals( Frame.to_python({ 'filename': 'x', 'vars': {'x': float('nan')}, }).vars, {'x': '<nan>'}, )
def test_get_hash_ignores_javassist(self): interface = Frame.to_python( { 'module': 'com.example.api.entry.EntriesResource_$$_javassist_seam_74', 'function': 'fn', } ) result = interface.get_hash(platform='java') self.assertEquals( result, [ 'com.example.api.entry.EntriesResource_$$_javassist<auto>', 'fn' ] ) interface = Frame.to_python( { 'module': 'com.example.api.entry.EntriesResource_$$_javassist_74', 'function': 'fn', } ) result = interface.get_hash(platform='java') self.assertEquals( result, [ 'com.example.api.entry.EntriesResource_$$_javassist<auto>', 'fn' ] ) interface = Frame.to_python( { 'filename': 'EntriesResource_$$_javassist_seam_74.java', 'function': 'fn', } ) result = interface.get_hash(platform='java') self.assertEquals( result, [ 'EntriesResource_$$_javassist<auto>.java', 'fn' ] )
def test_get_hash_ignores_module_if_page_url(self): """ When the abs_path is a URL without a file extension, and the module is a suffix of that URL, we should ignore the module. This takes care of a raven-js issue where page URLs (not source filenames) are being used as the module. """ interface = Frame.to_python({ 'filename': 'foo.py', 'abs_path': 'https://sentry.io/foo/bar/baz.js', 'module': 'foo/bar/baz', }) result = interface.get_hash(platform='javascript') assert result == ['foo/bar/baz'] interface = Frame.to_python({ 'filename': 'foo.py', 'abs_path': 'https://sentry.io/foo/bar/baz', 'module': 'foo/bar/baz', }) result = interface.get_hash(platform='javascript') assert result == ['<module>']
def test_compute_hashes_ignores_extra_ENHANCED_spring_classes(self): interface = Frame.to_python({ 'module': 'invalid.gruml.talkytalkyhub.common.config.' 'JipJipConfig$$EnhancerBySpringCGLIB$$1ebdddb0' '$$EnhancerBySpringCGLIB$$8219cd38' '$$FastClassBySpringCGLIB$$6c0b35d1', 'function': 'jipJipManagementApplication' }) result = interface.compute_hashes(platform='java') self.assertEquals(result, [[ 'invalid.gruml.talkytalkyhub.common.config.JipJipConfig' '$$EnhancerBySpringCGLIB$$<auto>$$EnhancerBySpringCGLIB$$<auto>' '$$FastClassBySpringCGLIB$$<auto>', 'jipJipManagementApplication', ]])
def test_bad_input(self): with self.assertRaises(InterfaceValidationError): Frame.to_python({ 'filename': 1, }) with self.assertRaises(InterfaceValidationError): Frame.to_python({ 'filename': 'foo', 'abs_path': 1, }) with self.assertRaises(InterfaceValidationError): Frame.to_python({ 'function': 1, }) with self.assertRaises(InterfaceValidationError): Frame.to_python({ 'module': 1, })
def format_chrome_ie_frame(self, frame): tokens = JavascriptLiteSourceProcessor.chrome_ie_stacktrace_expr.findall(frame)[0] frame = { 'filename': tokens[1], 'function': tokens[0] or '?', 'in_app': True, } try: frame['lineno'] = int(float(tokens[2])) except: pass try: frame['colno'] = int(float(tokens[3])) except: pass return Frame.to_python(frame)
def format_firefox_safari_frame(self, frame): tokens = JavascriptLiteSourceProcessor.firefox_safari_stacktrace_expr.findall(frame)[0] frame = { 'filename': tokens[2], 'function': tokens[0] or '?', 'in_app': True, } if tokens[1]: frame['args'] = tokens[1].split(',') try: frame['lineno'] = int(float(tokens[3])) except: pass try: frame['colno'] = int(float(tokens[4])) except: pass return Frame.to_python(frame)
def test_get_hash_ignores_filename_if_blob(self): interface = Frame.to_python({ 'filename': 'blob:http://example.com/7f7aaadf-a006-4217-9ed5-5fbf8585c6c0', }) result = interface.get_hash() self.assertEquals(result, [])
def test_get_hash_ignores_filename_if_abs_path_is_http(self): interface = Frame.to_python( {"context_line": "hello world", "abs_path": "https://foo.com/foo.py", "filename": "foo.py"} ) result = interface.get_hash() self.assertEquals(result, ["hello world"])
def test_get_hash_with_only_required_vars(self): interface = Frame.to_python({"lineno": 1, "filename": "foo.py"}) result = interface.get_hash() self.assertEquals(result, ["foo.py", 1])
def test_get_hash_uses_context_line_over_function(self): interface = Frame.to_python({"context_line": "foo bar", "lineno": 1, "filename": "foo.py", "function": "bar"}) result = interface.get_hash() self.assertEquals(result, ["foo.py", "foo bar"])
def test_get_hash_ignores_java8_lambda_function(self): interface = Frame.to_python({"module": "foo.bar.Baz", "function": "lambda$work$1"}) result = interface.get_hash() self.assertEquals(result, ["foo.bar.Baz", "<function>"])
def test_get_hash_uses_module_over_filename(self): interface = Frame.to_python({"lineno": 1, "filename": "foo.py", "module": "foo"}) result = interface.get_hash() self.assertEquals(result, ["foo", 1])