def test_url_not_found(self, mock_urlopen):
     mock_urlopen.side_effect = HTTPError('url', '404', 'nf', {}, None)
     key = authentication.jwks_to_public_key('<url-6>')
     assert key is None
 def test_kid_not_matched(self, mock_urlopen):
     mock_urlopen.return_value = self._test_jwks_bytes()
     key = authentication.jwks_to_public_key('<url-1>', kid='Y')
     assert key is None
 def test_invalid_url_format(self):
     key = authentication.jwks_to_public_key('<url-5>')
     assert key is None
 def test_non_json_value(self, mock_urlopen):
     mock_urlopen.return_value = io.BytesIO(b'<html></html>')
     key = authentication.jwks_to_public_key('<url-5>')
     assert key is None
 def test_cache_used(self, mock_urlopen):
     mock_urlopen.return_value = self._test_jwks_bytes()
     for _ in range(2):
         authentication.jwks_to_public_key('<url-3>', kid='X')
     assert mock_urlopen.call_count == 1
 def test_kid_matched(self, mock_urlopen):
     mock_urlopen.return_value = self._test_jwks_bytes()
     key = authentication.jwks_to_public_key('<url-2>', kid='X')
     assert key == json.load(self._test_jwks_bytes())['keys'][0]
 def test_missing_required_keys(self, mock_urlopen):
     mock_urlopen.return_value = self._test_jwks_bytes()
     key = authentication.jwks_to_public_key('<url-1>',
                                             kid='X',
                                             required_keys=['a'])
     assert key is None