summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Jerdonek <chris.jerdonek@gmail.com>2021-06-10 10:14:14 -0700
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-06-23 16:07:07 +0200
commit999402f1428870cf9f078940880c8646174bb909 (patch)
tree6dae293510adb213b485fb3c9d70c2d4dd9e75a3
parent1bbb98d9a4b7d83e422b14ae2429cb368eff5a13 (diff)
Refs #32817 -- Combined the bad-or-missing CSRF token tests.
-rw-r--r--tests/csrf_tests/tests.py35
1 files changed, 11 insertions, 24 deletions
diff --git a/tests/csrf_tests/tests.py b/tests/csrf_tests/tests.py
index 7cf69fd6c5..992ac36767 100644
--- a/tests/csrf_tests/tests.py
+++ b/tests/csrf_tests/tests.py
@@ -128,33 +128,20 @@ class CsrfViewMiddlewareTestMixin:
self.assertEqual(403, resp.status_code)
self.assertEqual(cm.records[0].getMessage(), 'Forbidden (%s): ' % expected)
- def test_csrf_cookie_no_token(self):
+ def test_csrf_cookie_bad_or_missing_token(self):
"""
- If a CSRF cookie is present but with no token, the middleware rejects
- the incoming request.
- """
- self._check_bad_or_missing_token(None, REASON_CSRF_TOKEN_MISSING)
-
- def test_csrf_cookie_bad_token_characters(self):
- """
- If a CSRF cookie is present but the token has invalid characters, the
- middleware rejects the incoming request.
- """
- self._check_bad_or_missing_token(64 * '*', 'CSRF token has invalid characters.')
-
- def test_csrf_cookie_bad_token_length(self):
- """
- If a CSRF cookie is present but the token has an incorrect length, the
+ If a CSRF cookie is present but the token is missing or invalid, the
middleware rejects the incoming request.
"""
- self._check_bad_or_missing_token(16 * 'a', 'CSRF token has incorrect length.')
-
- def test_csrf_cookie_incorrect_token(self):
- """
- If a CSRF cookie is present but the correctly formatted token is
- incorrect, the middleware rejects the incoming request.
- """
- self._check_bad_or_missing_token(64 * 'a', 'CSRF token incorrect.')
+ cases = [
+ (None, REASON_CSRF_TOKEN_MISSING),
+ (64 * '*', 'CSRF token has invalid characters.'),
+ (16 * 'a', 'CSRF token has incorrect length.'),
+ (64 * 'a', 'CSRF token incorrect.'),
+ ]
+ for token, expected in cases:
+ with self.subTest(token=token):
+ self._check_bad_or_missing_token(expected, token)
def test_process_request_csrf_cookie_and_token(self):
"""