def test_Processor2015_init(self): cm = ConfigurationManager( definition_source=Processor2015.get_required_config(), values_source_list=[{ 'rule_sets': rule_set_02_str }], ) config = cm.get_config() config.logger = Mock() p = Processor2015(config) ok_(isinstance(p.rule_system, DotDict)) eq_(len(p.rule_system), 2) ok_('ruleset01' in p.rule_system) ok_(isinstance(p.rule_system.ruleset01, TransformRuleSystem)) trs = p.rule_system.ruleset01 eq_(trs.act, trs.apply_all_rules) eq_(len(trs.rules), 2) ok_(isinstance(trs.rules[0], BitguardClassifier)) ok_(isinstance(trs.rules[1], OutOfDateClassifier)) ok_('ruleset02' in p.rule_system) ok_(isinstance(p.rule_system.ruleset02, TransformRuleSystem)) trs = p.rule_system.ruleset02 eq_(trs.act, trs.apply_until_action_succeeds) eq_(len(trs.rules), 2) ok_(isinstance(trs.rules[0], SetWindowPos)) ok_(isinstance(trs.rules[1], UpdateWindowAttributes))
def test_process_crash_existing_processed_crash(self): cm = ConfigurationManager( definition_source=Processor2015.get_required_config(), values_source_list=[{ 'rule_sets': '[]' }], ) config = cm.get_config() config.logger = Mock() config.processor_name = 'dwight' p = Processor2015(config) raw_crash = DotDict() raw_dumps = {} processed_crash = DotDict() processed_crash.processor_notes = "we've been here before; yep" processed_crash.started_datetime = '2014-01-01T00:00:00' with patch('socorro.processor.processor_2015.utc_now') as faked_utcnow: faked_utcnow.return_value = '2015-01-01T00:00:00' processed_crash = p.process_crash(raw_crash, raw_dumps, processed_crash) assert processed_crash.success assert processed_crash.started_datetime == '2015-01-01T00:00:00' assert processed_crash.startedDateTime == '2015-01-01T00:00:00' assert processed_crash.completed_datetime == '2015-01-01T00:00:00' assert processed_crash.completeddatetime == '2015-01-01T00:00:00' expected = ( "dwight; Processor2015; earlier processing: 2014-01-01T00:00:00; we've been here " "before; yep") assert processed_crash.processor_notes == expected
def test_convert_raw_crash_to_processed_crash_no_rules(self): cm = ConfigurationManager( definition_source=Processor2015.get_required_config(), values_source_list=[{ 'rule_sets': '[]' }], ) config = cm.get_config() config.logger = Mock() config.processor_name = 'dwight' p = Processor2015(config) raw_crash = DotDict() raw_dumps = {} with patch('socorro.processor.processor_2015.utc_now') as faked_utcnow: faked_utcnow.return_value = '2015-01-01T00:00:00' processed_crash = p.convert_raw_crash_to_processed_crash( raw_crash, raw_dumps) ok_(processed_crash.success) eq_(processed_crash.started_datetime, '2015-01-01T00:00:00') eq_(processed_crash.startedDateTime, '2015-01-01T00:00:00') eq_(processed_crash.completed_datetime, '2015-01-01T00:00:00') eq_(processed_crash.completeddatetime, '2015-01-01T00:00:00') eq_(processed_crash.processor_notes, 'dwight; Processor2015')
def test_Processor2015_init(self): cm = ConfigurationManager( definition_source=Processor2015.get_required_config(), values_source_list=[], ) config = cm.get_config() config.logger = Mock() Processor2015(config)
def test_rule_error(self, mock_raven): captured_exceptions = [] # a global def mock_capture_exception(exc_info): captured_exceptions.append(exc_info[1]) return 'someidentifier' client = MagicMock() def mock_Client(**config): client.config = config client.captureException.side_effect = mock_capture_exception return client mock_raven.Client.side_effect = mock_Client config = self.get_config() config.sentry = DotDict() config.sentry.dsn = '' # Test with no dsn set raw_crash = { 'uuid': '1' } processed_crash = DotDict() processor = Processor2015(config, rules=[BadRule]) processor.process_crash(raw_crash, {}, processed_crash) # Notes were added assert ( processed_crash.processor_notes == 'dwight; Processor2015; rule BadRule failed: KeyError' ) # Test with dsn set config.sentry.dsn = 'https://*****:*****@sentry.example.com/01/' processed_crash = DotDict() processor = Processor2015(config, rules=[BadRule]) processor.process_crash(raw_crash, {}, processed_crash) # Notes were added again assert ( processed_crash.processor_notes == 'dwight; Processor2015; rule BadRule failed: KeyError' ) assert isinstance(captured_exceptions[0], KeyError)
def test_convert_raw_crash_to_processed_crash_no_rules(self): cm = ConfigurationManager( definition_source=Processor2015.get_required_config(), values_source_list=[{'rule_sets': '[]'}], ) config = cm.get_config() config.logger = Mock() config.processor_name = 'dwight' p = Processor2015(config) raw_crash = DotDict() raw_dumps = {} with patch('socorro.processor.processor_2015.utc_now') as faked_utcnow: faked_utcnow.return_value = '2015-01-01T00:00:00' processed_crash = p.convert_raw_crash_to_processed_crash( raw_crash, raw_dumps ) ok_(processed_crash.success) eq_(processed_crash.started_datetime, '2015-01-01T00:00:00') eq_(processed_crash.startedDateTime, '2015-01-01T00:00:00') eq_(processed_crash.completed_datetime, '2015-01-01T00:00:00') eq_(processed_crash.completeddatetime, '2015-01-01T00:00:00') eq_(processed_crash.processor_notes, 'dwight; Processor2015')
def test_Processor2015_init(self): cm = ConfigurationManager( definition_source=Processor2015.get_required_config(), values_source_list=[{'rule_sets': rule_set_02_str}], ) config = cm.get_config() config.logger = Mock() p = Processor2015(config) ok_(isinstance(p.rule_system, DotDict)) eq_(len(p.rule_system), 2) ok_('ruleset01' in p.rule_system) print p.rule_system.ruleset01 ok_(isinstance(p.rule_system.ruleset01, TransformRuleSystem)) trs = p.rule_system.ruleset01 eq_(trs.act, trs.apply_all_rules) eq_(len(trs.rules), 2) ok_(isinstance(trs.rules[0], BitguardClassifier)) ok_(isinstance(trs.rules[1], OutOfDateClassifier)) ok_('ruleset02' in p.rule_system) ok_(isinstance(p.rule_system.ruleset02, TransformRuleSystem)) trs = p.rule_system.ruleset02 eq_(trs.act, trs.apply_until_action_succeeds) eq_(len(trs.rules), 2) ok_(isinstance(trs.rules[0], SetWindowPos)) ok_(isinstance(trs.rules[1], UpdateWindowAttributes))
def test_process_crash_existing_processed_crash(self): raw_crash = DotDict({'uuid': '1'}) raw_dumps = {} processed_crash = DotDict({ 'processor_notes': 'we\'ve been here before; yep', 'started_datetime': '2014-01-01T00:00:00' }) p = Processor2015(self.get_config(), rules=[ CPUInfoRule, OSInfoRule, ]) with patch('socorro.processor.processor_2015.utc_now') as faked_utcnow: faked_utcnow.return_value = '2015-01-01T00:00:00' processed_crash = p.process_crash(raw_crash, raw_dumps, processed_crash) assert processed_crash.success assert processed_crash.started_datetime == '2015-01-01T00:00:00' assert processed_crash.startedDateTime == '2015-01-01T00:00:00' assert processed_crash.completed_datetime == '2015-01-01T00:00:00' assert processed_crash.completeddatetime == '2015-01-01T00:00:00' expected = ( "dwight; Processor2015; earlier processing: 2014-01-01T00:00:00;" " we've been here before; yep") assert processed_crash.processor_notes == expected
def test_rule_error_sentry_enabled(self, is_enabled, mock_get_hub): config = self.get_config() captured_exceptions = [] # a global def mock_capture_exception(error): captured_exceptions.append(error[1]) return 'someidentifier' hub = MagicMock() def mock_Hub(): hub.capture_exception.side_effect = mock_capture_exception return hub mock_get_hub.side_effect = mock_Hub # Test with Sentry enabled (dsn set) raw_crash = {'uuid': '1'} processed_crash = DotDict() processor = Processor2015(config, rules=[BadRule]) processor.process_crash(raw_crash, {}, processed_crash) # Notes were added again assert (processed_crash.processor_notes == 'dwight; Processor2015; rule BadRule failed: KeyError') assert isinstance(captured_exceptions[0], KeyError)
def test_process_crash_existing_processed_crash(self): cm = ConfigurationManager( definition_source=Processor2015.get_required_config(), values_source_list=[{'rule_sets': '[]'}], ) config = cm.get_config() config.logger = Mock() config.processor_name = 'dwight' p = Processor2015(config) raw_crash = DotDict() raw_dumps = {} processed_crash = DotDict() processed_crash.processor_notes = "we've been here before; yep" processed_crash.started_datetime = '2014-01-01T00:00:00' with patch('socorro.processor.processor_2015.utc_now') as faked_utcnow: faked_utcnow.return_value = '2015-01-01T00:00:00' processed_crash = p.process_crash( raw_crash, raw_dumps, processed_crash ) ok_(processed_crash.success) eq_(processed_crash.started_datetime, '2015-01-01T00:00:00') eq_(processed_crash.startedDateTime, '2015-01-01T00:00:00') eq_(processed_crash.completed_datetime, '2015-01-01T00:00:00') eq_(processed_crash.completeddatetime, '2015-01-01T00:00:00') eq_( processed_crash.processor_notes, "dwight; Processor2015; earlier processing: 2014-01-01T00:00:00; " "we've been here before; yep" )
def get_config(self): cm = ConfigurationManager( definition_source=Processor2015.get_required_config(), values_source_list=[], ) config = cm.get_config() config.database_class = Mock() config.sentry = Mock() config.processor_name = 'dwight' return config
def test_Processor2015_init(self): cm = ConfigurationManager( definition_source=Processor2015.get_required_config(), values_source_list=[{ 'rule_sets': rule_set_01_str }], ) config = cm.get_config() config.logger = Mock() p = Processor2015(config) assert isinstance(p.rule_system, DotDict) assert len(p.rule_system) == 1 assert 'ruleset01' in p.rule_system assert isinstance(p.rule_system.ruleset01, TransformRuleSystem) trs = p.rule_system.ruleset01 assert trs.act == trs.apply_all_rules assert len(trs.rules) == 2 assert isinstance(trs.rules[0], CPUInfoRule) assert isinstance(trs.rules[1], OSInfoRule)
def test_rule_error_sentry_disabled(self, is_enabled, mock_get_hub): config = self.get_config() # Test with Sentry disabled (no dsn set) raw_crash = {'uuid': '1'} processed_crash = DotDict() processor = Processor2015(config, rules=[BadRule]) processor.process_crash(raw_crash, {}, processed_crash) # Notes were added assert (processed_crash.processor_notes == 'dwight; Processor2015; rule BadRule failed: KeyError') mock_get_hub.assert_not_called()
def test_process_over_255_chars(self, mocked_subprocess_module): thread_over_255_chars = { "frames": [ { "file": "nsTerminator.cpp:604367e1fa5e", "frame": 0, "function": ("mozilla::`anonymous namespace::" "RunWatchdog(void *)" + "a" * 255), "function_offset": "0x0", "line": 151, "module": "xul.dll", "module_offset": "0x783f2b", "offset": "0x67903f2b", "registers": { "eax": "0x0000003f", "ebp": "0x163ff96c", "ebx": "0x0cf44450", "ecx": "0x691e3698", "edi": "0x76d3f551", "edx": "0x01dc1010", "efl": "0x00000246", "eip": "0x67903f2b", "esi": "0x0000003f", "esp": "0x163ff968" }, "trust": "context" } ] } stackwalker_output_str = ujson.dumps({ "crash_info": { "address": "0x0", "crashing_thread": 0, "type": "EXC_BAD_ACCESS / KERN_INVALID_ADDRESS" }, "status": "OK", "crashing_thread": thread_over_255_chars, "threads": [thread_over_255_chars], "system_info": { "os": "Windows NT", "cpu_arch": "x86" }, "sensitive": { "exploitability": "high" }, }) cm = ConfigurationManager( definition_source=( Processor2015.get_required_config(), ), values_source_list=[] ) config = cm.get_config() config.logger = Mock() config.processor_name = 'dwight' mocked_subprocess_handle = ( mocked_subprocess_module.Popen.return_value ) mocked_subprocess_handle.wait.return_value = 0 mocked_subprocess_handle.stdout.read.return_value = ( stackwalker_output_str ) p = Processor2015(config) raw_crash = DotDict({ "uuid": "00000000-0000-0000-0000-000002140504", "CrashTime": "1336519554", "SecondsSinceLastCrash": "86985", "PluginHang": "1", "ProductName": "Firefox", "Version": "19", "BuildID": "20121031" }) raw_dumps = {"upload_file_minidump": "a_fake_dump.dump"} processed_crash = p.process_crash( raw_crash, raw_dumps, DotDict() ) assert processed_crash.success expected = ( 'dwight; Processor2015; SigTrunc: signature truncated due to length' ) assert processed_crash.processor_notes == expected assert processed_crash.signature.startswith('shutdownhang') assert len(processed_crash.signature) == 255