============================= test session starts ==============================
platform linux -- Python 3.10.12, pytest-9.0.2, pluggy-1.6.0
rootdir: /workspace/pyjwt
configfile: tox.ini
plugins: cov-7.0.0, metadata-3.1.1, anyio-4.12.1, json-report-1.5.0
collected 262 items

tests/test_advisory.py .                                                 [  0%]
tests/test_algorithms.py ............................................... [ 18%]
............................FF                                           [ 29%]
tests/test_api_jwk.py FFFFFFFFFFFFsFFFF..                                [ 37%]
tests/test_api_jws.py ................F..........F......s...FF....FF.... [ 56%]
............FF.FFFFFF                                                    [ 64%]
tests/test_api_jwt.py ..........F.FFF........F...F.......F............FF [ 83%]
.F.FFFFF.                                                                [ 86%]
tests/test_compressed_jwt.py .                                           [ 87%]
tests/test_exceptions.py .                                               [ 87%]
tests/test_jwks_client.py ....F.......F.F..F..                           [ 95%]
tests/test_jwt.py .                                                      [ 95%]
tests/test_utils.py .....x......                                         [100%]

=================================== FAILURES ===================================
________________ TestOKPAlgorithms.test_rsa_can_compute_digest _________________

self = <tests.test_algorithms.TestOKPAlgorithms object at 0x700fe133d180>

    @crypto_required
    def test_rsa_can_compute_digest(self):
        # this is the well-known sha256 hash of "foo"
        foo_hash = base64.b64decode(b"LCa0a2j/xo/5m0U8HTBBNBNCLXBkg7+g+YpeiGJm564=")
    
        algo = RSAAlgorithm(RSAAlgorithm.SHA256)
>       computed_hash = algo.compute_hash_digest(b"foo")

tests/test_algorithms.py:1093: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <jwt.algorithms.RSAAlgorithm object at 0x700fe0ffdf30>, bytestr = b'foo'

    def compute_hash_digest(self, bytestr: bytes) -> bytes:
        h = self.hash_alg()
>       h.update(bytestr)
E       AttributeError: 'SHA256' object has no attribute 'update'

jwt/algorithms.py:206: AttributeError
________________ TestOKPAlgorithms.test_hmac_can_compute_digest ________________

self = <tests.test_algorithms.TestOKPAlgorithms object at 0x700fe131ffa0>

    def test_hmac_can_compute_digest(self):
        # this is the well-known sha256 hash of "foo"
        foo_hash = base64.b64decode(b"LCa0a2j/xo/5m0U8HTBBNBNCLXBkg7+g+YpeiGJm564=")
    
        algo = HMACAlgorithm(HMACAlgorithm.SHA256)
>       computed_hash = algo.compute_hash_digest(b"foo")

tests/test_algorithms.py:1101: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <jwt.algorithms.HMACAlgorithm object at 0x700fe0e2be80>, bytestr = b'foo'

    def compute_hash_digest(self, bytestr: bytes) -> bytes:
        """
        Compute a hash digest using the specified algorithm's hash algorithm.
    
        If there is no hash algorithm, raises a NotImplementedError.
        """
>       raise NotImplementedError()
E       NotImplementedError

jwt/algorithms.py:78: NotImplementedError
______________ TestPyJWK.test_should_load_key_from_jwk_data_dict _______________

self = <tests.test_api_jwk.TestPyJWK object at 0x700fe131f9d0>

    @crypto_required
    def test_should_load_key_from_jwk_data_dict(self):
        algo = RSAAlgorithm(RSAAlgorithm.SHA256)
    
        with open(key_path("jwk_rsa_pub.json")) as keyfile:
            pub_key = algo.from_jwk(keyfile.read())
    
        key_data_str = algo.to_jwk(pub_key)
        key_data = json.loads(key_data_str)
    
        # TODO Should `to_jwk` set these?
        key_data["alg"] = "RS256"
        key_data["use"] = "sig"
        key_data["kid"] = "keyid-abc123"
    
>       jwk = PyJWK.from_dict(key_data)
E       AttributeError: type object 'PyJWK' has no attribute 'from_dict'

tests/test_api_jwk.py:31: AttributeError
___________ TestPyJWK.test_should_load_key_from_jwk_data_json_string ___________

self = <tests.test_api_jwk.TestPyJWK object at 0x700fe131fcd0>

    @crypto_required
    def test_should_load_key_from_jwk_data_json_string(self):
        algo = RSAAlgorithm(RSAAlgorithm.SHA256)
    
        with open(key_path("jwk_rsa_pub.json")) as keyfile:
            pub_key = algo.from_jwk(keyfile.read())
    
        key_data_str = algo.to_jwk(pub_key)
        key_data = json.loads(key_data_str)
    
        # TODO Should `to_jwk` set these?
        key_data["alg"] = "RS256"
        key_data["use"] = "sig"
        key_data["kid"] = "keyid-abc123"
    
>       jwk = PyJWK.from_json(json.dumps(key_data))
E       AttributeError: type object 'PyJWK' has no attribute 'from_json'

tests/test_api_jwk.py:52: AttributeError
_____________ TestPyJWK.test_should_load_key_without_alg_from_dict _____________

self = <tests.test_api_jwk.TestPyJWK object at 0x700fe12ef070>

    @crypto_required
    def test_should_load_key_without_alg_from_dict(self):
        with open(key_path("jwk_rsa_pub.json")) as keyfile:
            key_data = json.loads(keyfile.read())
    
>       jwk = PyJWK.from_dict(key_data)
E       AttributeError: type object 'PyJWK' has no attribute 'from_dict'

tests/test_api_jwk.py:63: AttributeError
___________ TestPyJWK.test_should_load_key_from_dict_with_algorithm ____________

self = <tests.test_api_jwk.TestPyJWK object at 0x700fe133d480>

    @crypto_required
    def test_should_load_key_from_dict_with_algorithm(self):
        with open(key_path("jwk_rsa_pub.json")) as keyfile:
            key_data = json.loads(keyfile.read())
    
>       jwk = PyJWK.from_dict(key_data, algorithm="RS256")
E       AttributeError: type object 'PyJWK' has no attribute 'from_dict'

tests/test_api_jwk.py:74: AttributeError
_______________ TestPyJWK.test_should_load_key_ec_p256_from_dict _______________

self = <tests.test_api_jwk.TestPyJWK object at 0x700fe133d090>

    @crypto_required
    def test_should_load_key_ec_p256_from_dict(self):
        with open(key_path("jwk_ec_pub_P-256.json")) as keyfile:
            key_data = json.loads(keyfile.read())
    
>       jwk = PyJWK.from_dict(key_data)
E       AttributeError: type object 'PyJWK' has no attribute 'from_dict'

tests/test_api_jwk.py:85: AttributeError
_______________ TestPyJWK.test_should_load_key_ec_p384_from_dict _______________

self = <tests.test_api_jwk.TestPyJWK object at 0x700fe133c970>

    @crypto_required
    def test_should_load_key_ec_p384_from_dict(self):
        with open(key_path("jwk_ec_pub_P-384.json")) as keyfile:
            key_data = json.loads(keyfile.read())
    
>       jwk = PyJWK.from_dict(key_data)
E       AttributeError: type object 'PyJWK' has no attribute 'from_dict'

tests/test_api_jwk.py:96: AttributeError
_______________ TestPyJWK.test_should_load_key_ec_p521_from_dict _______________

self = <tests.test_api_jwk.TestPyJWK object at 0x700fe133c670>

    @crypto_required
    def test_should_load_key_ec_p521_from_dict(self):
        with open(key_path("jwk_ec_pub_P-521.json")) as keyfile:
            key_data = json.loads(keyfile.read())
    
>       jwk = PyJWK.from_dict(key_data)
E       AttributeError: type object 'PyJWK' has no attribute 'from_dict'

tests/test_api_jwk.py:107: AttributeError
____________ TestPyJWK.test_should_load_key_ec_secp256k1_from_dict _____________

self = <tests.test_api_jwk.TestPyJWK object at 0x700fe133c100>

    @crypto_required
    def test_should_load_key_ec_secp256k1_from_dict(self):
        with open(key_path("jwk_ec_pub_secp256k1.json")) as keyfile:
            key_data = json.loads(keyfile.read())
    
>       jwk = PyJWK.from_dict(key_data)
E       AttributeError: type object 'PyJWK' has no attribute 'from_dict'

tests/test_api_jwk.py:118: AttributeError
________________ TestPyJWK.test_should_load_key_hmac_from_dict _________________

self = <tests.test_api_jwk.TestPyJWK object at 0x700fe133d600>

    @crypto_required
    def test_should_load_key_hmac_from_dict(self):
        with open(key_path("jwk_hmac.json")) as keyfile:
            key_data = json.loads(keyfile.read())
    
>       jwk = PyJWK.from_dict(key_data)
E       AttributeError: type object 'PyJWK' has no attribute 'from_dict'

tests/test_api_jwk.py:129: AttributeError
__________ TestPyJWK.test_should_load_key_hmac_without_alg_from_dict ___________

self = <tests.test_api_jwk.TestPyJWK object at 0x700fe133d8d0>

    @crypto_required
    def test_should_load_key_hmac_without_alg_from_dict(self):
        with open(key_path("jwk_hmac.json")) as keyfile:
            key_data = json.loads(keyfile.read())
    
        del key_data["alg"]
>       jwk = PyJWK.from_dict(key_data)
E       AttributeError: type object 'PyJWK' has no attribute 'from_dict'

tests/test_api_jwk.py:141: AttributeError
___________ TestPyJWK.test_should_load_key_okp_without_alg_from_dict ___________

self = <tests.test_api_jwk.TestPyJWK object at 0x700fe133dba0>

    @crypto_required
    def test_should_load_key_okp_without_alg_from_dict(self):
        with open(key_path("jwk_okp_pub_Ed25519.json")) as keyfile:
            key_data = json.loads(keyfile.read())
    
>       jwk = PyJWK.from_dict(key_data)
E       AttributeError: type object 'PyJWK' has no attribute 'from_dict'

tests/test_api_jwk.py:152: AttributeError
______ TestPyJWK.test_from_dict_should_throw_exception_if_arg_is_invalid _______

self = <tests.test_api_jwk.TestPyJWK object at 0x700fe133de70>

    @crypto_required
    def test_from_dict_should_throw_exception_if_arg_is_invalid(self):
        with open(key_path("jwk_rsa_pub.json")) as keyfile:
            valid_rsa_pub = json.loads(keyfile.read())
        with open(key_path("jwk_ec_pub_P-256.json")) as keyfile:
            valid_ec_pub = json.loads(keyfile.read())
        with open(key_path("jwk_okp_pub_Ed25519.json")) as keyfile:
            valid_okp_pub = json.loads(keyfile.read())
    
        # Unknown algorithm
        with pytest.raises(PyJWKError):
>           PyJWK.from_dict(valid_rsa_pub, algorithm="unknown")
E           AttributeError: type object 'PyJWK' has no attribute 'from_dict'

tests/test_api_jwk.py:168: AttributeError
____________ TestPyJWKSet.test_should_load_keys_from_jwk_data_dict _____________

self = <tests.test_api_jwk.TestPyJWKSet object at 0x700fe131f6d0>

    def test_should_load_keys_from_jwk_data_dict(self):
        algo = RSAAlgorithm(RSAAlgorithm.SHA256)
    
        with open(key_path("jwk_rsa_pub.json")) as keyfile:
            pub_key = algo.from_jwk(keyfile.read())
    
        key_data_str = algo.to_jwk(pub_key)
        key_data = json.loads(key_data_str)
    
        # TODO Should `to_jwk` set these?
        key_data["alg"] = "RS256"
        key_data["use"] = "sig"
        key_data["kid"] = "keyid-abc123"
    
>       jwk_set = PyJWKSet.from_dict({"keys": [key_data]})
E       AttributeError: type object 'PyJWKSet' has no attribute 'from_dict'

tests/test_api_jwk.py:223: AttributeError
_________ TestPyJWKSet.test_should_load_keys_from_jwk_data_json_string _________

self = <tests.test_api_jwk.TestPyJWKSet object at 0x700fe133dd50>

    def test_should_load_keys_from_jwk_data_json_string(self):
        algo = RSAAlgorithm(RSAAlgorithm.SHA256)
    
        with open(key_path("jwk_rsa_pub.json")) as keyfile:
            pub_key = algo.from_jwk(keyfile.read())
    
        key_data_str = algo.to_jwk(pub_key)
        key_data = json.loads(key_data_str)
    
        # TODO Should `to_jwk` set these?
        key_data["alg"] = "RS256"
        key_data["use"] = "sig"
        key_data["kid"] = "keyid-abc123"
    
>       jwk_set = PyJWKSet.from_json(json.dumps({"keys": [key_data]}))
E       AttributeError: type object 'PyJWKSet' has no attribute 'from_json'

tests/test_api_jwk.py:244: AttributeError
_________________ TestPyJWKSet.test_keyset_should_index_by_kid _________________

self = <tests.test_api_jwk.TestPyJWKSet object at 0x700fe133d9c0>

    def test_keyset_should_index_by_kid(self):
        algo = RSAAlgorithm(RSAAlgorithm.SHA256)
    
        with open(key_path("jwk_rsa_pub.json")) as keyfile:
            pub_key = algo.from_jwk(keyfile.read())
    
        key_data_str = algo.to_jwk(pub_key)
        key_data = json.loads(key_data_str)
    
        # TODO Should `to_jwk` set these?
        key_data["alg"] = "RS256"
        key_data["use"] = "sig"
        key_data["kid"] = "keyid-abc123"
    
>       jwk_set = PyJWKSet.from_dict({"keys": [key_data]})
E       AttributeError: type object 'PyJWKSet' has no attribute 'from_dict'

tests/test_api_jwk.py:265: AttributeError
__________________ TestPyJWKSet.test_keyset_with_unknown_alg ___________________

self = <tests.test_api_jwk.TestPyJWKSet object at 0x700fe133d4e0>

    def test_keyset_with_unknown_alg(self):
        # first keyset with unusable key and usable key
        with open(key_path("jwk_keyset_with_unknown_alg.json")) as keyfile:
            jwks_text = keyfile.read()
        jwks = json.loads(jwks_text)
        assert len(jwks.get("keys")) == 2
>       keyset = PyJWKSet.from_json(jwks_text)
E       AttributeError: type object 'PyJWKSet' has no attribute 'from_json'

tests/test_api_jwk.py:279: AttributeError
__________________ TestJWS.test_encode_with_headers_alg_none ___________________

self = <tests.test_api_jws.TestJWS object at 0x700fe133fbb0>
jws = <jwt.api_jws.PyJWS object at 0x700fe0d35960>, payload = b'hello world'

    def test_encode_with_headers_alg_none(self, jws, payload):
        msg = jws.encode(payload, key=None, headers={"alg": "none"})
        with pytest.raises(DecodeError) as context:
>           jws.decode(msg, algorithms=["none"])

tests/test_api_jws.py:172: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
jwt/api_jws.py:227: in decode
    decoded = self.decode_complete(jwt, key, algorithms, options, **kwargs)
jwt/api_jws.py:209: in decode_complete
    key_obj = alg_obj.prepare_key(key)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <jwt.algorithms.NoneAlgorithm object at 0x700fe0d368c0>, key = ''

    def prepare_key(self, key: Any) -> Any:
        if key is not None:
>           raise InvalidKeyError('When alg = "none", key must be None.')
E           jwt.exceptions.InvalidKeyError: When alg = "none", key must be None.

jwt/algorithms.py:128: InvalidKeyError
_________________ TestJWS.test_decode_with_optional_algorithms _________________

self = <tests.test_api_jws.TestJWS object at 0x700fe117d990>
jws = <jwt.api_jws.PyJWS object at 0x700fe0df06d0>

    def test_decode_with_optional_algorithms(self, jws):
        example_secret = "secret"
        example_jws = (
            b"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9."
            b"aGVsbG8gd29ybGQ."
            b"SIr03zM64awWRdPrAM_61QWsZchAtgDV3pphfHPPWkI"
        )
    
>       with pytest.raises(DecodeError) as exc:
E       Failed: DID NOT RAISE <class 'jwt.exceptions.DecodeError'>

tests/test_api_jws.py:326: Failed
____________________ TestJWS.test_sorting_of_headers[False] ____________________

self = <tests.test_api_jws.TestJWS object at 0x700fe117d570>
jws = <jwt.api_jws.PyJWS object at 0x700fe0cc9930>, payload = b'hello world'
sort_headers = False

    @pytest.mark.parametrize("sort_headers", (False, True))
    def test_sorting_of_headers(self, jws, payload, sort_headers):
>       jws_message = jws.encode(
            payload,
            key="\xc2",
            headers={"b": "1", "a": "2"},
            sort_headers=sort_headers,
        )
E       TypeError: PyJWS.encode() got an unexpected keyword argument 'sort_headers'

tests/test_api_jws.py:418: TypeError
____________________ TestJWS.test_sorting_of_headers[True] _____________________

self = <tests.test_api_jws.TestJWS object at 0x700fe117d540>
jws = <jwt.api_jws.PyJWS object at 0x700fe0df22f0>, payload = b'hello world'
sort_headers = True

    @pytest.mark.parametrize("sort_headers", (False, True))
    def test_sorting_of_headers(self, jws, payload, sort_headers):
>       jws_message = jws.encode(
            payload,
            key="\xc2",
            headers={"b": "1", "a": "2"},
            sort_headers=sort_headers,
        )
E       TypeError: PyJWS.encode() got an unexpected keyword argument 'sort_headers'

tests/test_api_jws.py:418: TypeError
________________ TestJWS.test_decode_with_algo_none_should_fail ________________

self = <tests.test_api_jws.TestJWS object at 0x700fe117f070>
jws = <jwt.api_jws.PyJWS object at 0x700fe0cc8c40>, payload = b'hello world'

    def test_decode_with_algo_none_should_fail(self, jws, payload):
>       jws_message = jws.encode(payload, key=None, algorithm=None)

tests/test_api_jws.py:480: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <jwt.api_jws.PyJWS object at 0x700fe0cc8c40>, payload = b'hello world'
key = None, algorithm = None, headers = {}, json_encoder = None

    def encode(
        self,
        payload: bytes,
        key: AllowedPrivateKeys | str | bytes,
        algorithm: str = "HS256",
        headers: dict[str, Any] | None = None,
        json_encoder: type[json.JSONEncoder] | None = None,
    ) -> str:
        # Prepare the header
        if headers is None:
            headers = {}
        else:
            headers = dict(headers)  # Make a copy
    
        # Determine the algorithm - from headers or from the algorithm parameter
        alg = headers.get("alg", algorithm)
    
        # Check that we have a valid algorithm
        if alg not in self._algorithms:
>           raise NotImplementedError("Algorithm not supported")
E           NotImplementedError: Algorithm not supported

jwt/api_jws.py:117: NotImplementedError
_______ TestJWS.test_decode_with_algo_none_and_verify_false_should_pass ________

self = <tests.test_api_jws.TestJWS object at 0x700fe117f370>
jws = <jwt.api_jws.PyJWS object at 0x700fe0d1e5c0>, payload = b'hello world'

    def test_decode_with_algo_none_and_verify_false_should_pass(self, jws, payload):
>       jws_message = jws.encode(payload, key=None, algorithm=None)

tests/test_api_jws.py:486: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <jwt.api_jws.PyJWS object at 0x700fe0d1e5c0>, payload = b'hello world'
key = None, algorithm = None, headers = {}, json_encoder = None

    def encode(
        self,
        payload: bytes,
        key: AllowedPrivateKeys | str | bytes,
        algorithm: str = "HS256",
        headers: dict[str, Any] | None = None,
        json_encoder: type[json.JSONEncoder] | None = None,
    ) -> str:
        # Prepare the header
        if headers is None:
            headers = {}
        else:
            headers = dict(headers)  # Make a copy
    
        # Determine the algorithm - from headers or from the algorithm parameter
        alg = headers.get("alg", algorithm)
    
        # Check that we have a valid algorithm
        if alg not in self._algorithms:
>           raise NotImplementedError("Algorithm not supported")
E           NotImplementedError: Algorithm not supported

jwt/api_jws.py:117: NotImplementedError
__________________ TestJWS.test_encode_with_typ_empty_string ___________________

self = <tests.test_api_jws.TestJWS object at 0x700fe11a4400>
jws = <jwt.api_jws.PyJWS object at 0x700fe0ccaf20>, payload = b'hello world'

    def test_encode_with_typ_empty_string(self, jws, payload):
        token = jws.encode(payload, "secret", headers={"typ": ""})
    
        header = token[0 : token.index(".")].encode()
        header = base64url_decode(header)
        header_obj = json.loads(header)
    
>       assert "typ" not in header_obj
E       AssertionError: assert 'typ' not in {'alg': 'HS256', 'typ': ''}

tests/test_api_jws.py:701: AssertionError
______________________ TestJWS.test_encode_with_typ_none _______________________

self = <tests.test_api_jws.TestJWS object at 0x700fe11a4700>
jws = <jwt.api_jws.PyJWS object at 0x700fe0df2920>, payload = b'hello world'

    def test_encode_with_typ_none(self, jws, payload):
        token = jws.encode(payload, "secret", headers={"typ": None})
    
        header = token[0 : token.index(".")].encode()
        header = base64url_decode(header)
        header_obj = json.loads(header)
    
>       assert "typ" not in header_obj
E       AssertionError: assert 'typ' not in {'alg': 'HS256', 'typ': None}

tests/test_api_jws.py:710: AssertionError
________________ TestJWS.test_encode_fails_on_invalid_kid_types ________________

self = <tests.test_api_jws.TestJWS object at 0x700fe11a4d00>
jws = <jwt.api_jws.PyJWS object at 0x700fe0cc84f0>, payload = b'hello world'

    def test_encode_fails_on_invalid_kid_types(self, jws, payload):
>       with pytest.raises(InvalidTokenError) as exc:
E       Failed: DID NOT RAISE <class 'jwt.exceptions.InvalidTokenError'>

tests/test_api_jws.py:724: Failed
_______________ TestJWS.test_encode_decode_with_detached_content _______________

self = <tests.test_api_jws.TestJWS object at 0x700fe117ff10>
jws = <jwt.api_jws.PyJWS object at 0x700fe117e440>, payload = b'hello world'

    def test_encode_decode_with_detached_content(self, jws, payload):
        secret = "secret"
>       jws_message = jws.encode(
            payload, secret, algorithm="HS256", is_payload_detached=True
        )
E       TypeError: PyJWS.encode() got an unexpected keyword argument 'is_payload_detached'

tests/test_api_jws.py:736: TypeError
_____________ TestJWS.test_encode_detached_content_with_b64_header _____________

self = <tests.test_api_jws.TestJWS object at 0x700fe117d6c0>
jws = <jwt.api_jws.PyJWS object at 0x700fe0cc8f70>, payload = b'hello world'

    def test_encode_detached_content_with_b64_header(self, jws, payload):
        secret = "secret"
    
        # Check that detached content is automatically detected when b64 is false
        headers = {"b64": False}
        token = jws.encode(payload, secret, "HS256", headers)
    
        msg_header, msg_payload, _ = token.split(".")
        msg_header = base64url_decode(msg_header.encode())
        msg_header_obj = json.loads(msg_header)
    
        assert "b64" in msg_header_obj
        assert msg_header_obj["b64"] is False
        # Check that the payload is not inside the token
>       assert not msg_payload
E       AssertionError: assert not 'aGVsbG8gd29ybGQ'

tests/test_api_jws.py:756: AssertionError
_________ TestJWS.test_decode_detached_content_without_proper_argument _________

self = <tests.test_api_jws.TestJWS object at 0x700fe117c880>
jws = <jwt.api_jws.PyJWS object at 0x700fe0e2f760>

    def test_decode_detached_content_without_proper_argument(self, jws):
        example_jws = (
            "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImI2NCI6ZmFsc2V9"
            "."
            ".65yNkX_ZH4A_6pHaTL_eI84OXOHtfl4K0k5UnlXZ8f4"
        )
        example_secret = "secret"
    
        with pytest.raises(DecodeError) as exc:
            jws.decode(example_jws, example_secret, algorithms=["HS256"])
    
>       assert (
            'It is required that you pass in a value for the "detached_payload" argument to decode a message having the b64 header set to false.'
            in str(exc.value)
        )
E       assert 'It is required that you pass in a value for the "detached_payload" argument to decode a message having the b64 header set to false.' in 'Signature verification failed'
E        +  where 'Signature verification failed' = str(InvalidSignatureError('Signature verification failed'))
E        +    where InvalidSignatureError('Signature verification failed') = <ExceptionInfo InvalidSignatureError('Signature verification failed') tblen=3>.value

tests/test_api_jws.py:780: AssertionError
________________ TestJWS.test_decode_warns_on_unsupported_kwarg ________________

self = <tests.test_api_jws.TestJWS object at 0x700fe117ebc0>
jws = <jwt.api_jws.PyJWS object at 0x700fe0d1b5b0>, payload = b'hello world'

    def test_decode_warns_on_unsupported_kwarg(self, jws, payload):
        secret = "secret"
>       jws_message = jws.encode(
            payload, secret, algorithm="HS256", is_payload_detached=True
        )
E       TypeError: PyJWS.encode() got an unexpected keyword argument 'is_payload_detached'

tests/test_api_jws.py:787: TypeError
___________ TestJWS.test_decode_complete_warns_on_unuspported_kwarg ____________

self = <tests.test_api_jws.TestJWS object at 0x700fe117fca0>
jws = <jwt.api_jws.PyJWS object at 0x700fe133cb20>, payload = b'hello world'

    def test_decode_complete_warns_on_unuspported_kwarg(self, jws, payload):
        secret = "secret"
>       jws_message = jws.encode(
            payload, secret, algorithm="HS256", is_payload_detached=True
        )
E       TypeError: PyJWS.encode() got an unexpected keyword argument 'is_payload_detached'

tests/test_api_jws.py:804: TypeError
____________ TestJWT.test_decode_raises_exception_if_exp_is_not_int ____________

self = <tests.test_api_jwt.TestJWT object at 0x700fe11a68f0>
jwt = <jwt.api_jwt.PyJWT object at 0x700fe0d1b850>

    def test_decode_raises_exception_if_exp_is_not_int(self, jwt):
        # >>> jwt.encode({'exp': 'not-an-int'}, 'secret')
        example_jwt = (
            "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9."
            "eyJleHAiOiJub3QtYW4taW50In0."
            "P65iYgoHtBqB07PMtBSuKNUEIPPPfmjfJG217cEE66s"
        )
    
        with pytest.raises(DecodeError) as exc:
>           jwt.decode(example_jwt, "secret", algorithms=["HS256"])

tests/test_api_jwt.py:206: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
jwt/api_jwt.py:227: in decode
    decoded = self.decode_complete(jwt, key, algorithms, options, audience, issuer, leeway, **kwargs)
jwt/api_jwt.py:208: in decode_complete
    self._validate_claims(payload, merged_options, audience, issuer, leeway)
jwt/api_jwt.py:80: in _validate_claims
    self._validate_exp(payload, leeway)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <jwt.api_jwt.PyJWT object at 0x700fe0d1b850>
payload = {'exp': 'not-an-int'}, leeway = 0

    def _validate_exp(self, payload: dict[str, Any], leeway: int | float) -> None:
        """Validate the expiration time."""
        if "exp" not in payload:
            return
    
        exp = payload["exp"]
        if not isinstance(exp, (int, float)):
>           raise ExpiredSignatureError("Expiration time must be an integer")
E           jwt.exceptions.ExpiredSignatureError: Expiration time must be an integer

jwt/api_jwt.py:105: ExpiredSignatureError
_______ TestJWT.test_decode_raises_exception_if_iat_is_greater_than_now ________

self = <tests.test_api_jwt.TestJWT object at 0x700fe11a6f50>
jwt = <jwt.api_jwt.PyJWT object at 0x700fe0d37ca0>
payload = {'claim': 'insanity', 'exp': 1769605190, 'iat': 1769605185, 'iss': 'jeff'}

    def test_decode_raises_exception_if_iat_is_greater_than_now(self, jwt, payload):
        payload["iat"] = utc_timestamp() + 10
        secret = "secret"
        jwt_message = jwt.encode(payload, secret)
    
>       with pytest.raises(ImmatureSignatureError):
E       Failed: DID NOT RAISE <class 'jwt.exceptions.ImmatureSignatureError'>

tests/test_api_jwt.py:226: Failed
_____________ TestJWT.test_decode_works_if_iat_is_str_of_a_number ______________

self = <tests.test_api_jwt.TestJWT object at 0x700fe11a7250>
jwt = <jwt.api_jwt.PyJWT object at 0x700fe0df63e0>
payload = {'claim': 'insanity', 'exp': 1769605190, 'iat': '1638202770', 'iss': 'jeff'}

    def test_decode_works_if_iat_is_str_of_a_number(self, jwt, payload):
        payload["iat"] = "1638202770"
        secret = "secret"
        jwt_message = jwt.encode(payload, secret)
>       data = jwt.decode(jwt_message, secret, algorithms=["HS256"])

tests/test_api_jwt.py:233: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
jwt/api_jwt.py:227: in decode
    decoded = self.decode_complete(jwt, key, algorithms, options, audience, issuer, leeway, **kwargs)
jwt/api_jwt.py:208: in decode_complete
    self._validate_claims(payload, merged_options, audience, issuer, leeway)
jwt/api_jwt.py:88: in _validate_claims
    self._validate_iat(payload)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <jwt.api_jwt.PyJWT object at 0x700fe0df63e0>
payload = {'claim': 'insanity', 'exp': 1769605190, 'iat': '1638202770', 'iss': 'jeff'}

    def _validate_iat(self, payload: dict[str, Any]) -> None:
        """Validate the issued at time."""
        if "iat" not in payload:
            return
    
        iat = payload["iat"]
        if not isinstance(iat, (int, float)):
>           raise InvalidIssuedAtError("Issued at time must be an integer")
E           jwt.exceptions.InvalidIssuedAtError: Issued at time must be an integer

jwt/api_jwt.py:131: InvalidIssuedAtError
____________ TestJWT.test_decode_raises_exception_if_nbf_is_not_int ____________

self = <tests.test_api_jwt.TestJWT object at 0x700fe11a7550>
jwt = <jwt.api_jwt.PyJWT object at 0x700fe0d46620>

    def test_decode_raises_exception_if_nbf_is_not_int(self, jwt):
        # >>> jwt.encode({'nbf': 'not-an-int'}, 'secret')
        example_jwt = (
            "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9."
            "eyJuYmYiOiJub3QtYW4taW50In0."
            "c25hldC8G2ZamC8uKpax9sYMTgdZo3cxrmzFHaAAluw"
        )
    
        with pytest.raises(DecodeError):
>           jwt.decode(example_jwt, "secret", algorithms=["HS256"])

tests/test_api_jwt.py:245: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
jwt/api_jwt.py:227: in decode
    decoded = self.decode_complete(jwt, key, algorithms, options, audience, issuer, leeway, **kwargs)
jwt/api_jwt.py:208: in decode_complete
    self._validate_claims(payload, merged_options, audience, issuer, leeway)
jwt/api_jwt.py:84: in _validate_claims
    self._validate_nbf(payload, leeway)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <jwt.api_jwt.PyJWT object at 0x700fe0d46620>
payload = {'nbf': 'not-an-int'}, leeway = 0

    def _validate_nbf(self, payload: dict[str, Any], leeway: int | float) -> None:
        """Validate the not before time."""
        if "nbf" not in payload:
            return
    
        nbf = payload["nbf"]
        if not isinstance(nbf, (int, float)):
>           raise ImmatureSignatureError("Not before time must be an integer")
E           jwt.exceptions.ImmatureSignatureError: Not before time must be an integer

jwt/api_jwt.py:118: ImmatureSignatureError
_______________ TestJWT.test_decode_with_expiration_with_leeway ________________

self = <tests.test_api_jwt.TestJWT object at 0x700fe11a64d0>
jwt = <jwt.api_jwt.PyJWT object at 0x700fe0e29570>
payload = {'claim': 'insanity', 'exp': 1769605173, 'iss': 'jeff'}

    def test_decode_with_expiration_with_leeway(self, jwt, payload):
        payload["exp"] = utc_timestamp() - 2
        secret = "secret"
        jwt_message = jwt.encode(payload, secret)
    
        # With 5 seconds leeway, should be ok
        for leeway in (5, timedelta(seconds=5)):
>           decoded = jwt.decode(
                jwt_message, secret, leeway=leeway, algorithms=["HS256"]
            )

tests/test_api_jwt.py:370: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
jwt/api_jwt.py:227: in decode
    decoded = self.decode_complete(jwt, key, algorithms, options, audience, issuer, leeway, **kwargs)
jwt/api_jwt.py:208: in decode_complete
    self._validate_claims(payload, merged_options, audience, issuer, leeway)
jwt/api_jwt.py:80: in _validate_claims
    self._validate_exp(payload, leeway)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <jwt.api_jwt.PyJWT object at 0x700fe0e29570>
payload = {'claim': 'insanity', 'exp': 1769605173, 'iss': 'jeff'}
leeway = datetime.timedelta(seconds=5)

    def _validate_exp(self, payload: dict[str, Any], leeway: int | float) -> None:
        """Validate the expiration time."""
        if "exp" not in payload:
            return
    
        exp = payload["exp"]
        if not isinstance(exp, (int, float)):
            raise ExpiredSignatureError("Expiration time must be an integer")
    
        now = timegm(datetime.now(tz=timezone.utc).utctimetuple())
>       if exp < (now - leeway):
E       TypeError: unsupported operand type(s) for -: 'int' and 'datetime.timedelta'

jwt/api_jwt.py:108: TypeError
__________________ TestJWT.test_check_audience_none_specified __________________

self = <tests.test_api_jwt.TestJWT object at 0x700fe11cc280>
jwt = <jwt.api_jwt.PyJWT object at 0x700fe0d374c0>

    def test_check_audience_none_specified(self, jwt):
        payload = {"some": "payload", "aud": "urn:me"}
        token = jwt.encode(payload, "secret")
>       with pytest.raises(InvalidAudienceError):
E       Failed: DID NOT RAISE <class 'jwt.exceptions.InvalidAudienceError'>

tests/test_api_jwt.py:409: Failed
____ TestJWT.test_raise_exception_token_with_aud_none_and_without_audience _____

self = <tests.test_api_jwt.TestJWT object at 0x700fe11a5510>
jwt = <jwt.api_jwt.PyJWT object at 0x700fe0d46860>

    def test_raise_exception_token_with_aud_none_and_without_audience(self, jwt):
        payload = {"some": "payload", "aud": None}
        token = jwt.encode(payload, "secret")
    
        with pytest.raises(MissingRequiredClaimError) as exc:
>           jwt.decode(token, "secret", audience="urn:me", algorithms=["HS256"])

tests/test_api_jwt.py:481: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
jwt/api_jwt.py:227: in decode
    decoded = self.decode_complete(jwt, key, algorithms, options, audience, issuer, leeway, **kwargs)
jwt/api_jwt.py:208: in decode_complete
    self._validate_claims(payload, merged_options, audience, issuer, leeway)
jwt/api_jwt.py:92: in _validate_claims
    self._validate_aud(payload, audience)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <jwt.api_jwt.PyJWT object at 0x700fe0d46860>
payload = {'aud': None, 'some': 'payload'}, audience = 'urn:me'

    def _validate_aud(self, payload: dict[str, Any], audience: str | Iterable[str] | None) -> None:
        """Validate the audience."""
        if audience is None:
            return
    
        if not isinstance(audience, (str, Iterable)):
            raise TypeError("audience must be a string, iterable or None")
    
        if "aud" not in payload:
            raise MissingRequiredClaimError("aud")
    
        aud = payload["aud"]
        if isinstance(aud, str):
            aud = [aud]
        elif not isinstance(aud, Iterable):
>           raise InvalidAudienceError("Invalid claim format in token")
E           jwt.exceptions.InvalidAudienceError: Invalid claim format in token

jwt/api_jwt.py:148: InvalidAudienceError
_________ TestJWT.test_decode_with_verify_exp_option_and_signature_off _________

self = <tests.test_api_jwt.TestJWT object at 0x700fe11ce650>
jwt = <jwt.api_jwt.PyJWT object at 0x700fe0e0d990>
payload = {'claim': 'insanity', 'exp': 1769605174, 'iss': 'jeff'}

    def test_decode_with_verify_exp_option_and_signature_off(self, jwt, payload):
        payload["exp"] = utc_timestamp() - 1
        secret = "secret"
        jwt_message = jwt.encode(payload, secret)
    
>       jwt.decode(
            jwt_message,
            options={"verify_signature": False},
        )

tests/test_api_jwt.py:656: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
jwt/api_jwt.py:227: in decode
    decoded = self.decode_complete(jwt, key, algorithms, options, audience, issuer, leeway, **kwargs)
jwt/api_jwt.py:208: in decode_complete
    self._validate_claims(payload, merged_options, audience, issuer, leeway)
jwt/api_jwt.py:80: in _validate_claims
    self._validate_exp(payload, leeway)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <jwt.api_jwt.PyJWT object at 0x700fe0e0d990>
payload = {'claim': 'insanity', 'exp': 1769605174, 'iss': 'jeff'}, leeway = 0

    def _validate_exp(self, payload: dict[str, Any], leeway: int | float) -> None:
        """Validate the expiration time."""
        if "exp" not in payload:
            return
    
        exp = payload["exp"]
        if not isinstance(exp, (int, float)):
            raise ExpiredSignatureError("Expiration time must be an integer")
    
        now = timegm(datetime.now(tz=timezone.utc).utctimetuple())
        if exp < (now - leeway):
>           raise ExpiredSignatureError("Signature has expired")
E           jwt.exceptions.ExpiredSignatureError: Signature has expired

jwt/api_jwt.py:109: ExpiredSignatureError
_________________ TestJWT.test_decode_with_optional_algorithms _________________

self = <tests.test_api_jwt.TestJWT object at 0x700fe11ce950>
jwt = <jwt.api_jwt.PyJWT object at 0x700fe117ccd0>
payload = {'claim': 'insanity', 'exp': 1769605190, 'iss': 'jeff'}

    def test_decode_with_optional_algorithms(self, jwt, payload):
        secret = "secret"
        jwt_message = jwt.encode(payload, secret)
    
>       with pytest.raises(DecodeError) as exc:
E       Failed: DID NOT RAISE <class 'jwt.exceptions.DecodeError'>

tests/test_api_jwt.py:671: Failed
__________________ TestJWT.test_decode_legacy_verify_warning ___________________

self = <tests.test_api_jwt.TestJWT object at 0x700fe11a68c0>
jwt = <jwt.api_jwt.PyJWT object at 0x700fe0d60130>
payload = {'claim': 'insanity', 'exp': 1769605190, 'iss': 'jeff'}

    def test_decode_legacy_verify_warning(self, jwt, payload):
        secret = "secret"
        jwt_message = jwt.encode(payload, secret)
    
>       with pytest.deprecated_call():
E       Failed: DID NOT WARN. No warnings of type (<class 'DeprecationWarning'>, <class 'PendingDeprecationWarning'>, <class 'FutureWarning'>) were emitted.
E        Emitted warnings: [].

tests/test_api_jwt.py:689: Failed
________________ TestJWT.test_decode_warns_on_unsupported_kwarg ________________

self = <tests.test_api_jwt.TestJWT object at 0x700fe117c310>
jwt = <jwt.api_jwt.PyJWT object at 0x700fe11cc130>
payload = {'claim': 'insanity', 'exp': 1769605190, 'iss': 'jeff'}

    def test_decode_warns_on_unsupported_kwarg(self, jwt, payload):
        secret = "secret"
        jwt_message = jwt.encode(payload, secret)
    
>       with pytest.warns(RemovedInPyjwt3Warning) as record:
E       Failed: DID NOT WARN. No warnings of type (<class 'jwt.warnings.RemovedInPyjwt3Warning'>,) were emitted.
E        Emitted warnings: [].

tests/test_api_jwt.py:713: Failed
___________ TestJWT.test_decode_complete_warns_on_unsupported_kwarg ____________

self = <tests.test_api_jwt.TestJWT object at 0x700fe11ce7a0>
jwt = <jwt.api_jwt.PyJWT object at 0x700fe0d9e560>
payload = {'claim': 'insanity', 'exp': 1769605190, 'iss': 'jeff'}

    def test_decode_complete_warns_on_unsupported_kwarg(self, jwt, payload):
        secret = "secret"
        jwt_message = jwt.encode(payload, secret)
    
>       with pytest.warns(RemovedInPyjwt3Warning) as record:
E       Failed: DID NOT WARN. No warnings of type (<class 'jwt.warnings.RemovedInPyjwt3Warning'>,) were emitted.
E        Emitted warnings: [].

tests/test_api_jwt.py:722: Failed
_____________ TestJWT.test_decode_strict_aud_forbids_list_audience _____________

self = <tests.test_api_jwt.TestJWT object at 0x700fe11ce620>
jwt = <jwt.api_jwt.PyJWT object at 0x700fe0d1afe0>
payload = {'aud': 'urn:foo', 'claim': 'insanity', 'exp': 1769605190, 'iss': 'jeff'}

    def test_decode_strict_aud_forbids_list_audience(self, jwt, payload):
        secret = "secret"
        payload["aud"] = "urn:foo"
        jwt_message = jwt.encode(payload, secret)
    
        # Decodes without `strict_aud`.
        jwt.decode(
            jwt_message,
            secret,
            audience=["urn:foo", "urn:bar"],
            options={"strict_aud": False},
            algorithms=["HS256"],
        )
    
        # Fails with `strict_aud`.
>       with pytest.raises(InvalidAudienceError, match=r"Invalid audience \(strict\)"):
E       Failed: DID NOT RAISE <class 'jwt.exceptions.InvalidAudienceError'>

tests/test_api_jwt.py:742: Failed
______________ TestJWT.test_decode_strict_aud_forbids_list_claim _______________

self = <tests.test_api_jwt.TestJWT object at 0x700fe11cdea0>
jwt = <jwt.api_jwt.PyJWT object at 0x700fe0d9cf10>
payload = {'aud': ['urn:foo', 'urn:bar'], 'claim': 'insanity', 'exp': 1769605190, 'iss': 'jeff'}

    def test_decode_strict_aud_forbids_list_claim(self, jwt, payload):
        secret = "secret"
        payload["aud"] = ["urn:foo", "urn:bar"]
        jwt_message = jwt.encode(payload, secret)
    
        # Decodes without `strict_aud`.
        jwt.decode(
            jwt_message,
            secret,
            audience="urn:foo",
            options={"strict_aud": False},
            algorithms=["HS256"],
        )
    
        # Fails with `strict_aud`.
>       with pytest.raises(
            InvalidAudienceError, match=r"Invalid claim format in token \(strict\)"
        ):
E       Failed: DID NOT RAISE <class 'jwt.exceptions.InvalidAudienceError'>

tests/test_api_jwt.py:766: Failed
________________ TestJWT.test_decode_strict_aud_does_not_match _________________

self = <tests.test_api_jwt.TestJWT object at 0x700fe11cd8a0>
jwt = <jwt.api_jwt.PyJWT object at 0x700fe0d197b0>
payload = {'aud': 'urn:foo', 'claim': 'insanity', 'exp': 1769605190, 'iss': 'jeff'}

    def test_decode_strict_aud_does_not_match(self, jwt, payload):
        secret = "secret"
        payload["aud"] = "urn:foo"
        jwt_message = jwt.encode(payload, secret)
    
        with pytest.raises(
            InvalidAudienceError, match=r"Audience doesn't match \(strict\)"
        ):
>           jwt.decode(
                jwt_message,
                secret,
                audience="urn:bar",
                options={"strict_aud": True},
                algorithms=["HS256"],
            )

tests/test_api_jwt.py:785: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
jwt/api_jwt.py:227: in decode
    decoded = self.decode_complete(jwt, key, algorithms, options, audience, issuer, leeway, **kwargs)
jwt/api_jwt.py:208: in decode_complete
    self._validate_claims(payload, merged_options, audience, issuer, leeway)
jwt/api_jwt.py:92: in _validate_claims
    self._validate_aud(payload, audience)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <jwt.api_jwt.PyJWT object at 0x700fe0d197b0>
payload = {'aud': 'urn:foo', 'claim': 'insanity', 'exp': 1769605190, 'iss': 'jeff'}
audience = ['urn:bar']

    def _validate_aud(self, payload: dict[str, Any], audience: str | Iterable[str] | None) -> None:
        """Validate the audience."""
        if audience is None:
            return
    
        if not isinstance(audience, (str, Iterable)):
            raise TypeError("audience must be a string, iterable or None")
    
        if "aud" not in payload:
            raise MissingRequiredClaimError("aud")
    
        aud = payload["aud"]
        if isinstance(aud, str):
            aud = [aud]
        elif not isinstance(aud, Iterable):
            raise InvalidAudienceError("Invalid claim format in token")
        elif not all(isinstance(item, str) for item in aud):
            raise InvalidAudienceError("Invalid claim format in token")
    
        if isinstance(audience, str):
            audience = [audience]
    
        if not any(a in aud for a in audience):
>           raise InvalidAudienceError("Invalid audience")
E           jwt.exceptions.InvalidAudienceError: Invalid audience

jwt/api_jwt.py:156: InvalidAudienceError

During handling of the above exception, another exception occurred:

self = <tests.test_api_jwt.TestJWT object at 0x700fe11cd8a0>
jwt = <jwt.api_jwt.PyJWT object at 0x700fe0d197b0>
payload = {'aud': 'urn:foo', 'claim': 'insanity', 'exp': 1769605190, 'iss': 'jeff'}

    def test_decode_strict_aud_does_not_match(self, jwt, payload):
        secret = "secret"
        payload["aud"] = "urn:foo"
        jwt_message = jwt.encode(payload, secret)
    
>       with pytest.raises(
            InvalidAudienceError, match=r"Audience doesn't match \(strict\)"
        ):
E       AssertionError: Regex pattern did not match.
E         Expected regex: "Audience doesn't match \\(strict\\)"
E         Actual message: 'Invalid audience'

tests/test_api_jwt.py:782: AssertionError
__________ TestPyJWKClient.test_get_signing_keys_raises_if_none_found __________

self = <tests.test_jwks_client.TestPyJWKClient object at 0x700fe121d720>

    def test_get_signing_keys_raises_if_none_found(self):
        url = "https://dev-87evx9ru.auth0.com/.well-known/jwks.json"
    
        mocked_key = RESPONSE_DATA_WITH_MATCHING_KID["keys"][0].copy()
        mocked_key["use"] = "enc"
        response = {"keys": [mocked_key]}
        with mocked_success_response(response):
            jwks_client = PyJWKClient(url)
    
>           with pytest.raises(PyJWKClientError) as exc:
E           Failed: DID NOT RAISE <class 'jwt.exceptions.PyJWKClientError'>

tests/test_jwks_client.py:146: Failed
______ TestPyJWKClient.test_get_jwt_set_failed_request_should_clear_cache ______

self = <tests.test_jwks_client.TestPyJWKClient object at 0x700fe117e860>

    def test_get_jwt_set_failed_request_should_clear_cache(self):
        url = "https://dev-87evx9ru.auth0.com/.well-known/jwks.json"
    
        jwks_client = PyJWKClient(url)
        with mocked_success_response(RESPONSE_DATA_WITH_MATCHING_KID):
            jwks_client.get_jwk_set()
    
        with pytest.raises(PyJWKClientError):
            with mocked_failed_response():
>               jwks_client.get_jwk_set(refresh=True)
E               TypeError: PyJWKClient.get_jwk_set() got an unexpected keyword argument 'refresh'

tests/test_jwks_client.py:283: TypeError
________________ TestPyJWKClient.test_get_jwt_set_refresh_cache ________________

self = <tests.test_jwks_client.TestPyJWKClient object at 0x700fe121ea10>

    def test_get_jwt_set_refresh_cache(self):
        url = "https://dev-87evx9ru.auth0.com/.well-known/jwks.json"
        jwks_client = PyJWKClient(url)
    
        kid = "NEE1QURBOTM4MzI5RkFDNTYxOTU1MDg2ODgwQ0UzMTk1QjYyRkRFQw"
    
        # The first call will return response with no matching kid,
        # the function should make another call to try to refresh the cache.
        with mocked_first_call_wrong_kid_second_call_correct_kid(
            RESPONSE_DATA_NO_MATCHING_KID, RESPONSE_DATA_WITH_MATCHING_KID
        ) as call_data:
>           jwks_client.get_signing_key(kid)

tests/test_jwks_client.py:307: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <jwt.jwks_client.PyJWKClient object at 0x700fe0d19e10>
kid = 'NEE1QURBOTM4MzI5RkFDNTYxOTU1MDg2ODgwQ0UzMTk1QjYyRkRFQw'

    def get_signing_key(self, kid: str) -> PyJWK:
        signing_keys = self.get_signing_keys()
        for key in signing_keys:
            if key.key_id == kid:
                return key
>       raise PyJWKClientError(f'Unable to find a signing key that matches: "{kid}"')
E       jwt.exceptions.PyJWKClientError: Unable to find a signing key that matches: "NEE1QURBOTM4MzI5RkFDNTYxOTU1MDg2ODgwQ0UzMTk1QjYyRkRFQw"

jwt/jwks_client.py:72: PyJWKClientError
___________________ TestPyJWKClient.test_get_jwt_set_timeout ___________________

self = <tests.test_jwks_client.TestPyJWKClient object at 0x700fe121dea0>

    def test_get_jwt_set_timeout(self):
        url = "https://dev-87evx9ru.auth0.com/.well-known/jwks.json"
        jwks_client = PyJWKClient(url, timeout=5)
    
        with pytest.raises(PyJWKClientError) as exc:
            with mocked_timeout():
>               jwks_client.get_jwk_set()

tests/test_jwks_client.py:336: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
jwt/jwks_client.py:50: in get_jwk_set
    data = self.fetch_data()
jwt/jwks_client.py:37: in fetch_data
    response = urllib.request.urlopen(req, timeout=self.timeout)
/usr/lib/python3.10/unittest/mock.py:1114: in __call__
    return self._mock_call(*args, **kwargs)
/usr/lib/python3.10/unittest/mock.py:1118: in _mock_call
    return self._execute_mock_call(*args, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <MagicMock name='urlopen' id='123213499988912'>
args = (<urllib.request.Request object at 0x700fe0d1b130>,)
kwargs = {'timeout': 5}, effect = TimeoutError('timed out')

    def _execute_mock_call(self, /, *args, **kwargs):
        # separate from _increment_mock_call so that awaited functions are
        # executed separately from their call, also AsyncMock overrides this method
    
        effect = self.side_effect
        if effect is not None:
            if _is_exception(effect):
>               raise effect
E               TimeoutError: timed out

/usr/lib/python3.10/unittest/mock.py:1173: TimeoutError
--------------------------------- JSON report ----------------------------------
report saved to: report.json
=========================== short test summary info ============================
SKIPPED [1] tests/test_api_jwk.py:200: Requires cryptography library not installed
SKIPPED [1] tests/test_api_jws.py:387: Requires cryptography library not installed
XFAIL tests/test_utils.py::test_to_base64url_uint[-1-]
FAILED tests/test_algorithms.py::TestOKPAlgorithms::test_rsa_can_compute_digest
FAILED tests/test_algorithms.py::TestOKPAlgorithms::test_hmac_can_compute_digest
FAILED tests/test_api_jwk.py::TestPyJWK::test_should_load_key_from_jwk_data_dict
FAILED tests/test_api_jwk.py::TestPyJWK::test_should_load_key_from_jwk_data_json_string
FAILED tests/test_api_jwk.py::TestPyJWK::test_should_load_key_without_alg_from_dict
FAILED tests/test_api_jwk.py::TestPyJWK::test_should_load_key_from_dict_with_algorithm
FAILED tests/test_api_jwk.py::TestPyJWK::test_should_load_key_ec_p256_from_dict
FAILED tests/test_api_jwk.py::TestPyJWK::test_should_load_key_ec_p384_from_dict
FAILED tests/test_api_jwk.py::TestPyJWK::test_should_load_key_ec_p521_from_dict
FAILED tests/test_api_jwk.py::TestPyJWK::test_should_load_key_ec_secp256k1_from_dict
FAILED tests/test_api_jwk.py::TestPyJWK::test_should_load_key_hmac_from_dict
FAILED tests/test_api_jwk.py::TestPyJWK::test_should_load_key_hmac_without_alg_from_dict
FAILED tests/test_api_jwk.py::TestPyJWK::test_should_load_key_okp_without_alg_from_dict
FAILED tests/test_api_jwk.py::TestPyJWK::test_from_dict_should_throw_exception_if_arg_is_invalid
FAILED tests/test_api_jwk.py::TestPyJWKSet::test_should_load_keys_from_jwk_data_dict
FAILED tests/test_api_jwk.py::TestPyJWKSet::test_should_load_keys_from_jwk_data_json_string
FAILED tests/test_api_jwk.py::TestPyJWKSet::test_keyset_should_index_by_kid
FAILED tests/test_api_jwk.py::TestPyJWKSet::test_keyset_with_unknown_alg - At...
FAILED tests/test_api_jws.py::TestJWS::test_encode_with_headers_alg_none - jw...
FAILED tests/test_api_jws.py::TestJWS::test_decode_with_optional_algorithms
FAILED tests/test_api_jws.py::TestJWS::test_sorting_of_headers[False] - TypeE...
FAILED tests/test_api_jws.py::TestJWS::test_sorting_of_headers[True] - TypeEr...
FAILED tests/test_api_jws.py::TestJWS::test_decode_with_algo_none_should_fail
FAILED tests/test_api_jws.py::TestJWS::test_decode_with_algo_none_and_verify_false_should_pass
FAILED tests/test_api_jws.py::TestJWS::test_encode_with_typ_empty_string - As...
FAILED tests/test_api_jws.py::TestJWS::test_encode_with_typ_none - AssertionE...
FAILED tests/test_api_jws.py::TestJWS::test_encode_fails_on_invalid_kid_types
FAILED tests/test_api_jws.py::TestJWS::test_encode_decode_with_detached_content
FAILED tests/test_api_jws.py::TestJWS::test_encode_detached_content_with_b64_header
FAILED tests/test_api_jws.py::TestJWS::test_decode_detached_content_without_proper_argument
FAILED tests/test_api_jws.py::TestJWS::test_decode_warns_on_unsupported_kwarg
FAILED tests/test_api_jws.py::TestJWS::test_decode_complete_warns_on_unuspported_kwarg
FAILED tests/test_api_jwt.py::TestJWT::test_decode_raises_exception_if_exp_is_not_int
FAILED tests/test_api_jwt.py::TestJWT::test_decode_raises_exception_if_iat_is_greater_than_now
FAILED tests/test_api_jwt.py::TestJWT::test_decode_works_if_iat_is_str_of_a_number
FAILED tests/test_api_jwt.py::TestJWT::test_decode_raises_exception_if_nbf_is_not_int
FAILED tests/test_api_jwt.py::TestJWT::test_decode_with_expiration_with_leeway
FAILED tests/test_api_jwt.py::TestJWT::test_check_audience_none_specified - F...
FAILED tests/test_api_jwt.py::TestJWT::test_raise_exception_token_with_aud_none_and_without_audience
FAILED tests/test_api_jwt.py::TestJWT::test_decode_with_verify_exp_option_and_signature_off
FAILED tests/test_api_jwt.py::TestJWT::test_decode_with_optional_algorithms
FAILED tests/test_api_jwt.py::TestJWT::test_decode_legacy_verify_warning - Fa...
FAILED tests/test_api_jwt.py::TestJWT::test_decode_warns_on_unsupported_kwarg
FAILED tests/test_api_jwt.py::TestJWT::test_decode_complete_warns_on_unsupported_kwarg
FAILED tests/test_api_jwt.py::TestJWT::test_decode_strict_aud_forbids_list_audience
FAILED tests/test_api_jwt.py::TestJWT::test_decode_strict_aud_forbids_list_claim
FAILED tests/test_api_jwt.py::TestJWT::test_decode_strict_aud_does_not_match
FAILED tests/test_jwks_client.py::TestPyJWKClient::test_get_signing_keys_raises_if_none_found
FAILED tests/test_jwks_client.py::TestPyJWKClient::test_get_jwt_set_failed_request_should_clear_cache
FAILED tests/test_jwks_client.py::TestPyJWKClient::test_get_jwt_set_refresh_cache
FAILED tests/test_jwks_client.py::TestPyJWKClient::test_get_jwt_set_timeout
============= 51 failed, 208 passed, 2 skipped, 1 xfailed in 5.85s =============