Skip to content

Commit

Permalink
Add case-insensitive headers to oauth1 BaseEndpoint (#669)
Browse files Browse the repository at this point in the history
Add case-insensitive headers to oauth1 BaseEndpoint
  • Loading branch information
JonathanHuot committed May 6, 2019
2 parents 30321dd + f037c11 commit c376e27
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions oauthlib/oauth1/rfc5849/endpoints/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import time

from oauthlib.common import Request, generate_token
from oauthlib.common import CaseInsensitiveDict, Request, generate_token

from .. import (CONTENT_TYPE_FORM_URLENCODED, SIGNATURE_HMAC, SIGNATURE_RSA,
SIGNATURE_TYPE_AUTH_HEADER, SIGNATURE_TYPE_BODY,
Expand Down Expand Up @@ -67,7 +67,7 @@ def _get_signature_type_and_params(self, request):

def _create_request(self, uri, http_method, body, headers):
# Only include body data from x-www-form-urlencoded requests
headers = headers or {}
headers = CaseInsensitiveDict(headers or {})
if ("Content-Type" in headers and
CONTENT_TYPE_FORM_URLENCODED in headers["Content-Type"]):
request = Request(uri, http_method, body, headers)
Expand Down
13 changes: 12 additions & 1 deletion tests/oauth1/rfc5849/endpoints/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from mock import MagicMock

from oauthlib.common import safe_string_equals
from oauthlib.common import CaseInsensitiveDict, safe_string_equals
from oauthlib.oauth1 import Client, RequestValidator
from oauthlib.oauth1.rfc5849 import (SIGNATURE_HMAC, SIGNATURE_PLAINTEXT,
SIGNATURE_RSA, errors)
Expand Down Expand Up @@ -179,6 +179,17 @@ def test_oauth_timestamp(self):
self.assertRaises(errors.InvalidRequestError,
e._check_mandatory_parameters, r)

def test_case_insensitive_headers(self):
"""Ensure headers are case-insensitive"""
v = RequestValidator()
e = BaseEndpoint(v)
r = e._create_request('https://a.b', 'POST',
('oauth_signature=a&oauth_consumer_key=b&oauth_nonce=c&'
'oauth_version=1.0&oauth_signature_method=RSA-SHA1&'
'oauth_timestamp=123456789a'),
URLENCODED)
self.assertIsInstance(r.headers, CaseInsensitiveDict)

def test_signature_method_validation(self):
"""Ensure valid signature method is used."""

Expand Down

0 comments on commit c376e27

Please sign in to comment.