Skip to content

Commit

Permalink
Cisco SMA fixed spaces encoding in query params (demisto#29068)
Browse files Browse the repository at this point in the history
* Added quote_params_via in message_search command

* RN

* params_parser

* pre-commit

* RN
  • Loading branch information
MosheEichler authored and xsoar-bot committed Oct 5, 2023
1 parent c0c162e commit 34fd795
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
15 changes: 6 additions & 9 deletions Packs/CiscoSMA/Integrations/CiscoSMA/CiscoSMA.py
@@ -1,6 +1,6 @@
import demistomock as demisto # noqa: F401
from CommonServerPython import * # noqa: F401
from typing import Callable, Tuple
from collections.abc import Callable

import uuid

Expand Down Expand Up @@ -460,7 +460,7 @@ def message_search_request(
**format_custom_query_args(custom_query),
)

return self._http_request("GET", "message-tracking/messages", params=params)
return self._http_request("GET", "message-tracking/messages", params=params, params_parser=urllib.parse.quote)

def message_details_get_request(
self,
Expand Down Expand Up @@ -614,12 +614,9 @@ def format_custom_query_args(custom_query: str = None) -> Dict[str, Any]:
"""
try:
if custom_query:
return {
key: value
for key, value in (
field.split("=") for field in custom_query.split(";")
)
}
return dict(
field.split("=") for field in custom_query.split(";")
)
else:
return {}
except ValueError:
Expand Down Expand Up @@ -769,7 +766,7 @@ def format_list_entry_arguments(view_by: str, args: Dict[str, Any]) -> Dict[str,
return args


def pagination(request_command: Callable, args: Dict[str, Any], **kwargs) -> Tuple:
def pagination(request_command: Callable, args: Dict[str, Any], **kwargs) -> tuple:
"""
Executing Manual Pagination (using the page and page size arguments)
or Automatic Pagination (display a number of total results).
Expand Down
2 changes: 1 addition & 1 deletion Packs/CiscoSMA/Integrations/CiscoSMA/CiscoSMA.yml
Expand Up @@ -94,7 +94,7 @@ script:
script: ''
type: python
subtype: python3
dockerimage: demisto/python3:3.10.12.68714
dockerimage: demisto/python3:3.10.13.72123
isfetch: true
commands:
- name: cisco-sma-spam-quarantine-message-search
Expand Down
12 changes: 9 additions & 3 deletions Packs/CiscoSMA/Integrations/CiscoSMA/CiscoSMA_test.py
Expand Up @@ -24,7 +24,7 @@ def load_mock_response(file_name: str) -> str:
str: Mock file content.
"""
with open(
os.path.join("test_data/outputs", file_name), mode="r", encoding="utf-8"
os.path.join("test_data/outputs", file_name), encoding="utf-8"
) as mock_file:
return json.loads(mock_file.read())

Expand Down Expand Up @@ -452,18 +452,21 @@ def test_list_entry_delete_command(


@pytest.mark.parametrize(
"response_file_name,command_arguments,expected_outputs_len,expected_message_id,expected_recipients",
"response_file_name,command_arguments,expected_outputs_len,expected_message_id,expected_recipients,requested_params",
[
(
"message_search.json",
{
"start_date": "1 week",
"end_date": "now",
"limit": "4",
"subject_filter_operator": "contains",
"subject_filter_value": "bla bla",
},
4,
[315],
["test@test.com"],
"bla%20bla",
),
(
"message_search.json",
Expand All @@ -478,6 +481,7 @@ def test_list_entry_delete_command(
4,
[315],
["test@test.com"],
"test%40test.com",
),
],
)
Expand All @@ -487,6 +491,7 @@ def test_message_search_command(
expected_outputs_len,
expected_message_id,
expected_recipients,
requested_params,
requests_mock,
mock_client,
):
Expand All @@ -507,11 +512,12 @@ def test_message_search_command(

mock_response = load_mock_response(response_file_name)
url = f"{BASE_URL}/message-tracking/messages"
requests_mock.get(url=url, json=mock_response)
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
Expand Down
5 changes: 5 additions & 0 deletions Packs/CiscoSMA/ReleaseNotes/1_1_18.md
@@ -0,0 +1,5 @@

#### Integrations
##### Cisco Security Management Appliance
- Updated the Docker image to: *demisto/python3:3.10.13.72123*.
- Fixed an issue where the ***cisco-sma-message-search*** command with the **subject_filter_operator** argument did not filter the message correctly.
2 changes: 1 addition & 1 deletion Packs/CiscoSMA/pack_metadata.json
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.17",
"currentVersion": "1.1.18",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down

0 comments on commit 34fd795

Please sign in to comment.