Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix python 3 incompatibility for McAfee MAR #27576

Merged
merged 5 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Packs/McAfee-MAR/Integrations/McAfee-MAR/McAfee-MAR.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def create_entry(header, contents, table, context={}, headers=None):

def translate_dict(d, translator):
res = {}
for key, value in d.iteritems():
for key, value in d.items():
new_key = translator.get(key, key)
res[new_key] = value
return res
Expand Down Expand Up @@ -134,7 +134,7 @@ def extract_item_output(item, capitalize):
}

# map <CollectorName>|<OutputName> to <OutputName>
for key, value in output.iteritems():
for key, value in output.items():
splited_key = key.split('|')
if(len(splited_key) > 1):
new_key = splited_key[1]
Expand Down
4 changes: 3 additions & 1 deletion Packs/McAfee-MAR/Integrations/McAfee-MAR/McAfee-MAR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,8 @@ script:
- contextPath: MAR.HostInfo.Os
description: Host operation system
description: Gets host information from McAfee Active Response
dockerimage: demisto/dxl:1.0.0.35274
dockerimage: demisto/dxl:1.0.0.63890
runonce: false
fromversion: 5.0.0
tests:
- No tests (auto formatted)
94 changes: 94 additions & 0 deletions Packs/McAfee-MAR/Integrations/McAfee-MAR/McAfee-MAR_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import unittest

import demistomock as demisto
import importlib
import pytest
Expand Down Expand Up @@ -62,3 +64,95 @@ def test_get_client_config(mocker):
'broker_ca_bundle': spaces_in_certificate}
mocker.patch.object(demisto, "params", return_value=valid_params)
mcafee_mar.validate_certificates_format()


class TestTranslateDict(unittest.TestCase):
"""
Test cases for the translate_dict function.
"""

def test_translate_dict_no_translation_needed(self):
"""
Test the scenario where no translation is needed.
"""
mcafee_mar = importlib.import_module("McAfee-MAR")
d = {'key1': 'value1', 'key2': 'value2'}
translator = {'key1': 'key1', 'key2': 'key2'}
expected = {'key1': 'value1', 'key2': 'value2'}
self.assertEqual(mcafee_mar.translate_dict(d, translator), expected)

def test_translate_dict_translation_needed(self):
"""
Test the scenario where every key in the dictionary needs to be translated.
"""
mcafee_mar = importlib.import_module("McAfee-MAR")
d = {'key1': 'value1', 'key2': 'value2'}
translator = {'key1': 'new_key1', 'key2': 'new_key2'}
expected = {'new_key1': 'value1', 'new_key2': 'value2'}
self.assertEqual(mcafee_mar.translate_dict(d, translator), expected)

def test_translate_dict_partial_translation(self):
"""
Test the scenario where only some keys in the dictionary need to be translated.
"""
mcafee_mar = importlib.import_module("McAfee-MAR")
d = {'key1': 'value1', 'key2': 'value2', 'key3': 'value3'}
translator = {'key1': 'new_key1'}
expected = {'new_key1': 'value1', 'key2': 'value2', 'key3': 'value3'}
self.assertEqual(mcafee_mar.translate_dict(d, translator), expected)

def test_translate_dict_empty_dict(self):
"""
Test the scenario where the input dictionary is empty.
"""
mcafee_mar = importlib.import_module("McAfee-MAR")
d = {}
translator = {'key1': 'new_key1', 'key2': 'new_key2'}
expected = {}
self.assertEqual(mcafee_mar.translate_dict(d, translator), expected)


class TestExtractItemOutput(unittest.TestCase):
"""
Test cases for the extract_item_output function.
"""

def test_extract_item_output_no_capitalize(self):
"""
Test the scenario where 'capitalize' is False.
"""
mcafee_mar = importlib.import_module("McAfee-MAR")
item = {'output': {'Collector1|Key1': 'value1', 'Collector2|Key2': 'value2'}, 'created_at': '2023-06-20'}
capitalize = False
expected = {'created_at': '2023-06-20', 'Key1': 'value1', 'Key2': 'value2'}
self.assertEqual(mcafee_mar.extract_item_output(item, capitalize), expected)

def test_extract_item_output_with_capitalize(self):
"""
Test the scenario where 'capitalize' is True.
"""
mcafee_mar = importlib.import_module("McAfee-MAR")
item = {'output': {'Collector1|Key1': 'value1', 'Collector2|Key2': 'value2'}, 'created_at': '2023-06-20'}
capitalize = True
expected = {'created_at': '2023-06-20', 'Key1': 'value1', 'Key2': 'value2'}
self.assertEqual(mcafee_mar.extract_item_output(item, capitalize), expected)

def test_extract_item_output_no_pipe_in_key(self):
"""
Test the scenario where there is no pipe ('|') in the output keys.
"""
mcafee_mar = importlib.import_module("McAfee-MAR")
item = {'output': {'Key1': 'value1', 'Key2': 'value2'}, 'created_at': '2023-06-20'}
capitalize = False
expected = {'created_at': '2023-06-20', 'Key1': 'value1', 'Key2': 'value2'}
self.assertEqual(mcafee_mar.extract_item_output(item, capitalize), expected)

def test_extract_item_output_empty_output(self):
"""
Test the scenario where the output in the item is empty.
"""
mcafee_mar = importlib.import_module("McAfee-MAR")
item = {'output': {}, 'created_at': '2023-06-20'}
capitalize = False
expected = {'created_at': '2023-06-20'}
self.assertEqual(mcafee_mar.extract_item_output(item, capitalize), expected)
6 changes: 6 additions & 0 deletions Packs/McAfee-MAR/ReleaseNotes/1_0_7.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#### Integrations

##### McAfee Active Response
- Updated the Docker image to: *demisto/dxl:1.0.0.63890*.
- Fixed an issue where certain parts of the integration were incompatible with Python 3.
2 changes: 1 addition & 1 deletion Packs/McAfee-MAR/pack_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "McAfee Active Response",
"description": "Connect to MAR using its DXL client",
"support": "xsoar",
"currentVersion": "1.0.6",
"currentVersion": "1.0.7",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down