Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

from __future__ import annotations

import urllib.parse

from typing import TYPE_CHECKING

from TIPCommon.consts import DATAPLANE_1P_HEADER, DEFAULT_1P_PAGE_SIZE
Expand Down Expand Up @@ -390,7 +392,7 @@ def get_traking_list_record(self) -> SingleJson:
base_endpoint = "/system/settings/customLists"

if filter_string:
initial_endpoint = f"{base_endpoint}?$filter={filter_string}&pageSize={_PAGE_SIZE}"
initial_endpoint = f"{base_endpoint}?$filter={urllib.parse.quote(filter_string)}&pageSize={_PAGE_SIZE}"
else:
initial_endpoint = f"{base_endpoint}?pageSize={_PAGE_SIZE}"

Expand All @@ -411,7 +413,7 @@ def get_traking_list_records_filtered(self) -> SingleJson:
base_endpoint = "/system/settings/customLists"

if filter_string:
initial_endpoint = f"{base_endpoint}?$filter={filter_string}&pageSize={_PAGE_SIZE}"
initial_endpoint = f"{base_endpoint}?$filter={urllib.parse.quote(filter_string)}&pageSize={_PAGE_SIZE}"
else:
initial_endpoint = f"{base_endpoint}?pageSize={_PAGE_SIZE}"

Expand Down Expand Up @@ -845,7 +847,7 @@ def get_cases_by_timestamp_filter(self) -> list[SingleJson]:

base_endpoint = "/cases"
initial_endpoint = (
f"{base_endpoint}?$filter={filter_string}"
f"{base_endpoint}?$filter={urllib.parse.quote(filter_string)}"
"&$select=id, updateTime"
"&$expand=tags"
f"&pageSize={_PAGE_SIZE}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,3 +369,68 @@ def test_save_or_update_job_invalid_resource_path(

assert "Cannot parse resource path" in str(exc_info.value)
assert 'Invalid parameter "name"' in str(exc_info.value)


def test_get_traking_list_records_filtered_url_encoded(
mocker: MockerFixture, mock_chronicle_soar: MagicMock, mock_get_sdk_api_uri: MagicMock
) -> None:
"""Test get_traking_list_records_filtered URL-encodes special characters in OData filter."""
import urllib.parse

client = OnePlatformSoarApi(mock_chronicle_soar)
params: Any = client.params
params.environment = "Indevis GmbH & Co. KG"
params.category_name = "Indevis_Test_&_München"
params.entity_id = "192.168.1.100"

mock_response = mocker.MagicMock()
mock_response.status_code = 200
mock_response.json.return_value = {"customLists": [{"id": "list_1"}], "nextPageToken": None}
mock_chronicle_soar.session.request.return_value = mock_response

records = client.get_traking_list_records_filtered()

assert records == [{"id": "list_1"}]
expected_filter = client._build_tracking_list_filter_string(
params.category_name, params.entity_id, environment=params.environment
)
expected_url = (
f"https://mock-soar-api.com/system/settings/customLists?$filter={urllib.parse.quote(expected_filter)}&pageSize=1000"
)
mock_chronicle_soar.session.request.assert_called_once_with(
"GET",
expected_url,
params=None,
json=None,
)


def test_get_traking_list_record_url_encoded(
mocker: MockerFixture, mock_chronicle_soar: MagicMock, mock_get_sdk_api_uri: MagicMock
) -> None:
"""Test get_traking_list_record URL-encodes special characters in OData filter."""
import urllib.parse

client = OnePlatformSoarApi(mock_chronicle_soar)
params: Any = client.params
params.category_name = "Indevis_Test_&_München"
params.entity_id = "192.168.1.100"

mock_response = mocker.MagicMock()
mock_response.status_code = 200
mock_response.json.return_value = {"customLists": [{"id": "list_2"}], "nextPageToken": None}
mock_chronicle_soar.session.request.return_value = mock_response

records = client.get_traking_list_record()

assert records == [{"id": "list_2"}]
expected_filter = client._build_tracking_list_filter_string(params.category_name, params.entity_id)
expected_url = (
f"https://mock-soar-api.com/system/settings/customLists?$filter={urllib.parse.quote(expected_filter)}&pageSize=1000"
)
mock_chronicle_soar.session.request.assert_called_once_with(
"GET",
expected_url,
params=None,
json=None,
)