summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2013-09-07 10:25:43 -0500
committerAymeric Augustin <aymeric.augustin@m4x.org>2013-09-07 10:25:43 -0500
commit8aaca651cf5732bbf395d24a7d9f2edfab00250c (patch)
tree314d71ef8fc02da645f90fb77ae8d8fbf5de05a4 /tests
parentae7f9afaf6592fa477792647bd8cee0a8560b4eb (diff)
Fixed #20557 -- Properly decoded non-ASCII cookies on Python 3.
Thanks mitsuhiko for the report. Non-ASCII values are supported. Non-ASCII keys still aren't, because the current parser mangles them. That's another bug.
Diffstat (limited to 'tests')
-rw-r--r--tests/handlers/tests.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/tests/handlers/tests.py b/tests/handlers/tests.py
index 2f9f304b81..9d47b0b083 100644
--- a/tests/handlers/tests.py
+++ b/tests/handlers/tests.py
@@ -1,8 +1,11 @@
-from django.core.handlers.wsgi import WSGIHandler
+from __future__ import unicode_literals
+
+from django.core.handlers.wsgi import WSGIHandler, WSGIRequest
from django.core.signals import request_started, request_finished
from django.db import close_old_connections, connection
from django.test import RequestFactory, TestCase, TransactionTestCase
from django.test.utils import override_settings
+from django.utils import six
class HandlerTests(TestCase):
@@ -30,11 +33,19 @@ class HandlerTests(TestCase):
def test_bad_path_info(self):
"""Tests for bug #15672 ('request' referenced before assignment)"""
environ = RequestFactory().get('/').environ
- environ['PATH_INFO'] = '\xed'
+ environ['PATH_INFO'] = b'\xed' if six.PY2 else '\xed'
handler = WSGIHandler()
response = handler(environ, lambda *a, **k: None)
self.assertEqual(response.status_code, 400)
+ def test_non_ascii_cookie(self):
+ """Test that non-ASCII cookies set in JavaScript are properly decoded (#20557)."""
+ environ = RequestFactory().get('/').environ
+ raw_cookie = 'want="café"'.encode('utf-8')
+ environ['HTTP_COOKIE'] = raw_cookie if six.PY2 else raw_cookie.decode('iso-8859-1')
+ request = WSGIRequest(environ)
+ self.assertEqual(request.COOKIES['want'], "café")
+
class TransactionsPerRequestTests(TransactionTestCase):