Skip to content

Commit

Permalink
GetUserData - adding an 'attributes' parameter (#37908)
Browse files Browse the repository at this point in the history
* add AD attributes to the GetUserData.py script when running 'ad-get-user' command

* RN

* add UT

* Update Packs/CommonScripts/Scripts/GetUserData/GetUserData.yml

Co-authored-by: JudithB <[email protected]>

* Update Packs/CommonScripts/ReleaseNotes/1_19_1.md

Co-authored-by: JudithB <[email protected]>

* CR

---------

Co-authored-by: JudithB <[email protected]>
  • Loading branch information
rshunim and jbabazadeh authored Jan 2, 2025
1 parent 6718704 commit 95e613f
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 2 deletions.
6 changes: 6 additions & 0 deletions Packs/CommonScripts/ReleaseNotes/1_19_1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#### Scripts

##### get-user-data

- Added the **attributes** parameter to the ***ad-get-user*** command in this script to retrieve additional user information.
3 changes: 2 additions & 1 deletion Packs/CommonScripts/Scripts/GetUserData/GetUserData.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,7 @@ def main():
users_ids = argToList(args.get("user_id", []))
users_names = argToList(args.get("user_name", []))
users_emails = argToList(args.get("user_email", []))
attributes = args.get("attributes")
domain = args.get("domain", "")
verbose = argToBoolean(args.get("verbose", False))
brands_to_run = argToList(args.get("brands", []))
Expand Down Expand Up @@ -771,7 +772,7 @@ def main():
ad_get_user_command = Command(
brand="Active Directory Query v2",
name="ad-get-user",
args={"username": user_name, "email": user_email},
args={"username": user_name, "email": user_email, "attributes": attributes},
)
if modules.is_brand_available(ad_get_user_command) and is_valid_args(
ad_get_user_command
Expand Down
2 changes: 2 additions & 0 deletions Packs/CommonScripts/Scripts/GetUserData/GetUserData.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ args:
- description: List of emails of the users to retrieve.
name: user_email
isArray: true
- description: list of AD user's attributes to retrieve, separated by comma.
name: attributes
- description: The domain to retrieve users from. Available only for the iam-get-user command.
name: domain
- description: |-
Expand Down
54 changes: 54 additions & 0 deletions Packs/CommonScripts/Scripts/GetUserData/GetUserData_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,60 @@ def test_ad_get_user(self, mocker: MockerFixture):
assert result[1] == expected_account
assert result[2] == "CN=Manager,OU=Users,DC=example,DC=com"

def test_ad_get_user_attributes(self, mocker: MockerFixture):
"""
Given:
A Command object for ad_get_user.
When:
The function is called with the Command object and attributes.
Then:
It returns the expected tuple of readable outputs, account output, and manager DN.
"""
command = Command(
"Active Directory Query v2", "ad-get-user", {"username": "ad_user", "attributes": "whenCreated"}
)
mock_outputs = {
"sAMAccountName": "ad_user",
"displayName": "AD User",
"mail": "[email protected]",
"memberOf": ["Group1"],
"userAccountControlFields": {"ACCOUNTDISABLE": False},
"manager": ["CN=Manager,OU=Users,DC=example,DC=com"],
"whenCreated": ["2024-11-05 09:11:18+00:00"]
}
expected_account = {
"username": {"Value": "ad_user", "Source": "Active Directory Query v2"},
"display_name": {"Value": "AD User", "Source": "Active Directory Query v2"},
"email_address": {
"Value": "[email protected]",
"Source": "Active Directory Query v2",
},
"groups": {"Value": "Group1", "Source": "Active Directory Query v2"},
"is_enabled": {"Value": True, "Source": "Active Directory Query v2"},
"whenCreated": {'Source': 'Active Directory Query v2',
'Value': '2024-11-05 09:11:18+00:00'}
}

mocker.patch(
"GetUserData.run_execute_command",
return_value=([mock_outputs], "Human readable output", []),
)
mocker.patch("GetUserData.get_output_key", return_value="ActiveDirectory.Users")
mocker.patch("GetUserData.get_outputs", return_value=mock_outputs)
mocker.patch("GetUserData.prepare_human_readable", return_value=[])

result = ad_get_user(command)

assert isinstance(result, tuple)
assert len(result) == 3
assert isinstance(result[0], list)
assert isinstance(result[1], dict)
assert isinstance(result[2], str)
assert result[1] == expected_account
assert result[2] == "CN=Manager,OU=Users,DC=example,DC=com"
assert len(result[1])
assert "whenCreated" in result[1]

def test_ad_get_user_manager(self, mocker: MockerFixture):
"""
Given:
Expand Down
2 changes: 1 addition & 1 deletion Packs/CommonScripts/pack_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Common Scripts",
"description": "Frequently used scripts pack.",
"support": "xsoar",
"currentVersion": "1.19.0",
"currentVersion": "1.19.1",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down

0 comments on commit 95e613f

Please sign in to comment.