|
18 | 18 |
|
19 | 19 | import CommonServerPython
|
20 | 20 | import demistomock as demisto
|
21 |
| -from CommonServerPython import xml2json, json2xml, entryTypes, formats, tableToMarkdown, underscoreToCamelCase, \ |
22 |
| - flattenCell, date_to_timestamp, datetime, timedelta, camelize, pascalToSpace, argToList, \ |
23 |
| - remove_nulls_from_dictionary, is_error, get_error, hash_djb2, fileResult, is_ip_valid, get_demisto_version, \ |
24 |
| - IntegrationLogger, parse_date_string, IS_PY3, PY_VER_MINOR, DebugLogger, b64_encode, parse_date_range, \ |
25 |
| - return_outputs, is_filename_valid, convert_dict_values_bytes_to_str, \ |
26 |
| - argToBoolean, ipv4Regex, ipv4cidrRegex, ipv6cidrRegex, urlRegex, ipv6Regex, domainRegex, batch, FeedIndicatorType, \ |
27 |
| - encode_string_results, safe_load_json, remove_empty_elements, aws_table_to_markdown, is_demisto_version_ge, \ |
28 |
| - appendContext, auto_detect_indicator_type, handle_proxy, get_demisto_version_as_str, get_x_content_info_headers, \ |
29 |
| - url_to_clickable_markdown, WarningsHandler, DemistoException, SmartGetDict, JsonTransformer, \ |
30 |
| - remove_duplicates_from_list_arg, DBotScoreType, DBotScoreReliability, Common, send_events_to_xsiam, ExecutionMetrics, \ |
31 |
| - response_to_context, is_integration_command_execution, is_xsiam_or_xsoar_saas, is_xsoar, is_xsoar_on_prem, \ |
32 |
| - is_xsoar_hosted, is_xsoar_saas, is_xsiam, send_data_to_xsiam, censor_request_logs, censor_request_logs, safe_sleep |
| 21 | +from CommonServerPython import (xml2json, json2xml, entryTypes, formats, tableToMarkdown, underscoreToCamelCase, |
| 22 | + flattenCell, date_to_timestamp, datetime, timedelta, camelize, pascalToSpace, argToList, |
| 23 | + remove_nulls_from_dictionary, is_error, get_error, hash_djb2, fileResult, is_ip_valid, |
| 24 | + get_demisto_version, IntegrationLogger, parse_date_string, IS_PY3, PY_VER_MINOR, DebugLogger, |
| 25 | + b64_encode, parse_date_range, return_outputs, is_filename_valid, convert_dict_values_bytes_to_str, |
| 26 | + argToBoolean, ipv4Regex, ipv4cidrRegex, ipv6cidrRegex, urlRegex, ipv6Regex, domainRegex, batch, |
| 27 | + FeedIndicatorType, encode_string_results, safe_load_json, remove_empty_elements, |
| 28 | + aws_table_to_markdown, is_demisto_version_ge, appendContext, auto_detect_indicator_type, |
| 29 | + handle_proxy, get_demisto_version_as_str, get_x_content_info_headers, url_to_clickable_markdown, |
| 30 | + WarningsHandler, DemistoException, SmartGetDict, JsonTransformer, remove_duplicates_from_list_arg, |
| 31 | + DBotScoreType, DBotScoreReliability, Common, send_events_to_xsiam, ExecutionMetrics, |
| 32 | + response_to_context, is_integration_command_execution, is_xsiam_or_xsoar_saas, is_xsoar, |
| 33 | + is_xsoar_on_prem, is_xsoar_hosted, is_xsoar_saas, is_xsiam, send_data_to_xsiam, |
| 34 | + censor_request_logs, censor_request_logs, safe_sleep, get_server_config |
| 35 | + ) |
33 | 36 |
|
34 | 37 | EVENTS_LOG_ERROR = \
|
35 | 38 | """Error sending new events into XSIAM.
|
@@ -9769,3 +9772,50 @@ def test_sleep_mocked_time(mocker):
|
9769 | 9772 |
|
9770 | 9773 | # Verify sleep duration based on mocked time difference
|
9771 | 9774 | assert sleep_mocker.call_count == 2
|
| 9775 | + |
| 9776 | + |
| 9777 | +def test_get_server_config(mocker): |
| 9778 | + mock_response = { |
| 9779 | + 'body': '{"sysConf":{"incident.closereasons":"CustomReason1, CustomReason 2, Foo","versn":40},"defaultMap":{}}\n', |
| 9780 | + 'headers': { |
| 9781 | + 'Content-Length': ['104'], |
| 9782 | + 'X-Xss-Protection': ['1; mode=block'], |
| 9783 | + 'X-Content-Type-Options': ['nosniff'], |
| 9784 | + 'Strict-Transport-Security': ['max-age=10886400000000000; includeSubDomains'], |
| 9785 | + 'Vary': ['Accept-Encoding'], |
| 9786 | + 'Server-Timing': ['7'], |
| 9787 | + 'Date': ['Wed, 03 Jul 2010 09:11:35 GMT'], |
| 9788 | + 'X-Frame-Options': ['DENY'], |
| 9789 | + 'Content-Type': ['application/json'] |
| 9790 | + }, |
| 9791 | + 'status': '200 OK', |
| 9792 | + 'statusCode': 200 |
| 9793 | + } |
| 9794 | + |
| 9795 | + mocker.patch.object(demisto, 'internalHttpRequest', return_value=mock_response) |
| 9796 | + server_config = get_server_config() |
| 9797 | + assert server_config == {'incident.closereasons': 'CustomReason1, CustomReason 2, Foo', 'versn': 40} |
| 9798 | + |
| 9799 | + |
| 9800 | +def test_get_server_config_fail(mocker): |
| 9801 | + mock_response = { |
| 9802 | + 'body': 'NOT A VALID JSON', |
| 9803 | + 'headers': { |
| 9804 | + 'Content-Length': ['104'], |
| 9805 | + 'X-Xss-Protection': ['1; mode=block'], |
| 9806 | + 'X-Content-Type-Options': ['nosniff'], |
| 9807 | + 'Strict-Transport-Security': ['max-age=10886400000000000; includeSubDomains'], |
| 9808 | + 'Vary': ['Accept-Encoding'], |
| 9809 | + 'Server-Timing': ['7'], |
| 9810 | + 'Date': ['Wed, 03 Jul 2010 09:11:35 GMT'], |
| 9811 | + 'X-Frame-Options': ['DENY'], |
| 9812 | + 'Content-Type': ['application/json'] |
| 9813 | + }, |
| 9814 | + 'status': '200 OK', |
| 9815 | + 'statusCode': 200 |
| 9816 | + } |
| 9817 | + |
| 9818 | + mocker.patch.object(demisto, 'internalHttpRequest', return_value=mock_response) |
| 9819 | + mocked_error = mocker.patch.object(demisto, 'error') |
| 9820 | + assert get_server_config() == {} |
| 9821 | + assert mocked_error.call_args[0][0] == 'Error decoding JSON: Expecting value: line 1 column 1 (char 0)' |
0 commit comments