def test_success_with_limited_json_dump_class(self, espy_mock): """Test a successful index of a crash report""" modified_config = self.get_tuned_config(ESCrashStorage) modified_config.json_dump_whitelist_keys = [ "largest_free_vm_block", "tiny_block_size", "write_combine_size", "system_info", ] modified_config.es_redactor = DotDict() modified_config.es_redactor.redactor_class = Redactor modified_config.es_redactor.forbidden_keys = ( "memory_report, " "upload_file_minidump_flash1.json_dump, " "upload_file_minidump_flash2.json_dump, " "upload_file_minidump_browser.json_dump") modified_config.raw_crash_es_redactor = DotDict() modified_config.raw_crash_es_redactor.redactor_class = RawCrashRedactor modified_config.raw_crash_es_redactor.forbidden_keys = 'unsused' sub_mock = mock.MagicMock() espy_mock.Elasticsearch.return_value = sub_mock es_storage = ESCrashStorageRedactedJsonDump(config=modified_config) crash_id = a_processed_crash['uuid'] # Submit a crash like normal, except that the back-end ES object is # mocked (see the decorator above). es_storage.save_raw_and_processed( raw_crash=deepcopy(a_raw_crash), dumps=None, processed_crash=deepcopy(a_processed_crash), crash_id=crash_id, ) # Ensure that the ES objects were instantiated by ConnectionContext. assert espy_mock.Elasticsearch.called # Ensure that the IndicesClient was also instantiated (this happens in # IndexCreator but is part of the crashstorage workflow). assert espy_mock.client.IndicesClient.called expected_processed_crash = deepcopy( a_processed_crash_with_no_stackwalker) expected_processed_crash['json_dump'] = { k: a_processed_crash['json_dump'][k] for k in modified_config.json_dump_whitelist_keys } del expected_processed_crash['memory_report'] # The actual call to index the document (crash). document = { 'crash_id': crash_id, 'processed_crash': expected_processed_crash, 'raw_crash': a_raw_crash } additional = { 'doc_type': 'crash_reports', 'id': crash_id, 'index': 'socorro_integration_test_reports' } sub_mock.index.assert_called_with(body=document, **additional)
def test_success_with_limited_json_dump_class(self, espy_mock): """Test a successful index of a crash report""" modified_config = self.get_tuned_config(ESCrashStorage) modified_config.json_dump_allowlist_keys = [ "largest_free_vm_block", "tiny_block_size", "write_combine_size", "system_info", ] modified_config.es_redactor = DotDict() modified_config.es_redactor.redactor_class = Redactor modified_config.es_redactor.forbidden_keys = ( "memory_report, " "upload_file_minidump_flash1.json_dump, " "upload_file_minidump_flash2.json_dump, " "upload_file_minidump_browser.json_dump") modified_config.raw_crash_es_redactor = DotDict() modified_config.raw_crash_es_redactor.redactor_class = RawCrashRedactor modified_config.raw_crash_es_redactor.forbidden_keys = "unsused" processed_crash = { "build": "20120309050057", "date_processed": "2012-04-08 10:56:41.558922", "product": "FennecAndroid", "uuid": "936ce666-ff3b-4c7a-9674-367fe2120408", "json_dump": { # json dump allowed keys "largest_free_vm_block": "0x2F42", "system_info": { "cpu_count": 42, "os": "Linux" }, "tiny_block_size": 42, "write_combine_size": 43, # not allowed keys: "badkey1": "foo", "badkey2": { "badsubkey": "foo" }, }, } sub_mock = mock.MagicMock() espy_mock.Elasticsearch.return_value = sub_mock es_storage = ESCrashStorageRedactedJsonDump(config=modified_config) crash_id = processed_crash["uuid"] # Submit a crash like normal, except that the back-end ES object is # mocked (see the decorator above). es_storage.save_processed_crash( raw_crash=deepcopy(a_raw_crash), processed_crash=processed_crash, ) # Ensure that the ES objects were instantiated by ConnectionContext. assert espy_mock.Elasticsearch.called # Ensure that the IndicesClient was also instantiated (this happens in # IndexCreator but is part of the crashstorage workflow). assert espy_mock.client.IndicesClient.called expected_processed_crash = deepcopy(processed_crash) reconstitute_datetimes(expected_processed_crash) expected_processed_crash["json_dump"] = { k: a_processed_crash["json_dump"][k] for k in modified_config.json_dump_allowlist_keys } # The actual call to index the document (crash). document = { "crash_id": crash_id, "processed_crash": expected_processed_crash, "raw_crash": a_raw_crash, } additional = { "doc_type": "crash_reports", "id": crash_id, "index": "socorro_integration_test_reports", } sub_mock.index.assert_called_with(body=document, **additional)
def test_success_with_limited_json_dump_class(self, espy_mock): """Test a successful index of a crash report. """ modified_config = deepcopy(self.config) modified_config.json_dump_whitelist_keys = [ "largest_free_vm_block", "tiny_block_size", "write_combine_size", ] modified_config.es_redactor = DotDict() modified_config.es_redactor.redactor_class = Redactor modified_config.es_redactor.forbidden_keys = ( "upload_file_minidump_flash1.json_dump, " "upload_file_minidump_flash2.json_dump, " "upload_file_minidump_browser.json_dump" ) # It's mocks all the way down. sub_mock = mock.MagicMock() espy_mock.Elasticsearch.return_value = sub_mock es_storage = ESCrashStorageRedactedJsonDump(config=modified_config) crash_id = a_processed_crash['uuid'] # Submit a crash like normal, except that the back-end ES object is # mocked (see the decorator above). es_storage.save_raw_and_processed( raw_crash=a_raw_crash, dumps=None, processed_crash=a_processed_crash, crash_id=crash_id, ) # Ensure that the ES objects were instantiated by ConnectionContext. ok_(espy_mock.Elasticsearch.called) # Ensure that the IndicesClient was also instantiated (this happens in # IndexCreator but is part of the crashstorage workflow). ok_(espy_mock.client.IndicesClient.called) expected_processed_crash = deepcopy( a_processed_crash_with_no_stackwalker ) expected_processed_crash['json_dump'] = { k: a_processed_crash['json_dump'][k] for k in modified_config.json_dump_whitelist_keys } # The actual call to index the document (crash). document = { 'crash_id': crash_id, 'processed_crash': expected_processed_crash, 'raw_crash': a_raw_crash } additional = { 'doc_type': 'crash_reports', 'id': crash_id, 'index': 'socorro_integration_test_reports' } sub_mock.index.assert_called_with( body=document, **additional )