summaryrefslogtreecommitdiff
path: root/tests/httpwrappers
diff options
context:
space:
mode:
authorKeryn Knight <keryn@kerynknight.com>2022-02-09 16:05:23 +0000
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-03-02 20:23:39 +0100
commit9bde906fb2b8f63f056284347c660a3fec92ef34 (patch)
tree035fb0fc87128094030a3b10de8d9d9df3b5119c /tests/httpwrappers
parentd436554861b9b818994276d7bf110bf03aa565f5 (diff)
downloaddjango-9bde906fb2b8f63f056284347c660a3fec92ef34.tar.gz
Refs #10188 -- Added tests for BadHeaderErrors when HTTP header with newlines cannot be encoded/decoded.
Diffstat (limited to 'tests/httpwrappers')
-rw-r--r--tests/httpwrappers/tests.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/httpwrappers/tests.py b/tests/httpwrappers/tests.py
index f68524a484..7ee20f9ce9 100644
--- a/tests/httpwrappers/tests.py
+++ b/tests/httpwrappers/tests.py
@@ -364,6 +364,27 @@ class HttpResponseTests(SimpleTestCase):
with self.assertRaises(BadHeaderError):
r.headers.__setitem__("test\nstr", "test")
+ def test_encoded_with_newlines_in_headers(self):
+ """
+ Keys & values which throw a UnicodeError when encoding/decoding should
+ still be checked for newlines and re-raised as a BadHeaderError.
+ These specifically would still throw BadHeaderError after decoding
+ successfully, because the newlines are sandwiched in the middle of the
+ string and email.Header leaves those as they are.
+ """
+ r = HttpResponse()
+ pairs = (
+ ("†\nother", "test"),
+ ("test", "†\nother"),
+ (b"\xe2\x80\xa0\nother", "test"),
+ ("test", b"\xe2\x80\xa0\nother"),
+ )
+ msg = "Header values can't contain newlines"
+ for key, value in pairs:
+ with self.subTest(key=key, value=value):
+ with self.assertRaisesMessage(BadHeaderError, msg):
+ r[key] = value
+
def test_dict_behavior(self):
"""
Test for bug #14020: Make HttpResponse.get work like dict.get