public void TestEventsLogged() { var events = new EventsController(); events.Log(new GenericEvent() { Success = true, GenericEventType = GenericEventType.SecurityGroupAdded }); Assert.AreEqual(1, events.LoggedEvents.Count); }
public void TestResultSuccess() { EventsController events = new EventsController(); ICommandResult result = events.Tunnel(CommandBuilder.EventsLog(new GenericEvent() { Name = "Nothing" }).SetOrigin(CommandOrigin.Local)); Assert.IsTrue(result.Success); Assert.AreEqual(CommandResultType.Success, result.CommandResultType); }
public void TestResultInsufficientPermissions() { EventsController events = new EventsController(); ICommandResult result = events.Tunnel(CommandBuilder.EventsLog(new GenericEvent() { Name = "Nothing" }).SetOrigin(CommandOrigin.Remote).SetAuthentication(new CommandAuthenticationModel() { Username = "******" })); Assert.IsFalse(result.Success); Assert.AreEqual(CommandResultType.InsufficientPermissions, result.CommandResultType); }
public void TestEventsLoggedDisposed() { var events = new EventsController(); events.Log(new GenericEvent() { Success = true, GenericEventType = GenericEventType.SecurityGroupAdded }); events.Dispose(); Assert.IsNull(events.LoggedEvents); }
public void TestEventsLoggedEventFired() { var requestWait = new AutoResetEvent(false); var events = new EventsController(); events.EventLogged += (sender, args) => requestWait.Set(); events.Log(new GenericEvent() { Success = true, GenericEventType = GenericEventType.SecurityGroupAdded }); // This shouldn't wait at all if the event was actually fired. Assert.IsTrue(requestWait.WaitOne(60000)); }
/// <summary> /// Tests that setting the variables in a random order will still setup the push end points correctly. /// </summary> /// <param name="seed">A random number shouldn't be passed in, otherwise you won't be able to duplicate the results.</param> protected void TestEventsPushControllerMultipleEndPointsRandomVariableAssignment(int seed) { String pushConfigGroupNameOne = StringExtensions.RandomString(10); String pushConfigGroupNameTwo = StringExtensions.RandomString(10); var variables = new VariableController(); var events = new EventsController(); var pushEvents = (PushEventsController)new PushEventsController() { Shared = { Variables = variables, Events = events } }.Execute(); var groupVariables = new Dictionary<String, Object>() { {CommonVariableNames.EventsPushConfigGroups.ToString(), new List<String>() { pushConfigGroupNameOne, pushConfigGroupNameTwo }}, {VariableModel.NamespaceVariableName(String.Empty, CommonVariableNames.EventsPushUri), "http://localhost/blank.php"}, {VariableModel.NamespaceVariableName(String.Empty, CommonVariableNames.EventPushIntervalSeconds), 10}, {VariableModel.NamespaceVariableName(pushConfigGroupNameOne, CommonVariableNames.EventsPushUri), "http://localhost/one.php"}, {VariableModel.NamespaceVariableName(pushConfigGroupNameOne, CommonVariableNames.EventPushIntervalSeconds), 20}, {VariableModel.NamespaceVariableName(pushConfigGroupNameTwo, CommonVariableNames.EventsPushUri), "http://localhost/two.php"}, {VariableModel.NamespaceVariableName(pushConfigGroupNameTwo, CommonVariableNames.EventPushIntervalSeconds), 30} }; var rand = new Random(seed); foreach (String groupVariableKey in groupVariables.Keys.OrderBy(key => rand.Next()).ToList()) { variables.Set(new Command() { Origin = CommandOrigin.Local, CommandType = CommandType.VariablesSet }, groupVariableKey, groupVariables[groupVariableKey]); } Assert.IsTrue(pushEvents.EndPoints.ContainsKey(String.Empty)); Assert.AreEqual("http://localhost/blank.php", pushEvents.EndPoints[String.Empty].Uri.ToString()); Assert.AreEqual(10, pushEvents.EndPoints[String.Empty].Interval); Assert.IsTrue(pushEvents.EndPoints.ContainsKey(pushConfigGroupNameOne)); Assert.AreEqual("http://localhost/one.php", pushEvents.EndPoints[pushConfigGroupNameOne].Uri.ToString()); Assert.AreEqual(20, pushEvents.EndPoints[pushConfigGroupNameOne].Interval); Assert.IsTrue(pushEvents.EndPoints.ContainsKey(pushConfigGroupNameTwo)); Assert.AreEqual("http://localhost/two.php", pushEvents.EndPoints[pushConfigGroupNameTwo].Uri.ToString()); Assert.AreEqual(30, pushEvents.EndPoints[pushConfigGroupNameTwo].Interval); }
public void TestEventLogged() { EventsController events = new EventsController(); PotatoController instance = new PotatoController { Shared = { Events = events } }; instance.Tunnel(CommandBuilder.PotatoServiceRestart().SetOrigin(CommandOrigin.Local)); Assert.IsNotEmpty(events.LoggedEvents); Assert.AreEqual("PotatoServiceRestarting", events.LoggedEvents.First().Name); instance.Dispose(); }
public void TestEventsAfterEventIdExcludingExpired() { var events = new EventsController(); events.Log(new GenericEvent() { Success = true, GenericEventType = GenericEventType.SecurityGroupAdded, Scope = new CommandData() { Accounts = new List<AccountModel>() { new AccountModel() { Username = "******" } } } }); events.Log(new GenericEvent() { Success = true, GenericEventType = GenericEventType.SecurityGroupAdded, Scope = new CommandData() { Accounts = new List<AccountModel>() { new AccountModel() { Username = "******" } } }, Stamp = DateTime.Now.AddHours(-1) }); ICommandResult result = events.Tunnel(new Command() { Origin = CommandOrigin.Local, CommandType = CommandType.EventsFetchAfterEventId, Parameters = TestHelpers.ObjectListToContentList(new List<Object>() { 0 }) }); Assert.IsTrue(result.Success); Assert.AreEqual(CommandResultType.Success, result.CommandResultType); Assert.AreEqual(1, result.Now.Events.Count); Assert.AreEqual("Phogue", result.Now.Events.First().Scope.Accounts.First().Username); }
public void TestRepositoryCacheBuiltEventLogged() { EventsController events = new EventsController(); var cache = new RepositoryCache(); var localRepository = new MockPackageRepository(new List<IPackage>() { new DataServicePackage() { Id = "A", Version = "1.0.0", Tags = "Procon Potato Tag2" } }); cache.Add("localhost"); cache.SourceRepositories.TryAdd("localhost", new MockPackageRepository(new List<IPackage>() { new DataServicePackage() { Id = "A", Version = "2.0.0", Tags = "Procon Potato Tag2", IsLatestVersion = true } })); PackagesController packages = new PackagesController() { LocalRepository = localRepository, Cache = cache }; packages.Shared.Events = events; packages.Poke(); Assert.IsNotEmpty(events.LoggedEvents); Assert.AreEqual("PackagesCacheRebuilt", events.LoggedEvents.First().Name); Assert.AreEqual("A", events.LoggedEvents.First().Now.Repositories.First(repository => repository.Uri == "localhost").Packages.First().Id); Assert.AreEqual(PackageState.UpdateAvailable, events.LoggedEvents.First().Now.Repositories.First(repository => repository.Uri == "localhost").Packages.First().State); }
public void TestEventsPushControllerDispose() { var variables = new VariableController(); var events = new EventsController(); var pushEvents = (PushEventsController)new PushEventsController() { Shared = { Variables = variables, Events = events } }.Execute(); variables.Set(new Command() { Origin = CommandOrigin.Local, CommandType = CommandType.VariablesSet }, CommonVariableNames.EventsPushUri, "http://localhost/pushme.php"); variables.Set(new Command() { Origin = CommandOrigin.Local, CommandType = CommandType.VariablesSet }, CommonVariableNames.EventPushIntervalSeconds, 10); variables.Set(new Command() { Origin = CommandOrigin.Local, CommandType = CommandType.VariablesSet }, CommonVariableNames.EventPushInclusiveNames, new List<String>() { "EventName" }); // Validate the end point has been added. Assert.IsTrue(pushEvents.EndPoints.ContainsKey(String.Empty)); Assert.AreEqual("http://localhost/pushme.php", pushEvents.EndPoints[String.Empty].Uri.ToString()); Assert.AreEqual(10, pushEvents.EndPoints[String.Empty].Interval); events.Log(new GenericEvent() { Name = "EventName", Message = "Yo." }); Assert.AreEqual(1, pushEvents.EndPoints[String.Empty].EventsStream.Count); pushEvents.Dispose(); Assert.IsNull(pushEvents.EndPoints); Assert.IsNull(pushEvents.Tasks); }
/// <summary> /// Sets up the static controllers in this class to all use one-another for their internal /// references to the objects. This method is used so once all the static controllers have been setup /// we can update all of their references in one hit, ensuring they all communicate with each other. /// /// This makes the default controllers coupled with one another, but not a particular reference of the /// object (useful for unit testing!). The alternative is to not have the static objects at all, but the /// code does get very messy on some of the controllers that go a few levels deep (Potato.Core.Security or ..Plugins) /// </summary> public static void Setup() { SharedReferences._masterVariables = new VariableController(); SharedReferences._masterLanguages = new LanguageController(); SharedReferences._masterSecurity = new SecurityController(); SharedReferences._masterEvents = new EventsController(); if (SharedReferences._masterVariables != null && SharedReferences._masterLanguages != null && SharedReferences._masterSecurity != null && SharedReferences._masterEvents != null) { SharedReferences._masterVariables.Shared.Variables = SharedReferences._masterLanguages.Shared.Variables = SharedReferences._masterSecurity.Shared.Variables = SharedReferences._masterEvents.Shared.Variables = SharedReferences._masterVariables; SharedReferences._masterVariables.Shared.Languages = SharedReferences._masterLanguages.Shared.Languages = SharedReferences._masterSecurity.Shared.Languages = SharedReferences._masterEvents.Shared.Languages = SharedReferences._masterLanguages; SharedReferences._masterVariables.Shared.Security = SharedReferences._masterLanguages.Shared.Security = SharedReferences._masterSecurity.Shared.Security = SharedReferences._masterEvents.Shared.Security = SharedReferences._masterSecurity; SharedReferences._masterVariables.Shared.Events = SharedReferences._masterLanguages.Shared.Events = SharedReferences._masterSecurity.Shared.Events = SharedReferences._masterEvents.Shared.Events = SharedReferences._masterEvents; _masterVariables.Execute(); _masterLanguages.Execute(); _masterSecurity.Execute(); _masterEvents.Execute(); } }
public void TestEventsPushControllerSingleEndPointNoNamespace() { var variables = new VariableController(); var events = new EventsController(); var pushEvents = (PushEventsController)new PushEventsController() { Shared = { Variables = variables, Events = events } }.Execute(); variables.Set(new Command() { Origin = CommandOrigin.Local, CommandType = CommandType.VariablesSet }, CommonVariableNames.EventsPushUri, "http://localhost/pushme.php"); variables.Set(new Command() { Origin = CommandOrigin.Local, CommandType = CommandType.VariablesSet }, CommonVariableNames.EventPushIntervalSeconds, 20); Assert.IsTrue(pushEvents.EndPoints.ContainsKey(String.Empty)); Assert.AreEqual("http://localhost/pushme.php", pushEvents.EndPoints[String.Empty].Uri.ToString()); Assert.AreEqual(20, pushEvents.EndPoints[String.Empty].Interval); }
public void TestEventsAfterEventIdInsufficientPermission() { var events = new EventsController(); events.Log(new GenericEvent() { Success = true, GenericEventType = GenericEventType.SecurityGroupAdded, Scope = new CommandData() { Accounts = new List<AccountModel>() { new AccountModel() { Username = "******" } } } }); ICommandResult result = events.Tunnel(new Command() { Authentication = { Username = "******" }, Origin = CommandOrigin.Remote, CommandType = CommandType.EventsFetchAfterEventId, Parameters = TestHelpers.ObjectListToContentList(new List<Object>() { 0 }) }); Assert.IsFalse(result.Success); Assert.AreEqual(CommandResultType.InsufficientPermissions, result.CommandResultType); }
public void TestEventsPushControllerNamespacedSingleEndPointForwardSetting() { String pushConfigGroupName = StringExtensions.RandomString(10); var variables = new VariableController(); var events = new EventsController(); var pushEvents = (PushEventsController)new PushEventsController() { Shared = { Variables = variables, Events = events } }.Execute(); variables.Set(new Command() { Origin = CommandOrigin.Local, CommandType = CommandType.VariablesSet }, VariableModel.NamespaceVariableName(pushConfigGroupName, CommonVariableNames.EventsPushUri), "http://localhost/pushme.php"); variables.Set(new Command() { Origin = CommandOrigin.Local, CommandType = CommandType.VariablesSet }, VariableModel.NamespaceVariableName(pushConfigGroupName, CommonVariableNames.EventPushIntervalSeconds), 20); variables.Set(new Command() { Origin = CommandOrigin.Local, CommandType = CommandType.VariablesSet }, CommonVariableNames.EventsPushConfigGroups, new List<String>() { pushConfigGroupName }); Assert.IsTrue(pushEvents.EndPoints.ContainsKey(pushConfigGroupName)); Assert.AreEqual("http://localhost/pushme.php", pushEvents.EndPoints[pushConfigGroupName].Uri.ToString()); Assert.AreEqual(20, pushEvents.EndPoints[pushConfigGroupName].Interval); }
public void TestVariablesSetPriorToPushEventsControllerExecution() { String pushConfigGroupName = StringExtensions.RandomString(10); var variables = new VariableController(); variables.Tunnel(CommandBuilder.VariablesSet(VariableModel.NamespaceVariableName(pushConfigGroupName, CommonVariableNames.EventsPushUri), "http://localhost/pushme.php").SetOrigin(CommandOrigin.Local)); variables.Tunnel(CommandBuilder.VariablesSet(VariableModel.NamespaceVariableName(pushConfigGroupName, CommonVariableNames.EventPushIntervalSeconds), "20").SetOrigin(CommandOrigin.Local)); variables.Tunnel(CommandBuilder.VariablesSet(CommonVariableNames.EventsPushConfigGroups, pushConfigGroupName).SetOrigin(CommandOrigin.Local)); var events = new EventsController(); var pushEvents = (PushEventsController)new PushEventsController() { Shared = { Variables = variables, Events = events } }.Execute(); Assert.IsTrue(pushEvents.EndPoints.ContainsKey(pushConfigGroupName)); Assert.AreEqual("http://localhost/pushme.php", pushEvents.EndPoints[pushConfigGroupName].Uri.ToString()); Assert.AreEqual(20, pushEvents.EndPoints[pushConfigGroupName].Interval); }
public void TestEventsPushControllerIntervalTickedEventsPushed() { var requestWait = new AutoResetEvent(false); var variables = new VariableController(); var events = new EventsController(); var pushEvents = (PushEventsController)new PushEventsController() { Shared = { Variables = variables, Events = events } }.Execute(); variables.Set(new Command() { Origin = CommandOrigin.Local, CommandType = CommandType.VariablesSet }, CommonVariableNames.EventsPushUri, "http://localhost/pushme.php"); variables.Set(new Command() { Origin = CommandOrigin.Local, CommandType = CommandType.VariablesSet }, CommonVariableNames.EventPushIntervalSeconds, 1); variables.Set(new Command() { Origin = CommandOrigin.Local, CommandType = CommandType.VariablesSet }, CommonVariableNames.EventPushInclusiveNames, new List<String>() { "EventName" }); // Validate the end point has been added. Assert.IsTrue(pushEvents.EndPoints.ContainsKey(String.Empty)); Assert.AreEqual("http://localhost/pushme.php", pushEvents.EndPoints[String.Empty].Uri.ToString()); Assert.AreEqual(1, pushEvents.EndPoints[String.Empty].Interval); events.Log(new GenericEvent() { Name = "EventName", Message = "Yo." }); pushEvents.EndPoints[String.Empty].PushCompleted += sender => requestWait.Set(); Assert.IsTrue(requestWait.WaitOne(5000)); Assert.AreEqual(0, pushEvents.EndPoints[String.Empty].EventsStream.Count); }
public void TestEventLoggedOnFileDoesNotExist() { var events = new EventsController(); var certificate = new CertificateController() { Shared = { Events = events } }; Assert.IsFalse(certificate.Load(Path.Combine(Defines.BaseDirectory.FullName, "Remote", "Certificates", "DoesNotExist.pfx"))); Assert.IsNotEmpty(events.LoggedEvents); Assert.IsFalse(events.LoggedEvents.First(e => e.Name == GenericEventType.CommandServerStarted.ToString()).Success); }
public void TestEventLoggedOnNoPasswordButPasswordSupplied() { var events = new EventsController(); var certificate = new CertificateController() { Shared = { Events = events } }; Assert.IsFalse(certificate.Load(Path.Combine(Defines.BaseDirectory.FullName, "Remote", "Certificates", "NoPassword.pfx"), "This is a password that isn't needed")); Assert.IsNotEmpty(events.LoggedEvents); Assert.IsFalse(events.LoggedEvents.First(e => e.Name == GenericEventType.CommandServerStarted.ToString()).Success); }
public void TestEventsUnexpiredWrittenToFile() { // The current time, to the second. DateTime now = DateTime.Now; // When the event was logged. DateTime then = now.AddHours(-1); // Then, rounded to the nearest hour. var roundedThenHour = new DateTime(then.Year, then.Month, then.Day, then.Hour, 0, 0); var events = new EventsController(); events.Shared.Variables.Tunnel(CommandBuilder.VariablesSet(CommonVariableNames.WriteLogEventsToFile, true.ToString()).SetOrigin(CommandOrigin.Local)); events.Log(new GenericEvent() { Success = true, GenericEventType = GenericEventType.SecurityGroupAdded, Scope = new CommandData() { Accounts = new List<AccountModel>() { new AccountModel() { Username = "******" } } }, Stamp = now }); events.Log(new GenericEvent() { Success = true, GenericEventType = GenericEventType.SecurityGroupAdded, Scope = new CommandData() { Accounts = new List<AccountModel>() { new AccountModel() { Username = "******" } } }, Stamp = then }); events.WriteEvents(now); String logFileName = events.EventsLogFileName(roundedThenHour); var logEvent = JsonConvert.DeserializeObject<GenericEvent>(File.ReadAllText(logFileName).Trim(',', '\r', '\n')); Assert.IsTrue(logEvent.Success); Assert.AreEqual("SecurityGroupAdded", logEvent.Name); Assert.AreEqual("Phogue", logEvent.Scope.Accounts.First().Username); }
/// <summary> /// Initializes the default references from the static controllers. /// </summary> public SharedReferences() : base() { this.Variables = SharedReferences._masterVariables; this.Languages = SharedReferences._masterLanguages; this.Security = SharedReferences._masterSecurity; this.Events = SharedReferences._masterEvents; }