From 3ef63ee3d80700f42ad7d2f7d763fd60cc5ae2b3 Mon Sep 17 00:00:00 2001 From: Nathan Oyler Date: Fri, 31 Jan 2025 11:40:04 -0700 Subject: [PATCH 1/3] handle payload json string to dict, type check --- auditmiddleware/_api.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/auditmiddleware/_api.py b/auditmiddleware/_api.py index 1d97234..45a81da 100644 --- a/auditmiddleware/_api.py +++ b/auditmiddleware/_api.py @@ -776,7 +776,26 @@ def _get_action_from_payload(self, request, res_spec, res_id): """Determine the CADF action from the payload.""" try: payload = request.json + + # Handle case where payload is a string (JSON-encoded) + if isinstance(payload, str): + try: + payload = json.loads(payload) + except json.JSONDecodeError: + self._log.warning( + "Invalid JSON string payload for path: %s", + request.path) + return None + if payload: + # Type checking for payload + if not isinstance(payload, dict): + self._log.warning( + "Unexpected payload type %s for path: %s", + type(payload), request.path + ) + return None + rest_action = next(iter(payload)) # check for individual mapping of action action = res_spec.custom_actions.get(rest_action) From 0053eb6e3a0348d889ffca59bb7e571279ee04d5 Mon Sep 17 00:00:00 2001 From: Nathan Oyler Date: Fri, 31 Jan 2025 11:54:27 -0700 Subject: [PATCH 2/3] add pytz to test-requirements.txt --- test-requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/test-requirements.txt b/test-requirements.txt index 4737ee8..c061f4a 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -11,6 +11,7 @@ coverage!=4.4,>=4.0 # Apache-2.0 fixtures>=3.0.0 # Apache-2.0/BSD mock>=3.0.0 # BSD oslotest>=3.8.0 # Apache-2.0 +pytz==2025.1 # MIT requests-mock>=1.2.0 # Apache-2.0 #stevedore>=1.20.0 # Apache-2.0 stestr>=2.0.0 # Apache-2.0 From 7ae2293cb404968a8206deee9dcf4a8fd0ba6f84 Mon Sep 17 00:00:00 2001 From: Nathan Oyler Date: Fri, 31 Jan 2025 11:58:21 -0700 Subject: [PATCH 3/3] update pytx to 2024.2 --- test-requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-requirements.txt b/test-requirements.txt index c061f4a..e0ed2a9 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -11,7 +11,7 @@ coverage!=4.4,>=4.0 # Apache-2.0 fixtures>=3.0.0 # Apache-2.0/BSD mock>=3.0.0 # BSD oslotest>=3.8.0 # Apache-2.0 -pytz==2025.1 # MIT +pytz==2024.2 # MIT requests-mock>=1.2.0 # Apache-2.0 #stevedore>=1.20.0 # Apache-2.0 stestr>=2.0.0 # Apache-2.0