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
ecb8a460
Commit
ecb8a460
authored
Jun 05, 2013
by
Alex Burgel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix serialization exception when using non-existent consumer
parent
181e4fdd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
2 deletions
+44
-2
rest_framework/authentication.py
+3
-2
rest_framework/tests/test_authentication.py
+41
-0
No files found.
rest_framework/authentication.py
View file @
ecb8a460
...
...
@@ -230,8 +230,9 @@ class OAuthAuthentication(BaseAuthentication):
try
:
consumer_key
=
oauth_request
.
get_parameter
(
'oauth_consumer_key'
)
consumer
=
oauth_provider_store
.
get_consumer
(
request
,
oauth_request
,
consumer_key
)
except
oauth_provider
.
store
.
InvalidConsumerError
as
err
:
raise
exceptions
.
AuthenticationFailed
(
err
)
except
oauth_provider
.
store
.
InvalidConsumerError
:
msg
=
'Invalid consumer token:
%
s'
%
oauth_request
.
get_parameter
(
'oauth_consumer_key'
)
raise
exceptions
.
AuthenticationFailed
(
msg
)
if
consumer
.
status
!=
oauth_provider
.
consts
.
ACCEPTED
:
msg
=
'Invalid consumer key status:
%
s'
%
consumer
.
get_status_display
()
...
...
rest_framework/tests/test_authentication.py
View file @
ecb8a460
...
...
@@ -428,6 +428,47 @@ class OAuthTests(TestCase):
response
=
self
.
csrf_client
.
post
(
'/oauth-with-scope/'
,
params
)
self
.
assertEqual
(
response
.
status_code
,
200
)
@unittest.skipUnless
(
oauth_provider
,
'django-oauth-plus not installed'
)
@unittest.skipUnless
(
oauth
,
'oauth2 not installed'
)
def
test_bad_consumer_key
(
self
):
"""Ensure POSTing using HMAC_SHA1 signature method passes"""
params
=
{
'oauth_version'
:
"1.0"
,
'oauth_nonce'
:
oauth
.
generate_nonce
(),
'oauth_timestamp'
:
int
(
time
.
time
()),
'oauth_token'
:
self
.
token
.
key
,
'oauth_consumer_key'
:
'badconsumerkey'
}
req
=
oauth
.
Request
(
method
=
"POST"
,
url
=
"http://testserver/oauth/"
,
parameters
=
params
)
signature_method
=
oauth
.
SignatureMethod_HMAC_SHA1
()
req
.
sign_request
(
signature_method
,
self
.
consumer
,
self
.
token
)
auth
=
req
.
to_header
()[
"Authorization"
]
response
=
self
.
csrf_client
.
post
(
'/oauth/'
,
HTTP_AUTHORIZATION
=
auth
)
self
.
assertEqual
(
response
.
status_code
,
401
)
@unittest.skipUnless
(
oauth_provider
,
'django-oauth-plus not installed'
)
@unittest.skipUnless
(
oauth
,
'oauth2 not installed'
)
def
test_bad_token_key
(
self
):
"""Ensure POSTing using HMAC_SHA1 signature method passes"""
params
=
{
'oauth_version'
:
"1.0"
,
'oauth_nonce'
:
oauth
.
generate_nonce
(),
'oauth_timestamp'
:
int
(
time
.
time
()),
'oauth_token'
:
'badtokenkey'
,
'oauth_consumer_key'
:
self
.
consumer
.
key
}
req
=
oauth
.
Request
(
method
=
"POST"
,
url
=
"http://testserver/oauth/"
,
parameters
=
params
)
signature_method
=
oauth
.
SignatureMethod_HMAC_SHA1
()
req
.
sign_request
(
signature_method
,
self
.
consumer
,
self
.
token
)
auth
=
req
.
to_header
()[
"Authorization"
]
response
=
self
.
csrf_client
.
post
(
'/oauth/'
,
HTTP_AUTHORIZATION
=
auth
)
self
.
assertEqual
(
response
.
status_code
,
401
)
class
OAuth2Tests
(
TestCase
):
"""OAuth 2.0 authentication"""
...
...
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