public void TestVariableEnabledEnabledThenPort() { var commandServer = new CommandServerController(); commandServer.Shared.Variables.Tunnel(new Command() { Origin = CommandOrigin.Local, CommandType = CommandType.VariablesSet, Parameters = TestHelpers.ObjectListToContentList(new List<Object>() { CommonVariableNames.CommandServerEnabled, true }) }); commandServer.Shared.Variables.Tunnel(new Command() { Origin = CommandOrigin.Local, CommandType = CommandType.VariablesSet, Parameters = TestHelpers.ObjectListToContentList(new List<Object>() { CommonVariableNames.CommandServerPort, 3200 }) }); commandServer.Execute(); Assert.IsNotNull(commandServer.CommandServerListener); Assert.IsNotNull(commandServer.CommandServerListener.Listener); commandServer.Dispose(); }
public void TestCommandServerDisposed() { var commandServer = new CommandServerController(); commandServer.Dispose(); Assert.IsNull(commandServer.CommandServerListener); Assert.IsNull(commandServer.TunnelObjects); }
public void TestMalformedRequestReturnsBadRequest() { CommandServerPacket packet = null; CommandServerController commandServer = new CommandServerController() { CommandServerListener = new CommandServerListener() }; commandServer.OnPacketReceived(new MockCommandServerClient() { SentCallback = wrapper => { packet = wrapper as CommandServerPacket; } }, new CommandServerPacket() { Content = "ike" // Subtle. }); Assert.IsNotNull(packet); Assert.AreEqual(HttpStatusCode.BadRequest, packet.StatusCode); }
public void TestSimpleCommandSuccess() { CommandServerPacket packet = null; CommandServerController commandServer = new CommandServerController() { CommandServerListener = new CommandServerListener() }; commandServer.OnPacketReceived(new MockCommandServerClient() { SentCallback = wrapper => { packet = wrapper as CommandServerPacket; } }, new CommandServerPacket() { Headers = new WebHeaderCollection() { { HttpRequestHeader.ContentType, Mime.ApplicationJson } }, Content = JsonConvert.SerializeObject(new Command() { CommandType = CommandType.VariablesSet }) }); Assert.IsNotNull(packet); Assert.AreEqual(HttpStatusCode.OK, packet.StatusCode); }
public void TestAuthenticationSuccess() { CommandServerPacket packet = null; CommandServerController commandServer = new CommandServerController() { CommandServerListener = new CommandServerListener() }; commandServer.Shared.Security.Tunnel(new Command() { Origin = CommandOrigin.Local, CommandType = CommandType.SecurityAddGroup, Parameters = TestHelpers.ObjectListToContentList(new List<Object>() { "GroupName" }) }); commandServer.Shared.Security.Tunnel(new Command() { Origin = CommandOrigin.Local, CommandType = CommandType.SecurityGroupAddAccount, Parameters = TestHelpers.ObjectListToContentList(new List<Object>() { "GroupName", "Phogue" }) }); commandServer.Shared.Security.Tunnel(new Command() { Origin = CommandOrigin.Local, CommandType = CommandType.SecurityAccountSetPassword, Parameters = TestHelpers.ObjectListToContentList(new List<Object>() { "Phogue", "password" }) }); commandServer.Shared.Security.Tunnel(new Command() { Origin = CommandOrigin.Local, CommandType = CommandType.SecurityGroupSetPermission, Parameters = TestHelpers.ObjectListToContentList(new List<Object>() { "GroupName", CommandType.SecurityAccountAuthenticate, 1 }) }); commandServer.OnPacketReceived(new MockCommandServerClient() { SentCallback = wrapper => { packet = wrapper as CommandServerPacket; } }, new CommandServerPacket() { Headers = new WebHeaderCollection() { { HttpRequestHeader.ContentType, Mime.ApplicationJson } }, Content = JsonConvert.SerializeObject(new Command() { CommandType = CommandType.VariablesSet, Authentication = { Username = "******", PasswordPlainText = "password" } }) }); Assert.IsNotNull(packet); var responseCommandResult = JsonConvert.DeserializeObject<CommandResult>(packet.Content); Assert.IsTrue(responseCommandResult.Success); Assert.AreEqual(CommandResultType.Continue, responseCommandResult.CommandResultType); }
public void TestCommandTunnelled() { ICommand propogatedCommand = null; CommandServerController commandServer = new CommandServerController() { CommandServerListener = new CommandServerListener(), TunnelObjects = new List<ICoreController>() { new MockCommandHandler() { PropogateHandlerCallback = command => { propogatedCommand = command; } } } }; commandServer.Shared.Security.Tunnel(new Command() { Origin = CommandOrigin.Local, CommandType = CommandType.SecurityAddGroup, Parameters = TestHelpers.ObjectListToContentList(new List<Object>() { "GroupName" }) }); commandServer.Shared.Security.Tunnel(new Command() { Origin = CommandOrigin.Local, CommandType = CommandType.SecurityGroupAddAccount, Parameters = TestHelpers.ObjectListToContentList(new List<Object>() { "GroupName", "Phogue" }) }); commandServer.Shared.Security.Tunnel(new Command() { Origin = CommandOrigin.Local, CommandType = CommandType.SecurityAccountSetPassword, Parameters = TestHelpers.ObjectListToContentList(new List<Object>() { "Phogue", "password" }) }); commandServer.Shared.Security.Tunnel(new Command() { Origin = CommandOrigin.Local, CommandType = CommandType.SecurityGroupSetPermission, Parameters = TestHelpers.ObjectListToContentList(new List<Object>() { "GroupName", CommandType.SecurityAccountAuthenticate, 1 }) }); commandServer.OnPacketReceived(new MockCommandServerClient(), new CommandServerPacket() { Headers = new WebHeaderCollection() { { HttpRequestHeader.ContentType, Mime.ApplicationJson } }, Content = JsonConvert.SerializeObject(new Command() { CommandType = CommandType.VariablesSet, Authentication = { Username = "******", PasswordPlainText = "password" } }) }); Assert.IsNotNull(propogatedCommand); Assert.AreEqual(CommandType.VariablesSet.ToString(), propogatedCommand.Name); }
public void TestEventLoggedOnConfiguredDisabled() { var commandServer = new CommandServerController(); commandServer.Shared.Variables.Tunnel(new Command() { Origin = CommandOrigin.Local, CommandType = CommandType.VariablesSet, Parameters = TestHelpers.ObjectListToContentList(new List<Object>() { CommonVariableNames.CommandServerPort, 3500 }) }); commandServer.Shared.Variables.Tunnel(new Command() { Origin = CommandOrigin.Local, CommandType = CommandType.VariablesSet, Parameters = TestHelpers.ObjectListToContentList(new List<Object>() { CommonVariableNames.CommandServerEnabled, true }) }); commandServer.Execute(); commandServer.Shared.Variables.Tunnel(new Command() { Origin = CommandOrigin.Local, CommandType = CommandType.VariablesSet, Parameters = TestHelpers.ObjectListToContentList(new List<Object>() { CommonVariableNames.CommandServerEnabled, false }) }); Assert.IsNotEmpty(commandServer.Shared.Events.LoggedEvents); Assert.AreEqual(GenericEventType.CommandServerStopped, commandServer.Shared.Events.LoggedEvents.First(e => e.GenericEventType == GenericEventType.CommandServerStopped).GenericEventType); Assert.AreEqual(CommandResultType.Success, commandServer.Shared.Events.LoggedEvents.First(e => e.GenericEventType == GenericEventType.CommandServerStarted).CommandResultType); Assert.IsTrue(commandServer.Shared.Events.LoggedEvents.First(e => e.GenericEventType == GenericEventType.CommandServerStarted).Success); commandServer.Dispose(); }