Exemplo n.º 1
0
def test_invalid_audience(
    mocker: MockFixture,
    authenticator: Auth0Authenticator,
    access_token: str,
    sign_key: Dict[str, Any],
):
    mock_valid_time(mocker)
    authenticator.audience = "SomeRandomAudience"
    with pytest.raises(Exception, match=r"Invalid claims"):
        authenticator._get_payload(access_token, sign_key)
Exemplo n.º 2
0
def test_expired_token(
    mocker: MockFixture,
    authenticator: Auth0Authenticator,
    access_token: str,
    sign_key: Dict[str, Any],
):
    datetime_mock = mocker.patch("jose.jwt.datetime")
    datetime_mock.utcnow = Mock(return_value=datetime(2050, 1, 1))
    authenticator.audience = "SomeRandomAudience"
    with pytest.raises(Exception, match=r"Token is expired"):
        authenticator._get_payload(access_token, sign_key)
Exemplo n.º 3
0
def test_authenticate_failure(
    mocker: MockFixture,
    flask_app: Flask,
    authenticator: Auth0Authenticator,
    access_token: str,
):
    mock_valid_time(mocker)
    authenticator.audience = "SomeRandomAudience"
    with flask_app.test_request_context(
            headers={"Authorization": f"Bearer {access_token}"}):
        with pytest.raises(errors.Unauthorized):
            authenticator.authenticate()