@@ -117,6 +117,32 @@ def test_verify_token_jwk(decode, get_unverified_header, py_jwk_set, _fetch_cert
117117 )
118118
119119
120+ @mock .patch ("google.oauth2.id_token._fetch_certs" , autospec = True )
121+ @mock .patch ("jwt.api_jwk.PyJWKSet" , autospec = True )
122+ @mock .patch ("jwt.get_unverified_header" , autospec = True )
123+ @mock .patch ("jwt.decode" , autospec = True )
124+ def test_verify_token_jwk_missing_kid (decode , get_unverified_header , py_jwk_set , _fetch_certs ):
125+ from jwt .exceptions import PyJWKClientError
126+
127+ certs_url = "abc123"
128+ data = {"keys" : [{"alg" : "RS256" }]}
129+ _fetch_certs .return_value = data
130+ get_unverified_header .return_value = {"kid" : "mock-kid" }
131+
132+ mock_key = mock .MagicMock ()
133+ mock_key .key_id = "different-kid"
134+ mock_key .public_key_use = "sig"
135+ mock_key .key = mock .sentinel .key
136+ mock_key .algorithm_name = "mock-alg"
137+ py_jwk_set .from_dict .return_value .keys = [mock_key ]
138+
139+ with pytest .raises (PyJWKClientError , match = 'Unable to find a signing key that matches: "mock-kid"' ):
140+ id_token .verify_token (
141+ mock .sentinel .token , mock .sentinel .request , certs_url = certs_url
142+ )
143+
144+
145+
120146@mock .patch ("google.auth.jwt.decode" , autospec = True )
121147@mock .patch ("google.oauth2.id_token._fetch_certs" , autospec = True )
122148def test_verify_token_args (_fetch_certs , decode ):
0 commit comments