Exemplo n.º 1
0
def cli_login():
    try:
        auth.login(verify=True)
    except auth.LoginError as e:
        raise click.ClickException(str(e))
    except auth.AccessError as e:
        raise click.ClickException(str(e))
Exemplo n.º 2
0
def test_direct_auth_works_viaconfig_without_client(login_mocks,
                                                    no_kubernetes):
    login_mocks.pykube_in_cluster.side_effect = FileNotFoundError

    login()

    assert login_mocks.pykube_in_cluster.called
    assert login_mocks.pykube_from_file.called
Exemplo n.º 3
0
def test_direct_auth_works_incluster_with_client(login_mocks, kubernetes):
    login()

    assert login_mocks.pykube_in_cluster.called
    assert not login_mocks.pykube_from_file.called

    assert login_mocks.client_in_cluster.called
    assert not login_mocks.client_from_file.called
Exemplo n.º 4
0
def test_direct_auth_fails_on_errors_in_pykube(login_mocks, any_kubernetes):
    login_mocks.pykube_in_cluster.side_effect = FileNotFoundError
    login_mocks.pykube_from_file.side_effect = FileNotFoundError

    with pytest.raises(LoginError):
        login()

    assert login_mocks.pykube_in_cluster.called
    assert login_mocks.pykube_from_file.called
Exemplo n.º 5
0
def test_direct_check_fails_on_tcp_error_in_pykube(login_mocks,
                                                   any_kubernetes):
    login_mocks.pykube_checker.side_effect = requests.exceptions.ConnectionError(
    )

    with pytest.raises(AccessError):
        login(verify=True)

    assert login_mocks.pykube_in_cluster.called
    assert not login_mocks.pykube_from_file.called
    assert login_mocks.pykube_checker.called
Exemplo n.º 6
0
def test_direct_auth_works_viaconfig_with_client(login_mocks, kubernetes):
    login_mocks.pykube_in_cluster.side_effect = FileNotFoundError
    login_mocks.client_in_cluster.side_effect = kubernetes.config.ConfigException

    login()

    assert login_mocks.pykube_in_cluster.called
    assert login_mocks.pykube_from_file.called

    assert login_mocks.client_in_cluster.called
    assert login_mocks.client_from_file.called
Exemplo n.º 7
0
def test_direct_check_fails_on_401_error_in_pykube(login_mocks,
                                                   any_kubernetes):
    login_mocks.pykube_checker.side_effect = requests.exceptions.HTTPError(
        response=RESPONSE_401)

    with pytest.raises(AccessError):
        login(verify=True)

    assert login_mocks.pykube_in_cluster.called
    assert not login_mocks.pykube_from_file.called
    assert login_mocks.pykube_checker.called
Exemplo n.º 8
0
def test_direct_auth_fails_on_errors_in_client(login_mocks, kubernetes):
    login_mocks.client_in_cluster.side_effect = kubernetes.config.ConfigException
    login_mocks.client_from_file.side_effect = kubernetes.config.ConfigException

    with pytest.raises(LoginError):
        login()

    assert login_mocks.pykube_in_cluster.called
    assert not login_mocks.pykube_from_file.called

    assert login_mocks.client_in_cluster.called
    assert login_mocks.client_from_file.called
Exemplo n.º 9
0
def test_direct_check_fails_on_tcp_error_in_client(login_mocks, kubernetes):
    login_mocks.client_checker.side_effect = urllib3.exceptions.HTTPError()

    with pytest.raises(AccessError):
        login(verify=True)

    assert login_mocks.pykube_in_cluster.called
    assert not login_mocks.pykube_from_file.called
    assert login_mocks.pykube_checker.called

    assert login_mocks.client_in_cluster.called
    assert not login_mocks.client_from_file.called
    assert login_mocks.client_checker.called
Exemplo n.º 10
0
def test_direct_auth_works_incluster(mocker):
    # We do not test the client, we assume it works when used properly.
    core_api = mocker.patch.object(kubernetes.client, 'CoreApi')
    load_kube_config = mocker.patch.object(kubernetes.config,
                                           'load_kube_config')
    load_incluster_config = mocker.patch.object(kubernetes.config,
                                                'load_incluster_config')

    login()

    assert load_incluster_config.called
    assert not load_kube_config.called
    assert core_api.called  # to verify that auth worked
Exemplo n.º 11
0
def test_direct_check_fails_on_401_error_in_client(login_mocks, kubernetes):
    login_mocks.client_checker.side_effect = kubernetes.client.rest.ApiException(
        status=401)

    with pytest.raises(AccessError):
        login(verify=True)

    assert login_mocks.pykube_in_cluster.called
    assert not login_mocks.pykube_from_file.called
    assert login_mocks.pykube_checker.called

    assert login_mocks.client_in_cluster.called
    assert not login_mocks.client_from_file.called
    assert login_mocks.client_checker.called
Exemplo n.º 12
0
def test_direct_api_fails(mocker):
    # We do not test the client, we assume it works when used properly.
    core_api = mocker.patch.object(kubernetes.client, 'CoreApi')
    load_kube_config = mocker.patch.object(kubernetes.config,
                                           'load_kube_config')
    load_incluster_config = mocker.patch.object(kubernetes.config,
                                                'load_incluster_config')
    core_api.side_effect = kubernetes.client.rest.ApiException(status=401)

    with pytest.raises(LoginError):
        login()

    assert load_incluster_config.called
    assert not load_kube_config.called
    assert core_api.called  # to verify that auth worked
Exemplo n.º 13
0
def autologin(request):
    if request.config.getoption('--with-e2e') or request.config.getoption('--only-e2e'):
        login()  # or anything like that; it is not a unit-under-test
Exemplo n.º 14
0
def autologin():
    if os.environ.get('E2E'):
        login()  # or anything like that; it is not a unit-under-test
Exemplo n.º 15
0
def cli_login():
    try:
        auth.login()
    except auth.LoginError as e:
        raise click.ClickException(str(e))