@@ -174,7 +174,7 @@ def test_signing(self):
174
174
def test_bearer_token (self ):
175
175
"""Verify that the authorization header is set when a bearer token is provided"""
176
176
177
- bearer_token = "Bearer myBearerToken "
177
+ bearer_token = "Bearer eyJraWQiOiJWcmVsOE9zZ0JXaUpHeEpMeFJ4bE1UaVwvbjgyc1hwWktUaTd2UExUNFQ0TT0iLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJoMTBlM2hwajliNjc4bXMwOG8zbGlibHQ2IiwidG9rZW5fdXNlIjoiYWNjZXNzIiwic2NvcGUiOiJ3ZWJcL2dldCB3ZWJcL3Bvc3QiLCJhdXRoX3RpbWUiOjE1OTM3MjM1NDgsImlzcyI6Imh0dHBzOlwvXC9jb2duaXRvLWlkcC51cy1lYXN0LTEuYW1hem9uYXdzLmNvbVwvdXMtZWFzdC0xX1d6aEZzTGlPRyIsImV4cCI6MTU5MzcyNzE0OCwiaWF0IjoxNTkzNzIzNTQ4LCJ2ZXJzaW9uIjoyLCJqdGkiOiI4Njk5ZDEwYy05Mjg4LTQ0YmEtODIxNi01OTJjZGU3MDBhY2MiLCJjbGllbnRfaWQiOiJoMTBlM2hwajliNjc4bXMwOG8zbGlibHQ2In0.YA_yiD-x6UuBMShprUbUKuB_DO6ogCtd5srfgpJA6Ve_qsf8n19nVMmFsZBy3GxzN92P1ZXiFY99FfNPohhQtaRRhpeUkir08hgJN2bEHCJ5Ym8r9mr9mlwSG6FoiedgLaUVGwJujD9c2rcA83NEo8ayTyfCynF2AZ2pMxLHvqOYtvscGMiMzIwlZfJV301iKUVgPODJM5lpJ4iKCpOy2ByCl2_KL1uxIxgMkglpB-i7kgJc-WmYoJFoN88D89ugnEoAxNfK14N4_RyEkrLNGape9kew79nUeR6fWbVFLiGDDu25_9z-7VB-GGGk7L_Hb7YgVJ5W2FwESnkDvV1T4Q "
178
178
179
179
with tempfile .NamedTemporaryFile () as config_file , tempfile .NamedTemporaryFile () as key_file :
180
180
with open (config_file .name , "w" ) as f :
@@ -202,3 +202,29 @@ def test_bearer_token(self):
202
202
authorization_header_value = prepared_get .headers ["authorization" ]
203
203
self .assertEqual (authorization_header_value , bearer_token )
204
204
self .assertNotIn ("x-user-token" , prepared_get .headers )
205
+
206
+ def test_malformed_bearer_token (self ):
207
+ """Verify that an exception is thrown when a malformed JWT bearer token is provided"""
208
+
209
+ bearer_token = "Bearer myBigBadBearerToken"
210
+
211
+ with tempfile .NamedTemporaryFile () as config_file , tempfile .NamedTemporaryFile () as key_file :
212
+ with open (config_file .name , "w" ) as f :
213
+ json .dump (
214
+ {
215
+
216
+ "token" : bearer_token ,
217
+ "organization_id" : "transcriptic" ,
218
+ "api_root" : "http://foo:5555" ,
219
+ "analytics" : True ,
220
+ "user_id" : "ufoo2" ,
221
+ "feature_groups" : [
222
+ "can_submit_autoprotocol" ,
223
+ "can_upload_packages" ,
224
+ ],
225
+ },
226
+ f ,
227
+ )
228
+
229
+ with self .assertRaisesRegexp (ValueError , "Malformed JWT Bearer Token" ):
230
+ transcriptic .config .Connection .from_file (config_file .name )
0 commit comments