From b4f391c63a5a7126a377556e295c156e21922612 Mon Sep 17 00:00:00 2001 From: Yurii Klymenko Date: Wed, 17 May 2023 11:26:31 -0400 Subject: [PATCH 1/4] add certificate_fail error code --- stix_shifter_utils/utils/error_response.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/stix_shifter_utils/utils/error_response.py b/stix_shifter_utils/utils/error_response.py index 89132a1a4..00ad7f643 100644 --- a/stix_shifter_utils/utils/error_response.py +++ b/stix_shifter_utils/utils/error_response.py @@ -26,6 +26,7 @@ class ErrorCode(Enum): TRANSMISSION_CONNECT = 'service_unavailable' TRANSMISSION_AUTH_SSL = 'authentication_fail' TRANSMISSION_AUTH_CREDENTIALS = 'authentication_fail' + TRANSMISSION_CERT_ERROR = 'certificate_fail' TRANSMISSION_MODULE_DEFAULT_ERROR = 'unknown' TRANSMISSION_QUERY_PARSING_ERROR = 'invalid_query' TRANSMISSION_QUERY_LOGICAL_ERROR = 'invalid_query' @@ -105,7 +106,9 @@ def fill_error(return_object, message_struct=None, message_path=None, message=No if message is not None and len(message) > 0: if error_code.value == ErrorCode.TRANSMISSION_UNKNOWN.value: - if 'uthenticat' in message or 'uthoriz' in message or 'access denied' in message: + if 'certificate' in message: + error_code = ErrorCode.TRANSMISSION_CERT_ERROR + elif 'uthenticat' in message or 'uthoriz' in message or 'access denied' in message: error_code = ErrorCode.TRANSMISSION_AUTH_CREDENTIALS elif 'query_syntax_error' in message: error_code = ErrorCode.TRANSMISSION_QUERY_PARSING_ERROR From 7f281ee41917e09111e630861f46308d8439347a Mon Sep 17 00:00:00 2001 From: Yurii Klymenko Date: Wed, 17 May 2023 12:19:07 -0400 Subject: [PATCH 2/4] more service_unavailable --- stix_shifter_utils/utils/error_response.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stix_shifter_utils/utils/error_response.py b/stix_shifter_utils/utils/error_response.py index 00ad7f643..576259aad 100644 --- a/stix_shifter_utils/utils/error_response.py +++ b/stix_shifter_utils/utils/error_response.py @@ -116,7 +116,7 @@ def fill_error(return_object, message_struct=None, message_path=None, message=No error_code = ErrorCode.TRANSMISSION_FORBIDDEN elif 'too_many_requests' in message or 'Too Many Requests' in message: error_code = ErrorCode.TRANSMISSION_TOO_MANY_REQUESTS - elif 'client_connector_error' in message: + elif any(m in message for m in ['client_connector_error', 'server timeout_error', 'ailed to establish']): error_code = ErrorCode.TRANSMISSION_CONNECT message = '{} connector error => {}'.format(connector, str(message)) return_object['error'] = str(message) From 481b82d091cb2006a144bf6923edd9afca5f224e Mon Sep 17 00:00:00 2001 From: Yurii Klymenko Date: Wed, 17 May 2023 12:43:09 -0400 Subject: [PATCH 3/4] hide Errno 61 --- stix_shifter_utils/utils/error_response.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stix_shifter_utils/utils/error_response.py b/stix_shifter_utils/utils/error_response.py index 576259aad..560cf9be8 100644 --- a/stix_shifter_utils/utils/error_response.py +++ b/stix_shifter_utils/utils/error_response.py @@ -119,7 +119,8 @@ def fill_error(return_object, message_struct=None, message_path=None, message=No elif any(m in message for m in ['client_connector_error', 'server timeout_error', 'ailed to establish']): error_code = ErrorCode.TRANSMISSION_CONNECT message = '{} connector error => {}'.format(connector, str(message)) - return_object['error'] = str(message) + message = message.replace('[Errno 61] ','') + return_object['error'] = message ErrorMapperBase.set_error_code(return_object, error_code.value, connector=connector) if error_code == ErrorCode.TRANSMISSION_UNKNOWN: ErrorResponder.call_module_error_mapper(message_struct, return_object, connector) From ffa98f659a0252521e7c1c86df7cabc5a065423d Mon Sep 17 00:00:00 2001 From: Yurii Klymenko Date: Wed, 17 May 2023 14:57:57 -0400 Subject: [PATCH 4/4] fix tests --- .../infoblox/test/stix_transmission/test_transmission.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stix_shifter_modules/infoblox/test/stix_transmission/test_transmission.py b/stix_shifter_modules/infoblox/test/stix_transmission/test_transmission.py index 043188856..7c5d26cae 100644 --- a/stix_shifter_modules/infoblox/test/stix_transmission/test_transmission.py +++ b/stix_shifter_modules/infoblox/test/stix_transmission/test_transmission.py @@ -84,7 +84,7 @@ def test_ping_exception(self, mock_ping): mock_ping.side_effect = ConnectionError("Failed to establish a new connection") transmission = StixTransmission(MODULE, CONNECTION, CONFIG) ping_response = transmission.ping() - self.assertEqual(ping_response, {'code': 'unknown', 'connector': 'infoblox', 'error': "infoblox connector error => Failed to establish a new connection", 'success': False}) + self.assertEqual(ping_response, {'code': 'service_unavailable', 'connector': 'infoblox', 'error': "infoblox connector error => Failed to establish a new connection", 'success': False}) ############################### ## QUERY @@ -316,7 +316,7 @@ def test_results_exception(self, mock_ping): mock_ping.side_effect = ConnectionError("Failed to establish a new connection") transmission = StixTransmission(MODULE, CONNECTION, CONFIG) results_response = transmission.results(self._get_query(), 4, 3) - self.assertEqual(results_response, {"success": False,'connector': 'infoblox',"error": "infoblox connector error => Failed to establish a new connection","code": "unknown"}) + self.assertEqual(results_response, {"success": False,'connector': 'infoblox',"error": "infoblox connector error => Failed to establish a new connection","code": "service_unavailable"}) class TestDossierTransmission(unittest.TestCase): def get_dialect(self): @@ -487,7 +487,7 @@ def test_results_exception(self, mock_ping): mock_ping.side_effect = ConnectionError("Failed to establish a new connection") transmission = StixTransmission(MODULE, CONNECTION, CONFIG) results_response = transmission.results(self._get_query(threat_type="host"), 4, 3) - self.assertEqual(results_response, {"success": False,'connector': 'infoblox',"error": "infoblox connector error => Failed to establish a new connection","code": "unknown"}) + self.assertEqual(results_response, {"success": False,'connector': 'infoblox',"error": "infoblox connector error => Failed to establish a new connection","code": "service_unavailable"}) class TestTideDbTransmission(unittest.TestCase): def get_dialect(self): @@ -672,4 +672,4 @@ def test_results_exception(self, mock_ping): mock_ping.side_effect = ConnectionError("Failed to establish a new connection") transmission = StixTransmission(MODULE, CONNECTION, CONFIG) results_response = transmission.results(self._get_query(threat_type="host"), 4, 3) - self.assertEqual(results_response, {"success": False,'connector': 'infoblox',"error": "infoblox connector error => Failed to establish a new connection","code": "unknown"}) + self.assertEqual(results_response, {"success": False,'connector': 'infoblox',"error": "infoblox connector error => Failed to establish a new connection","code": "service_unavailable"})