@@ -114,11 +114,7 @@ def test_decode_works_with_unicode_token(self, jws):
114114
115115 def test_decode_missing_segments_throws_exception (self , jws ):
116116 secret = "secret"
117- example_jws = (
118- "eyJhbGciOiAiSFMyNTYiLCAidHlwIjogIkpXVCJ9"
119- ".eyJoZWxsbyI6ICJ3b3JsZCJ9"
120- ""
121- ) # Missing segment
117+ example_jws = "eyJhbGciOiAiSFMyNTYiLCAidHlwIjogIkpXVCJ9.eyJoZWxsbyI6ICJ3b3JsZCJ9" # Missing segment
122118
123119 with pytest .raises (DecodeError ) as context :
124120 jws .decode (example_jws , secret , algorithms = ["HS256" ])
@@ -160,9 +156,7 @@ def test_decode_with_non_mapping_header_throws_exception(self, jws):
160156 exception = context .value
161157 assert str (exception ) == "Invalid header string: must be a json object"
162158
163- def test_encode_algorithm_param_should_be_case_sensitive (
164- self , jws , payload
165- ):
159+ def test_encode_algorithm_param_should_be_case_sensitive (self , jws , payload ):
166160
167161 jws .encode (payload , "secret" , algorithm = "HS256" )
168162
@@ -207,9 +201,7 @@ def test_decodes_valid_jws(self, jws, payload):
207201 b"gEW0pdU4kxPthjtehYdhxB9mMOGajt1xCKlGGXDJ8PM"
208202 )
209203
210- decoded_payload = jws .decode (
211- example_jws , example_secret , algorithms = ["HS256" ]
212- )
204+ decoded_payload = jws .decode (example_jws , example_secret , algorithms = ["HS256" ])
213205
214206 assert decoded_payload == payload
215207
@@ -221,9 +213,7 @@ def test_decodes_complete_valid_jws(self, jws, payload):
221213 b"gEW0pdU4kxPthjtehYdhxB9mMOGajt1xCKlGGXDJ8PM"
222214 )
223215
224- decoded = jws .decode_complete (
225- example_jws , example_secret , algorithms = ["HS256" ]
226- )
216+ decoded = jws .decode_complete (example_jws , example_secret , algorithms = ["HS256" ])
227217
228218 assert decoded == {
229219 "header" : {"alg" : "HS256" , "typ" : "JWT" },
@@ -248,9 +238,7 @@ def test_decodes_valid_es384_jws(self, jws):
248238 b"eyJoZWxsbyI6IndvcmxkIn0.TORyNQab_MoXM7DvNKaTwbrJr4UY"
249239 b"d2SsX8hhlnWelQFmPFSf_JzC2EbLnar92t-bXsDovzxp25ExazrVHkfPkQ"
250240 )
251- decoded_payload = jws .decode (
252- example_jws , example_pubkey , algorithms = ["ES256" ]
253- )
241+ decoded_payload = jws .decode (example_jws , example_pubkey , algorithms = ["ES256" ])
254242 json_payload = json .loads (decoded_payload )
255243
256244 assert json_payload == example_payload
@@ -276,9 +264,7 @@ def test_decodes_valid_rs384_jws(self, jws):
276264 b"uwmrtSWCBUjiN8sqJ00CDgycxKqHfUndZbEAOjcCAhBr"
277265 b"qWW3mSVivUfubsYbwUdUG3fSRPjaUPcpe8A"
278266 )
279- decoded_payload = jws .decode (
280- example_jws , example_pubkey , algorithms = ["RS384" ]
281- )
267+ decoded_payload = jws .decode (example_jws , example_pubkey , algorithms = ["RS384" ])
282268 json_payload = json .loads (decoded_payload )
283269
284270 assert json_payload == example_payload
@@ -299,9 +285,7 @@ def test_load_verify_valid_jws(self, jws, payload):
299285 def test_allow_skip_verification (self , jws , payload ):
300286 right_secret = "foo"
301287 jws_message = jws .encode (payload , right_secret )
302- decoded_payload = jws .decode (
303- jws_message , options = {"verify_signature" : False }
304- )
288+ decoded_payload = jws .decode (jws_message , options = {"verify_signature" : False })
305289
306290 assert decoded_payload == payload
307291
@@ -364,14 +348,8 @@ def test_verify_signature_with_no_secret(self, jws, payload):
364348
365349 assert "Signature verification" in str (exc .value )
366350
367- def test_verify_signature_with_no_algo_header_throws_exception (
368- self , jws , payload
369- ):
370- example_jws = (
371- b"e30"
372- b".eyJhIjo1fQ"
373- b".KEh186CjVw_Q8FadjJcaVnE7hO5Z9nHBbU8TgbhHcBY"
374- )
351+ def test_verify_signature_with_no_algo_header_throws_exception (self , jws , payload ):
352+ example_jws = b"e30.eyJhIjo1fQ.KEh186CjVw_Q8FadjJcaVnE7hO5Z9nHBbU8TgbhHcBY"
375353
376354 with pytest .raises (InvalidAlgorithmError ):
377355 jws .decode (example_jws , "secret" , algorithms = ["HS256" ])
@@ -467,9 +445,7 @@ def test_decode_with_algo_none_should_fail(self, jws, payload):
467445 with pytest .raises (DecodeError ):
468446 jws .decode (jws_message , algorithms = ["none" ])
469447
470- def test_decode_with_algo_none_and_verify_false_should_pass (
471- self , jws , payload
472- ):
448+ def test_decode_with_algo_none_and_verify_false_should_pass (self , jws , payload ):
473449 jws_message = jws .encode (payload , key = None , algorithm = None )
474450 jws .decode (jws_message , options = {"verify_signature" : False })
475451
@@ -486,9 +462,7 @@ def test_get_unverified_header_returns_header_values(self, jws, payload):
486462 assert "kid" in header
487463 assert header ["kid" ] == "toomanysecrets"
488464
489- def test_get_unverified_header_fails_on_bad_header_types (
490- self , jws , payload
491- ):
465+ def test_get_unverified_header_fails_on_bad_header_types (self , jws , payload ):
492466 # Contains a bad kid value (int 123 instead of string)
493467 example_jws = (
494468 "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6MTIzfQ"
@@ -505,9 +479,7 @@ def test_get_unverified_header_fails_on_bad_header_types(
505479 def test_encode_decode_with_rsa_sha256 (self , jws , payload ):
506480 # PEM-formatted RSA key
507481 with open (key_path ("testkey_rsa.priv" ), "rb" ) as rsa_priv_file :
508- priv_rsakey = load_pem_private_key (
509- rsa_priv_file .read (), password = None
510- )
482+ priv_rsakey = load_pem_private_key (rsa_priv_file .read (), password = None )
511483 jws_message = jws .encode (payload , priv_rsakey , algorithm = "RS256" )
512484
513485 with open (key_path ("testkey_rsa.pub" ), "rb" ) as rsa_pub_file :
@@ -528,9 +500,7 @@ def test_encode_decode_with_rsa_sha256(self, jws, payload):
528500 def test_encode_decode_with_rsa_sha384 (self , jws , payload ):
529501 # PEM-formatted RSA key
530502 with open (key_path ("testkey_rsa.priv" ), "rb" ) as rsa_priv_file :
531- priv_rsakey = load_pem_private_key (
532- rsa_priv_file .read (), password = None
533- )
503+ priv_rsakey = load_pem_private_key (rsa_priv_file .read (), password = None )
534504 jws_message = jws .encode (payload , priv_rsakey , algorithm = "RS384" )
535505
536506 with open (key_path ("testkey_rsa.pub" ), "rb" ) as rsa_pub_file :
@@ -550,9 +520,7 @@ def test_encode_decode_with_rsa_sha384(self, jws, payload):
550520 def test_encode_decode_with_rsa_sha512 (self , jws , payload ):
551521 # PEM-formatted RSA key
552522 with open (key_path ("testkey_rsa.priv" ), "rb" ) as rsa_priv_file :
553- priv_rsakey = load_pem_private_key (
554- rsa_priv_file .read (), password = None
555- )
523+ priv_rsakey = load_pem_private_key (rsa_priv_file .read (), password = None )
556524 jws_message = jws .encode (payload , priv_rsakey , algorithm = "RS512" )
557525
558526 with open (key_path ("testkey_rsa.pub" ), "rb" ) as rsa_pub_file :
@@ -592,9 +560,7 @@ def test_rsa_related_algorithms(self, jws):
592560 def test_encode_decode_with_ecdsa_sha256 (self , jws , payload ):
593561 # PEM-formatted EC key
594562 with open (key_path ("testkey_ec.priv" ), "rb" ) as ec_priv_file :
595- priv_eckey = load_pem_private_key (
596- ec_priv_file .read (), password = None
597- )
563+ priv_eckey = load_pem_private_key (ec_priv_file .read (), password = None )
598564 jws_message = jws .encode (payload , priv_eckey , algorithm = "ES256" )
599565
600566 with open (key_path ("testkey_ec.pub" ), "rb" ) as ec_pub_file :
@@ -615,9 +581,7 @@ def test_encode_decode_with_ecdsa_sha384(self, jws, payload):
615581
616582 # PEM-formatted EC key
617583 with open (key_path ("testkey_ec.priv" ), "rb" ) as ec_priv_file :
618- priv_eckey = load_pem_private_key (
619- ec_priv_file .read (), password = None
620- )
584+ priv_eckey = load_pem_private_key (ec_priv_file .read (), password = None )
621585 jws_message = jws .encode (payload , priv_eckey , algorithm = "ES384" )
622586
623587 with open (key_path ("testkey_ec.pub" ), "rb" ) as ec_pub_file :
@@ -637,9 +601,7 @@ def test_encode_decode_with_ecdsa_sha384(self, jws, payload):
637601 def test_encode_decode_with_ecdsa_sha512 (self , jws , payload ):
638602 # PEM-formatted EC key
639603 with open (key_path ("testkey_ec.priv" ), "rb" ) as ec_priv_file :
640- priv_eckey = load_pem_private_key (
641- ec_priv_file .read (), password = None
642- )
604+ priv_eckey = load_pem_private_key (ec_priv_file .read (), password = None )
643605 jws_message = jws .encode (payload , priv_eckey , algorithm = "ES512" )
644606
645607 with open (key_path ("testkey_ec.pub" ), "rb" ) as ec_pub_file :
0 commit comments