Security HTTP provider fix

This commit is contained in:
p1c2u 2020-03-23 13:20:08 +00:00
parent 89ec335210
commit e2ae4f35d0
4 changed files with 4 additions and 17 deletions

View file

@ -1,8 +1,6 @@
import binascii
import warnings import warnings
from openapi_core.security.exceptions import SecurityError from openapi_core.security.exceptions import SecurityError
from openapi_core.security.util import b64decode
class BaseProvider(object): class BaseProvider(object):
@ -40,7 +38,5 @@ class HttpProvider(BaseProvider):
if auth_type.lower() != self.scheme.scheme.value: if auth_type.lower() != self.scheme.scheme.value:
raise SecurityError( raise SecurityError(
'Unknown authorization method %s' % auth_type) 'Unknown authorization method %s' % auth_type)
try:
return b64decode(encoded_credentials).decode('latin1') return encoded_credentials
except binascii.Error:
raise SecurityError('Invalid base64 encoding.')

View file

@ -1,9 +0,0 @@
from base64 import urlsafe_b64decode
def b64decode(s):
# Code from
# https://github.com/GehirnInc/python-jwt/blob/master/jwt/utils.py#L29
s_bin = s.encode('ascii')
s_bin += b'=' * (4 - len(s_bin) % 4)
return urlsafe_b64decode(s_bin)

View file

@ -283,7 +283,7 @@ class TestRequestValidator(object):
}, },
) )
assert result.security == { assert result.security == {
'petstore_auth': self.api_key, 'petstore_auth': self.api_key_encoded,
} }

View file

@ -30,4 +30,4 @@ class TestHttpProvider(object):
result = provider(request) result = provider(request)
assert result == '1' assert result == jwt