예제 #1
0
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
예제 #2
0
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")
예제 #3
0
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')
예제 #4
0
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()
예제 #5
0
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")
예제 #6
0
def test_decode():
    """verify that decode decodes the jwt"""
    byujwt = byu_jwt.JWT_Handler()
    decoded_jwt = byujwt.decode(JWT, verify=False)
    assert decoded_jwt
예제 #7
0
def test_is_valid():
    """check that is_valid returns False for expired JWT"""
    byujwt = byu_jwt.JWT_Handler()
    assert not byujwt.is_valid(JWT)
예제 #8
0
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
예제 #9
0
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
예제 #10
0
def test_get_signing_cert():
    """Testing ability to retrieve signing certs"""
    byujwt = byu_jwt.JWT_Handler()
    assert byujwt.get_signing_cert()
예제 #11
0
 def __init__(self):
     self.raw_jwt = self._retrieve_jwt()
     self.jwt_handler = byu_jwt.JWT_Handler()