def test_add_msi(self): client_guid = "kjhjk" object_guid = "87687687" res_guid = "kajsdghdijewhag" kcsb = [ KustoConnectionStringBuilder.with_aad_managed_service_identity_authentication("localhost0", timeout=1), KustoConnectionStringBuilder.with_aad_managed_service_identity_authentication("localhost1", client_id=client_guid, timeout=2), KustoConnectionStringBuilder.with_aad_managed_service_identity_authentication("localhost2", object_id=object_guid, timeout=3), KustoConnectionStringBuilder.with_aad_managed_service_identity_authentication("localhost3", msi_res_id=res_guid), ] assert kcsb[0].msi_authentication assert kcsb[0].msi_parameters["resource"] == "localhost0" assert kcsb[0].msi_parameters["timeout"] == 1 assert "client_id" not in kcsb[0].msi_parameters assert "object_id" not in kcsb[0].msi_parameters assert "msi_res_id" not in kcsb[0].msi_parameters assert kcsb[1].msi_authentication assert kcsb[1].msi_parameters["resource"] == "localhost1" assert kcsb[1].msi_parameters["timeout"] == 2 assert kcsb[1].msi_parameters["client_id"] == client_guid assert "object_id" not in kcsb[1].msi_parameters assert "msi_res_id" not in kcsb[1].msi_parameters assert kcsb[2].msi_authentication assert kcsb[2].msi_parameters["resource"] == "localhost2" assert kcsb[2].msi_parameters["timeout"] == 3 assert "client_id" not in kcsb[2].msi_parameters assert kcsb[2].msi_parameters["object_id"] == object_guid assert "msi_res_id" not in kcsb[2].msi_parameters assert kcsb[3].msi_authentication assert kcsb[3].msi_parameters["resource"] == "localhost3" assert "timeout" not in kcsb[3].msi_parameters assert "client_id" not in kcsb[3].msi_parameters assert "object_id" not in kcsb[3].msi_parameters assert kcsb[3].msi_parameters["msi_res_id"] == res_guid exception_occurred = False try: fault = KustoConnectionStringBuilder.with_aad_managed_service_identity_authentication("localhost", client_id=client_guid, object_id=object_guid) except ValueError as e: exception_occurred = True finally: assert exception_occurred
def test_msi_auth(): """ * * * Note * * * Each connection test takes about 15-20 seconds which is the time it takes TCP to fail connecting to the nonexistent MSI endpoint The timeout option does not seem to affect this behavior. Could be it only affects the waiting time fora response in successful connections. Please be prudent in adding any future tests! """ client_guid = "kjhjk" object_guid = "87687687" res_guid = "kajsdghdijewhag" kcsb = [ KustoConnectionStringBuilder.with_aad_managed_service_identity_authentication("localhost", timeout=1), KustoConnectionStringBuilder.with_aad_managed_service_identity_authentication("localhost", client_id=client_guid, timeout=1), KustoConnectionStringBuilder.with_aad_managed_service_identity_authentication("localhost", object_id=object_guid, timeout=1), KustoConnectionStringBuilder.with_aad_managed_service_identity_authentication("localhost", msi_res_id=res_guid, timeout=1), ] helpers = [_AadHelper(kcsb[0]), _AadHelper(kcsb[1]), _AadHelper(kcsb[2]), _AadHelper(kcsb[3])] try: helpers[0].acquire_authorization_header() except KustoAuthenticationError as e: assert e.authentication_method == AuthenticationMethod.aad_msi.value assert "client_id" not in e.kwargs assert "object_id" not in e.kwargs assert "msi_res_id" not in e.kwargs try: helpers[1].acquire_authorization_header() except KustoAuthenticationError as e: assert e.authentication_method == AuthenticationMethod.aad_msi.value assert e.kwargs["client_id"] == client_guid assert "object_id" not in e.kwargs assert "msi_res_id" not in e.kwargs assert str(e.exception).index("client_id") > -1 assert str(e.exception).index(client_guid) > -1