def test_verify_decode_jwt_error_parsing(): """Test decode jwt when the token cannot be parsed""" with pytest.raises(AuthError) as err: verify_decode_jwt(latte_token, "latte") assert err.value.code == 400 assert err.value.description == "Unable to parse authentication token."
def test_verify_decode_jwt_bad_jwks(): """Test decode jwt when the token is bad""" with pytest.raises(AuthError) as err: verify_decode_jwt(latte_token, "latte") assert err.value.code == 400 assert err.value.description == "Unable to find the appropriate key."
def test_verify_decode_jwt_bad_claims(): """Test decode jwt when the token has an incorrect audience""" with pytest.raises(AuthError) as err: verify_decode_jwt(latte_token, "derps") assert err.value.code == 401 assert err.value.description == "Incorrect claims. Please, check the audience and issuer."
def test_verify_decode_jwt_expired(): """Test decode jwt when the token has expired""" with pytest.raises(AuthError) as err: verify_decode_jwt(exp_latte_token, "latte") assert err.value.code == 401 assert err.value.description == "Token expired."
def test_verify_decode_jwt_malformed_header(): """Test decode jwt when the token header is malformed""" with pytest.raises(AuthError) as err: verify_decode_jwt("12345asdf", "latte") assert err.value.code == 401 assert err.value.description == "Malformed header value."
def test_verify_decode_jwt_malformed_authorization(): """Test decode jwt when the token authorization is malformed""" with pytest.raises(AuthError) as err: verify_decode_jwt( "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3OD" "kwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJwZXJtaX" "NzaW9ucyI6WyJnZXQ6bGF0dGUiLCJwb3N0OmxhdHRlIiwicGF0Y2g6bGF0dG" "UiLCJkZWxldGU6bGF0dGUiXX0.uPZwwhHdd6FtMFNU-xmkSzWNiE9-S0szTQkT7a6m0ss", "latte", ) assert err.value.code == 401 assert err.value.description == "Authorization malformed."
def test_verify_decode_jwt_latte(): """Test decode jwt for latte api""" res = verify_decode_jwt(latte_token, "latte") assert "iss" in res assert "sub" in res assert "aud" in res assert "exp" in res assert "permissions" in res assert "get:latte" in res["permissions"] assert "post:latte" in res["permissions"] assert "delete:latte" in res["permissions"] assert "patch:latte" in res["permissions"]
def test_verify_decode_jwt_project(): """Test decode jwt for project api""" res = verify_decode_jwt(project_token, "project") assert "iss" in res assert "sub" in res assert "aud" in res assert "exp" in res assert "permissions" in res assert "get:project" in res["permissions"] assert "post:project" in res["permissions"] assert "delete:project" in res["permissions"] assert "patch:project" in res["permissions"]