Skip to content

Commit

Permalink
Handle list risk tags for 2 cmds{
Browse files Browse the repository at this point in the history
  • Loading branch information
Juliya Smith committed Jun 26, 2020
1 parent 17d9be5 commit e8d3ec5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
19 changes: 13 additions & 6 deletions Packs/Code42/Integrations/Code42/Code42.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ def _get_all_high_risk_employees_from_page(page, risk_tags):
return res


def _try_convert_str_list_to_list(str_list):
if isinstance(str_list, str):
return str_list.split()
return str_list


class Code42Client(BaseClient):
"""
Client will implement the service API, should not contain Cortex XSOAR logic.
Expand Down Expand Up @@ -193,18 +199,19 @@ def remove_user_from_high_risk_employee(self, username):
return user_id

def add_user_risk_tags(self, username, risk_tags):
risk_tags = _try_convert_str_list_to_list(risk_tags)
user_id = self.get_user_id(username)
self._sdk.detectionlists.add_user_risk_tags(user_id, risk_tags)
return user_id

def remove_user_risk_tags(self, username, risk_tags):
risk_tags = _try_convert_str_list_to_list(risk_tags)
user_id = self.get_user_id(username)
self._sdk.detectionlists.remove_user_risk_tags(user_id, risk_tags)
return user_id

def get_all_high_risk_employees(self, risk_tags=None):
if isinstance(risk_tags, str):
risk_tags = [risk_tags]
risk_tags = _try_convert_str_list_to_list(risk_tags)
res = []
pages = self._sdk.detectionlists.high_risk_employee.get_all()
for page in pages:
Expand Down Expand Up @@ -631,8 +638,8 @@ def highriskemployee_get_all_command(client, args):

@logger
def highriskemployee_add_risk_tags_command(client, args):
username = args["username"]
tags = args["risktags"]
username = args.get("username")
tags = args.get("risktags")
try:
user_id = client.add_user_risk_tags(username, tags)
rt_context = {"UserID": user_id, "Username": username, "RiskTags": tags}
Expand All @@ -644,8 +651,8 @@ def highriskemployee_add_risk_tags_command(client, args):

@logger
def highriskemployee_remove_risk_tags_command(client, args):
username = args["username"]
tags = args["risktags"]
username = args.get("username")
tags = args.get("risktags")
try:
user_id = client.remove_user_risk_tags(username, tags)
rt_context = {"UserID": user_id, "Username": username, "RiskTags": tags}
Expand Down
18 changes: 4 additions & 14 deletions Packs/Code42/Integrations/Code42/Code42_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1307,13 +1307,7 @@ def test_highriskemployee_get_all_command_when_given_risk_tags_only_gets_employe
client = create_client(code42_high_risk_employee_mock)
_, _, res = highriskemployee_get_all_command(
client,
{
"risktags": [
"PERFORMANCE_CONCERNS",
"SUSPICIOUS_SYSTEM_ACTIVITY",
"POOR_SECURITY_PRACTICES",
]
},
{"risktags": "PERFORMANCE_CONCERNS SUSPICIOUS_SYSTEM_ACTIVITY POOR_SECURITY_PRACTICES"},
)
# Only first employee has the given risk tags
expected = [json.loads(MOCK_GET_ALL_HIGH_RISK_EMPLOYEES_RESPONSE)["items"][0]]
Expand All @@ -1332,11 +1326,7 @@ def test_highriskemployee_get_all_command_when_no_employees(code42_high_risk_emp
_, _, res = highriskemployee_get_all_command(
client,
{
"risktags": [
"PERFORMANCE_CONCERNS",
"SUSPICIOUS_SYSTEM_ACTIVITY",
"POOR_SECURITY_PRACTICES",
]
"risktags": "PERFORMANCE_CONCERNS SUSPICIOUS_SYSTEM_ACTIVITY POOR_SECURITY_PRACTICES"
},
)
# Only first employee has the given risk tags
Expand All @@ -1353,14 +1343,14 @@ def test_highriskemployee_add_risk_tags_command(code42_sdk_mock):
expected_user_id = "123412341234123412" # value found in GET_USER_RESPONSE
assert res == expected_user_id
code42_sdk_mock.detectionlists.add_user_risk_tags.assert_called_once_with(
expected_user_id, "FLIGHT_RISK"
expected_user_id, ["FLIGHT_RISK"]
)


def test_highriskemployee_remove_risk_tags_command(code42_sdk_mock):
client = create_client(code42_sdk_mock)
_, _, res = highriskemployee_remove_risk_tags_command(
client, {"username": "[email protected]", "risktags": ["FLIGHT_RISK", "CONTRACT_EMPLOYEE"]}
client, {"username": "[email protected]", "risktags": "FLIGHT_RISK CONTRACT_EMPLOYEE"}
)
expected_user_id = "123412341234123412" # value found in GET_USER_RESPONSE
assert res == expected_user_id
Expand Down

0 comments on commit e8d3ec5

Please sign in to comment.