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

Code42 new playbooks #26431

Merged
merged 3 commits into from
May 10, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 18 additions & 6 deletions Packs/Code42/Integrations/Code42/Code42.py
Original file line number Diff line number Diff line change
Expand Up @@ -972,9 +972,6 @@ def highriskemployee_remove_risk_tags_command(client, args):

@logger
def securitydata_search_command(client, args):
file_events_version = demisto.incident()["CustomFields"].get("code42fileeventsversion", "1")
if file_events_version == "2":
return_error("Integration has been configured for V2 file events, use '!code42-file-events-search' instead.")
code42_security_data_context = []
_json = args.get("json")
file_context = []
Expand Down Expand Up @@ -1021,9 +1018,6 @@ def securitydata_search_command(client, args):

@logger
def file_events_search_command(client, args):
file_events_version = demisto.incident()["CustomFields"].get("code42fileeventsversion", "1")
if file_events_version != "2":
return_error("The current incident was created with V1 file events, use '!code42-securitydata-search' instead.")
json_query = args.get("json")
add_to_context = argToBoolean(args.get("add-to-context"))
page_size = arg_to_number(args.get("results"), arg_name="results")
Expand Down Expand Up @@ -1295,6 +1289,23 @@ def update_user_risk_profile(client, args):
)


@logger
def get_user_risk_profile(client, args):
username = args.get("username")
resp = client.sdk.userriskprofile.get_by_username(username)
outputs = {
"Username": username,
"EndDate": resp.data.get("endDate"),
"StartDate": resp.data.get("startDate"),
"Notes": resp.data.get("notes"),
}
return CommandResults(
outputs_prefix="Code42.UserRiskProfiles",
outputs_key_field="Profile",
outputs=outputs,
)


@logger
def remove_user_from_watchlist_command(client, args):
username = args.get("username")
Expand Down Expand Up @@ -1569,6 +1580,7 @@ def main():
"code42-user-unblock": user_unblock_command,
"code42-user-deactivate": user_deactivate_command,
"code42-user-reactivate": user_reactivate_command,
"code42-user-get-risk-profile": get_user_risk_profile,
"code42-user-update-risk-profile": update_user_risk_profile,
"code42-legalhold-add-user": legal_hold_add_user_command,
"code42-legalhold-remove-user": legal_hold_remove_user_command,
Expand Down
24 changes: 23 additions & 1 deletion Packs/Code42/Integrations/Code42/Code42.yml
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,28 @@ script:
- contextPath: Code42.WatchlistUsers.AddedTime
description: The datetime the user was added to the watchlist.
type: datetime
- name: code42-user-get-risk-profile
description: Get the risk profile details for a given user
arguments:
- name: username
description: The user to get risk profile for.
required: true
secret: false
isArray: false
default: false
outputs:
- contextPath: Code42.UserRiskProfiles.Username
description: The username.
type: string
- contextPath: Code42.UserRiskProfiles.StartDate
description: The startDate value of the UserRiskProfile.
type: date
- contextPath: Code42.UserRiskProfiles.EndDate
description: The startDate value of the UserRiskProfile.
type: date
- contextPath: Code42.UserRiskProfiles.Notes
description: The notes value of the UserRiskProfile.
type: string
- name: code42-user-update-risk-profile
description: Update a user's risk profile.
arguments:
Expand Down Expand Up @@ -1013,7 +1035,7 @@ script:
- all
- incident
- searches
dockerimage: demisto/py42:1.0.0.56463
dockerimage: demisto/py42:1.0.0.58221
feed: false
isfetch: true
longRunning: false
Expand Down
38 changes: 18 additions & 20 deletions Packs/Code42/Integrations/Code42/Code42_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
user_deactivate_command,
user_reactivate_command,
update_user_risk_profile,
get_user_risk_profile,
legal_hold_add_user_command,
legal_hold_remove_user_command,
list_watchlists_command,
Expand Down Expand Up @@ -1196,10 +1197,11 @@ def code42_users_mock(code42_sdk_mock, mocker):

@pytest.fixture
def code42_user_risk_profile_mock(code42_sdk_mock, mocker):
update_risk_profile_response = create_mock_code42_sdk_response(
risk_profile_response = create_mock_code42_sdk_response(
mocker, MOCK_USER_RISK_PROFILE_RESPONSE
)
code42_sdk_mock.userriskprofile.update.return_value = update_risk_profile_response
code42_sdk_mock.userriskprofile.get_by_username.return_value = risk_profile_response
code42_sdk_mock.userriskprofile.update.return_value = risk_profile_response
return code42_sdk_mock


Expand Down Expand Up @@ -2027,6 +2029,20 @@ def test_user_reactivate_command(code42_users_mock):
code42_users_mock.users.reactivate.assert_called_once_with(123456)


def test_user_get_risk_profile_command(code42_user_risk_profile_mock):
client = _create_client(code42_user_risk_profile_mock)
cmd_res = get_user_risk_profile(client, args={"username": "profile@example.com"})
assert cmd_res.raw_response == {
"EndDate": {"day": 10, "month": 10, "year": 2023},
"Notes": "test update",
"StartDate": {"day": 10, "month": 10, "year": 2020},
"Username": "profile@example.com",
}
assert cmd_res.outputs["EndDate"] == {"day": 10, "month": 10, "year": 2023}
assert cmd_res.outputs_prefix == "Code42.UserRiskProfiles"
code42_user_risk_profile_mock.userriskprofile.get_by_username.assert_called_once_with("profile@example.com")


def test_user_update_risk_profile_command(code42_user_risk_profile_mock):
client = _create_client(code42_user_risk_profile_mock)
cmd_res = update_user_risk_profile(
Expand Down Expand Up @@ -2511,24 +2527,6 @@ def test_security_data_search_command_searches_exposure_exists_when_no_exposure_
assert len(filter_groups) == 3


def test_file_events_search_command_returns_error_when_v2_events_not_configured(
mocker, code42_file_events_mock
):
mock_demisto = mocker.patch("Code42.demisto")
mock_demisto.params.return_value = {"v2_events": False}
client = _create_client(code42_file_events_mock)
with pytest.raises(SystemExit):
file_events_search_command(
client,
args={
"hash": "d41d8cd98f00b204e9800998ecf8427e",
"hostname": "DESKTOP-0001",
"username": "user3@example.com",
"results": 50,
},
)


def test_file_events_search_command_returns_only_table_when_add_to_context_false(
mocker, code42_file_events_mock
):
Expand Down
24 changes: 24 additions & 0 deletions Packs/Code42/Integrations/Code42/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,30 @@ List all users who have been explicitly added to a given watchlist.
| Code42.WatchlistUsers.Username | string | The username on the watchlist. |
| Code42.WatchlistUsers.AddedTime | datetime | The datetime the user was added to the watchlist. |

### code42-get-user-risk-profile

***
Get the risk profile details for a given user.

#### Base Command

`code42-user-get-risk-profile`

#### Input

| **Argument Name** | **Description** | **Required** |
| --- | --- | --- |
| username | The user to get risk profile for. | Required |

#### Context Output

| **Path** | **Type** | **Description** |
| --- | --- | --- |
| Code42.UserRiskProfiles.Username | string | The username. |
| Code42.UserRiskProfiles.StartDate | date | The startDate value of the UserRiskProfile. |
| Code42.UserRiskProfiles.EndDate | date | The startDate value of the UserRiskProfile. |
| Code42.UserRiskProfiles.Notes | string | The notes value of the UserRiskProfile. |

### code42-user-update-risk-profile

***
Expand Down