Ejemplo n.º 1
0
        public static void StartServer(TestContext ctx)
        {
            var serverSetup = new IpcBinaryServerProtocolSetup("OneWayTest");

            ZyanHost = new ZyanComponentHost("OneWayServer", serverSetup);
            ZyanHost.RegisterComponent <ISampleServer, SampleServer>();
            ZyanConnection = new ZyanConnection("ipc://OneWayTest/OneWayServer");
        }
Ejemplo n.º 2
0
        public static void StartServer(TestContext ctx)
        {
            var serverSetup = new IpcBinaryServerProtocolSetup("StreamsTest");

            ZyanHost = new ZyanComponentHost("SampleStreamServer", serverSetup);
            ZyanHost.RegisterComponent <IStreamService, StreamService>();
            ZyanConnection = new ZyanConnection("ipc://StreamsTest/SampleStreamServer");
        }
Ejemplo n.º 3
0
        public void TestIpcBinaryVulnerability(object payload)
        {
            var portName    = "ZyanVulnerabilityTest";
            var serverUrl   = $"ipc://{portName}/{HostName}";
            var serverSetup = new IpcBinaryServerProtocolSetup(portName);
            var clientSetup = new IpcBinaryClientProtocolSetup();

            TestVulnerability(HostName, serverUrl, serverSetup, clientSetup, payload);
        }
Ejemplo n.º 4
0
        private EventServer()
        {
            _catalog = new ComponentCatalog();
            _catalog.RegisterComponent <IEventComponentSingleton, EventComponentSingleton>(ActivationType.Singleton);
            _catalog.RegisterComponent <IEventComponentSingleCall, EventComponentSingleCall>(ActivationType.SingleCall);
            _catalog.RegisterComponent <ICallbackComponentSingleton, CallbackComponentSingleton>(ActivationType.Singleton);
            _catalog.RegisterComponent <ICallbackComponentSingleCall, CallbackComponentSingleCall>(ActivationType.SingleCall);
            _catalog.RegisterComponent <IRequestResponseCallbackSingleCall, RequestResponseCallbackSingleCall>(ActivationType.SingleCall);
            _catalog.RegisterComponent <ITimerTriggeredEvent, TimerTriggeredEvent>(ActivationType.Singleton);

            // Setting compression threshold to 1 byte means that all messages will be compressed.
            // This setting should not be used in production code because smaller packets will grow in size.
            // By default, Zyan only compresses messages larger than 64 kilobytes.
            var tcpBinaryProtocol = new TcpBinaryServerProtocolSetup(8082);

            tcpBinaryProtocol.AddServerSinkBeforeFormatter(new CompressionServerChannelSinkProvider(1, CompressionMethod.LZF));
            _tcpBinaryHost = new ZyanComponentHost("TcpBinaryEventTest", tcpBinaryProtocol, _catalog);

            var ipcBinaryProtocol = new IpcBinaryServerProtocolSetup("IpcTestServer");

            ipcBinaryProtocol.AddServerSinkBeforeFormatter(new CompressionServerChannelSinkProvider(1, CompressionMethod.DeflateStream));
            _ipcBinaryHost = new ZyanComponentHost("IpcBinaryEventTest", ipcBinaryProtocol, _catalog);

            var tcpCustomProtocol = new TcpCustomServerProtocolSetup(8083, new NullAuthenticationProvider(), true)
            {
                CompressionThreshold = 1,
                CompressionMethod    = CompressionMethod.DeflateStream
            };

            _tcpCustomHost = new ZyanComponentHost("TcpCustomEventTest", tcpCustomProtocol, _catalog);

            var tcpDuplexProtocol = new TcpDuplexServerProtocolSetup(8084, new NullAuthenticationProvider(), true)
            {
                CompressionThreshold = 1,
                CompressionMethod    = CompressionMethod.DeflateStream
            };

            tcpDuplexProtocol.AddChannelSetting("bindTo", "127.0.0.1");

            _tcpDuplexHost = new ZyanComponentHost("TcpDuplexEventTest", tcpDuplexProtocol, _catalog);

            var httpCustomProtocol = new HttpCustomServerProtocolSetup(8085, new NullAuthenticationProvider(), true)
            {
                CompressionThreshold = 1,
                CompressionMethod    = CompressionMethod.LZF
            };

            _httpCustomHost = new ZyanComponentHost("HttpCustomEventTest", httpCustomProtocol, _catalog);

            var nullChannelProtocol = new NullServerProtocolSetup(1234);

            _nullChannelHost = new ZyanComponentHost("NullEventTest", nullChannelProtocol, _catalog);

            // use legacy blocking events mode because we check the handlers synchronously
            ZyanSettings.LegacyBlockingEvents        = true;
            ZyanSettings.LegacyBlockingSubscriptions = true;
        }
Ejemplo n.º 5
0
        public static void StartServer(TestContext ctx)
        {
            ZyanConnection.AllowUrlRandomization = false;

            var serverSetup = new IpcBinaryServerProtocolSetup("ZyanProxyTest");

            ZyanHost = new ZyanComponentHost("ZyanProxyServer", serverSetup);
            ZyanHost.RegisterComponent <ISampleServer, SampleServer>(ActivationType.Singleton);

            var clientSetup = new IpcBinaryClientProtocolSetup();

            ZyanConnection = new ZyanConnection("ipc://ZyanProxyTest/ZyanProxyServer", clientSetup);
        }
Ejemplo n.º 6
0
        public static void StartServer(TestContext ctx)
        {
            var serverSetup = new IpcBinaryServerProtocolSetup("MefClientTest");

            ZyanHost = new ZyanComponentHost("MefClientServer", serverSetup);
            ZyanHost.RegisterComponent <IMefClientSample, MefClientSample>();
            ZyanHost.RegisterComponent <IMefClientSample, MefClientSample2>("AnotherComponent");

            ZyanConnection = new ZyanConnection("ipc://MefClientTest/MefClientServer");

            MefCatalog   = new ZyanCatalog(ZyanConnection);
            MefContainer = new CompositionContainer(MefCatalog);
        }
Ejemplo n.º 7
0
        public void OwnedComponentCatalog_IsDisposed()
        {
            var disposed = false;
            var server   = new ReleasableComponent {
                Handler = () => disposed = true
            };

            Assert.IsFalse(disposed);

            var serverSetup = new IpcBinaryServerProtocolSetup("CleanupTest1");

            using (var host = new ZyanComponentHost("SampleServer1", serverSetup))
            {
                host.RegisterComponent <ISampleComponent, ReleasableComponent>(
                    server, s => ((ReleasableComponent)s).Release());
            }

            Assert.IsTrue(disposed);
        }
Ejemplo n.º 8
0
        public void ExternalComponentCatalog_IsNotDisposed()
        {
            var disposed = false;
            var server   = new ReleasableComponent {
                Handler = () => disposed = true
            };

            Assert.IsFalse(disposed);

            var serverSetup = new IpcBinaryServerProtocolSetup("CleanupTest2");

            using (var catalog = new ComponentCatalog())
                using (var host = new ZyanComponentHost("SampleServer2", serverSetup, new InProcSessionManager(), catalog))
                {
                    host.RegisterComponent <ISampleComponent, ReleasableComponent>(
                        server, s => ((ReleasableComponent)s).Release());

                    Assert.IsFalse(disposed);
                    server.Release();
                    Assert.IsTrue(disposed);
                }
        }
Ejemplo n.º 9
0
        public void TestGenericWrapperOverZyan()
        {
            var serverProto = new IpcBinaryServerProtocolSetup("Test");
            var clientProto = new IpcBinaryClientProtocolSetup();

            var host = new ZyanComponentHost("TestServer", serverProto);

            host.RegisterComponent <INonGenericInterface>(() => new NonGenericWrapper(new GenericClass()), ActivationType.Singleton);

            var conn  = new ZyanConnection("ipc://Test/TestServer");
            var proxy = conn.CreateProxy <INonGenericInterface>();

            // same as usual
            var test        = new GenericWrapper(proxy);
            var prioritySet = false;

            // GetDefault
            Assert.AreEqual(default(int), test.GetDefault <int>());
            Assert.AreEqual(default(string), test.GetDefault <string>());
            Assert.AreEqual(default(Guid), test.GetDefault <Guid>());

            // Equals
            Assert.IsTrue(test.Equals(123, 123));
            Assert.IsFalse(test.Equals("Some", null));

            // GetVersion
            Assert.AreEqual("DoSomething wasn't called yet", test.GetVersion());

            // DoSomething
            test.DoSomething(123, 'x', "y");
            Assert.AreEqual("DoSomething: A = 123, B = x, C = y", test.GetVersion());

            // Compute
            var dt = test.Compute <Guid, DateTime>(Guid.Empty, 123, "123");

            Assert.AreEqual(default(DateTime), dt);

            // CreateGuid
            var guid = test.CreateGuid(dt, 12345);

            Assert.AreEqual("00003039-0001-0001-0000-000000000000", guid.ToString());

            // LastDate
            Assert.AreEqual(dt, test.LastDate);
            test.LastDate = dt = DateTime.Now;
            Assert.AreEqual(dt, test.LastDate);

            // Name
            Assert.AreEqual("GenericClass, priority = 123", test.Name);

            // add OnPrioritySet
            EventHandler <EventArgs> handler = (s, a) => prioritySet = true;

            test.OnPrioritySet += handler;
            Assert.IsFalse(prioritySet);

            // Priority
            test.Priority = 321;
            Assert.IsTrue(prioritySet);
            Assert.AreEqual("GenericClass, priority = 321", test.Name);

            // remove OnPrioritySet
            prioritySet         = false;
            test.OnPrioritySet -= handler;
            test.Priority       = 111;
            Assert.IsFalse(prioritySet);
        }