public void TestEventsLogged() { var events = new EventsController(); events.Log(new GenericEvent() { Success = true, GenericEventType = GenericEventType.SecurityGroupAdded }); Assert.AreEqual(1, events.LoggedEvents.Count); }
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 TestEventsLoggedDisposed() { var events = new EventsController(); events.Log(new GenericEvent() { Success = true, GenericEventType = GenericEventType.SecurityGroupAdded }); events.Dispose(); Assert.IsNull(events.LoggedEvents); }
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); }
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 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 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)); }
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); }