summaryrefslogtreecommitdiff
path: root/tests/servers/test_basehttp.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/servers/test_basehttp.py')
-rw-r--r--tests/servers/test_basehttp.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/servers/test_basehttp.py b/tests/servers/test_basehttp.py
index cc4701114a..9190fc8a20 100644
--- a/tests/servers/test_basehttp.py
+++ b/tests/servers/test_basehttp.py
@@ -50,6 +50,21 @@ class WSGIRequestHandlerTestCase(SimpleTestCase):
cm.records[0].levelname, wrong_level.upper()
)
+ def test_log_message_escapes_control_sequences(self):
+ request = WSGIRequest(self.request_factory.get("/").environ)
+ request.makefile = lambda *args, **kwargs: BytesIO()
+ handler = WSGIRequestHandler(request, "192.168.0.2", None)
+
+ malicious_path = "\x1b[31mALERT\x1b[0m"
+
+ with self.assertLogs("django.server", "WARNING") as cm:
+ handler.log_message("GET %s %s", malicious_path, "404")
+
+ log = cm.output[0]
+
+ self.assertNotIn("\x1b[31m", log)
+ self.assertIn("\\x1b[31mALERT\\x1b[0m", log)
+
def test_https(self):
request = WSGIRequest(self.request_factory.get("/").environ)
request.makefile = lambda *args, **kwargs: BytesIO()