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)
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)
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()