Esempio n. 1
0
        public void ListConnectorsTest()
        {
            var bootstrap = new ServerBootstrap(EndPointDispatcher.GetRandomPort());

            bootstrap.AddFilterTypes(typeof(AuthenticationValidationFilter));
            bootstrap.StartUp(null,
                              new CommandServerModule(),
                              new RepositoryModule(),
                              new ClientModule(),
                              new TestModule(),
                              new DefinedIdentifierModule());

            var command = GetRegisteredAndAuthedSession(bootstrap, true).CreateCommand(CommandCode.ListConnectors);
            var result  = command.Run(5000);

            Assert.AreEqual(0, result.GetContent <List <string> >().Count);

            command = GetRegisteredAndAuthedSession(bootstrap, true).CreateCommand(CommandCode.ListConnectors);
            result  = command.Run(5000);
            Assert.AreEqual(1, result.GetContent <List <string> >().Count);

            command = GetRegisteredAndAuthedSession(bootstrap, true).CreateCommand(CommandCode.ListConnectors);
            result  = command.Run(5000);
            Assert.AreEqual(2, result.GetContent <List <string> >().Count);

            command = GetRegisteredAndAuthedSession(bootstrap, true).CreateCommand(CommandCode.ListConnectors);
            result  = command.Run(5000);
            Assert.AreEqual(3, result.GetContent <List <string> >().Count);

            command = GetRegisteredAndAuthedSession(bootstrap, true).CreateCommand(CommandCode.ListConnectors);
            result  = command.Run(5000);
            Assert.AreEqual(4, result.GetContent <List <string> >().Count);
        }
Esempio n. 2
0
        public void RegisterAndAuthTest()
        {
            var bootstrap = new ServerBootstrap(EndPointDispatcher.GetRandomPort());

            bootstrap.AddFilterTypes(typeof(AuthenticationValidationFilter));
            bootstrap.StartUp(null,
                              new CommandServerModule(),
                              new RepositoryModule(),
                              new ClientModule(),
                              new TestModule());

            //dont register client module for they are in the same context.
            //new ClientInitializer().Init(new TestModule());
            using (var scope = ObjectHost.Host.BeginLifetimeScope())
            {
                var factory = scope.Resolve <IAsyncSessionFactory <DuplexMessage> >();
                var session = factory.OpenSession(string.Format("{0};{1};",
                                                                bootstrap.EndPoint.ToString(), "keepalive=false"));
                var command = session.CreateCommand(CommandCode.Register);
                command.SecurityEnabled = true;
                command.Parameter       = new RegisterInfo {
                    ClientMacAddr = NetworkInfoHelper.GetMacAddr(), ClientPubKey = new TestRsaKeyProvider().GetPublicKey(null)
                };
                var result = command.Run(5000);
                Assert.AreEqual(ErrorCode.NoError, result.Header.ErrorCode);
                Assert.AreEqual(command.ID, result.Header.MessageID);
                Assert.AreEqual(MessageType.Callback, result.Header.MessageType);

                command           = session.CreateCommand(CommandCode.Authentication);
                command.Parameter = new AuthInfo
                {
                    Identifier = scope.Resolve <IIdentifierProvider>().GetIdentifier(),
                    Mac        = NetworkInfoHelper.GetMacAddr()
                };
                command.SecurityEnabled = true;
                result = command.Run(5000);
                Assert.AreEqual(ErrorCode.NoError, result.Header.ErrorCode);
                Assert.AreEqual(command.ID, result.Header.MessageID);
                Assert.AreEqual(MessageType.Callback, result.Header.MessageType);

                command = session.CreateCommand(CommandCode.Test);
                result  = command.Run(5000);
                Assert.AreEqual(CommandCode.Test, result.Header.CommandCode);
                Assert.AreEqual(ErrorCode.BadRequest, result.Header.ErrorCode); // test command not registered, it's ture that it returns bad request
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            var endpoint  = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8001);
            var bootstrap = new ServerBootstrap(endpoint);

            if (args.Length == 0 || args[0] == "sample")
            {
                bootstrap.StartUp(null, new CommandServerModule(), new RepositoryModule(), new SampleModule());
            }
            else
            {
                bootstrap.AddFilterTypes(typeof(AuthenticationValidationFilter));
                bootstrap.StartUp(null, new CommandServerModule(), new RepositoryModule());
            }

            Console.ReadLine();
        }
Esempio n. 4
0
        public void UnauthorizedCommandTest()
        {
            var bootstrap = new ServerBootstrap(EndPointDispatcher.GetRandomPort());

            bootstrap.AddFilterTypes(typeof(AuthenticationValidationFilter));
            bootstrap.StartUp(null,
                              new CommandServerModule(),
                              new RepositoryModule(),
                              new ClientModule(),
                              new TestModule());

            //dont register client module for they are in the same context.
            //new ClientInitializer().Init(new TestModule());
            using (var scope = ObjectHost.Host.BeginLifetimeScope())
            {
                var factory = scope.Resolve <IAsyncSessionFactory <DuplexMessage> >();
                var session = factory.OpenSession(string.Format("{0};{1};",
                                                                bootstrap.EndPoint.ToString(), "keepalive=false"));
                var command = session.CreateCommand(CommandCode.Test);
                var result  = command.Run(60000);
                Assert.AreEqual(CommandCode.Test, result.Header.CommandCode);
                Assert.AreEqual(ErrorCode.UnauthorizedCommand, result.Header.ErrorCode);
            }
        }