Пример #1
0
def test_env_variables_override_config_file_credentials(
    auth_session: auth.AuthSession,
    mocker,
    monkeypatch,
    test_env_client_id: str,
    test_env_client_secret: str,
    expected_id: str,
    expected_secret: str,
):
    monkeypatch.setenv("LOOKERSDK_CLIENT_ID", test_env_client_id)
    monkeypatch.setenv("LOOKERSDK_CLIENT_SECRET", test_env_client_secret)
    mocked_request = mocker.patch.object(MockTransport, "request")
    mocked_request.return_value = transport.Response(
        ok=True,
        value=json.dumps({
            "access_token": "AdminAccessToken",
            "token_type": "Bearer",
            "expires_in": 3600,
        }).encode("utf-8"),
        response_mode=transport.ResponseMode.STRING,
    )

    auth_session.authenticate()

    expected_body = urllib.parse.urlencode({
        "client_id": expected_id,
        "client_secret": expected_secret
    }).encode("utf-8")
    mocked_request.assert_called()
    actual_request_body = mocked_request.call_args[1]["body"]
    assert actual_request_body == expected_body
Пример #2
0
def test_sudo_login_auto_logs_in(auth_session: auth.AuthSession):
    assert not auth_session.is_authenticated
    assert not auth_session.is_sudo_authenticated
    auth_session.login_user(5)
    assert auth_session.is_authenticated
    assert auth_session.is_sudo_authenticated
    auth_header = auth_session.authenticate()
    assert auth_header["Authorization"] == "Bearer UserAccessToken"
Пример #3
0
def test_auto_login(auth_session: auth.AuthSession):
    assert not auth_session.is_authenticated
    auth_header = auth_session.authenticate()
    assert auth_header["Authorization"] == "Bearer AdminAccessToken"
    assert auth_session.is_authenticated

    # even after explicit logout
    auth_session.logout()
    assert not auth_session.is_authenticated
    auth_header = auth_session.authenticate()
    assert isinstance(auth_header, dict)
    assert auth_header["Authorization"] == "Bearer AdminAccessToken"
    assert auth_session.is_authenticated
Пример #4
0
def test_is_sudo(auth_session: auth.AuthSession):
    assert auth_session.is_sudo is None
    auth_session.authenticate()  # auto-login admin
    assert auth_session.is_sudo is None
    auth_session.login_user(5)
    assert auth_session.is_sudo == 5
    auth_session.logout()
    assert auth_session.is_sudo is None
Пример #5
0
def test_login_sudo_login_sudo(auth_session: auth.AuthSession):
    auth_session.login_user(5)
    with pytest.raises(error.SDKError):
        auth_session.login_user(10)
Пример #6
0
def test_sudo_logout_leaves_logged_in(auth_session: auth.AuthSession):
    auth_session.login_user(5)
    auth_session.logout()
    assert not auth_session.is_sudo_authenticated
    assert auth_session.is_authenticated
Пример #7
0
def test_auto_login_with_transport_options(auth_session: auth.AuthSession):
    assert not auth_session.is_authenticated
    auth_header = auth_session.authenticate({"headers": {"foo": "bar"}})
    assert auth_header["Authorization"] == "Bearer AdminAccessToken"
    assert auth_session.is_authenticated
Пример #8
0
def test_login_user_login_user(auth_session: auth.AuthSession):
    auth_session.login_user(5)
    with pytest.raises(error.SDKError):  # type: ignore
        auth_session.login_user(10)