Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
139ba7ad
Commit
139ba7ad
authored
Jun 16, 2015
by
Xavier Ordoquy
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3006 from osantana/master
Handle invalid characters in "Authorization: token ..." headers
parents
5524339e
7ae71deb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
1 deletions
+15
-1
rest_framework/authentication.py
+7
-1
tests/test_authentication.py
+8
-0
No files found.
rest_framework/authentication.py
View file @
139ba7ad
...
...
@@ -170,7 +170,13 @@ class TokenAuthentication(BaseAuthentication):
msg
=
_
(
'Invalid token header. Token string should not contain spaces.'
)
raise
exceptions
.
AuthenticationFailed
(
msg
)
return
self
.
authenticate_credentials
(
auth
[
1
])
try
:
token
=
auth
[
1
]
.
decode
()
except
UnicodeError
:
msg
=
_
(
'Invalid token header. Token string should not contain invalid characters.'
)
raise
exceptions
.
AuthenticationFailed
(
msg
)
return
self
.
authenticate_credentials
(
token
)
def
authenticate_credentials
(
self
,
key
):
try
:
...
...
tests/test_authentication.py
View file @
139ba7ad
# coding: utf-8
from
__future__
import
unicode_literals
from
django.conf.urls
import
url
,
include
from
django.contrib.auth.models
import
User
...
...
@@ -161,6 +163,12 @@ class TokenAuthTests(TestCase):
response
=
self
.
csrf_client
.
post
(
'/token/'
,
{
'example'
:
'example'
},
HTTP_AUTHORIZATION
=
auth
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
def
test_fail_post_form_passing_invalid_token_auth
(
self
):
# add an 'invalid' unicode character
auth
=
'Token '
+
self
.
key
+
"¸"
response
=
self
.
csrf_client
.
post
(
'/token/'
,
{
'example'
:
'example'
},
HTTP_AUTHORIZATION
=
auth
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_401_UNAUTHORIZED
)
def
test_post_json_passing_token_auth
(
self
):
"""Ensure POSTing form over token auth with correct credentials passes and does not require CSRF"""
auth
=
"Token "
+
self
.
key
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment