File tree Expand file tree Collapse file tree 3 files changed +44
-3
lines changed Expand file tree Collapse file tree 3 files changed +44
-3
lines changed Original file line number Diff line number Diff line change 1
- import base64
2
1
import binascii
3
2
import warnings
4
3
5
4
from openapi_core .security .exceptions import SecurityError
5
+ from openapi_core .security .util import b64decode
6
6
7
7
8
8
class BaseProvider (object ):
@@ -41,7 +41,6 @@ def __call__(self, request):
41
41
raise SecurityError (
42
42
'Unknown authorization method %s' % auth_type )
43
43
try :
44
- return base64 .b64decode (
45
- encoded_credentials .encode ('ascii' )).decode ('latin1' )
44
+ return b64decode (encoded_credentials ).decode ('latin1' )
46
45
except binascii .Error :
47
46
raise SecurityError ('Invalid base64 encoding.' )
Original file line number Diff line number Diff line change
1
+ from base64 import urlsafe_b64decode
2
+
3
+
4
+ def b64decode (s ):
5
+ # Code from
6
+ # https://github.com/GehirnInc/python-jwt/blob/master/jwt/utils.py#L29
7
+ s_bin = s .encode ('ascii' )
8
+ s_bin += b'=' * (4 - len (s_bin ) % 4 )
9
+ return urlsafe_b64decode (s_bin )
Original file line number Diff line number Diff line change
1
+ import pytest
2
+
3
+ from openapi_core .schema .security_schemes .models import SecurityScheme
4
+ from openapi_core .security .providers import HttpProvider
5
+ from openapi_core .testing import MockRequest
6
+
7
+
8
+ class TestHttpProvider (object ):
9
+
10
+ @pytest .fixture
11
+ def scheme (self ):
12
+ return SecurityScheme ('http' , scheme = 'bearer' )
13
+
14
+ @pytest .fixture
15
+ def provider (self , scheme ):
16
+ return HttpProvider (scheme )
17
+
18
+ def test_issue29427 (self , provider ):
19
+ """Tests HttpProvider against Issue29427
20
+ https://bugs.python.org/issue29427
21
+ """
22
+ jwt = 'MQ'
23
+ headers = {
24
+ 'Authorization' : 'Bearer {0}' .format (jwt ),
25
+ }
26
+ request = MockRequest (
27
+ 'http://localhost' , 'GET' , '/pets' ,
28
+ headers = headers ,
29
+ )
30
+
31
+ result = provider (request )
32
+
33
+ assert result == '1'
You can’t perform that action at this time.
0 commit comments