Skip to content

Commit f32b3d5

Browse files
almog2296Content BotShellyber
authored
Get user data ciac 14680 (#41213)
* Commit * Commit * Chnaged argname under ad-get-user * Update release notes * Merged From Master * Bump pack from version AggregatedScripts to 1.1.12. * Update Packs/AggregatedScripts/ReleaseNotes/1_1_12.md Co-authored-by: Shelly Tzohar <[email protected]> * added tests * Bump pack from version AggregatedScripts to 1.1.14. * update relesae notes --------- Co-authored-by: Content Bot <[email protected]> Co-authored-by: Shelly Tzohar <[email protected]>
1 parent 06d6403 commit f32b3d5

File tree

4 files changed

+202
-2
lines changed

4 files changed

+202
-2
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
#### Scripts
3+
4+
##### get-user-data
5+
6+
- Fixed the **get-user-data** script to search Active Directory using the *username* argument instead of the name argument.

Packs/AggregatedScripts/Scripts/GetUserData/GetUserData.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ def main():
910910
modules=modules,
911911
brand_name="Active Directory Query v2",
912912
command_name="ad-get-user",
913-
arg_name="name",
913+
arg_name="username",
914914
arg_value=user_name.split("\\")[1],
915915
cmd=ad_get_user,
916916
additional_fields=additional_fields,

Packs/AggregatedScripts/Scripts/GetUserData/GetUserData_test.py

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import demistomock as demisto
2+
import pytest
23
from CommonServerPython import *
34
from GetUserData import (
45
Command,
@@ -2138,3 +2139,196 @@ def test_run_list_users_command_empty_outputs_from_api(mocker: MockerFixture):
21382139
assert len(users) == 2 # Both emails marked as not found
21392140
assert all(user["Status"] == "not found" for user in users)
21402141
assert {user["Email"] for user in users} == set(email_list)
2142+
2143+
2144+
# --- helpers to mute all other adapters so main can run quietly ---
2145+
def _mute_all_other_adapters(mocker: MockerFixture, except_fn: str | None = None):
2146+
fns = {
2147+
"ad_get_user",
2148+
"okta_get_user",
2149+
"aws_iam_get_user",
2150+
"msgraph_user_get",
2151+
"prisma_cloud_get_user",
2152+
"iam_get_user", # <- shared by Okta IAM and AWS-ILM
2153+
"gsuite_get_user",
2154+
"azure_get_risky_user",
2155+
}
2156+
for fn in fns:
2157+
if fn == except_fn:
2158+
continue
2159+
mocker.patch(f"GetUserData.{fn}", return_value=([], []))
2160+
2161+
2162+
# -------------- Testing Calling the right argument per command --------------
2163+
# ---------- Username flows (no domain) ----------
2164+
@pytest.mark.parametrize(
2165+
"brand_name,command_name,adapter_fn,expected_key,expected_value",
2166+
[
2167+
("Active Directory Query v2", "ad-get-user", "ad_get_user", "username", "alice"),
2168+
("Okta v2", "okta-get-user", "okta_get_user", "username", "alice"),
2169+
("AWS - IAM", "aws-iam-get-user", "aws_iam_get_user", "userName", "alice"),
2170+
("Microsoft Graph User", "msgraph-user-get", "msgraph_user_get", "user", "alice"),
2171+
("PrismaCloud v2", "prisma-cloud-users-list", "prisma_cloud_get_user", "usernames", "alice"),
2172+
("Okta IAM", "iam-get-user", "iam_get_user", "user-profile", '{"login":"alice"}'),
2173+
("AWS-ILM", "iam-get-user", "iam_get_user", "user-profile", '{"login":"alice"}'),
2174+
],
2175+
)
2176+
def test_username_arg_mapping_to_adapter(
2177+
mocker: MockerFixture, brand_name, command_name, adapter_fn, expected_key, expected_value
2178+
):
2179+
"""
2180+
Given:
2181+
- calling get-user-data with username = alice.
2182+
- brand_name = brand_name.
2183+
When:
2184+
- main() executes by username flows.
2185+
Then:
2186+
- The right command is being called with the right argument name.
2187+
"""
2188+
mocker.patch.object(demisto, "args", return_value={"user_name": ["alice"]})
2189+
mocker.patch.object(demisto, "getModules", return_value={})
2190+
mocker.patch.object(Modules, "is_brand_in_brands_to_run", return_value=True)
2191+
mocker.patch.object(Modules, "is_brand_available", return_value=True)
2192+
mocker.patch("GetUserData.get_core_and_xdr_data", return_value=([], []))
2193+
mocker.patch("GetUserData.return_results")
2194+
2195+
_mute_all_other_adapters(mocker, except_fn=adapter_fn)
2196+
seen = {"ok": False}
2197+
2198+
def _assert_adapter(command: Command, additional_fields: bool):
2199+
# Only assert for the exact brand+command under test; ignore other calls to the same adapter.
2200+
if command.brand != brand_name or command.name != command_name:
2201+
return ([], [])
2202+
assert command.args.get(expected_key) == expected_value
2203+
assert command.args.get("using-brand") == brand_name
2204+
if expected_key == "username":
2205+
assert "name" not in command.args # regression guard
2206+
seen["ok"] = True
2207+
return ([], [])
2208+
2209+
mocker.patch(f"GetUserData.{adapter_fn}", side_effect=_assert_adapter)
2210+
main()
2211+
assert seen["ok"] is True
2212+
2213+
2214+
# ---------- Username flow with domain prefix (DOMAIN\\username) ----------
2215+
def test_domain_username_branch_uses_username_key_for_ad(mocker: MockerFixture):
2216+
"""
2217+
Given:
2218+
- calling get-user-data with username = ACME\\alice.
2219+
- brand_name = brand_name.
2220+
When:
2221+
- main() executes by username flows.
2222+
Then:
2223+
- The right command is being called with the right argument name.
2224+
"""
2225+
mocker.patch.object(demisto, "args", return_value={"user_name": ["ACME\\alice"]})
2226+
mocker.patch.object(demisto, "getModules", return_value={})
2227+
mocker.patch.object(Modules, "is_brand_in_brands_to_run", return_value=True)
2228+
mocker.patch.object(Modules, "is_brand_available", return_value=True)
2229+
mocker.patch("GetUserData.get_core_and_xdr_data", return_value=([], []))
2230+
mocker.patch("GetUserData.return_results")
2231+
2232+
_mute_all_other_adapters(mocker, except_fn="ad_get_user")
2233+
hit = {"seen": False}
2234+
2235+
def _assert_ad(command: Command, additional_fields: bool):
2236+
if command.brand != "Active Directory Query v2" or command.name != "ad-get-user":
2237+
return ([], [])
2238+
assert command.args.get("username") == "alice"
2239+
assert "name" not in command.args
2240+
assert command.args.get("using-brand") == "Active Directory Query v2"
2241+
hit["seen"] = True
2242+
return ([], [])
2243+
2244+
mocker.patch("GetUserData.ad_get_user", side_effect=_assert_ad)
2245+
main()
2246+
assert hit["seen"] is True
2247+
2248+
2249+
# ---------- User ID flows ----------
2250+
@pytest.mark.parametrize(
2251+
"brand_name,command_name,adapter_fn,expected_key,expected_value",
2252+
[
2253+
("Okta v2", "okta-get-user", "okta_get_user", "userId", "u123"),
2254+
("Microsoft Graph User", "msgraph-user-get", "msgraph_user_get", "user", "u123"),
2255+
("AzureRiskyUsers", "azure-risky-user-get", "azure_get_risky_user", "id", "u123"),
2256+
("Okta IAM", "iam-get-user", "iam_get_user", "user-profile", '{"id":"u123"}'),
2257+
("AWS-ILM", "iam-get-user", "iam_get_user", "user-profile", '{"id":"u123"}'),
2258+
("GSuiteAdmin", "gsuite-user-get", "gsuite_get_user", "user", "u123"),
2259+
],
2260+
)
2261+
def test_userid_arg_mapping_to_adapter(mocker: MockerFixture, brand_name, command_name, adapter_fn, expected_key, expected_value):
2262+
"""
2263+
Given:
2264+
- calling get-user-data with user_id = u123.
2265+
- brand_name = brand_name.
2266+
When:
2267+
-main() executes by user ID flows.
2268+
Then:
2269+
- The right command is being called with the right argument name.
2270+
"""
2271+
mocker.patch.object(demisto, "args", return_value={"user_id": ["u123"]})
2272+
mocker.patch.object(demisto, "getModules", return_value={})
2273+
mocker.patch.object(Modules, "is_brand_in_brands_to_run", return_value=True)
2274+
mocker.patch.object(Modules, "is_brand_available", return_value=True)
2275+
mocker.patch("GetUserData.get_core_and_xdr_data", return_value=([], []))
2276+
mocker.patch("GetUserData.return_results")
2277+
2278+
_mute_all_other_adapters(mocker, except_fn=adapter_fn)
2279+
seen = {"ok": False}
2280+
2281+
def _assert_adapter(command: Command, additional_fields: bool):
2282+
if command.brand != brand_name or command.name != command_name:
2283+
return ([], [])
2284+
assert command.args.get(expected_key) == expected_value
2285+
assert command.args.get("using-brand") == brand_name
2286+
seen["ok"] = True
2287+
return ([], [])
2288+
2289+
mocker.patch(f"GetUserData.{adapter_fn}", side_effect=_assert_adapter)
2290+
main()
2291+
assert seen["ok"] is True
2292+
2293+
2294+
# ---------- Email flows ----------
2295+
@pytest.mark.parametrize(
2296+
"brand_name,command_name,adapter_fn,expected_key,expected_value",
2297+
[
2298+
("Active Directory Query v2", "ad-get-user", "ad_get_user", "email", "[email protected]"),
2299+
("Okta IAM", "iam-get-user", "iam_get_user", "user-profile", '{"email":"[email protected]"}'),
2300+
("AWS-ILM", "iam-get-user", "iam_get_user", "user-profile", '{"email":"[email protected]"}'),
2301+
("GSuiteAdmin", "gsuite-user-get", "gsuite_get_user", "user", "[email protected]"),
2302+
],
2303+
)
2304+
def test_email_arg_mapping_to_adapter(mocker: MockerFixture, brand_name, command_name, adapter_fn, expected_key, expected_value):
2305+
"""
2306+
Given:
2307+
- calling get-user-data with user_email = [email protected].
2308+
- brand_name = brand_name.
2309+
When:
2310+
- main() executes by email flows.
2311+
Then:
2312+
- The right command is being called with the right argument name.
2313+
"""
2314+
mocker.patch.object(demisto, "args", return_value={"user_email": ["[email protected]"]})
2315+
mocker.patch.object(demisto, "getModules", return_value={})
2316+
mocker.patch.object(Modules, "is_brand_in_brands_to_run", return_value=True)
2317+
mocker.patch.object(Modules, "is_brand_available", return_value=True)
2318+
mocker.patch("GetUserData.get_core_and_xdr_data", return_value=([], []))
2319+
mocker.patch("GetUserData.return_results")
2320+
2321+
_mute_all_other_adapters(mocker, except_fn=adapter_fn)
2322+
seen = {"ok": False}
2323+
2324+
def _assert_adapter(command: Command, additional_fields: bool):
2325+
if command.brand != brand_name or command.name != command_name:
2326+
return ([], [])
2327+
assert command.args.get(expected_key) == expected_value
2328+
assert command.args.get("using-brand") == brand_name
2329+
seen["ok"] = True
2330+
return ([], [])
2331+
2332+
mocker.patch(f"GetUserData.{adapter_fn}", side_effect=_assert_adapter)
2333+
main()
2334+
assert seen["ok"] is True

Packs/AggregatedScripts/pack_metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "Aggregated Scripts",
33
"description": "A pack containing all aggregated scripts.",
44
"support": "xsoar",
5-
"currentVersion": "1.1.13",
5+
"currentVersion": "1.1.14",
66
"author": "Cortex XSOAR",
77
"url": "https://www.paloaltonetworks.com/cortex",
88
"email": "",

0 commit comments

Comments
 (0)