Skip to content

Fixed authentication chain issue #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions rest_framework_httpsignature/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ def authenticate(self, request):
sent_string = request.META.get(authorization_header)
if not sent_string:
raise exceptions.AuthenticationFailed('No signature provided')

# Check if signature string matches signature pattern
sent_signature = self.get_signature_from_signature_string(sent_string)
if not sent_signature:
return None

# Fetch credentials for API key from the data store.
try:
Expand Down
15 changes: 14 additions & 1 deletion rest_framework_httpsignature/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,24 @@ def test_only_api_key(self):
self.assertRaises(AuthenticationFailed,
self.auth.authenticate, request)

def test_no_signature(self):
request = RequestFactory().get(
ENDPOINT, {},
HTTP_X_API_KEY=KEYID,
HTTP_AUTHORIZATION='no-signature')
res = self.auth.authenticate(request)
self.assertIsNone(res)

def test_bad_signature(self):
headers = ['(request-target)', 'accept', 'date', 'host']
signature = build_signature(
headers,
key_id=KEYID,
signature='some-wrong-value')
request = RequestFactory().get(
ENDPOINT, {},
HTTP_X_API_KEY=KEYID,
HTTP_AUTHORIZATION='some-wrong-value')
HTTP_AUTHORIZATION=signature)
self.assertRaises(AuthenticationFailed,
self.auth.authenticate, request)

Expand Down