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

CiscoSMA- Added timeout parameter #29372

Merged
merged 20 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions Packs/CiscoSMA/Integrations/CiscoSMA/CiscoSMA.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ class Client(BaseClient):
"""Client class to interact with Cisco SMA API."""

def __init__(
self, server_url: str, username: str, password: str, verify: bool, proxy: bool
self, server_url: str, username: str, password: str, verify: bool, proxy: bool, timeout: None | int = 60
):
super().__init__(base_url=server_url, headers={}, verify=verify, proxy=proxy)
super().__init__(base_url=server_url, headers={}, verify=verify, proxy=proxy, timeout=timeout)
self.username = username
self.password = password
self.handle_request_headers()
Expand Down Expand Up @@ -73,7 +73,7 @@ def retrieve_jwt_token(self) -> str:
return dict_safe_get(response, ["data", "jwtToken"])

except DemistoException as e:
if e.res.status_code == 401:
if hasattr(e.res, 'status_code') and e.res.status_code == 401:
raise Exception(
"Authorization Error: make sure username and password are set correctly."
)
Expand Down Expand Up @@ -1851,7 +1851,7 @@ def main() -> None:
filter_value = params.get("filter_value")
recipient_filter_operator = params.get("recipient_filter_operator")
recipient_filter_value = params.get("recipient_filter_value")

timeout = arg_to_number(params.get("timeout")) if params.get("timeout") else None
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
timeout = arg_to_number(params.get("timeout")) if params.get("timeout") else None
timeout = arg_to_number(params.get("timeout"))

arg_to_number returns None when None is passed, which means we do not need to check if it is None (Also the default value of get it None)

verify_certificate: bool = not params.get("insecure", False)
proxy = params.get("proxy", False)

Expand Down Expand Up @@ -1880,6 +1880,7 @@ def main() -> None:
password,
verify_certificate,
proxy,
timeout=timeout
)

if command == "test-module":
Expand Down
5 changes: 5 additions & 0 deletions Packs/CiscoSMA/Integrations/CiscoSMA/CiscoSMA.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ configuration:
type: 0
additionalinfo: Recipient filter value to fetch by message field.
required: false
- name: timeout
display: Timeout
type: 0
additionalinfo: Timeout for the integration HTTP requests in seconds.
sapirshuker marked this conversation as resolved.
Show resolved Hide resolved
required: false
sapirshuker marked this conversation as resolved.
Show resolved Hide resolved
- name: proxy
display: Use system proxy settings
defaultvalue: 'false'
Expand Down
64 changes: 64 additions & 0 deletions Packs/CiscoSMA/Integrations/CiscoSMA/CiscoSMA_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ def test_message_search_command(
assert len(outputs) == expected_outputs_len
assert outputs[0]["mid"] == expected_message_id
assert outputs[1]["recipient"] == expected_recipients
assert mock_request.last_request.timeout == 60


@pytest.mark.parametrize(
Expand Down Expand Up @@ -872,3 +873,66 @@ def test_format_timestamp(timestamp, output_format, expected_result):
result = format_timestamp(timestamp, output_format)

assert result == expected_result


@pytest.mark.parametrize(
"response_file_name,command_arguments,expected_outputs_len,expected_message_id,expected_recipients,requested_params",
[
(
"message_search.json",
{
"start_date": "2 weeks",
"end_date": "1 day",
"page": "2",
"page_size": "4",
"recipient_filter_operator": "is",
"recipient_filter_value": "test@test.com",
"timeout": "90"
},
4,
[315],
["test@test.com"],
"test%40test.com",
),
],
)
sapirshuker marked this conversation as resolved.
Show resolved Hide resolved
@patch("CiscoSMA.Client.handle_request_headers", mock_access_token)
def test_test_message_search_command_with_timout(
response_file_name,
command_arguments,
expected_outputs_len,
expected_message_id,
expected_recipients,
requested_params,
requests_mock
):
"""
Scenario: Tracking message search.
Given:
- User has provided valid credentials.
- User may provided pagination args.
- User may Provided filtering arguments.
When:
- cisco-sma-message-search command called.
Then:
- Ensure outputs prefix is correct.
- Ensure number of items is correct.
- Ensure that the timeout argument was sent.
- Validate outputs' fields.
"""
from CiscoSMA import message_search_command
from CiscoSMA import Client
mock_client = Client(BASE_URL, USERNAME, PASSWORD, verify=False, proxy=False, timeout=90)
mock_response = load_mock_response(response_file_name)
url = f"{BASE_URL}/message-tracking/messages"
mock_request = requests_mock.get(url=url, json=mock_response)

result = message_search_command(mock_client, command_arguments)
outputs = result.outputs

assert requested_params in mock_request.last_request.query
assert result.outputs_prefix == "CiscoSMA.Message"
assert len(outputs) == expected_outputs_len
assert outputs[0]["mid"] == expected_message_id
assert outputs[1]["recipient"] == expected_recipients
assert mock_request.last_request.timeout == 90
1 change: 1 addition & 0 deletions Packs/CiscoSMA/Integrations/CiscoSMA/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ This integration was integrated and tested with version 12.0 of Cisco Security M
| Filter value | The value to search for. | False |
| Recipient filter operator | Recipient operator filter. | False |
| Recipient filter value | Recipient filter value to fetch by message field. | False |
| Timeout | Timeout for the integration HTTP requests in seconds. | False |
sapirshuker marked this conversation as resolved.
Show resolved Hide resolved
| Use system proxy settings | | False |
| Trust any certificate (not secure) | | False |
| Incident type | | False |
Expand Down
5 changes: 5 additions & 0 deletions Packs/CiscoSMA/ReleaseNotes/1_1_19.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

#### Integrations

##### Cisco Security Management Appliance
- Added support for the *timeout* integration parameter.
2 changes: 1 addition & 1 deletion Packs/CiscoSMA/pack_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "CiscoSMA",
"description": "The Security Management Appliance (SMA) is used to centralize services from Email Security Appliances (ESAs) and Web Security Appliances (WSAs).",
"support": "xsoar",
"currentVersion": "1.1.18",
"currentVersion": "1.1.19",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down