openapi-core/tests/unit/security/test_providers.py

45 lines
1 KiB
Python
Raw Normal View History

2020-03-03 12:02:58 +00:00
import pytest
from openapi_core.security.providers import HttpProvider
2021-04-23 11:36:27 +00:00
from openapi_core.spec.paths import SpecPath
2020-03-03 12:02:58 +00:00
from openapi_core.testing import MockRequest
class TestHttpProvider(object):
@pytest.fixture
2021-04-23 11:36:27 +00:00
def spec(self):
return {
'type': 'http',
'scheme': 'bearer',
}
@pytest.fixture
def scheme(self, spec):
return SpecPath.from_spec(spec)
2020-03-03 12:02:58 +00:00
@pytest.fixture
def provider(self, scheme):
return HttpProvider(scheme)
2020-04-11 09:47:36 +00:00
@pytest.mark.parametrize(
'header',
['authorization', 'Authorization', 'AUTHORIZATION'],
)
def test_header(self, provider, header):
2020-03-03 12:02:58 +00:00
"""Tests HttpProvider against Issue29427
https://bugs.python.org/issue29427
"""
jwt = 'MQ'
headers = {
2020-04-11 09:47:36 +00:00
header: 'Bearer {0}'.format(jwt),
2020-03-03 12:02:58 +00:00
}
request = MockRequest(
'http://localhost', 'GET', '/pets',
headers=headers,
)
result = provider(request)
2020-03-23 13:20:08 +00:00
assert result == jwt