Пример #1
0
def test_authorization_callback_redirect(mocker, client_without_db):
    client = client_without_db
    mocker.patch("app.auth.routes.oauth.google.authorize_access_token")
    mocker.patch("app.auth.routes.oauth.google.parse_id_token")
    query = mocker.patch("data.models.user.User.query")

    oauth.google.authorize_access_token.return_value = {
        "access_token": "TOKEN"
    }

    oauth.google.parse_id_token.return_value = UserInfo(regular_user_info())
    query.filter_by.one_or_none.return_value = True

    with client.session_transaction() as session:
        session["redirect_path"] = "/FOO"

    resp = client.get("/auth/authorized")

    assert resp.status_code == 302
    assert resp.headers.get("Location") == "http://localhost/FOO"

    oauth.google.authorize_access_token.assert_called_once()
    oauth.google.parse_id_token.assert_called_once_with(
        {"access_token": "TOKEN"})
    with client.session_transaction() as session:
        assert "user_info" in session
        assert "redirect_path" not in session
Пример #2
0
def test_authorization_callback_redirect(
    mocker: pytest_mock.MockFixture,
    client_without_db: testing.FlaskClient,
):
    client = client_without_db
    mocker.patch("app.auth.routes.oauth.google.authorize_access_token")
    mocker.patch("app.auth.routes.oauth.google.parse_id_token")
    # normally one should do
    # query = mocker.patch("data.models.user.User.query")
    # but this makes issues if there is no database available
    with patch_query("data.models.user.User") as query:
        oauth.google.authorize_access_token.return_value = {
            "access_token": "TOKEN"
        }

        oauth.google.parse_id_token.return_value = UserInfo(
            regular_user_info())
        query.filter_by.one_or_none.return_value = True

        with client.session_transaction() as session:
            session["redirect_path"] = "/FOO"

        resp = client.get("/auth/authorized")

        assert resp.status_code == 302
        assert resp.headers.get("Location") == "http://localhost/FOO"

        oauth.google.authorize_access_token.assert_called_once()
        oauth.google.parse_id_token.assert_called_once_with(
            {"access_token": "TOKEN"})
        with client.session_transaction() as session:
            assert "user_info" in session
            assert "redirect_path" not in session
Пример #3
0
 def json(self):
     return regular_user_info()
Пример #4
0
 class Resp:
     data = regular_user_info()