Пример #1
0
def test_authenticate_ok(
    mocker: MockFixture,
    flask_app: Flask,
    authenticator: Auth0Authenticator,
    access_token: str,
):
    mock_valid_time(mocker)
    with flask_app.test_request_context(
            headers={"Authorization": f"Bearer {access_token}"}):
        authenticator.authenticate()
        assert get_access_token_claims() != {}
Пример #2
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()
Пример #3
0
def test_create_user_failure(
    mocker: MockFixture,
    flask_app: Flask,
    authenticator: Auth0Authenticator,
    access_token: str,
):
    @authenticator.identity_handler
    def create_user(claims: Dict[str, Any]):
        raise Exception

    mock_valid_time(mocker)
    with flask_app.test_request_context(
            headers={"Authorization": f"Bearer {access_token}"}):
        with pytest.raises(errors.Unauthorized):
            authenticator.authenticate()
Пример #4
0
def test_create_user_ok(
    mocker: MockFixture,
    flask_app: Flask,
    authenticator: Auth0Authenticator,
    access_token: str,
):
    @authenticator.identity_handler
    def create_user(claims: Dict[str, Any]):
        return {"User": claims["sub"]}

    mock_valid_time(mocker)
    with flask_app.test_request_context(
            headers={"Authorization": f"Bearer {access_token}"}):
        authenticator.authenticate()
        assert (get_authenticated_user()["User"] ==
                "Tlapef2d0GHcq32k2W0PycmFL4wIxuGM@clients")