@@ -207,8 +207,11 @@ def test_django_request_body_plain_attack(client, test_spans, tracer):
207207 assert query == "1' or '1' = '1'"
208208
209209
210- def test_django_request_body_json_empty (caplog , client , test_spans , tracer ):
211- with caplog .at_level (logging .WARNING ), override_global_config (dict (_appsec_enabled = True )), override_env (
210+ def test_django_request_body_json_bad (caplog , client , test_spans , tracer ):
211+ # Note: there is some odd interaction between hypotheses or pytest and
212+ # caplog where if you set this to WARNING the second test won't get
213+ # output unless you set all to DEBUG.
214+ with caplog .at_level (logging .DEBUG ), override_global_config (dict (_appsec_enabled = True )), override_env (
212215 dict (DD_APPSEC_RULES = RULES_GOOD_PATH )
213216 ):
214217 payload = '{"attack": "bad_payload",}'
@@ -225,6 +228,23 @@ def test_django_request_body_json_empty(caplog, client, test_spans, tracer):
225228 assert "Failed to parse request body" in caplog .text
226229
227230
231+ def test_django_request_body_xml_bad_logs_warning (caplog , client , test_spans , tracer ):
232+ # see above about caplog
233+ with caplog .at_level (logging .DEBUG ), override_global_config (dict (_appsec_enabled = True )), override_env (
234+ dict (DD_APPSEC_RULES = RULES_GOOD_PATH )
235+ ):
236+ _ , response = _aux_appsec_get_root_span (
237+ client ,
238+ test_spans ,
239+ tracer ,
240+ payload = "bad xml" ,
241+ content_type = "application/xml" ,
242+ )
243+
244+ assert response .status_code == 200
245+ assert "Failed to parse request body" in caplog .text
246+
247+
228248def test_django_path_params (client , test_spans , tracer ):
229249 with override_global_config (dict (_appsec_enabled = True )):
230250 root_span , _ = _aux_appsec_get_root_span (
0 commit comments