Merge pull request #225 from p1c2u/fix/security-http-provider-fix

Security HTTP provider fix
This commit is contained in:
A 2020-04-11 13:10:33 +01:00 committed by GitHub
commit 1270d5a6b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 4 additions and 17 deletions

View file

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

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 == {
'petstore_auth': self.api_key,
'petstore_auth': self.api_key_encoded,
}

View file

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