def test_success_with_redacted_raw_crash(self, espy_mock): """Test a successful index of a crash report""" modified_config = deepcopy(self.config) modified_config.es_redactor = DotDict() modified_config.es_redactor.redactor_class = Redactor modified_config.es_redactor.forbidden_keys = 'unsused' 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 = ESCrashStorageRedactedSave(config=modified_config) crash_id = a_processed_crash['uuid'] # Add a 'StackTraces' field to be redacted. raw_crash = deepcopy(a_raw_crash) raw_crash['StackTraces'] = 'something' # 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(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) reconstitute_datetimes(expected_processed_crash) # The actual call to index the document (crash). document = { 'crash_id': crash_id, 'processed_crash': expected_processed_crash, 'raw_crash': a_raw_crash # Note here we expect the original dict } 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_redacted_raw_crash(self, espy_mock): """Test a successful index of a crash report""" modified_config = deepcopy(self.config) modified_config.es_redactor = DotDict() modified_config.es_redactor.redactor_class = Redactor modified_config.es_redactor.forbidden_keys = 'unsused' 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 = ESCrashStorageRedactedSave(config=modified_config) crash_id = a_processed_crash['uuid'] # Add a 'StackTraces' field to be redacted. raw_crash = deepcopy(a_raw_crash) raw_crash['StackTraces'] = 'something' # 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(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) reconstitute_datetimes(expected_processed_crash) # The actual call to index the document (crash). document = { 'crash_id': crash_id, 'processed_crash': expected_processed_crash, 'raw_crash': a_raw_crash # Note here we expect the original dict } 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(self, espy_mock): """Test a successful index of a crash report""" raw_crash = { "BuildID": "20200605000", "ProductName": "Firefox", "ReleaseChannel": "nightly", } processed_crash = { "uuid": "936ce666-ff3b-4c7a-9674-367fe2120408", "json_dump": {}, "date_processed": "2012-04-08 10:56:41.558922", } sub_mock = mock.MagicMock() espy_mock.Elasticsearch.return_value = sub_mock 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 = ESCrashStorage(config=self.config) es_storage.save_processed_crash( raw_crash=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) # The actual call to index the document (crash). document = { "crash_id": crash_id, "processed_crash": expected_processed_crash, "raw_crash": 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(self, espy_mock): """Test a successful index of a crash report""" sub_mock = mock.MagicMock() espy_mock.Elasticsearch.return_value = sub_mock 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 = ESCrashStorage(config=self.config) 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) reconstitute_datetimes(expected_processed_crash) # 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(self, espy_mock): """Test a successful index of a crash report""" sub_mock = mock.MagicMock() espy_mock.Elasticsearch.return_value = sub_mock 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 = ESCrashStorage(config=self.config) 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) reconstitute_datetimes(expected_processed_crash) # 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_redacted_raw_crash(self, espy_mock): """Test a successful index of a crash report""" modified_config = deepcopy(self.config) modified_config.es_redactor = DotDict() modified_config.es_redactor.redactor_class = Redactor modified_config.es_redactor.forbidden_keys = "unsused" 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 = ESCrashStorageRedactedSave(config=modified_config) raw_crash = { "BuildID": "20200605000", "ProductName": "Firefox", "ReleaseChannel": "nightly", # Add a 'StackTraces' field to be redacted. "StackTraces": "something", } processed_crash = { "date_processed": date_to_string(utc_now()), "uuid": "936ce666-ff3b-4c7a-9674-367fe2120408", } 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=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_raw_crash = deepcopy(raw_crash) del expected_raw_crash["StackTraces"] expected_processed_crash = deepcopy(processed_crash) reconstitute_datetimes(expected_processed_crash) # The actual call to index the document (crash). document = { "crash_id": crash_id, "processed_crash": expected_processed_crash, "raw_crash": expected_raw_crash, } additional = { "doc_type": "crash_reports", "id": crash_id, "index": self.es_context.get_index_for_date(utc_now()), } sub_mock.index.assert_called_with(body=document, **additional)