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

Remove checking 6.2 server version #30351

Merged
merged 40 commits into from Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
6a42d57
removed usage of is_ge_version function with server version less than…
merit-maita Oct 23, 2023
db8426a
added rn
merit-maita Oct 23, 2023
bae8967
updated docker image
merit-maita Oct 23, 2023
1eec546
Merge branch 'master' into Remove_checking_6.2_server_version
merit-maita Oct 26, 2023
a39d71c
added rn
merit-maita Oct 26, 2023
62e3e27
Merge branch 'master' into Remove_checking_6.2_server_version
merit-maita Oct 26, 2023
e0d607b
removed unit tests
merit-maita Oct 26, 2023
1517be0
fixed unittests
merit-maita Oct 26, 2023
ef5642a
Merge branch 'master' into Remove_checking_6.2_server_version
merit-maita Oct 26, 2023
0038d9d
edit unittest
merit-maita Oct 26, 2023
094b12f
Merge branch 'master' into Remove_checking_6.2_server_version
merit-maita Oct 26, 2023
09ea479
fixed unittest
merit-maita Oct 26, 2023
2320777
Merge branch 'master' into Remove_checking_6.2_server_version
merit-maita Oct 26, 2023
2afc176
edited unittests
merit-maita Oct 26, 2023
612d994
Merge branch 'master' into Remove_checking_6.2_server_version
merit-maita Oct 26, 2023
3943436
edited unittests
merit-maita Oct 26, 2023
3cbe083
mypy fixes
merit-maita Oct 26, 2023
38484a3
fixes
merit-maita Oct 27, 2023
39c967e
Merge branch 'master' into Remove_checking_6.2_server_version
merit-maita Oct 27, 2023
14b85eb
fixes
merit-maita Oct 28, 2023
9d9a1f5
Merge branch 'master' into Remove_checking_6.2_server_version
merit-maita Oct 28, 2023
6aed779
updated docker image
merit-maita Oct 29, 2023
d632820
Merge branch 'master' into Remove_checking_6.2_server_version
merit-maita Oct 29, 2023
a1232aa
added rn
merit-maita Oct 29, 2023
322276e
mypy fixes
merit-maita Oct 29, 2023
d1a4e86
edited unittests
merit-maita Oct 29, 2023
b534d47
Merge branch 'master' into Remove_checking_6.2_server_version
merit-maita Oct 29, 2023
5bdb238
edit
merit-maita Oct 29, 2023
25897e5
edit unit tests
merit-maita Oct 30, 2023
3ede376
Merge branch 'master' into Remove_checking_6.2_server_version
merit-maita Oct 30, 2023
0ab44c1
Merge branch 'master' into Remove_checking_6.2_server_version
merit-maita Oct 31, 2023
3e7f4a9
Merge branch 'master' into Remove_checking_6.2_server_version
merit-maita Nov 1, 2023
4597094
edited the tpb to work with ng server
merit-maita Nov 1, 2023
69e2599
Merge branch 'master' into Remove_checking_6.2_server_version
merit-maita Nov 1, 2023
de11eb3
edited tpb
merit-maita Nov 1, 2023
e4e5e70
Merge branch 'master' into Remove_checking_6.2_server_version
merit-maita Nov 1, 2023
0a5571f
Merge branch 'master' into Remove_checking_6.2_server_version
merit-maita Nov 2, 2023
3f1c612
Merge branch 'master' into Remove_checking_6.2_server_version
merit-maita Nov 2, 2023
c81ad00
removed paging unit tests, removed arguments
merit-maita Nov 2, 2023
5fdf83f
reverted removing the args
merit-maita Nov 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -468,16 +468,16 @@
'Address': '98.136.103.23', 'ASN': 'AS36647 YAHOO-GQ1', 'Geo': {'Location': '37.751:-97.822', 'Country': 'US'},
'Relationships': [{'Relationship': 'indicator-of', 'EntityA': '98.136.103.23', 'EntityAType': 'IP',
'EntityB': 'T1140 - Deobfuscate/Decode Files or Information',
'EntityBType': 'STIX Attack Pattern'},
'EntityBType': 'Attack Pattern'},
merit-maita marked this conversation as resolved.
Show resolved Hide resolved
{'Relationship': 'indicator-of', 'EntityA': '98.136.103.23', 'EntityAType': 'IP',
'EntityB': 'T1040 - Network Sniffing', 'EntityBType': 'STIX Attack Pattern'},
'EntityB': 'T1040 - Network Sniffing', 'EntityBType': 'Attack Pattern'},
{'Relationship': 'indicator-of', 'EntityA': '98.136.103.23', 'EntityAType': 'IP',
'EntityB': 'T1053 - Scheduled Task/Job', 'EntityBType': 'STIX Attack Pattern'},
'EntityB': 'T1053 - Scheduled Task/Job', 'EntityBType': 'Attack Pattern'},
{'Relationship': 'indicator-of', 'EntityA': '98.136.103.23', 'EntityAType': 'IP',
'EntityB': 'T1060 - Registry Run Keys / Startup Folder',
'EntityBType': 'STIX Attack Pattern'},
'EntityBType': 'Attack Pattern'},
{'Relationship': 'indicator-of', 'EntityA': '98.136.103.23', 'EntityAType': 'IP',
'EntityB': 'T1071 - Application Layer Protocol', 'EntityBType': 'STIX Attack Pattern'}]
'EntityB': 'T1071 - Application Layer Protocol', 'EntityBType': 'Attack Pattern'}]
}],
'DBotScore(val.Indicator && val.Indicator == obj.Indicator && val.Vendor == obj.Vendor && val.Type == obj.Type)': [{
'Indicator': '98.136.103.23', 'Type': 'ip', 'Vendor': 'AlienVault OTX v2', 'Score': 2,
Expand Down Expand Up @@ -519,24 +519,24 @@
{'name': 'indicator-of', 'reverseName': 'indicated-by', 'type': 'IndicatorToIndicator',
'entityA': '98.136.103.23',
'entityAFamily': 'Indicator', 'entityAType': 'IP', 'entityB': 'T1140 - Deobfuscate/Decode Files or Information',
'entityBFamily': 'Indicator', 'entityBType': 'STIX Attack Pattern', 'fields': {},
'entityBFamily': 'Indicator', 'entityBType': 'Attack Pattern', 'fields': {},
'reliability': 'C - Fairly reliable',
'brand': 'AlienVault OTX v2'},
{'name': 'indicator-of', 'reverseName': 'indicated-by', 'type': 'IndicatorToIndicator',
'entityA': '98.136.103.23', 'entityAFamily': 'Indicator', 'entityAType': 'IP',
'entityB': 'T1040 - Network Sniffing', 'entityBFamily': 'Indicator', 'entityBType': 'STIX Attack Pattern',
'entityB': 'T1040 - Network Sniffing', 'entityBFamily': 'Indicator', 'entityBType': 'Attack Pattern',
'fields': {}, 'reliability': 'C - Fairly reliable', 'brand': 'AlienVault OTX v2'},
{'name': 'indicator-of', 'reverseName': 'indicated-by', 'type': 'IndicatorToIndicator', 'entityA': '98.136.103.23',
'entityAFamily': 'Indicator', 'entityAType': 'IP', 'entityB': 'T1053 - Scheduled Task/Job',
'entityBFamily': 'Indicator', 'entityBType': 'STIX Attack Pattern', 'fields': {}, 'reliability': 'C - Fairly reliable',
'entityBFamily': 'Indicator', 'entityBType': 'Attack Pattern', 'fields': {}, 'reliability': 'C - Fairly reliable',
'brand': 'AlienVault OTX v2'},
{'name': 'indicator-of', 'reverseName': 'indicated-by', 'type': 'IndicatorToIndicator', 'entityA': '98.136.103.23',
'entityAFamily': 'Indicator', 'entityAType': 'IP', 'entityB': 'T1060 - Registry Run Keys / Startup Folder',
'entityBFamily': 'Indicator', 'entityBType': 'STIX Attack Pattern', 'fields': {}, 'reliability': 'C - Fairly reliable',
'entityBFamily': 'Indicator', 'entityBType': 'Attack Pattern', 'fields': {}, 'reliability': 'C - Fairly reliable',
'brand': 'AlienVault OTX v2'},
{'name': 'indicator-of', 'reverseName': 'indicated-by', 'type': 'IndicatorToIndicator', 'entityA': '98.136.103.23',
'entityAFamily': 'Indicator', 'entityAType': 'IP', 'entityB': 'T1071 - Application Layer Protocol',
'entityBFamily': 'Indicator', 'entityBType': 'STIX Attack Pattern', 'fields': {}, 'reliability': 'C - Fairly reliable',
'entityBFamily': 'Indicator', 'entityBType': 'Attack Pattern', 'fields': {}, 'reliability': 'C - Fairly reliable',
'brand': 'AlienVault OTX v2'},
{'name': 'indicator-of', 'reverseName': 'indicated-by', 'type': 'IndicatorToIndicator', 'entityA': '98.136.103.23',
'entityAFamily': 'Indicator', 'entityAType': 'IP', 'entityB': 'mojorojorestaurante.com',
Expand Down
Expand Up @@ -359,7 +359,7 @@ def test_get_indicators_with_relations():
{'name': 'indicator-of', 'reverseName': 'indicated-by', 'type': 'IndicatorToIndicator',
'entityA': '127.0.0.1', 'entityAFamily': 'Indicator', 'entityAType': 'IP',
'entityB': 'Test',
'entityBFamily': 'Indicator', 'entityBType': 'STIX Malware', 'fields': {}}],
'entityBFamily': 'Indicator', 'entityBType': 'Malware', 'fields': {}}],
'fields': {'tags': []}}], True)

asn_ranges = '"2021-01-17 07:44:49","127.0.0.1","3889","online","2021-04-22","Test"'
Expand Down
Expand Up @@ -385,7 +385,7 @@ def test_create_relationships_list():
- The relationships that are created contain the expected types and names.
"""
from AutofocusV2 import create_relationships_list
expected_entity_b_types = ['STIX Threat Actor', 'Campaign', 'STIX Malware', 'STIX Attack Pattern']
expected_entity_b_types = ['Threat Actor', 'Campaign', 'Malware', 'Attack Pattern']
expected_name = 'indicator-of'
expected_name_entity_b = ['Upatre1', 'Upatre2', 'Upatre3', 'Upatre5']

Expand Down
6 changes: 6 additions & 0 deletions Packs/Base/ReleaseNotes/1_32_41.md
@@ -0,0 +1,6 @@

#### Scripts

##### CommonServerPython

- Updated the *CommonServerPython* methods to work without checking if server version is greater than 6.2.0.
48 changes: 17 additions & 31 deletions Packs/Base/Scripts/CommonServerPython/CommonServerPython.py
Expand Up @@ -600,7 +600,7 @@ def indicator_type_by_server_version(indicator_type):
:return:: Indicator type .
:rtype: ``str``
"""
if is_demisto_version_ge("6.2.0") and indicator_type.startswith(STIX_PREFIX):
if indicator_type.startswith(STIX_PREFIX):
return indicator_type[len(STIX_PREFIX):]
return indicator_type

Expand Down Expand Up @@ -2875,10 +2875,7 @@ def is_valid_score(score):

@staticmethod
def get_context_path():
if is_demisto_version_ge('5.5.0'):
return Common.DBotScore.CONTEXT_PATH
else:
return Common.DBotScore.CONTEXT_PATH_PRIOR_V5_5
return Common.DBotScore.CONTEXT_PATH

def to_context(self):
dbot_context = {
Expand Down Expand Up @@ -6140,16 +6137,15 @@ def __init__(

@staticmethod
def raise_error_if_not_supported():
if not is_demisto_version_ge('6.2.0'):
raise DemistoException(ScheduledCommand.VERSION_MISMATCH_ERROR)
return True

@staticmethod
def supports_polling():
"""
Check if the integration supports polling.
Check if the integration supports polling (if server version is greater than 6.2.0).
Returns: Boolean
"""
return True if is_demisto_version_ge('6.2.0') else False
return True

def to_results(self):
"""
Expand Down Expand Up @@ -9646,9 +9642,9 @@ def __init__(self,
sort=None,
):
# searchAfter is available in searchIndicators from version 6.1.0
self._can_use_search_after = is_demisto_version_ge('6.1.0')
self._can_use_search_after = True
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@merit-maita it'll be a cleaner implementation if you remove this argument and its usage.
The same goes for _can_use_filter_fields.
These are feature flags - since they are no longer needed, the old implementation isn't needed either.

# populateFields merged in https://github.com/demisto/server/pull/18398
self._can_use_filter_fields = is_demisto_version_ge('6.1.0', build_number='1095800')
self._can_use_filter_fields = True
self._search_after_param = None
self._page = page
self._filter_fields = filter_fields
Expand Down Expand Up @@ -9782,8 +9778,6 @@ class AutoFocusKeyRetriever:
def __init__(self, api_key):
# demisto.getAutoFocusApiKey() is available from version 6.2.0
if not api_key:
if not is_demisto_version_ge("6.2.0"): # AF API key is available from version 6.2.0
raise DemistoException('For versions earlier than 6.2.0, configure an API Key.')
try:
api_key = demisto.getAutoFocusApiKey() # is not available on tenants
except ValueError as err:
Expand All @@ -9793,37 +9787,29 @@ def __init__(self, api_key):

def get_feed_last_run():
"""
This function gets the feed's last run: from XSOAR version 6.2.0: using `demisto.getLastRun()`.
Before XSOAR version 6.2.0: using `demisto.getIntegrationContext()`.
This function gets the feed's last run: using `demisto.getLastRun()`.
:rtype: ``dict``
:return: All indicators from the feed's last run
"""
if is_demisto_version_ge('6.2.0'):
feed_last_run = demisto.getLastRun() or {}
if not feed_last_run:
integration_ctx = demisto.getIntegrationContext()
if integration_ctx:
feed_last_run = integration_ctx
demisto.setLastRun(feed_last_run)
demisto.setIntegrationContext({})
else:
feed_last_run = demisto.getIntegrationContext() or {}
feed_last_run = demisto.getLastRun() or {}
if not feed_last_run:
integration_ctx = demisto.getIntegrationContext()
if integration_ctx:
feed_last_run = integration_ctx
demisto.setLastRun(feed_last_run)
demisto.setIntegrationContext({})
return feed_last_run


def set_feed_last_run(last_run_indicators):
"""
This function sets the feed's last run: from XSOAR version 6.2.0: using `demisto.setLastRun()`.
Before XSOAR version 6.2.0: using `demisto.setIntegrationContext()`.
This function sets the feed's last run: using `demisto.setLastRun()`.
:type last_run_indicators: ``dict``
:param last_run_indicators: Indicators to save in "lastRun" object.
:rtype: ``None``
:return: None
"""
if is_demisto_version_ge('6.2.0'):
demisto.setLastRun(last_run_indicators)
else:
demisto.setIntegrationContext(last_run_indicators)
demisto.setLastRun(last_run_indicators)


def set_last_mirror_run(last_mirror_run): # type: (Dict[Any, Any]) -> None
Expand Down
87 changes: 2 additions & 85 deletions Packs/Base/Scripts/CommonServerPython/CommonServerPython_test.py
Expand Up @@ -1650,27 +1650,6 @@ def test_return_error_get_modified_remote_data_not_implemented(mocker):
assert demisto.results.call_args[0][0]['Contents'] == err_msg


def test_indicator_type_by_server_version_under_6_1(mocker, clear_version_cache):
"""
Given
- demisto version mock under 6.2

When
- demisto version mock under 6.2

Then
- Do not remove the STIX indicator type prefix.
"""
mocker.patch.object(
demisto,
'demistoVersion',
return_value={
'version': '6.1.0',
}
)
assert FeedIndicatorType.indicator_type_by_server_version("STIX Attack Pattern") == "STIX Attack Pattern"


def test_indicator_type_by_server_version_6_2(mocker, clear_version_cache):
"""
Given
Expand Down Expand Up @@ -4116,25 +4095,6 @@ def test_merge_lists():
assert obj in expected


@pytest.mark.parametrize('version, expected',
[
({'version': '5.5.0'}, False),
({'version': '6.0.0'}, True),
]
)
def test_is_versioned_context_available(mocker, version, expected):
from CommonServerPython import is_versioned_context_available
# Set
mocker.patch.object(demisto, 'demistoVersion', return_value=version)

# Arrange
result = is_versioned_context_available()
get_demisto_version._version = None

# Assert
assert expected == result


def test_update_context_merge(mocker):
import CommonServerPython

Expand Down Expand Up @@ -6843,8 +6803,8 @@ def test_iterator__empty_page(self, mocker):
results = []
for res in search_indicators:
results.append(res)
assert len(results) == 0
assert search_indicators.page == 19
assert len(results) == 7
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@merit-maita please remove the test, using the page search should no longer be supported after 6.2.

assert search_indicators.page == 25

def test_iterator__research_flow(self, mocker):
from CommonServerPython import IndicatorsSearcher
Expand Down Expand Up @@ -6905,21 +6865,6 @@ def test_instantiate_class_with_param_key(self, mocker, clear_version_cache):
auto_focus_key_retriever = AutoFocusKeyRetriever(api_key='1234')
assert auto_focus_key_retriever.key == '1234'

def test_instantiate_class_pre_6_2_failed(self, mocker, clear_version_cache):
"""
Given:
- not giving the api_key parameter
When:
- Mocking getAutoFocusApiKey
- Mocking server version to be 6.1.0
Then:
- Validate an exception with appropriate error message is raised.
"""
from CommonServerPython import AutoFocusKeyRetriever
mocker.patch.object(demisto, 'getAutoFocusApiKey', return_value='test')
mocker.patch.object(demisto, 'demistoVersion', return_value={'version': '6.1.0', 'buildNumber': '61000'})
with raises(DemistoException, match='For versions earlier than 6.2.0, configure an API Key.'):
AutoFocusKeyRetriever(api_key='')

def test_instantiate_class_without_param_key(self, mocker, clear_version_cache):
"""
Expand Down Expand Up @@ -7223,19 +7168,6 @@ def test_get_last_run_in_6_2_when_get_last_run_has_results(self, mocker):
result = get_feed_last_run()
assert result == {1: "first indicator"}

def test_get_last_run_in_6_1_when_get_integration_context_has_results(self, mocker):
"""
Given: 6.1.0 environment and getIntegrationContext return results
When: Fetch indicators
This can happen when updating XSOAR version to 6.2.0 while a feed instance is already set.
Then: Returning all indicators from demisto.getIntegrationContext object
"""
import demistomock as demisto
from CommonServerPython import get_feed_last_run
mocker.patch('CommonServerPython.get_demisto_version', return_value={"version": "6.1.0"})
mocker.patch.object(demisto, 'getIntegrationContext', return_value={1: "first indicator"})
result = get_feed_last_run()
assert result == {1: "first indicator"}

def test_get_last_run_in_6_2_when_get_last_run_has_no_results(self, mocker):
"""
Expand Down Expand Up @@ -7284,21 +7216,6 @@ def test_set_last_run_in_6_2(self, mocker):
assert set_integration_context.called is False
set_last_run.assert_called_with({1: "first indicator"})

def test_set_last_run_in_6_1(self, mocker):
"""
Given: 6.1.0 environment
When: Fetch indicators
Then: Using demisto.setIntegrationContext to save results
"""
import demistomock as demisto
from CommonServerPython import set_feed_last_run
mocker.patch('CommonServerPython.get_demisto_version', return_value={"version": "6.1.0"})
set_last_run = mocker.patch.object(demisto, 'setLastRun', return_value={})
set_integration_context = mocker.patch.object(demisto, 'setIntegrationContext', return_value={})
set_feed_last_run({1: "first indicator"})
set_integration_context.assert_called_with({1: "first indicator"})
assert set_last_run.called is False


class TestIsDemistoServerGE:
@classmethod
Expand Down
Expand Up @@ -119,10 +119,6 @@ def test_validate_arguments(mocker):
'reverse_relationship': '',
'create_indicator': 'false'
}
mocker.patch.object(CommonServerPython, 'is_demisto_version_ge', return_value=False)
validate_arguments(args)
assert args['entity_a_type'] == 'STIX Malware'
assert args['entity_b_type'] == 'STIX Tool'

mocker.patch.object(CommonServerPython, 'is_demisto_version_ge', return_value=True)
validate_arguments(args)
Expand Down
2 changes: 1 addition & 1 deletion Packs/Base/pack_metadata.json
Expand Up @@ -2,7 +2,7 @@
"name": "Base",
"description": "The base pack for Cortex XSOAR.",
"support": "xsoar",
"currentVersion": "1.32.40",
"currentVersion": "1.32.41",
"author": "Cortex XSOAR",
"serverMinVersion": "6.0.0",
"url": "https://www.paloaltonetworks.com/cortex",
Expand Down
Expand Up @@ -33,34 +33,27 @@ def test_create_indicators_from_response():
assert res == indicators["expected_list"]


@pytest.mark.parametrize(
argnames='server_ge_620, expected_actor_type',
argvalues=[
(False, 'STIX Threat Actor'),
(True, 'Threat Actor')
])
def test_actor_type(mocker, server_ge_620, expected_actor_type):
def test_actor_type(mocker):
"""
Given:
- Server version above end bellow 6.2.0
- Server version above 6.2.0

When:
- Creating indicators

Then:
-
Validate 'STIX Threat Actor' are the type in server version < 6.2.0
and 'Threat Actor' for server >= 6.2.0
Validate 'Threat Actor' for server >= 6.2.0
"""

# prepare
mocker.patch('CommonServerPython.is_demisto_version_ge', return_value=server_ge_620)
mocker.patch('CommonServerPython.is_demisto_version_ge', return_value=True)

# run
res = Client.create_indicators_from_response(Client, indicators["list_data_cs"], {}, 'AMBER')

# validate
assert all(indicator['type'] == expected_actor_type for indicator in res)
assert all(indicator['type'] == 'Threat Actor' for indicator in res)


def test_fetch_indicators_with_limit(mocker, requests_mock):
Expand Down
Expand Up @@ -121,7 +121,7 @@

"expected_list": [
{
"type": "STIX Threat Actor",
"type": "Threat Actor",
"value": "A",
"rawJSON": {
"type": "STIX Threat Actor",
Expand Down Expand Up @@ -217,7 +217,7 @@
}
},
{
"type": "STIX Threat Actor",
"type": "Threat Actor",
"value": "B",
"rawJSON": {
"type": "STIX Threat Actor",
Expand Down