def test_get_jwks_data(): """get jwks data from uri from well-known data""" byujwt = byu_jwt.JWT_Handler() wellknown = byujwt._get_wellknown_data() r, ttl = byujwt._get_jwks_data(wellknown['jwks_uri']) assert r == JWKS assert ttl
def test_decode_handler_exception(mock_extract, mock_requests): """check decode exception handling""" mock_extract.return_value = 'bar' mock_requests.side_effect = byu_jwt.exceptions.JWTHandlerError() byujwt = byu_jwt.JWT_Handler() with pytest.raises(byu_jwt.exceptions.JWTHandlerError): byujwt.decode("foo")
def test_get_jwks_data_exception(mock_requests): """check exception handling getting jwks""" mock_requests.side_effect = [ requests.exceptions.HTTPError(), requests.exceptions.ConnectionError() ] byujwt = byu_jwt.JWT_Handler() with pytest.raises(byu_jwt.exceptions.JWTHandlerError): byujwt._get_jwks_data('foo') byujwt._get_jwks_data('foo')
def test_get_wellknown_data_exception(mock_requests): """check exception handling if well-knwon fails""" mock_requests.side_effect = [ requests.exceptions.HTTPError(), requests.exceptions.ConnectionError() ] byujwt = byu_jwt.JWT_Handler() with pytest.raises(byu_jwt.exceptions.JWTHandlerError): byujwt._get_wellknown_data() byujwt._get_wellknown_data()
def test_decode_jwt_exception(mock_decode): """check decode exception handling""" mock_decode.side_effect = jwt.exceptions.ExpiredSignatureError() byujwt = byu_jwt.JWT_Handler() with pytest.raises(byu_jwt.exceptions.JWTVerifyError): byujwt.decode("foo")
def test_decode(): """verify that decode decodes the jwt""" byujwt = byu_jwt.JWT_Handler() decoded_jwt = byujwt.decode(JWT, verify=False) assert decoded_jwt
def test_is_valid(): """check that is_valid returns False for expired JWT""" byujwt = byu_jwt.JWT_Handler() assert not byujwt.is_valid(JWT)
def test_get_wellknown_data(): """get well-known data""" byujwt = byu_jwt.JWT_Handler() well_known = byujwt._get_wellknown_data() assert 'jwks_uri' in well_known
def test_extract_public_keys(): """Attempting to extract public keys from a JWKS""" byujwt = byu_jwt.JWT_Handler() key_set = byujwt._extract_public_keys(JWKS) assert key_set
def test_get_signing_cert(): """Testing ability to retrieve signing certs""" byujwt = byu_jwt.JWT_Handler() assert byujwt.get_signing_cert()
def __init__(self): self.raw_jwt = self._retrieve_jwt() self.jwt_handler = byu_jwt.JWT_Handler()