@@ -209,8 +209,11 @@ def test_django_request_body_plain_attack(client, test_spans, tracer):
209209 assert query == "1' or '1' = '1'"
210210
211211
212- def test_django_request_body_json_empty (caplog , client , test_spans , tracer ):
213- with caplog .at_level (logging .WARNING ), override_global_config (dict (_appsec_enabled = True )), override_env (
212+ def test_django_request_body_json_bad (caplog , client , test_spans , tracer ):
213+ # Note: there is some odd interaction between hypotheses or pytest and
214+ # caplog where if you set this to WARNING the second test won't get
215+ # output unless you set all to DEBUG.
216+ with caplog .at_level (logging .DEBUG ), override_global_config (dict (_appsec_enabled = True )), override_env (
214217 dict (DD_APPSEC_RULES = RULES_GOOD_PATH )
215218 ):
216219 payload = '{"attack": "bad_payload",}'
@@ -227,6 +230,23 @@ def test_django_request_body_json_empty(caplog, client, test_spans, tracer):
227230 assert "Failed to parse request body" in caplog .text
228231
229232
233+ def test_django_request_body_xml_bad_logs_warning (caplog , client , test_spans , tracer ):
234+ # see above about caplog
235+ with caplog .at_level (logging .DEBUG ), override_global_config (dict (_appsec_enabled = True )), override_env (
236+ dict (DD_APPSEC_RULES = RULES_GOOD_PATH )
237+ ):
238+ _ , response = _aux_appsec_get_root_span (
239+ client ,
240+ test_spans ,
241+ tracer ,
242+ payload = "bad xml" ,
243+ content_type = "application/xml" ,
244+ )
245+
246+ assert response .status_code == 200
247+ assert "Failed to parse request body" in caplog .text
248+
249+
230250def test_django_path_params (client , test_spans , tracer ):
231251 with override_global_config (dict (_appsec_enabled = True )):
232252 root_span , _ = _aux_appsec_get_root_span (
0 commit comments