コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }