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
2596c12a
Commit
2596c12a
authored
Mar 08, 2013
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes for auth header checking.
parent
1016c14a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
6 deletions
+9
-6
rest_framework/authentication.py
+8
-5
rest_framework/tests/authentication.py
+1
-1
No files found.
rest_framework/authentication.py
View file @
2596c12a
...
@@ -63,7 +63,8 @@ class BasicAuthentication(BaseAuthentication):
...
@@ -63,7 +63,8 @@ class BasicAuthentication(BaseAuthentication):
if
len
(
auth
)
==
1
:
if
len
(
auth
)
==
1
:
msg
=
'Invalid basic header. No credentials provided.'
msg
=
'Invalid basic header. No credentials provided.'
if
len
(
auth
)
>
2
:
raise
exceptions
.
AuthenticationFailed
(
msg
)
elif
len
(
auth
)
>
2
:
msg
=
'Invalid basic header. Credentials string should not contain spaces.'
msg
=
'Invalid basic header. Credentials string should not contain spaces.'
raise
exceptions
.
AuthenticationFailed
(
msg
)
raise
exceptions
.
AuthenticationFailed
(
msg
)
...
@@ -144,12 +145,13 @@ class TokenAuthentication(BaseAuthentication):
...
@@ -144,12 +145,13 @@ class TokenAuthentication(BaseAuthentication):
def
authenticate
(
self
,
request
):
def
authenticate
(
self
,
request
):
auth
=
get_authorization_header
(
request
)
.
split
()
auth
=
get_authorization_header
(
request
)
.
split
()
if
not
auth
or
auth
[
0
]
.
lower
()
!=
"token"
:
if
not
auth
or
auth
[
0
]
.
lower
()
!=
b
'token'
:
return
None
return
None
if
len
(
auth
)
==
1
:
if
len
(
auth
)
==
1
:
msg
=
'Invalid token header. No credentials provided.'
msg
=
'Invalid token header. No credentials provided.'
if
len
(
auth
)
>
2
:
raise
exceptions
.
AuthenticationFailed
(
msg
)
elif
len
(
auth
)
>
2
:
msg
=
'Invalid token header. Token string should not contain spaces.'
msg
=
'Invalid token header. Token string should not contain spaces.'
raise
exceptions
.
AuthenticationFailed
(
msg
)
raise
exceptions
.
AuthenticationFailed
(
msg
)
...
@@ -293,12 +295,13 @@ class OAuth2Authentication(BaseAuthentication):
...
@@ -293,12 +295,13 @@ class OAuth2Authentication(BaseAuthentication):
auth
=
get_authorization_header
(
request
)
.
split
()
auth
=
get_authorization_header
(
request
)
.
split
()
if
not
auth
or
auth
[
0
]
.
lower
()
!=
'bearer'
:
if
not
auth
or
auth
[
0
]
.
lower
()
!=
b
'bearer'
:
return
None
return
None
if
len
(
auth
)
==
1
:
if
len
(
auth
)
==
1
:
msg
=
'Invalid bearer header. No credentials provided.'
msg
=
'Invalid bearer header. No credentials provided.'
if
len
(
auth
)
>
2
:
raise
exceptions
.
AuthenticationFailed
(
msg
)
elif
len
(
auth
)
>
2
:
msg
=
'Invalid bearer header. Token string should not contain spaces.'
msg
=
'Invalid bearer header. Token string should not contain spaces.'
raise
exceptions
.
AuthenticationFailed
(
msg
)
raise
exceptions
.
AuthenticationFailed
(
msg
)
...
...
rest_framework/tests/authentication.py
View file @
2596c12a
...
@@ -159,7 +159,7 @@ class TokenAuthTests(TestCase):
...
@@ -159,7 +159,7 @@ class TokenAuthTests(TestCase):
def
test_post_form_passing_token_auth
(
self
):
def
test_post_form_passing_token_auth
(
self
):
"""Ensure POSTing json over token auth with correct credentials passes and does not require CSRF"""
"""Ensure POSTing json over token auth with correct credentials passes and does not require CSRF"""
auth
=
"Token "
+
self
.
key
auth
=
'Token '
+
self
.
key
response
=
self
.
csrf_client
.
post
(
'/token/'
,
{
'example'
:
'example'
},
HTTP_AUTHORIZATION
=
auth
)
response
=
self
.
csrf_client
.
post
(
'/token/'
,
{
'example'
:
'example'
},
HTTP_AUTHORIZATION
=
auth
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
...
...
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