diff options
author | Aarni Koskela <akx@iki.fi> | 2022-12-10 17:44:04 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-10 21:44:04 +0600 |
commit | 2306f68b87c5f7eecbd838db900a2d3685b81b3c (patch) | |
tree | eba477f54ab693600e65cf325842fc0c15436a1b /tests/test_advisory.py | |
parent | fb9b3119449353dca6c03be27f32e482852473c3 (diff) | |
download | pyjwt-2306f68b87c5f7eecbd838db900a2d3685b81b3c.tar.gz |
Make mypy configuration stricter and improve typing (#830)
* PyJWS._verify_signature: raise early KeyError if header is missing alg
* Make Mypy configuration stricter
* Improve typing in jwt.utils
* Improve typing in jwt.help
* Improve typing in jwt.exceptions
* Improve typing in jwt.api_jwk
* Improve typing in jwt.api_jws
* Improve typing & clean up imports in jwt.algorithms
* Correct JWS.decode rettype to any (payload could be something else)
* Update typing in api_jwt
* Improve typing in jwks_client
* Improve typing in docs/conf.py
* Fix (benign) mistyping in test_advisory
* Fix misc type complaints in tests
Diffstat (limited to 'tests/test_advisory.py')
-rw-r--r-- | tests/test_advisory.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/tests/test_advisory.py b/tests/test_advisory.py index ed768d4..8a7e05e 100644 --- a/tests/test_advisory.py +++ b/tests/test_advisory.py @@ -1,6 +1,7 @@ import pytest import jwt +from jwt.algorithms import get_default_algorithms from jwt.exceptions import InvalidKeyError from .utils import crypto_required @@ -50,18 +51,20 @@ class TestAdvisory: # public key is a HMAC secret encoded_bad = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0ZXN0IjoxMjM0fQ.6ulDpqSlbHmQ8bZXhZRLFko9SwcHrghCwh8d-exJEE4" + algorithm_names = list(get_default_algorithms()) + # Both of the jwt tokens are validated as valid jwt.decode( encoded_good, pub_key_bytes, - algorithms=jwt.algorithms.get_default_algorithms(), + algorithms=algorithm_names, ) with pytest.raises(InvalidKeyError): jwt.decode( encoded_bad, pub_key_bytes, - algorithms=jwt.algorithms.get_default_algorithms(), + algorithms=algorithm_names, ) # Of course the receiver should specify ed25519 algorithm to be used if @@ -100,16 +103,17 @@ class TestAdvisory: # encoded_bad = jwt.encode({"test": 1234}, ssh_key_bytes, algorithm="HS256") encoded_bad = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0ZXN0IjoxMjM0fQ.5eYfbrbeGYmWfypQ6rMWXNZ8bdHcqKng5GPr9MJZITU" + algorithm_names = list(get_default_algorithms()) # Both of the jwt tokens are validated as valid jwt.decode( encoded_good, ssh_key_bytes, - algorithms=jwt.algorithms.get_default_algorithms(), + algorithms=algorithm_names, ) with pytest.raises(InvalidKeyError): jwt.decode( encoded_bad, ssh_key_bytes, - algorithms=jwt.algorithms.get_default_algorithms(), + algorithms=algorithm_names, ) |