def test_add_token_provider(self):
        caller_token = "caller token"
        token_provider = lambda: caller_token
        kscb = KustoConnectionStringBuilder.with_token_provider(
            "localhost", token_provider)

        assert kscb.token_provider() == caller_token

        exception_occurred = False
        try:
            kscb = KustoConnectionStringBuilder.with_token_provider(
                "localhost", caller_token)
        except AssertionError as ex:
            exception_occurred = True
        finally:
            assert exception_occurred
def test_token_provider_auth():
    valid_token_provider = lambda: "caller token"
    invalid_token_provider = lambda: 12345678

    valid_kcsb = KustoConnectionStringBuilder.with_token_provider("localhost", valid_token_provider)
    invalid_kcsb = KustoConnectionStringBuilder.with_token_provider("localhost", invalid_token_provider)

    valid_helper = _AadHelper(valid_kcsb)
    invalid_helper = _AadHelper(invalid_kcsb)

    auth_header = valid_helper.acquire_authorization_header()
    assert auth_header.index(valid_token_provider()) > -1

    try:
        invalid_helper.acquire_authorization_header()
    except KustoAuthenticationError as e:
        assert e.authentication_method == AuthenticationMethod.token_provider.value
        assert str(e.exception).index(str(type(invalid_token_provider()))) > -1
Exemplo n.º 3
0
def test_token_provider_auth():
    valid_token_provider = lambda: "caller token"
    invalid_token_provider = lambda: 12345678

    valid_kcsb = KustoConnectionStringBuilder.with_token_provider(
        KUSTO_TEST_URI, valid_token_provider)
    invalid_kcsb = KustoConnectionStringBuilder.with_token_provider(
        KUSTO_TEST_URI, invalid_token_provider)

    valid_helper = _AadHelper(valid_kcsb)
    invalid_helper = _AadHelper(invalid_kcsb)

    auth_header = valid_helper.acquire_authorization_header()
    assert auth_header.index(valid_token_provider()) > -1

    try:
        invalid_helper.acquire_authorization_header()
    except KustoAuthenticationError as e:
        assert e.authentication_method == CallbackTokenProvider.name()
        assert str(e.exception).index(str(type(invalid_token_provider()))) > -1
def proxy_kcsb(request) -> Tuple[KustoConnectionStringBuilder, bool]:
    cluster = KustoClientTestsMixin.HOST
    user = "******"
    password = "******"
    authority_id = "13456"
    uuid = "11111111-1111-1111-1111-111111111111"
    key = "key of application"
    token = "The app hardest token ever"

    return {
        "user_password":
        (KustoConnectionStringBuilder.with_aad_user_password_authentication(
            cluster, user, password, authority_id), True),
        "application_key":
        (KustoConnectionStringBuilder.with_aad_application_key_authentication(
            cluster, uuid, key, "microsoft.com"), True),
        "application_token": (KustoConnectionStringBuilder.
                              with_aad_application_token_authentication(
                                  cluster, application_token=token), False),
        "device":
        (KustoConnectionStringBuilder.with_aad_device_authentication(cluster),
         True),
        "user_token":
        (KustoConnectionStringBuilder.with_aad_user_token_authentication(
            cluster, user_token=token), False),
        "managed_identity":
        (KustoConnectionStringBuilder.
         with_aad_managed_service_identity_authentication(cluster), False),
        "token_provider": (KustoConnectionStringBuilder.with_token_provider(
            cluster, lambda x: x), False),
        "async_token_provider":
        (KustoConnectionStringBuilder.with_async_token_provider(
            cluster, lambda x: x), False),
        "az_cli":
        (KustoConnectionStringBuilder.with_az_cli_authentication(cluster),
         True),
        "interactive_login":
        (KustoConnectionStringBuilder.with_interactive_login(cluster), True),
    }[request.param]