From ac5c6762d83aea911fcc6c3bc775f432532a287d Mon Sep 17 00:00:00 2001 From: p1c2u Date: Sat, 11 Apr 2020 10:47:36 +0100 Subject: [PATCH] Case insensitive headers fix --- openapi_core/contrib/django/requests.py | 2 +- openapi_core/validation/request/datatypes.py | 6 +++--- tests/unit/security/test_providers.py | 8 ++++++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/openapi_core/contrib/django/requests.py b/openapi_core/contrib/django/requests.py index 72653d87..5e4e3a9a 100644 --- a/openapi_core/contrib/django/requests.py +++ b/openapi_core/contrib/django/requests.py @@ -39,7 +39,7 @@ def create(cls, request): parameters = RequestParameters( path=path, query=request.GET, - header=request.headers, + header=request.headers.items(), cookie=request.COOKIES, ) full_url_pattern = urljoin( diff --git a/openapi_core/validation/request/datatypes.py b/openapi_core/validation/request/datatypes.py index b8433b01..1ad629cb 100644 --- a/openapi_core/validation/request/datatypes.py +++ b/openapi_core/validation/request/datatypes.py @@ -1,6 +1,6 @@ """OpenAPI core validation request datatypes module""" import attr -from werkzeug.datastructures import ImmutableMultiDict +from werkzeug.datastructures import ImmutableMultiDict, Headers from openapi_core.validation.datatypes import BaseValidationResult @@ -13,14 +13,14 @@ class RequestParameters(object): query Query string parameters as MultiDict. Must support getlist method. header - Request headers as dict. + Request headers as Headers. cookie Request cookies as dict. path Path parameters as dict. Gets resolved against spec if empty. """ query = attr.ib(factory=ImmutableMultiDict) - header = attr.ib(factory=dict) + header = attr.ib(factory=Headers, converter=Headers) cookie = attr.ib(factory=dict) path = attr.ib(factory=dict) diff --git a/tests/unit/security/test_providers.py b/tests/unit/security/test_providers.py index d79e5926..1753871b 100644 --- a/tests/unit/security/test_providers.py +++ b/tests/unit/security/test_providers.py @@ -15,13 +15,17 @@ def scheme(self): def provider(self, scheme): return HttpProvider(scheme) - def test_issue29427(self, provider): + @pytest.mark.parametrize( + 'header', + ['authorization', 'Authorization', 'AUTHORIZATION'], + ) + def test_header(self, provider, header): """Tests HttpProvider against Issue29427 https://bugs.python.org/issue29427 """ jwt = 'MQ' headers = { - 'Authorization': 'Bearer {0}'.format(jwt), + header: 'Bearer {0}'.format(jwt), } request = MockRequest( 'http://localhost', 'GET', '/pets',