Skip to content

Commit 20f486d

Browse files
author
Juliya Smith
authored
Merge pull request #19 from code42/download-file
2 parents 1269e36 + d62497e commit 20f486d

15 files changed

+101
-804
lines changed

Packs/Code42/Integrations/Code42/Code42.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def _get_all_high_risk_employees_from_page(page, risk_tags):
152152

153153
def _try_convert_str_list_to_list(str_list):
154154
if isinstance(str_list, str):
155-
return str_list.split()
155+
return str_list.split(",")
156156
return str_list
157157

158158

@@ -952,9 +952,10 @@ def user_reactivate_command(client, args):
952952

953953
def download_file_command(client, args):
954954
file_hash = args.get("hash")
955+
filename = args.get("filename") or file_hash
955956
response = client.download_file(file_hash)
956957
file_chunks = [c for c in response.iter_content(chunk_size=128) if c]
957-
return fileResult(file_hash, data=b"".join(file_chunks))
958+
return fileResult(filename, data=b"".join(file_chunks))
958959

959960

960961
"""Fetching"""
@@ -1117,7 +1118,7 @@ def get_command_map():
11171118
"code42-user-block": user_block_command,
11181119
"code42-user-unblock": user_unblock_command,
11191120
"code42-user-deactivate": user_deactivate_command,
1120-
"code42_user-reactivate": user_reactivate_command,
1121+
"code42-user-reactivate": user_reactivate_command,
11211122
"code42-download-file": download_file_command,
11221123
}
11231124

Packs/Code42/Integrations/Code42/Code42.yml

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -419,11 +419,20 @@ script:
419419
description: The username of the High Risk Employee.
420420
type: Unknown
421421
- arguments:
422-
- default: false
423-
description: To filter results by employees who have these risk tags. Space
422+
- auto: PREDEFINED
423+
default: false
424+
description: To filter results by employees who have these risk tags. Comma
424425
delimited.
425426
isArray: false
426427
name: risktags
428+
predefined:
429+
- PERFORMANCE_CONCERNS
430+
- PERFORMANCE_CONCERNS
431+
- POOR_SECURITY_PRACTICES
432+
- HIGH_IMPACT_EMPLOYEE
433+
- ELEVATED_ACCESS_PRIVILEGES
434+
- FLIGHT_RISK
435+
- CONTRACT_EMPLOYEE
427436
required: false
428437
secret: false
429438
- default: false
@@ -453,10 +462,19 @@ script:
453462
name: username
454463
required: true
455464
secret: false
456-
- default: false
457-
description: Space-delimited risk tags to associate with the High Risk Employee.
465+
- auto: PREDEFINED
466+
default: false
467+
description: Comma-delimited risk tags to associate with the High Risk Employee.
458468
isArray: false
459469
name: risktags
470+
predefined:
471+
- PERFORMANCE_CONCERNS
472+
- PERFORMANCE_CONCERNS
473+
- POOR_SECURITY_PRACTICES
474+
- HIGH_IMPACT_EMPLOYEE
475+
- ELEVATED_ACCESS_PRIVILEGES
476+
- FLIGHT_RISK
477+
- CONTRACT_EMPLOYEE
460478
required: true
461479
secret: false
462480
deprecated: false
@@ -480,10 +498,19 @@ script:
480498
name: username
481499
required: true
482500
secret: false
483-
- default: false
484-
description: Space-delimited risk tags to disassociate from the High Risk Employee.
501+
- auto: PREDEFINED
502+
default: false
503+
description: Comma-delimited risk tags to disassociate from the High Risk Employee.
485504
isArray: false
486505
name: risktags
506+
predefined:
507+
- PERFORMANCE_CONCERNS
508+
- PERFORMANCE_CONCERNS
509+
- POOR_SECURITY_PRACTICES
510+
- HIGH_IMPACT_EMPLOYEE
511+
- ELEVATED_ACCESS_PRIVILEGES
512+
- FLIGHT_RISK
513+
- CONTRACT_EMPLOYEE
487514
required: true
488515
secret: false
489516
deprecated: false
@@ -604,6 +631,12 @@ script:
604631
name: hash
605632
required: true
606633
secret: false
634+
- default: false
635+
description: The filename to save the file as.
636+
isArray: false
637+
name: filename
638+
required: false
639+
secret: false
607640
deprecated: false
608641
description: Downloads a file from Code42 servers.
609642
execution: false

Packs/Code42/Integrations/Code42/Code42_test.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@
7070
"deviceUserName":"test@example.com",
7171
"osHostName":"HOSTNAME",
7272
"domainName":"host.docker.internal",
73-
"publicIpAddress":"162.222.47.183",
74-
"privateIpAddresses":["172.20.128.36","127.0.0.1"],
73+
"publicIpAddress":"255.255.255.255",
74+
"privateIpAddresses":["255.255.255.255","127.0.0.1"],
7575
"deviceUid":"935873453596901068",
7676
"userUid":"912098363086307495",
7777
"actor":null,
@@ -134,7 +134,7 @@
134134
"deviceUserName":"test@example.com",
135135
"osHostName":"TEST'S MAC",
136136
"domainName":"host.docker.internal",
137-
"publicIpAddress":"162.222.47.183",
137+
"publicIpAddress":"255.255.255.255",
138138
"privateIpAddresses":["127.0.0.1"],
139139
"deviceUid":"935873453596901068",
140140
"userUid":"912098363086307495",
@@ -198,7 +198,7 @@
198198
"deviceUserName":"test@example.com",
199199
"osHostName":"Test's Windows",
200200
"domainName":"host.docker.internal",
201-
"publicIpAddress":"162.222.47.183",
201+
"publicIpAddress":"255.255.255.255",
202202
"privateIpAddresses":["0:0:0:0:0:0:0:1","127.0.0.1"],
203203
"deviceUid":"935873453596901068",
204204
"userUid":"912098363086307495",
@@ -248,7 +248,7 @@
248248
MOCK_CODE42_EVENT_CONTEXT = [
249249
{
250250
"ApplicationTabURL": "example.com",
251-
"DevicePrivateIPAddress": ["172.20.128.36", "127.0.0.1"],
251+
"DevicePrivateIPAddress": ["255.255.255.255", "127.0.0.1"],
252252
"DeviceUsername": "test@example.com",
253253
"EndpointID": "935873453596901068",
254254
"EventID": "0_1d71796f-af5b-4231-9d8e-df6434da4663_935873453596901068_956171635867906205_5",
@@ -1380,7 +1380,7 @@ def test_departingemployee_get_all_command_when_no_employees(
13801380
no_employees_response
13811381
)
13821382
client = create_client(code42_departing_employee_mock)
1383-
cmd_res = departingemployee_get_all_command(client,{})
1383+
cmd_res = departingemployee_get_all_command(client, {})
13841384
assert cmd_res.outputs_prefix == "Code42.DepartingEmployee"
13851385
assert cmd_res.outputs_key_field == "UserID"
13861386
assert cmd_res.raw_response == {}
@@ -1456,7 +1456,7 @@ def test_highriskemployee_get_all_command_when_given_risk_tags_only_gets_employe
14561456
client = create_client(code42_high_risk_employee_mock)
14571457
cmd_res = highriskemployee_get_all_command(
14581458
client,
1459-
{"risktags": "PERFORMANCE_CONCERNS SUSPICIOUS_SYSTEM_ACTIVITY POOR_SECURITY_PRACTICES"},
1459+
{"risktags": "PERFORMANCE_CONCERNS,SUSPICIOUS_SYSTEM_ACTIVITY,POOR_SECURITY_PRACTICES"},
14601460
)
14611461
expected_response = [json.loads(MOCK_GET_ALL_HIGH_RISK_EMPLOYEES_RESPONSE)["items"][0]]
14621462
assert cmd_res.outputs_prefix == "Code42.HighRiskEmployee"
@@ -1494,7 +1494,7 @@ def test_highriskemployee_get_all_command_when_no_employees(code42_high_risk_emp
14941494
client = create_client(code42_high_risk_employee_mock)
14951495
cmd_res = highriskemployee_get_all_command(
14961496
client,
1497-
{"risktags": "PERFORMANCE_CONCERNS SUSPICIOUS_SYSTEM_ACTIVITY POOR_SECURITY_PRACTICES"},
1497+
{"risktags": "PERFORMANCE_CONCERNS,SUSPICIOUS_SYSTEM_ACTIVITY,POOR_SECURITY_PRACTICES"},
14981498
)
14991499
assert cmd_res.outputs_prefix == "Code42.HighRiskEmployee"
15001500
assert cmd_res.outputs_key_field == "UserID"
@@ -1507,7 +1507,7 @@ def test_highriskemployee_add_risk_tags_command(code42_sdk_mock):
15071507
tags = "FLIGHT_RISK"
15081508
client = create_client(code42_sdk_mock)
15091509
cmd_res = highriskemployee_add_risk_tags_command(
1510-
client, {"username": _TEST_USERNAME, "risktags": "FLIGHT_RISK"}
1510+
client, {"username": _TEST_USERNAME, "risktags": tags}
15111511
)
15121512
assert cmd_res.raw_response == _TEST_USER_ID
15131513
assert cmd_res.outputs_prefix == "Code42.HighRiskEmployee"
@@ -1516,21 +1516,21 @@ def test_highriskemployee_add_risk_tags_command(code42_sdk_mock):
15161516
assert cmd_res.outputs["Username"] == _TEST_USERNAME
15171517
assert cmd_res.outputs["RiskTags"] == tags
15181518
code42_sdk_mock.detectionlists.add_user_risk_tags.assert_called_once_with(
1519-
_TEST_USER_ID, ["FLIGHT_RISK"]
1519+
_TEST_USER_ID, [tags]
15201520
)
15211521

15221522

15231523
def test_highriskemployee_remove_risk_tags_command(code42_sdk_mock):
15241524
client = create_client(code42_sdk_mock)
15251525
cmd_res = highriskemployee_remove_risk_tags_command(
1526-
client, {"username": _TEST_USERNAME, "risktags": "FLIGHT_RISK CONTRACT_EMPLOYEE"}
1526+
client, {"username": _TEST_USERNAME, "risktags": "FLIGHT_RISK,CONTRACT_EMPLOYEE"}
15271527
)
15281528
assert cmd_res.raw_response == _TEST_USER_ID
15291529
assert cmd_res.outputs_prefix == "Code42.HighRiskEmployee"
15301530
assert cmd_res.outputs_key_field == "UserID"
15311531
assert cmd_res.outputs["UserID"] == _TEST_USER_ID
15321532
assert cmd_res.outputs["Username"] == _TEST_USERNAME
1533-
assert cmd_res.outputs["RiskTags"] == "FLIGHT_RISK CONTRACT_EMPLOYEE"
1533+
assert cmd_res.outputs["RiskTags"] == "FLIGHT_RISK,CONTRACT_EMPLOYEE"
15341534
code42_sdk_mock.detectionlists.remove_user_risk_tags.assert_called_once_with(
15351535
_TEST_USER_ID, ["FLIGHT_RISK", "CONTRACT_EMPLOYEE"]
15361536
)

Packs/Code42/Integrations/Code42/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ Get all employees on the High Risk Employee List.
420420

421421
| **Argument Name** | **Description** | **Required** |
422422
| --- | --- | --- |
423-
| risktags | To filter results by employees who have these risk tags. Space delimited. | Optional |
423+
| risktags | To filter results by employees who have these risk tags. Comma delimited. | Optional |
424424
| results | The number of items to return. | Optional |
425425

426426

0 commit comments

Comments
 (0)