summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNick Pope <nick@nickpope.me.uk>2021-02-16 10:14:17 +0000
committerCarlton Gibson <carlton.gibson@noumenal.es>2021-02-19 09:15:09 +0100
commitbe8237c7cce24b06aabde0b97afce98ddabbe3b6 (patch)
treeb4a01e3e621eaf21fe64dc33c081b94c37ca1600 /tests
parent0debc6ba5b99027dccd287f8c247b328e4fe9483 (diff)
[3.2.x] Fixed CVE-2021-23336 -- Fixed web cache poisoning via django.utils.http.parse_qsl().
Diffstat (limited to 'tests')
-rw-r--r--tests/handlers/test_exception.py2
-rw-r--r--tests/requests/test_data_upload_settings.py8
-rw-r--r--tests/utils_tests/test_http.py43
3 files changed, 34 insertions, 19 deletions
diff --git a/tests/handlers/test_exception.py b/tests/handlers/test_exception.py
index 7afd4acc6b..0c1e763990 100644
--- a/tests/handlers/test_exception.py
+++ b/tests/handlers/test_exception.py
@@ -6,7 +6,7 @@ from django.test.client import FakePayload
class ExceptionHandlerTests(SimpleTestCase):
def get_suspicious_environ(self):
- payload = FakePayload('a=1&a=2;a=3\r\n')
+ payload = FakePayload('a=1&a=2&a=3\r\n')
return {
'REQUEST_METHOD': 'POST',
'CONTENT_TYPE': 'application/x-www-form-urlencoded',
diff --git a/tests/requests/test_data_upload_settings.py b/tests/requests/test_data_upload_settings.py
index f60f1850ea..44897cc9fa 100644
--- a/tests/requests/test_data_upload_settings.py
+++ b/tests/requests/test_data_upload_settings.py
@@ -11,7 +11,7 @@ TOO_MUCH_DATA_MSG = 'Request body exceeded settings.DATA_UPLOAD_MAX_MEMORY_SIZE.
class DataUploadMaxMemorySizeFormPostTests(SimpleTestCase):
def setUp(self):
- payload = FakePayload('a=1&a=2;a=3\r\n')
+ payload = FakePayload('a=1&a=2&a=3\r\n')
self.request = WSGIRequest({
'REQUEST_METHOD': 'POST',
'CONTENT_TYPE': 'application/x-www-form-urlencoded',
@@ -117,7 +117,7 @@ class DataUploadMaxNumberOfFieldsGet(SimpleTestCase):
request = WSGIRequest({
'REQUEST_METHOD': 'GET',
'wsgi.input': BytesIO(b''),
- 'QUERY_STRING': 'a=1&a=2;a=3',
+ 'QUERY_STRING': 'a=1&a=2&a=3',
})
request.GET['a']
@@ -126,7 +126,7 @@ class DataUploadMaxNumberOfFieldsGet(SimpleTestCase):
request = WSGIRequest({
'REQUEST_METHOD': 'GET',
'wsgi.input': BytesIO(b''),
- 'QUERY_STRING': 'a=1&a=2;a=3',
+ 'QUERY_STRING': 'a=1&a=2&a=3',
})
request.GET['a']
@@ -168,7 +168,7 @@ class DataUploadMaxNumberOfFieldsMultipartPost(SimpleTestCase):
class DataUploadMaxNumberOfFieldsFormPost(SimpleTestCase):
def setUp(self):
- payload = FakePayload("\r\n".join(['a=1&a=2;a=3', '']))
+ payload = FakePayload("\r\n".join(['a=1&a=2&a=3', '']))
self.request = WSGIRequest({
'REQUEST_METHOD': 'POST',
'CONTENT_TYPE': 'application/x-www-form-urlencoded',
diff --git a/tests/utils_tests/test_http.py b/tests/utils_tests/test_http.py
index 1966386e77..bd44ee307a 100644
--- a/tests/utils_tests/test_http.py
+++ b/tests/utils_tests/test_http.py
@@ -363,8 +363,8 @@ class EscapeLeadingSlashesTests(unittest.TestCase):
# TODO: Remove when dropping support for PY37. Backport of unit tests for
-# urllib.parse.parse_qsl() from Python 3.8. Copyright (C) 2020 Python Software
-# Foundation (see LICENSE.python).
+# urllib.parse.parse_qsl() from Python 3.8.8. Copyright (C) 2021 Python
+# Software Foundation (see LICENSE.python).
class ParseQSLBackportTests(unittest.TestCase):
def test_parse_qsl(self):
tests = [
@@ -388,16 +388,10 @@ class ParseQSLBackportTests(unittest.TestCase):
(b'&a=b', [(b'a', b'b')]),
(b'a=a+b&b=b+c', [(b'a', b'a b'), (b'b', b'b c')]),
(b'a=1&a=2', [(b'a', b'1'), (b'a', b'2')]),
- (';', []),
- (';;', []),
- (';a=b', [('a', 'b')]),
- ('a=a+b;b=b+c', [('a', 'a b'), ('b', 'b c')]),
- ('a=1;a=2', [('a', '1'), ('a', '2')]),
- (b';', []),
- (b';;', []),
- (b';a=b', [(b'a', b'b')]),
- (b'a=a+b;b=b+c', [(b'a', b'a b'), (b'b', b'b c')]),
- (b'a=1;a=2', [(b'a', b'1'), (b'a', b'2')]),
+ (';a=b', [(';a', 'b')]),
+ ('a=a+b;b=b+c', [('a', 'a b;b=b c')]),
+ (b';a=b', [(b';a', b'b')]),
+ (b'a=a+b;b=b+c', [(b'a', b'a b;b=b c')]),
]
for original, expected in tests:
with self.subTest(original):
@@ -422,6 +416,27 @@ class ParseQSLBackportTests(unittest.TestCase):
def test_parse_qsl_max_num_fields(self):
with self.assertRaises(ValueError):
parse_qsl('&'.join(['a=a'] * 11), max_num_fields=10)
- with self.assertRaises(ValueError):
- parse_qsl(';'.join(['a=a'] * 11), max_num_fields=10)
parse_qsl('&'.join(['a=a'] * 10), max_num_fields=10)
+
+ def test_parse_qsl_separator(self):
+ tests = [
+ (';', []),
+ (';;', []),
+ ('=;a', []),
+ (';a=b', [('a', 'b')]),
+ ('a=a+b;b=b+c', [('a', 'a b'), ('b', 'b c')]),
+ ('a=1;a=2', [('a', '1'), ('a', '2')]),
+ (b';', []),
+ (b';;', []),
+ (b';a=b', [(b'a', b'b')]),
+ (b'a=a+b;b=b+c', [(b'a', b'a b'), (b'b', b'b c')]),
+ (b'a=1;a=2', [(b'a', b'1'), (b'a', b'2')]),
+ ]
+ for original, expected in tests:
+ with self.subTest(original):
+ result = parse_qsl(original, separator=';')
+ self.assertEqual(result, expected, 'Error parsing %r' % original)
+
+ def test_parse_qsl_bad_separator(self):
+ with self.assertRaisesRegex(ValueError, 'Separator must be of type string or bytes.'):
+ parse_qsl('a=b0c=d', separator=0)