aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/tests/authentication.py
diff options
context:
space:
mode:
authorTom Christie2013-02-01 14:03:28 +0000
committerTom Christie2013-02-01 14:03:28 +0000
commitf4f237e3ee02fef4fd5f389bf4fb3bbdd00173bd (patch)
tree80b5d9b042e0d66fa16cfe071a2a345cd4fdfdd6 /rest_framework/tests/authentication.py
parentd9c7b1c58523d63c8118d88f44ebfdf5f35e942a (diff)
downloaddjango-rest-framework-f4f237e3ee02fef4fd5f389bf4fb3bbdd00173bd.tar.bz2
3.2, 3.3 compat
Diffstat (limited to 'rest_framework/tests/authentication.py')
-rw-r--r--rest_framework/tests/authentication.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/rest_framework/tests/authentication.py b/rest_framework/tests/authentication.py
index ba2042cb..7dde6d22 100644
--- a/rest_framework/tests/authentication.py
+++ b/rest_framework/tests/authentication.py
@@ -1,6 +1,9 @@
+from __future__ import unicode_literals
+
from django.contrib.auth.models import User
from django.http import HttpResponse
from django.test import Client, TestCase
+from rest_framework import HTTP_HEADER_ENCODING
from rest_framework import permissions
from rest_framework.authtoken.models import Token
from rest_framework.authentication import TokenAuthentication, BasicAuthentication, SessionAuthentication
@@ -41,13 +44,17 @@ class BasicAuthTests(TestCase):
def test_post_form_passing_basic_auth(self):
"""Ensure POSTing json over basic auth with correct credentials passes and does not require CSRF"""
- auth = 'Basic %s' % base64.encodestring('%s:%s' % (self.username, self.password)).encode('iso-8859-1').strip().decode('iso-8859-1')
+ credentials = ('%s:%s' % (self.username, self.password))
+ base64_credentials = base64.b64encode(credentials.encode(HTTP_HEADER_ENCODING)).decode(HTTP_HEADER_ENCODING)
+ auth = 'Basic %s' % base64_credentials
response = self.csrf_client.post('/basic/', {'example': 'example'}, HTTP_AUTHORIZATION=auth)
self.assertEqual(response.status_code, 200)
def test_post_json_passing_basic_auth(self):
"""Ensure POSTing form over basic auth with correct credentials passes and does not require CSRF"""
- auth = 'Basic %s' % base64.encodestring('%s:%s' % (self.username, self.password)).encode('iso-8859-1').strip().decode('iso-8859-1')
+ credentials = ('%s:%s' % (self.username, self.password))
+ base64_credentials = base64.b64encode(credentials.encode(HTTP_HEADER_ENCODING)).decode(HTTP_HEADER_ENCODING)
+ auth = 'Basic %s' % base64_credentials
response = self.csrf_client.post('/basic/', json.dumps({'example': 'example'}), 'application/json', HTTP_AUTHORIZATION=auth)
self.assertEqual(response.status_code, 200)