Skip to content
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ in development
Fixed
~~~~~

* Fix deserialization bug for url encoded payloads. #5513

Contributed by @sravs-dev

* Fix Type error for ``time_diff`` critera comparison. convert the timediff value as float to match
``timedelta.total_seconds()`` return. #5462

Expand Down
10 changes: 3 additions & 7 deletions st2api/tests/unit/controllers/v1/test_webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,22 +262,18 @@ def test_json_request_body(self, dispatch_mock):
)
@mock.patch("st2common.transport.reactor.TriggerDispatcher.dispatch")
def test_form_encoded_request_body(self, dispatch_mock):
return
# TODO: Fix on deserialization on API side, body dict values being decoded as bytes
# instead of unicode which breakgs things. Likely issue / bug with form urlencoding
# parsing or perhaps in the test client when sending data
# Send request body as form urlencoded data
data = {"form": ["test"]}

headers = {
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"St2-Trace-Tag": "tag1",
}

self.app.post("/v1/webhooks/git", data, headers=headers)
post_resp = self.app.post("/v1/webhooks/git", data, headers=headers)
self.assertEqual(post_resp.status_int, http_client.ACCEPTED)
self.assertEqual(
dispatch_mock.call_args[1]["payload"]["headers"]["Content-Type"],
"application/x-www-form-urlencoded",
"application/x-www-form-urlencoded; charset=UTF-8",
)
self.assertEqual(dispatch_mock.call_args[1]["payload"]["body"], data)
self.assertEqual(dispatch_mock.call_args[1]["trace_context"].trace_tag, "tag1")
Expand Down
11 changes: 11 additions & 0 deletions st2auth/tests/unit/controllers/v1/test_sso.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,17 @@ def test_idp_callback(self):
self.assertIn("token", st2_auth_token)
self.assertEqual(st2_auth_token["user"], MOCK_USER)

@mock.patch.object(
sso_api_controller.SSO_BACKEND,
"verify_response",
mock.MagicMock(return_value={"referer": MOCK_REFERER, "username": MOCK_USER}),
)
def test_callback_url_encoded_payload(self):
data = {"foo": ["bar"]}
headers = {"Content-Type": "application/x-www-form-urlencoded"}
response = self.app.post(SSO_CALLBACK_V1_PATH, data, headers=headers)
self.assertTrue(response.status_code, http_client.OK)

@mock.patch.object(
sso_api_controller.SSO_BACKEND,
"verify_response",
Expand Down
2 changes: 1 addition & 1 deletion st2common/st2common/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ def __call__(self, req):
"application/x-www-form-urlencoded",
"multipart/form-data",
]:
data = urlparse.parse_qs(req.body)
data = urlparse.parse_qs(six.ensure_str(req.body))
else:
raise ValueError(
'Unsupported Content-Type: "%s"' % (content_type)
Expand Down