Skip to content

Fix issues from sagar #10

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 3 commits into from
Jun 26, 2020
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
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
8 changes: 4 additions & 4 deletions Packs/Code42/Integrations/Code42/Code42.yml
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ script:
- contextPath: Code42.HighRiskEmployee.Note
description: Note associated with the High Risk Employee.
type: string
description: Removes a user from the High Risk Employee List.
description: Adds a user from the High Risk Employee List.
- name: code42-highriskemployee-remove
arguments:
- name: username
Expand All @@ -333,7 +333,7 @@ script:
- name: code42-highriskemployee-get-all
arguments:
- name: risktags
description: To filter results by employees who have these risk tags.
description: To filter results by employees who have these risk tags. Space delimited.
outputs:
- contextPath: Code42.HighRiskEmployee.UserID
description: Internal Code42 User ID for the High Risk Employee.
Expand All @@ -352,7 +352,7 @@ script:
description: The username of the High Risk Employee.
- name: risktags
required: true
description: Risk tags to associate with the High Risk Employee.
description: Space-delimited risk tags to associate with the High Risk Employee.
outputs:
- contextPath: Code42.HighRiskEmployee.UserID
description: Internal Code42 User ID for the Departing Employee.
Expand All @@ -369,7 +369,7 @@ script:
description: The username of the High Risk Employee.
- name: risktags
required: true
description: Risk tags to disassociate from the High Risk Employee.
description: Space-delimited risk tags to disassociate from the High Risk Employee.
outputs:
- contextPath: Code42.HighRiskEmployee.UserID
description: Internal Code42 User ID for the Departing Employee.
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