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
05882cc5
Commit
05882cc5
authored
Jul 25, 2014
by
Ron Cohen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sending "Bearer" and "Bearer " resulted in a 500.
parent
299a8347
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
7 deletions
+16
-7
rest_framework/authentication.py
+7
-7
rest_framework/tests/test_authentication.py
+9
-0
No files found.
rest_framework/authentication.py
View file @
05882cc5
...
...
@@ -310,6 +310,13 @@ class OAuth2Authentication(BaseAuthentication):
auth
=
get_authorization_header
(
request
)
.
split
()
if
len
(
auth
)
==
1
:
msg
=
'Invalid bearer header. No credentials provided.'
raise
exceptions
.
AuthenticationFailed
(
msg
)
elif
len
(
auth
)
>
2
:
msg
=
'Invalid bearer header. Token string should not contain spaces.'
raise
exceptions
.
AuthenticationFailed
(
msg
)
if
auth
and
auth
[
0
]
.
lower
()
==
b
'bearer'
:
access_token
=
auth
[
1
]
elif
'access_token'
in
request
.
POST
:
...
...
@@ -319,13 +326,6 @@ class OAuth2Authentication(BaseAuthentication):
else
:
return
None
if
len
(
auth
)
==
1
:
msg
=
'Invalid bearer header. No credentials provided.'
raise
exceptions
.
AuthenticationFailed
(
msg
)
elif
len
(
auth
)
>
2
:
msg
=
'Invalid bearer header. Token string should not contain spaces.'
raise
exceptions
.
AuthenticationFailed
(
msg
)
return
self
.
authenticate_credentials
(
request
,
access_token
)
def
authenticate_credentials
(
self
,
request
,
access_token
):
...
...
rest_framework/tests/test_authentication.py
View file @
05882cc5
...
...
@@ -550,6 +550,15 @@ class OAuth2Tests(TestCase):
self
.
assertEqual
(
response
.
status_code
,
401
)
@unittest.skipUnless
(
oauth2_provider
,
'django-oauth2-provider not installed'
)
def
test_get_form_with_wrong_authorization_header_token_missing
(
self
):
"""Ensure that a wrong token lead to the correct HTTP error status code"""
auth
=
"Bearer"
response
=
self
.
csrf_client
.
get
(
'/oauth2-test/'
,
{},
HTTP_AUTHORIZATION
=
auth
)
self
.
assertEqual
(
response
.
status_code
,
401
)
response
=
self
.
csrf_client
.
get
(
'/oauth2-test/'
,
HTTP_AUTHORIZATION
=
auth
)
self
.
assertEqual
(
response
.
status_code
,
401
)
@unittest.skipUnless
(
oauth2_provider
,
'django-oauth2-provider not installed'
)
def
test_get_form_passing_auth
(
self
):
"""Ensure GETing form over OAuth with correct client credentials succeed"""
auth
=
self
.
_create_authorization_header
()
...
...
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