Skip to content

Commit 82fe2ca

Browse files
committed
Security provider factory refactor
1 parent fc2ac52 commit 82fe2ca

File tree

2 files changed

+18
-24
lines changed

2 files changed

+18
-24
lines changed

openapi_core/security/factories.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ class SecurityProviderFactory(object):
88
PROVIDERS = {
99
'apiKey': ApiKeyProvider,
1010
'http': HttpProvider,
11+
'oauth2': UnsupportedProvider,
12+
'openIdConnect': UnsupportedProvider,
1113
}
1214

1315
def create(self, scheme):
1416
scheme_type = scheme['type']
15-
if scheme_type == 'apiKey':
16-
return ApiKeyProvider(scheme)
17-
elif scheme_type == 'http':
18-
return HttpProvider(scheme)
19-
return UnsupportedProvider(scheme)
17+
provider_class = self.PROVIDERS[scheme_type]
18+
return provider_class(scheme)

tests/unit/security/test_providers.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,33 @@
77

88
class TestHttpProvider(object):
99

10-
@pytest.fixture
11-
def spec(self):
12-
return {
13-
'type': 'http',
14-
'scheme': 'bearer',
15-
}
16-
17-
@pytest.fixture
18-
def scheme(self, spec):
19-
return SpecPath.from_spec(spec)
20-
21-
@pytest.fixture
22-
def provider(self, scheme):
23-
return HttpProvider(scheme)
24-
2510
@pytest.mark.parametrize(
2611
'header',
2712
['authorization', 'Authorization', 'AUTHORIZATION'],
2813
)
29-
def test_header(self, provider, header):
14+
@pytest.mark.parametrize(
15+
'scheme',
16+
['basic', 'bearer', 'digest'],
17+
)
18+
def test_header(self, header, scheme):
3019
"""Tests HttpProvider against Issue29427
3120
https://bugs.python.org/issue29427
3221
"""
33-
jwt = 'MQ'
22+
spec = {
23+
'type': 'http',
24+
'scheme': scheme,
25+
}
26+
value = 'MQ'
3427
headers = {
35-
header: 'Bearer {0}'.format(jwt),
28+
header: ' '.join([scheme.title(), value]),
3629
}
3730
request = MockRequest(
3831
'http://localhost', 'GET', '/pets',
3932
headers=headers,
4033
)
34+
scheme = SpecPath.from_spec(spec)
35+
provider = HttpProvider(scheme)
4136

4237
result = provider(request)
4338

44-
assert result == jwt
39+
assert result == value

0 commit comments

Comments
 (0)