forked from demisto/content
-
Notifications
You must be signed in to change notification settings - Fork 0
Add support for exposure type exists criteria #22
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c71bbac
Add support for exposure type exists criteria when no exposure type i…
kiran-chaudhary 4c2053b
adjust test
alanag13 96d598d
Merge branch 'master' into filter-exposure-type-exists
alanag13 af7c457
To search for all exposure types specify all option
kiran-chaudhary ac93260
Fix
kiran-chaudhary ee4bfbc
Merge branch 'master' into filter-exposure-type-exists
kiran-chaudhary abdf253
Added changelog
kiran-chaudhary File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,28 @@ | |
"results": 50, | ||
} | ||
|
||
MOCK_SECURITY_DATA_SEARCH_QUERY_EXPOSURE_TYPE_ALL = { | ||
"hash": "d41d8cd98f00b204e9800998ecf8427e", | ||
"hostname": "DESKTOP-0001", | ||
"username": "[email protected]", | ||
"exposure": "All", | ||
"results": 50, | ||
} | ||
|
||
MOCK_SECURITY_DATA_SEARCH_QUERY_EXPOSURE_TYPE_ALL_WITH_OTHERS = { | ||
"hash": "d41d8cd98f00b204e9800998ecf8427e", | ||
"hostname": "DESKTOP-0001", | ||
"username": "[email protected]", | ||
"exposure": "ApplicationRead, All", | ||
"results": 50, | ||
} | ||
|
||
MOCK_SECURITY_DATA_SEARCH_QUERY_WITHOUT_EXPOSURE_TYPE = { | ||
"hash": "d41d8cd98f00b204e9800998ecf8427e", | ||
"hostname": "DESKTOP-0001", | ||
"username": "[email protected]", | ||
"results": 50, | ||
} | ||
|
||
MOCK_SECURITY_EVENT_RESPONSE = """ | ||
{ | ||
|
@@ -2067,3 +2089,74 @@ def test_fetch_incidents_fetch_limit(code42_fetch_incidents_mock): | |
assert len(incidents) == 1 | ||
assert next_run["last_fetch"] | ||
assert not remaining_incidents | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"query", | ||
[MOCK_SECURITY_DATA_SEARCH_QUERY_EXPOSURE_TYPE_ALL, | ||
MOCK_SECURITY_DATA_SEARCH_QUERY_EXPOSURE_TYPE_ALL_WITH_OTHERS | ||
] | ||
) | ||
def test_security_data_search_command_searches_exposure_exists_when_all_is_specified( | ||
code42_file_events_mock, query | ||
): | ||
client = create_client(code42_file_events_mock) | ||
cmd_res = securitydata_search_command(client, query) | ||
code42_res = cmd_res[0] | ||
file_res = cmd_res[1] | ||
|
||
assert code42_res.outputs_prefix == "Code42.SecurityData" | ||
assert code42_res.outputs_key_field == "EventID" | ||
assert file_res.outputs_prefix == "File" | ||
|
||
actual_query = code42_file_events_mock.securitydata.search_file_events.call_args[0][0] | ||
|
||
# Assert that the correct query gets made | ||
filter_groups = json.loads(str(actual_query))["groups"] | ||
expected_query_items = [ | ||
("md5Checksum", "d41d8cd98f00b204e9800998ecf8427e"), | ||
("osHostName", "DESKTOP-0001"), | ||
("deviceUserName", "[email protected]"), | ||
("exposure", None), | ||
] | ||
|
||
# Assert that the correct query gets made | ||
assert len(filter_groups) == len(expected_query_items) | ||
for i in range(0, len(filter_groups)): | ||
_filter = filter_groups[i]["filters"][0] | ||
assert _filter["term"] == expected_query_items[i][0] | ||
assert _filter["value"] == expected_query_items[i][1] | ||
|
||
assert len(filter_groups) == 4 | ||
|
||
|
||
def test_security_data_search_command_searches_exposure_exists_when_no_exposure_type_is_specified( | ||
code42_file_events_mock, | ||
): | ||
client = create_client(code42_file_events_mock) | ||
cmd_res = securitydata_search_command(client, MOCK_SECURITY_DATA_SEARCH_QUERY_WITHOUT_EXPOSURE_TYPE) | ||
code42_res = cmd_res[0] | ||
file_res = cmd_res[1] | ||
|
||
assert code42_res.outputs_prefix == "Code42.SecurityData" | ||
assert code42_res.outputs_key_field == "EventID" | ||
assert file_res.outputs_prefix == "File" | ||
|
||
actual_query = code42_file_events_mock.securitydata.search_file_events.call_args[0][0] | ||
|
||
# Assert that the correct query gets made | ||
filter_groups = json.loads(str(actual_query))["groups"] | ||
expected_query_items = [ | ||
("md5Checksum", "d41d8cd98f00b204e9800998ecf8427e"), | ||
("osHostName", "DESKTOP-0001"), | ||
("deviceUserName", "[email protected]"), | ||
] | ||
|
||
# Assert that the correct query gets made | ||
assert len(filter_groups) == len(expected_query_items) | ||
for i in range(0, len(filter_groups)): | ||
_filter = filter_groups[i]["filters"][0] | ||
assert _filter["term"] == expected_query_items[i][0] | ||
assert _filter["value"] == expected_query_items[i][1] | ||
|
||
assert len(filter_groups) == 3 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment looks like it was copied from CLI code, which could be a little confusing here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or is this referring to the
demisto-sdk
CLI?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't see this comment in the codebase for the CLI, so nevermind, you can leave this as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the CLI in Cortex XSOAR, like where you type commands in War Rooms