Skip to content

Commit

Permalink
CiscoSMA- Added timeout parameter (demisto#29372)
Browse files Browse the repository at this point in the history
* fix

* add_tests

* fix_test_description

* fix_yml_add_readme

* fixes - add timeout to the client

* add timeout to yml

* revert changes

* Update CiscoSMA.py

* Update CiscoSMA.py

* CR review

* add RN

* fix CR review

* update docker image
  • Loading branch information
sapirshuker authored and xsoar-bot committed Oct 5, 2023
1 parent 67941e5 commit ef29049
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 6 deletions.
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"))
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
8 changes: 7 additions & 1 deletion Packs/CiscoSMA/Integrations/CiscoSMA/CiscoSMA.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ configuration:
type: 0
additionalinfo: Recipient filter value to fetch by message field.
required: false
- name: timeout
display: Timeout
type: 0
defaultvalue: '60'
additionalinfo: HTTP requests timeout in seconds. The default is 60 seconds.
required: false
- name: proxy
display: Use system proxy settings
defaultvalue: 'false'
Expand All @@ -94,7 +100,7 @@ script:
script: ''
type: python
subtype: python3
dockerimage: demisto/python3:3.10.13.73190
dockerimage: demisto/python3:3.10.13.74666
isfetch: true
commands:
- name: cisco-sma-spam-quarantine-message-search
Expand Down
44 changes: 44 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,46 @@ def test_format_timestamp(timestamp, output_format, expected_result):
result = format_timestamp(timestamp, output_format)

assert result == expected_result


@patch("CiscoSMA.Client.handle_request_headers", mock_access_token)
def test_message_search_command_with_timout(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("message_search.json")
url = f"{BASE_URL}/message-tracking/messages"
mock_request = requests_mock.get(url=url, json=mock_response)

result = message_search_command(mock_client,
{
"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"
})
outputs = result.outputs

assert "test%40test.com" in mock_request.last_request.query
assert result.outputs_prefix == "CiscoSMA.Message"
assert len(outputs) == 4
assert outputs[0]["mid"] == [315]
assert outputs[1]["recipient"] == ["test@test.com"]
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 | HTTP requests timeout in seconds. The default is 60 seconds. | False |
| Use system proxy settings | | False |
| Trust any certificate (not secure) | | False |
| Incident type | | False |
Expand Down
6 changes: 6 additions & 0 deletions Packs/CiscoSMA/ReleaseNotes/1_1_20.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#### Integrations

##### Cisco Security Management Appliance
- Added support for the *timeout* integration parameter.
- Updated the Docker image to: *demisto/python3:3.10.13.74666*.
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.19",
"currentVersion": "1.1.20",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down

0 comments on commit ef29049

Please sign in to comment.