Skip to content
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

[XSUP 31458] Fix test-module in PANW Enterprise DLP #31983

Merged
merged 13 commits into from
Jan 10, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def __init__(self, url, credentials, insecure, proxy):
self.refresh_token = credentials[PASSWORD]
else:
self.access_token = ''
self._refresh_token_with_client_credentials()

def _refresh_token(self):
"""Refreshes Access Token"""
Expand Down Expand Up @@ -108,7 +109,7 @@ def _refresh_token_with_client_credentials(self):

except Exception as e:
print_debug_msg(str(e))
raise
raise e

def _handle_403_errors(self, res):
"""
Expand Down Expand Up @@ -225,7 +226,7 @@ def get_dlp_incidents(self, regions: str, start_time: int = None, end_time: int
query_string = urllib.parse.urlencode(params)
url = f"{url}?{query_string}"
resp, status_code = self._get_dlp_api_call(url)
return resp
return resp, status_code

def update_dlp_incident(self, incident_id: str, feedback: FeedbackStatus, user_id: str, region: str,
report_id: str, dlp_channel: str, error_details: str = None):
Expand Down Expand Up @@ -356,13 +357,19 @@ def parse_dlp_report(report_json) -> CommandResults:
)


def test(client):
def test(client: Client, params: dict):
""" Test Function to test validity of access and refresh tokens"""
report_json, status_code = client.get_dlp_report('1')
dlp_regions = params.get("dlp_regions")
report_json, status_code = client.get_dlp_incidents(regions=dlp_regions)
if status_code in [200, 204]:
return_results("ok")
else:
raise DemistoException(f"Integration test failed: Unexpected status ({status_code})")
message = f"Integration test failed: Unexpected status ({status_code}) - "
if "error" in report_json:
message += f"Error message: \"{report_json.get('error')}\""
else:
message += f"The DLP Regions \"{dlp_regions}\" might be invalid, please check them again."
yaakovpraisler marked this conversation as resolved.
Show resolved Hide resolved
raise DemistoException(message)


def print_debug_msg(msg: str):
Expand Down Expand Up @@ -447,7 +454,7 @@ def fetch_incidents(client: Client, regions: str, start_time: int = None, end_ti
else:
print_debug_msg('Start fetching most recent incidents')

notification_map = client.get_dlp_incidents(regions=regions, start_time=start_time, end_time=end_time)
notification_map, _ = client.get_dlp_incidents(regions=regions, start_time=start_time, end_time=end_time)
incidents = []
for region, notifications in notification_map.items():
for notification in notifications:
Expand Down Expand Up @@ -620,7 +627,7 @@ def main():
elif demisto.command() == 'pan-dlp-reset-last-run':
return_results(reset_last_run_command())
elif demisto.command() == "test-module":
test(client)
test(client, params)

except Exception as e:
return_error(f'Failed to execute {demisto.command()} command.\nError:\n{str(e)}')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ configuration:
- EU
- AP
- UK
defaultvalue: US,EU,AP,UK
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if a customer didn't configure this param because the default value fitted for him, and upgrades to your version?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my case it took the supported region in my DLP env (US), so I guess it will return the result for the support regions for the customers as well.

required: false
- display: Data profiles to allow exemption
name: dlp_exemptible_list
Expand Down
3 changes: 3 additions & 0 deletions Packs/Palo_Alto_Networks_Enterprise_DLP/ReleaseNotes/2_0_8.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#### Integrations

Check failure on line 1 in Packs/Palo_Alto_Networks_Enterprise_DLP/ReleaseNotes/2_0_8.md

View workflow job for this annotation

GitHub Actions / pre-commit / pre-commit

Validation Error BA125

Found internal terms in a customer-facing documentation file: test-module
##### Palo Alto Networks Enterprise DLP
- Fixed an issue where running the ***test-module*** and authenticating with the credentials option.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"support": "xsoar",
"author": "Palo Alto Networks Enterprise DLP",
"url": "https://www.paloaltonetworks.com/enterprise-data-loss-prevention",
"currentVersion": "2.0.7",
"currentVersion": "2.0.8",
"categories": [
"Network Security"
],
Expand Down