/// <summary> /// Register the current application and ensure that the local ApiKeyInfo is set and /// written to ApiKeyFilePath /// </summary> /// <returns></returns> protected internal bool RegisterApplicationProcess() { lock (_registerLock) { if (!IsInitialized) { FireEvent(Initializing); CoreServiceResponse response = ApplicationRegistryService.RegisterApplicationProcess(ProcessDescriptor); ApplicationRegistrationResult appRegistrationResult = response.Data.FromJObject <ApplicationRegistrationResult>(); if (response.Success) { IsInitialized = true; FireEvent(Initialized); ApiKeyInfo keyInfo = new ApiKeyInfo { ApiKey = appRegistrationResult.ApiKey, ApplicationClientId = appRegistrationResult.ClientId, ApplicationName = GetApplicationName() }; EnsureApiKeyFileDirectory(); keyInfo.ToJsonFile(ApiKeyFilePath); FireEvent(ApiKeyFileSaved); } else { Message = response.Message; FireEvent(InitializationFailed); } } return(IsInitialized); } }
public void CanSetGetAndDeleteProviders() { ServiceRegistry registry = CoreServicesTestRegistry.GetServiceRegistry(); AuthSettingsService svc = registry.Get <AuthSettingsService>(); svc.HttpContext = registry.Get <IHttpContext>(); Expect.AreEqual("CoreServicesTests", svc.ClientApplicationName); CoreServiceResponse <List <AuthClientSettings> > settingsResponse = svc.GetClientSettings(); Expect.IsTrue(settingsResponse.Success, "Failed to get client settings"); // this is technically clean up code Message.PrintLine("there are currently {0} oauthsettings", settingsResponse.TypedData().Count); foreach (AuthClientSettings setting in settingsResponse.Data) { CoreServiceResponse removeResponse = svc.RemoveProvider(setting.ProviderName); Expect.IsTrue(removeResponse.Success, "failed to delete test provider"); } string testProvider = "testprovider"; CoreServiceResponse <AuthClientSettings> response = svc.SetProvider(testProvider, "testclientid", "test-secret"); Expect.IsTrue(response.Success, "failed to set test provider"); CoreServiceResponse check = svc.RemoveProvider(testProvider); Expect.IsTrue(check.Success, "failed to remove test provider"); }
public void CanGetWebHookDescriptor() { string testWebHookName = $"{nameof(CanSubscribeWebHook)}_testWebHook"; WebHookService svc = GetTestWebHookService(); CoreServiceResponse <WebHookSubscriber> subscribeToWebHookResponse = svc.SubscribeToWebHook(testWebHookName, "TestWebHookUrl"); WebHookDescriptor[] descriptors = svc.WebHooksRepository.Query <WebHookDescriptor>(q => q.WebHookName == testWebHookName).ToArray(); Expect.IsTrue(descriptors.Length == 1, "Failed to retrieve webhook descriptor"); }
/// <summary> /// Register this client machine/process with the remote host /// </summary> /// <returns></returns> public CoreServiceResponse RegisterClient() { Client client = Client.Of(LocalCoreRegistryRepository, ApplicationName, HostName, Port); CoreServiceResponse registrationResponse = ApplicationRegistryService.RegisterClient(client); if (registrationResponse == null || !registrationResponse.Success) { throw new ClientRegistrationFailedException(registrationResponse); } return(registrationResponse); }
public void CanSubscribeWebHook() { string testWebHookName = "TestWebHook"; string testUrl = "testurl"; WebHookService svc = new WebHookService(new WebHooksRepository(), new Data.Repositories.DaoRepository(), new Server.AppConf()); CoreServiceResponse response = svc.SubscribeToWebHook(testWebHookName, testUrl); Expect.IsTrue(response.Success, "subscribe to webhook failed"); Expect.AreEqual(testWebHookName, response.Data.WebHookName); Expect.AreEqual(testUrl, response.Data.Url); }
public void CoreApplicationRegistryServiceMustBeLoggedInToRegister() { CoreApplicationRegistrationService svc = GetTestService(); string orgName = 5.RandomLetters(); string appName = 8.RandomLetters(); ProcessDescriptor descriptor = ProcessDescriptor.ForApplicationRegistration(svc.CoreRegistryRepository, "localhost", 8080, appName, orgName); CoreServiceResponse response = svc.RegisterApplication(descriptor); Expect.IsFalse(response.Success); Expect.IsNotNull(response.Data); Expect.IsInstanceOfType <ApplicationRegistrationResult>(response.Data); Expect.AreEqual(ApplicationRegistrationStatus.Unauthorized, ((ApplicationRegistrationResult)response.Data).Status); }
public void CoreClientCanRegisterAndConnectClient() { Message.PrintLine("This test requires a gloo server to be running on port 9100 of the localhost", ConsoleColor.Yellow); ApplicationRegistrationRepository repo = CoreServiceRegistryContainer.GetServiceRegistry().Get<ApplicationRegistrationRepository>(); ConsoleLogger logger = new ConsoleLogger() { AddDetails = false }; logger.StartLoggingThread(); CoreClient client = new CoreClient("Bam.Net", "CoreServicesTestApp", "localhost", 9100, logger); client.LocalCoreRegistryRepository = repo; CoreServiceResponse registrationResponse = client.RegisterClient(); Expect.IsTrue(registrationResponse.Success, registrationResponse.Message); CoreServiceResponse response = client.Connect(); List<CoreServiceResponse> responses = response.Data.FromJObject<List<CoreServiceResponse>>(); Expect.IsTrue(response.Success, string.Join("\r\n", responses.Select(r => r.Message).ToArray())); }
public void RegisterCreatesMachineEntry() { OutLineFormat("This test requires a gloo server to be running on port 9100 of the localhost", ConsoleColor.Yellow); ConsoleLogger logger = new ConsoleLogger(); logger.AddDetails = false; logger.StartLoggingThread(); ApplicationRegistrationRepository repo = CoreServiceRegistryContainer.GetServiceRegistry().Get <ApplicationRegistrationRepository>(); CoreClient client = new CoreClient("TestOrg", "TestApp", $".\\{nameof(RegisterCreatesMachineEntry)}", logger); client.LocalCoreRegistryRepository = repo; CoreServiceResponse registrationResponse = client.RegisterClient(); Machine machine = repo.OneMachineWhere(m => m.Name == Machine.Current.Name); Expect.IsNotNull(machine); Pass(nameof(RegisterCreatesMachineEntry)); }
public virtual CoreServiceResponse ListWebHooks() { try { HashSet <string> webhookNames = new HashSet <string>(); WebHooksRepository.BatchAllWebHookDescriptors(1000, (webhooks) => webhookNames.Each(whn => webhookNames.Add(whn))).Wait(); CoreServiceResponse response = new CoreServiceResponse { Success = true, Data = webhookNames.ToArray() }; return(response); } catch (Exception ex) { return(new CoreServiceResponse { Success = false, Message = ex.Message }); } }
public void WhoAmITest() { //OutLineFormat("This test requires a gloo server to be running on port 9100 of the localhost", ConsoleColor.Yellow); ConsoleLogger logger = new ConsoleLogger() { AddDetails = false }; const string server = "localhost";// "int-heart.bamapps.net"; const int port = 80; logger.StartLoggingThread(); ApplicationRegistrationRepository repo = ApplicationServiceRegistryContainer.GetServiceRegistry().Get <ApplicationRegistrationRepository>(); CoreClient client = new CoreClient("TestOrg", "TestApp", server, port, logger) { UseServiceSubdomains = false, LocalCoreRegistryRepository = repo }; client.InvocationException += (o, args) => logger.AddEntry("Invocation Exception: {0}", ((ServiceProxyInvokeEventArgs)args).Exception, args.PropertiesToString()); client.MethodInvoked += (o, args) => logger.AddEntry("ProxyClient Method Invoked: {0}", args.PropertiesToString()); CoreServiceResponse registrationResponse = client.RegisterClient(); Client current = Client.Of(client.LocalCoreRegistryRepository, client.ApplicationName, server, port); CoreServiceResponse response = client.Connect(); string whoAmI = client.UserRegistryService.WhoAmI(); Expect.AreEqual(current.ToString(), whoAmI); whoAmI = client.ApplicationRegistryService.WhoAmI(); Expect.AreEqual(current.ToString(), whoAmI); whoAmI = client.ConfigurationService.WhoAmI(); Expect.AreEqual(current.ToString(), whoAmI); whoAmI = client.LoggerService.WhoAmI(); Expect.AreEqual(current.ToString(), whoAmI); whoAmI = client.DiagnosticService.WhoAmI(); Expect.AreEqual(current.ToString(), whoAmI); Pass($"You are {whoAmI}"); }
public void OrganizationGetsCreated() { Log.Default = new ConsoleLogger(); Log.Default.StartLoggingThread(); string userName = 4.RandomLetters(); string orgName = 5.RandomLetters(); string appName = 8.RandomLetters(); CoreApplicationRegistrationService svc = GetTestServiceWithUser(userName); ProcessDescriptor descriptor = ProcessDescriptor.ForApplicationRegistration(svc.CoreRegistryRepository, "localhost", 8080, appName, orgName); CoreServiceResponse response = svc.RegisterApplication(descriptor); Expect.IsTrue(response.Success); var user = svc.CoreRegistryRepository.OneUserWhere(c => c.UserName == userName); user = svc.CoreRegistryRepository.Retrieve <ApplicationRegistration.User>(user.Id); Expect.IsNotNull(user); Expect.AreEqual(1, user.Organizations.Count); Thread.Sleep(1000); Pass($"{nameof(OrganizationGetsCreated)} Test Passed"); }
public void MustBeLoggedInToRegister() { After.Setup((Action <SetupContext>)(ctx => { ctx.CopyFrom((Incubation.Incubator)CoreServiceRegistryContainer.GetServiceRegistry()); })) .WhenA <CoreApplicationRegistrationService>("tries to register application when not logged in", cars => { ProcessDescriptor descriptor = ProcessDescriptor.ForApplicationRegistration(cars.CoreRegistryRepository, "localhost", 8080, "testApp", "testOrg"); return(cars.RegisterApplication(descriptor)); }) .TheTest .ShouldPass(because => { CoreServiceResponse result = because.ResultAs <CoreServiceResponse>(); because.ItsTrue("the response was not successful", !result.Success, "request should have failed"); because.ItsTrue("the message says 'You must be logged in to do that'", result.Message.Equals("You must be logged in to do that")); because.IllLookAtIt(result.Message); }) .SoBeHappy() .UnlessItFailed(); }
public void CanListWebHookSubscribers() { string testWebHookName = "TestWebHookName"; string[] testWebHookUrls = new string[] { 8.RandomLetters(), 6.RandomLetters(), 4.RandomLetters() }; WebHookService svc = new WebHookService(new WebHooksRepository(), new Data.Repositories.DaoRepository(), new Server.AppConf()); foreach (string testWebHookUrl in testWebHookUrls) { svc.SubscribeToWebHook(testWebHookName, testWebHookUrl); } CoreServiceResponse <WebHookSubscriptionInfo> response = svc.ListSubscribers(testWebHookName); WebHookSubscriptionInfo[] info = response.ToArray <WebHookSubscriptionInfo>(); Expect.AreEqual(3, info.Length); List <string> actual = info.Select(whsi => whsi.Url).ToList(); foreach (string expected in testWebHookUrls) { Expect.IsTrue(actual.Contains(expected)); } }
public void MustBeLoggedInToRegister() { After.Setup(setupContext => { setupContext.CopyFrom((CoreServiceRegistryContainer.GetServiceRegistry())); }) .WhenA <ApplicationRegistryService>("tries to register application when not logged in", applicationRegistryService => { ProcessDescriptor descriptor = ProcessDescriptor.ForApplicationRegistration(applicationRegistryService.ApplicationRegistrationRepository, "localhost", 8080, "testApp", "testOrg"); return(applicationRegistryService.RegisterApplicationProcess(descriptor)); }) .TheTest .ShouldPass((because, objectUnderTest) => { because.ItsTrue($"object under test is of type {nameof(ApplicationRegistryService)}", objectUnderTest.GetType() == typeof(ApplicationRegistryService)); CoreServiceResponse result = because.ResultAs <CoreServiceResponse>(); because.ItsTrue("the response was not successful", !result.Success, "request should have failed"); because.ItsTrue("the message says 'You must be logged in to do that'", result.Message.Equals("You must be logged in to do that")); because.IllLookAtIt(result.Message); }) .SoBeHappy() .UnlessItFailed(); }
public void WhoAmITest() { OutLineFormat("This test requires a gloo server to be running on port 9100 of the localhost", ConsoleColor.Yellow); ConsoleLogger logger = new ConsoleLogger(); logger.AddDetails = false; const string server = "localhost"; const int port = 9100; logger.StartLoggingThread(); ApplicationRegistrationRepository repo = CoreServiceRegistryContainer.GetServiceRegistry().Get <ApplicationRegistrationRepository>(); CoreClient client = new CoreClient("TestOrg", "TestApp", server, port, logger); client.LocalCoreRegistryRepository = repo; CoreServiceResponse registrationResponse = client.RegisterClient(); Client current = Client.Of(client.LocalCoreRegistryRepository, client.ApplicationName, server, port); CoreServiceResponse response = client.Connect(); string whoAmI = client.UserRegistryService.WhoAmI(); Expect.AreEqual(current.ToString(), whoAmI); whoAmI = client.ApplicationRegistryService.WhoAmI(); Expect.AreEqual(current.ToString(), whoAmI); whoAmI = client.ConfigurationService.WhoAmI(); Expect.AreEqual(current.ToString(), whoAmI); whoAmI = client.LoggerService.WhoAmI(); Expect.AreEqual(current.ToString(), whoAmI); whoAmI = client.DiagnosticService.WhoAmI(); Expect.AreEqual(current.ToString(), whoAmI); Pass($"You are {whoAmI}"); }