示例#1
0
        public static void Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                .WriteTo.ColoredConsole()
                .CreateLogger();

            Console.Title = "Halibut Client";

            var hostName = args.FirstOrDefault() ?? "localhost";
            var port = args.Skip(1).FirstOrDefault() ?? "8433";

            var certificate = new X509Certificate2("HalibutClient.pfx");

            using (var runtime = new HalibutRuntime(certificate))
            {
                Console.WriteLine("creating calculator");
                var calculator = runtime.CreateClient<ICalculatorService>("https://" + hostName + ":" + port + "/", "EF3A7A69AFE0D13130370B44A228F5CD15C069BC");

                Console.WriteLine("making call 1");
                var result = calculator.Add(12, 18);
                Console.WriteLine("making call 2");
                result = calculator.Add(12, 18);

                Console.WriteLine("12 + 18 = " + result);
                Console.ReadKey();
            }
        }
示例#2
0
        public void OctopusCanSendMessagesToWebSocketPollingTentacle()
        {
            const int octopusPort = 8450;

            AddSslCertToLocalStoreAndRegisterFor("0.0.0.0:" + octopusPort);

            try
            {
                using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
                    using (var tentaclePolling = new HalibutRuntime(services, Certificates.TentaclePolling))
                    {
                        octopus.ListenWebSocket($"https://+:{octopusPort}/Halibut");
                        octopus.Trust(Certificates.TentaclePollingPublicThumbprint);

                        tentaclePolling.Poll(new Uri("poll://SQ-TENTAPOLL"), new ServiceEndPoint(new Uri($"wss://localhost:{octopusPort}/Halibut"), Certificates.SslThumbprint));

                        var echo = octopus.CreateClient <IEchoService>("poll://SQ-TENTAPOLL", Certificates.TentaclePollingPublicThumbprint);
                        for (var i = 0; i < 2000; i++)
                        {
                            echo.SayHello("Deploy package A" + i).Should().Be("Deploy package A" + i + "...");
                        }
                    }
            }
            finally
            {
                RemoveSslCertBindingFor("0.0.0.0:" + octopusPort);
            }
        }
示例#3
0
 public void StartClient()
 {
     var DaClient     = new HalibutRuntime(Configuration.ClientCertificate);
     var DaService    = DaClient.CreateClient <ITestService>(Configuration.ClientEndpoint, Configuration.ServerCertificate.Thumbprint);
     var IntTester    = DaService.Add(1, 5);
     var StringSender = DaService.Send("Hi mom");
 }
        public Task StartAsync(CancellationToken cancellationToken)
        {
            var certificate = new X509Certificate2(_options.CertificateFile);

            _runtime = new HalibutRuntime(_serviceFactory, certificate, _trustProvider);

            if (_options.Trust.Count > 0)
            {
                foreach (var item in _options.Trust)
                {
                    _trustProvider.Add(item);
                }
            }

            _runtime.OnUnauthorizedClientConnect = _options.OnUnauthorizedClientConnect;

            switch (_options.Mode)
            {
            case HalibutServerMode.Listening:
                _runtime.Listen(_options.Listen.EndPoint);
                break;

            case HalibutServerMode.Polling:
                _runtime.Poll(new Uri($"poll://{_options.Polling.Subscription}"), new ServiceEndPoint(new Uri(_options.Polling.BaseUri), _options.Polling.RemoteThumbPrint, _options.ProxyDetails));

                break;

            case HalibutServerMode.WebSocketPolling:
                _runtime.Poll(new Uri($"poll://{_options.Polling.Subscription}"), new ServiceEndPoint(new Uri(_options.Polling.BaseUri), _options.Polling.RemoteThumbPrint, _options.ProxyDetails));
                break;
            }

            return(Task.CompletedTask);
        }
示例#5
0
        public static void Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                         .WriteTo.ColoredConsole()
                         .CreateLogger();

            Console.Title = "Halibut Client";

            var hostName = args.FirstOrDefault() ?? "localhost";
            var port     = args.Skip(1).FirstOrDefault() ?? "8433";

            var certificate = new X509Certificate2("HalibutClient.pfx");

            using (var runtime = new HalibutRuntime(certificate))
            {
                Console.WriteLine("creating calculator");
                var calculator = runtime.CreateClient <ICalculatorService>("https://" + hostName + ":" + port + "/", "EF3A7A69AFE0D13130370B44A228F5CD15C069BC");

                Console.WriteLine("making call 1");
                var result = calculator.Add(12, 18);
                Console.WriteLine("making call 2");
                result = calculator.Add(12, 18);


                Console.WriteLine("12 + 18 = " + result);
                Console.ReadKey();
            }
        }
示例#6
0
        public void OctopusCanSendMessagesToWebSocketPollingTentacle()
        {
            var       services    = GetDelegateServiceFactory();
            const int octopusPort = 8450;

            AddSslCertToLocalStoreAndRegisterFor("0.0.0.0:" + octopusPort);

            try
            {
                using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
                    using (var tentaclePolling = new HalibutRuntime(services, Certificates.TentaclePolling))
                    {
                        octopus.ListenWebSocket($"https://+:{octopusPort}/Halibut");
                        octopus.Trust(Certificates.TentaclePollingPublicThumbprint);

                        tentaclePolling.Poll(new Uri("poll://SQ-TENTAPOLL"), new ServiceEndPoint(new Uri($"wss://localhost:{octopusPort}/Halibut"), Certificates.SslThumbprint));

                        var echo = octopus.CreateClient <IEchoService>("poll://SQ-TENTAPOLL", Certificates.TentaclePollingPublicThumbprint);
                        for (var i = 0; i < 2000; i++)
                        {
                            echo.SayHello("Deploy package A" + i).Should().Be("Deploy package A" + i + "...");
                        }
                    }
            }
            catch (NotSupportedException nse) when(nse.Message == "The netstandard build of this library cannot act as the client in a WebSocket polling setup")
            {
                Assert.Inconclusive("This test cannot run on the netstandard build");
            }
            finally
            {
                RemoveSslCertBindingFor("0.0.0.0:" + octopusPort);
            }
        }
        public Task StopAsync(CancellationToken cancellationToken)
        {
            _runtime.Dispose();
            _runtime = null;

            return(Task.CompletedTask);
        }
示例#8
0
        const string SslCertificateThumbprint = "6E5C6492129B75A4C83E1A23797AF6344092E5C2"; // For WebSockets. This is different to the internally configured thumbprint
        public static void Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                         .WriteTo.ColoredConsole()
                         .MinimumLevel.Warning()
                         .CreateLogger();

            Console.Title = "Halibut Server";
            var certificate = new X509Certificate2("HalibutServer.pfx");

            var endPoint = new IPEndPoint(IPAddress.IPv6Any, 8433);

            var services = new DelegateServiceFactory();

            services.Register <ICalculatorService>(() => new CalculatorService());

            using (var server = new HalibutRuntime(services, certificate))
            {
                //Although this is the "Server" because it is the thing handling a request
                //in Octopus terms, this would be the Tentacle, being asked to do some work

                //Begin Listening Setup
                //server.Listen(endPoint);
                //server.Trust("2074529C99D93D5955FEECA859AEAC6092741205");
                //End Listening Setup

                //Begin Polling Setup
                //server.Poll(new Uri("poll://SQ-TENTAPOLL"), new ServiceEndPoint(new Uri("https://localhost:8433"), "2074529C99D93D5955FEECA859AEAC6092741205"));
                //End Polling Setup

                //Begin WebSocket Polling Setup

                server.Poll(new Uri("poll://SQ-TENTAPOLL"), new ServiceEndPoint(new Uri("wss://localhost:8433/Halibut"), SslCertificateThumbprint));
                //End WebSocket Polling Setup

                Console.WriteLine("Server listening on port 8433. Type 'exit' to quit, or 'cls' to clear...");
                while (true)
                {
                    var line = Console.ReadLine();
                    if (string.Equals("cls", line, StringComparison.OrdinalIgnoreCase))
                    {
                        Console.Clear();
                        continue;
                    }

                    if (string.Equals("q", line, StringComparison.OrdinalIgnoreCase))
                    {
                        return;
                    }

                    if (string.Equals("exit", line, StringComparison.OrdinalIgnoreCase))
                    {
                        return;
                    }

                    Console.WriteLine("Unknown command. Enter 'q' to quit.");
                }
            }
        }
示例#9
0
 static void RunListeningClient(X509Certificate2 clientCertificate, int port, string remoteThumbprint, bool expectSuccess = true)
 {
     using (var runtime = new HalibutRuntime(clientCertificate))
     {
         var calculator = runtime.CreateClient <ICalculatorService>($"https://localhost:{port}/", remoteThumbprint);
         MakeRequest(calculator, "listening", expectSuccess);
     }
 }
示例#10
0
 public void ConnectingOverHttpShouldFailQuickly()
 {
     using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
     {
         var listenPort = octopus.Listen();
         Assert.Throws<WebException>(() => DownloadStringIgnoringCertificateValidation("http://localhost:" + listenPort));
     }
 }
示例#11
0
        public OctopusForm()
        {
            InitializeComponent();

            log = new Logger(logBox);
            var services = new DelegateServiceFactory();
            serverHalibutRuntime = new HalibutRuntime(services, new X509Certificate2("OctopusServer.pfx"));
        }
 public void FailOnInvalidPort()
 {
     using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
     {
         var echo = octopus.CreateClient<IEchoService>("https://google.com:88", Certificates.TentacleListeningPublicThumbprint);
         var ex = Assert.Throws<HalibutClientException>(() => echo.Crash());
         Assert.That(ex.Message, Does.Contain("when sending a request to 'https://google.com:88/', before the request"));
     }
 }
示例#13
0
 public void FailOnInvalidHostname()
 {
     using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
     {
         var echo = octopus.CreateClient <IEchoService>("https://sduj08ud9382ujd98dw9fh934hdj2389u982:8000", Certificates.TentacleListeningPublicThumbprint);
         var ex   = Assert.Throws <HalibutClientException>(() => echo.Crash());
         ex.Message.Should().Contain("when sending a request to 'https://sduj08ud9382ujd98dw9fh934hdj2389u982:8000/', before the request").And.Contain("No such host is known");
     }
 }
示例#14
0
 public void FailsWhenSendingToPollingMachineButNothingPicksItUp()
 {
     using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
     {
         var echo  = octopus.CreateClient <IEchoService>("poll://SQ-TENTAPOLL", Certificates.TentaclePollingPublicThumbprint);
         var error = Assert.Throws <HalibutClientException>(() => echo.SayHello("Paul"));
         error.Message.Should().Contain("the polling endpoint did not collect the request within the allowed time");
     }
 }
 public void FailsWhenSendingToPollingMachineButNothingPicksItUp()
 {
     using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
     {
         var echo = octopus.CreateClient<IEchoService>("poll://SQ-TENTAPOLL", Certificates.TentaclePollingPublicThumbprint);
         var error = Assert.Throws<HalibutClientException>(() => echo.SayHello("Paul"));
         Assert.That(error.Message, Does.Contain("the polling endpoint did not collect the request within the allowed time"));
     }
 }
示例#16
0
 public void FailOnInvalidPort()
 {
     using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
     {
         var echo = octopus.CreateClient <IEchoService>("https://google.com:88", Certificates.TentacleListeningPublicThumbprint);
         var ex   = Assert.Throws <HalibutClientException>(() => echo.Crash());
         ex.Message.Should().Contain("when sending a request to 'https://google.com:88/', before the request");
     }
 }
 public void FailOnInvalidHostname()
 {
     using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
     {
         var echo = octopus.CreateClient<IEchoService>("https://sduj08ud9382ujd98dw9fh934hdj2389u982:8000", Certificates.TentacleListeningPublicThumbprint);
         var ex = Assert.Throws<HalibutClientException>(() => echo.Crash());
         Assert.That(ex.Message, Does.Contain("when sending a request to 'https://sduj08ud9382ujd98dw9fh934hdj2389u982:8000/', before the request").And.Contains("No such host is known"));
     }
 }
示例#18
0
        public OctopusForm()
        {
            InitializeComponent();

            log = new Logger(logBox);
            var services = new DelegateServiceFactory();

            serverHalibutRuntime = new HalibutRuntime(services, new X509Certificate2("OctopusServer.pfx"));
        }
示例#19
0
        public void StartServer()
        {
            var services = new DelegateServiceFactory();

            services.Register <ITestService>(() => new TestService());
            var DaServer = new HalibutRuntime(services, Configuration.ServerCertificate);

            DaServer.Listen(1337);
            DaServer.Trust(Configuration.ClientCertificate.Thumbprint);
        }
示例#20
0
        protected override void ProcessRecord()
        {
            using (var runtime = new HalibutRuntime(Configuration.ClientCertificate))
            {
                var pairing = runtime.CreateClient <IPairingService>(Configuration.ClientEndpoint,
                                                                     Configuration.ServerCertificate.Thumbprint);

                pairing.DualShockDevices.ToList().ForEach(WriteObject);
            }
        }
示例#21
0
        static int RunServer()
        {
            var services = new DelegateServiceFactory();
            services.Register<ICalculatorService>(() => new CalculatorService());

            var server = new HalibutRuntime(services, ServerCertificate);
            server.Trust("2074529C99D93D5955FEECA859AEAC6092741205");
            var port = server.Listen();
            return port;
        }
示例#22
0
        void DoConnectingOverHttpShouldFailQuickly()
        {
            var services = GetDelegateServiceFactory();

            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
            {
                var listenPort = octopus.Listen();
                Assert.ThrowsAsync <HttpRequestException>(() => DownloadStringIgnoringCertificateValidation("http://localhost:" + listenPort));
            }
        }
示例#23
0
        public void OctopusCanDiscoverTentacle()
        {
            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
                using (var tentacleListening = new HalibutRuntime(services, Certificates.TentacleListening))
                {
                    var tentaclePort = tentacleListening.Listen();

                    var info = octopus.Discover(new Uri("https://localhost:" + tentaclePort));
                    Assert.That(info.RemoteThumbprint, Is.EqualTo(Certificates.TentacleListeningPublicThumbprint));
                }
        }
示例#24
0
        public TentacleForm()
        {
            InitializeComponent();

            log = new Logger(textBox1);

            var tentacleServices = new DelegateServiceFactory();
            tentacleServices.Register<IHealthCheckService>(() => new HealthCheck(log));

            tentacleHalibutRuntime = new HalibutRuntime(tentacleServices, new X509Certificate2("OctopusTentacle.pfx"));
        }
示例#25
0
        public void OctopusCanDiscoverTentacle()
        {
            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
            using (var tentacleListening = new HalibutRuntime(services, Certificates.TentacleListening))
            {
                var tentaclePort = tentacleListening.Listen();

                var info = octopus.Discover(new Uri("https://localhost:" + tentaclePort));
                Assert.That(info.RemoteThumbprint, Is.EqualTo(Certificates.TentacleListeningPublicThumbprint));
            }
        }
示例#26
0
 public void SetUp()
 {
     var services = new DelegateServiceFactory();
     services.Register<IEchoService>(() => new EchoService());
     tentacle = new HalibutRuntime(services, Certificates.TentacleListening);
     var tentaclePort = tentacle.Listen();
     tentacle.Trust(Certificates.OctopusPublicThumbprint);
     endpoint = new ServiceEndPoint("https://localhost:" + tentaclePort, Certificates.TentacleListeningPublicThumbprint);
     log = new InMemoryConnectionLog(endpoint.ToString());
     HalibutLimits.ConnectionErrorRetryTimeout = TimeSpan.MaxValue;
 }
示例#27
0
        void DoConnectingOverHttpShouldFailQuickly()
        {
            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
            {
                var listenPort = octopus.Listen();
#if NET40
                Assert.Throws <WebException>(() => DownloadStringIgnoringCertificateValidation("http://localhost:" + listenPort));
#else
                Assert.Throws <HttpRequestException>(() => DownloadStringIgnoringCertificateValidation("http://localhost:" + listenPort));
#endif
            }
        }
示例#28
0
        public TentacleForm()
        {
            InitializeComponent();

            log = new Logger(textBox1);

            var tentacleServices = new DelegateServiceFactory();

            tentacleServices.Register <IHealthCheckService>(() => new HealthCheck(log));

            tentacleHalibutRuntime = new HalibutRuntime(tentacleServices, new X509Certificate2("OctopusTentacle.pfx"));
        }
示例#29
0
        public void SupportsHttpsGet(string uriFormat)
        {
            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
            {
                var listenPort = octopus.Listen();
                var uri        = uriFormat.Replace("{machine}", Environment.MachineName).Replace("{port}", listenPort.ToString());

                var result = DownloadStringIgnoringCertificateValidation(uri);

                result.Should().Be("<html><body><p>Hello!</p></body></html>");
            }
        }
        public void FailOnInvalidHostname()
        {
            var services = GetStubDelegateServiceFactory();

            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
            {
                var echo = octopus.CreateClient <IEchoService>("https://sduj08ud9382ujd98dw9fh934hdj2389u982:8000", Certificates.TentacleListeningPublicThumbprint);
                var ex   = Assert.Throws <HalibutClientException>(() => echo.Crash());
                ex.Message.Should().Contain("when sending a request to 'https://sduj08ud9382ujd98dw9fh934hdj2389u982:8000/', before the request")
                .And.Contain(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "No such host is known" : "No such device or address");
            }
        }
示例#31
0
        public void FailWhenListeningServerPresentsWrongCertificate()
        {
            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
                using (var tentacleListening = new HalibutRuntime(services, Certificates.TentacleListening))
                {
                    var tentaclePort = tentacleListening.Listen();
                    tentacleListening.Trust(Certificates.OctopusPublicThumbprint);

                    var echo = octopus.CreateClient <IEchoService>("https://localhost:" + tentaclePort, Certificates.TentaclePollingPublicThumbprint);

                    var ex = Assert.Throws <HalibutClientException>(() => echo.SayHello("World"));
                }
        }
示例#32
0
        public void FailWhenServerThrowsAnException()
        {
            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
                using (var tentacleListening = new HalibutRuntime(services, Certificates.TentacleListening))
                {
                    var tentaclePort = tentacleListening.Listen();
                    tentacleListening.Trust(Certificates.OctopusPublicThumbprint);

                    var echo = octopus.CreateClient <IEchoService>("https://localhost:" + tentaclePort, Certificates.TentacleListeningPublicThumbprint);
                    var ex   = Assert.Throws <HalibutClientException>(() => echo.Crash());
                    ex.Message.Should().Contain("at Halibut.Tests.TestServices.EchoService.Crash()").And.Contain("divide by zero");
                }
        }
示例#33
0
        static int RunServer()
        {
            var services = new DelegateServiceFactory();

            services.Register <ICalculatorService>(() => new CalculatorService());

            var server = new HalibutRuntime(services, ServerCertificate);

            server.Trust("2074529C99D93D5955FEECA859AEAC6092741205");
            var port = server.Listen();

            return(port);
        }
示例#34
0
        public SecureClientFixture()
        {
            var services = new DelegateServiceFactory();

            services.Register <IEchoService>(() => new EchoService());
            tentacle = new HalibutRuntime(services, Certificates.TentacleListening);
            var tentaclePort = tentacle.Listen();

            tentacle.Trust(Certificates.OctopusPublicThumbprint);
            endpoint = new ServiceEndPoint("https://localhost:" + tentaclePort, Certificates.TentacleListeningPublicThumbprint);
            log      = new InMemoryConnectionLog(endpoint.ToString());
            HalibutLimits.ConnectionErrorRetryTimeout = TimeSpan.MaxValue;
        }
示例#35
0
        static void RunClient(int port)
        {
            using (var runtime = new HalibutRuntime(ClientCertificate))
            {
                var calculator = runtime.CreateClient <ICalculatorService>("https://localhost:" + port + "/", "EF3A7A69AFE0D13130370B44A228F5CD15C069BC");

                for (int i = 0; i < RequestsPerClient; i++)
                {
                    var result = calculator.Add(12, 18);
                    Debug.Assert(result == 30);
                }
            }
        }
        public void FailWhenServerThrowsAnException()
        {
            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
            using (var tentacleListening = new HalibutRuntime(services, Certificates.TentacleListening))
            {
                var tentaclePort = tentacleListening.Listen();
                tentacleListening.Trust(Certificates.OctopusPublicThumbprint);

                var echo = octopus.CreateClient<IEchoService>("https://localhost:" + tentaclePort, Certificates.TentacleListeningPublicThumbprint);
                var ex = Assert.Throws<HalibutClientException>(() => echo.Crash());
                Assert.That(ex.Message, Does.Contain("at Halibut.Tests.TestServices.EchoService.Crash()").And.Contains("divide by zero"));
            }
        }
示例#37
0
        static void RunClient(int port)
        {
            using (var runtime = new HalibutRuntime(ClientCertificate))
            {
                var calculator = runtime.CreateClient<ICalculatorService>("https://localhost:" + port + "/", "EF3A7A69AFE0D13130370B44A228F5CD15C069BC");

                for (int i = 0; i < RequestsPerClient; i++)
                {
                    var result = calculator.Add(12, 18);
                    Debug.Assert(result == 30);
                }
            }
        }
        public void FailWhenListeningServerPresentsWrongCertificate()
        {
            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
            using (var tentacleListening = new HalibutRuntime(services, Certificates.TentacleListening))
            {
                var tentaclePort = tentacleListening.Listen();
                tentacleListening.Trust(Certificates.OctopusPublicThumbprint);

                var echo = octopus.CreateClient<IEchoService>("https://localhost:" + tentaclePort, Certificates.TentaclePollingPublicThumbprint);

                var ex = Assert.Throws<HalibutClientException>(() => echo.SayHello("World"));
            }
        }
示例#39
0
        public void OctopusCanDiscoverTentacle()
        {
            var services = GetDelegateServiceFactory();

            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
                using (var tentacleListening = new HalibutRuntime(services, Certificates.TentacleListening))
                {
                    var tentaclePort = tentacleListening.Listen();

                    var info = octopus.Discover(new Uri("https://localhost:" + tentaclePort));
                    info.RemoteThumbprint.Should().Be(Certificates.TentacleListeningPublicThumbprint);
                }
        }
示例#40
0
        public void CanSetCustomFriendlyHtmlPage(string html, string expectedResult = null)
        {
            expectedResult = expectedResult ?? html; // Handle the null case which reverts to default html

            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
            {
                octopus.SetFriendlyHtmlPageContent(html);
                var listenPort = octopus.Listen();

                var result = DownloadStringIgnoringCertificateValidation("https://localhost:" + listenPort);

                Assert.That(result, Is.EqualTo(expectedResult));
            }
        }
示例#41
0
        public void SetUp()
        {
            var services = new DelegateServiceFactory();

            services.Register <IEchoService>(() => new EchoService());
            tentacle = new HalibutRuntime(services, Certificates.TentacleListening);
            var tentaclePort = tentacle.Listen();

            tentacle.Trust(Certificates.OctopusPublicThumbprint);
            endpoint = new ServiceEndPoint("https://localhost:" + tentaclePort, Certificates.TentacleListeningPublicThumbprint)
            {
                ConnectionErrorRetryTimeout = TimeSpan.MaxValue
            };
        }
示例#42
0
        public void CanSetCustomFriendlyHtmlPage(string html, string expectedResult = null)
        {
            expectedResult = expectedResult ?? html; // Handle the null case which reverts to default html

            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
            {
                octopus.SetFriendlyHtmlPageContent(html);
                var listenPort = octopus.Listen();

                var result = DownloadStringIgnoringCertificateValidation("https://localhost:" + listenPort);

                result.Should().Be(expectedResult);
            }
        }
示例#43
0
        protected override void ProcessRecord()
        {
            if (!string.IsNullOrEmpty(HostAddress))
            {
                using (var runtime = new HalibutRuntime(Configuration.ClientCertificate))
                {
                    var pairing = runtime.CreateClient <IPairingService>(Configuration.ClientEndpoint,
                                                                         Configuration.ServerCertificate.Thumbprint);

                    var host = new UniqueAddress(HostAddress);

                    pairing.Pair(pairing.DualShockDevices.First(d => d.Equals(Device)), host);
                }
            }
        }
示例#44
0
        public void FailWhenServerThrowsAnExceptionOnPolling()
        {
            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
                using (var tentaclePolling = new HalibutRuntime(services, Certificates.TentaclePolling))
                {
                    var octopusPort = octopus.Listen();
                    octopus.Trust(Certificates.TentaclePollingPublicThumbprint);

                    tentaclePolling.Poll(new Uri("poll://SQ-TENTAPOLL"), new ServiceEndPoint(new Uri("https://localhost:" + octopusPort), Certificates.OctopusPublicThumbprint));

                    var echo = octopus.CreateClient <IEchoService>("poll://SQ-TENTAPOLL", Certificates.TentaclePollingPublicThumbprint);
                    var ex   = Assert.Throws <HalibutClientException>(() => echo.Crash());
                    ex.Message.Should().Contain("at Halibut.Tests.TestServices.EchoService.Crash()").And.Contain("divide by zero");
                }
        }
示例#45
0
        public void OctopusCanSendMessagesToPollingTentacle()
        {
            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
            using (var tentaclePolling = new HalibutRuntime(services, Certificates.TentaclePolling))
            {
                var octopusPort = octopus.Listen();
                octopus.Trust(Certificates.TentaclePollingPublicThumbprint);

                tentaclePolling.Poll(new Uri("poll://SQ-TENTAPOLL"), new ServiceEndPoint(new Uri("https://localhost:" + octopusPort), Certificates.OctopusPublicThumbprint));

                var echo = octopus.CreateClient<IEchoService>("poll://SQ-TENTAPOLL", Certificates.TentaclePollingPublicThumbprint);
                for (var i = 0; i < 2000; i++)
                {
                    Assert.That(echo.SayHello("Deploy package A" + i), Is.EqualTo("Deploy package A" + i + "..."));
                }
            }
        }
示例#46
0
        public void OctopusCanSendMessagesToListeningTentacle()
        {
            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
            using (var tentacleListening = new HalibutRuntime(services, Certificates.TentacleListening))
            {
                var tentaclePort = tentacleListening.Listen();
                tentacleListening.Trust(Certificates.OctopusPublicThumbprint);

                var echo = octopus.CreateClient<IEchoService>("https://localhost:" + tentaclePort, Certificates.TentacleListeningPublicThumbprint);
                Assert.That(echo.SayHello("Deploy package A"), Is.EqualTo("Deploy package A..."));
                var watch = Stopwatch.StartNew();
                for (var i = 0; i < 2000; i++)
                {
                    Assert.That(echo.SayHello("Deploy package A"), Is.EqualTo("Deploy package A..."));
                }

                Console.WriteLine("Complete in {0:n0}ms", watch.ElapsedMilliseconds);
            }
        }
示例#47
0
        public static void Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                .WriteTo.ColoredConsole()
                .CreateLogger();

            Console.Title = "Halibut Server";
            var certificate = new X509Certificate2("HalibutServer.pfx");

            var endPoint = new IPEndPoint(IPAddress.IPv6Any, 8433);

            var services = new DelegateServiceFactory();
            services.Register<ICalculatorService>(() => new CalculatorService());

            using (var server = new HalibutRuntime(services, certificate))
            {
                server.Listen(endPoint);
                server.Trust("2074529C99D93D5955FEECA859AEAC6092741205");

                Console.WriteLine("Server listening on port 8433. Type 'exit' to quit, or 'cls' to clear...");

                while (true)
                {
                    var line = Console.ReadLine();
                    if (string.Equals("cls", line, StringComparison.OrdinalIgnoreCase))
                    {
                        Console.Clear();
                        continue;
                    }

                    if (string.Equals("q", line, StringComparison.OrdinalIgnoreCase))
                        return;

                    if (string.Equals("exit", line, StringComparison.OrdinalIgnoreCase))
                        return;

                    Console.WriteLine("Unknown command. Enter 'q' to quit.");
                }
            }
        }
示例#48
0
        public void SupportsHttpsGet(string uriFormat)
        {
            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
            {
                var listenPort = octopus.Listen();
                var uri = uriFormat.Replace("{machine}", Environment.MachineName).Replace("{port}", listenPort.ToString());

                var result = DownloadStringIgnoringCertificateValidation(uri);

                Assert.That(result, Is.EqualTo("<html><body><p>Hello!</p></body></html>"));
            }
        }
示例#49
0
        public void FailWhenServerThrowsAnExceptionOnPolling()
        {
            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
            using (var tentaclePolling = new HalibutRuntime(services, Certificates.TentaclePolling))
            {
                var octopusPort = octopus.Listen();
                octopus.Trust(Certificates.TentaclePollingPublicThumbprint);

                tentaclePolling.Poll(new Uri("poll://SQ-TENTAPOLL"), new ServiceEndPoint(new Uri("https://localhost:" + octopusPort), Certificates.OctopusPublicThumbprint));

                var echo = octopus.CreateClient<IEchoService>("poll://SQ-TENTAPOLL", Certificates.TentaclePollingPublicThumbprint);
                var ex = Assert.Throws<HalibutClientException>(() => echo.Crash());
                Assert.That(ex.Message, Is.StringContaining("at Halibut.Tests.TestServices.EchoService.Crash()").And.StringContaining("divide by zero"));
            }
        }
示例#50
0
        public void StreamsCanBeSentToListeningWithProgressReporting()
        {
            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
            using (var tentacleListening = new HalibutRuntime(services, Certificates.TentacleListening))
            {
                var tentaclePort = tentacleListening.Listen();
                tentacleListening.Trust(Certificates.OctopusPublicThumbprint);

                var progressReported = new List<int>();

                var data = new byte[1024 * 1024 * 16 + 15];
                new Random().NextBytes(data);
                var stream = new MemoryStream(data);

                var echo = octopus.CreateClient<IEchoService>("https://localhost:" + tentaclePort, Certificates.TentacleListeningPublicThumbprint);

                var count = echo.CountBytes(DataStream.FromStream(stream, progressReported.Add));
                Assert.That(count, Is.EqualTo(1024 * 1024 * 16 + 15));

                CollectionAssert.AreEqual(Enumerable.Range(1, 100).ToList(), progressReported);
            }
        }
示例#51
0
        public void StreamsCanBeSentToListening()
        {
            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
            using (var tentacleListening = new HalibutRuntime(services, Certificates.TentacleListening))
            {
                var tentaclePort = tentacleListening.Listen();
                tentacleListening.Trust(Certificates.OctopusPublicThumbprint);

                var data = new byte[1024 * 1024 + 15];
                new Random().NextBytes(data);

                var echo = octopus.CreateClient<IEchoService>("https://localhost:" + tentaclePort, Certificates.TentacleListeningPublicThumbprint);

                for (var i = 0; i < 100; i++)
                {
                    var count = echo.CountBytes(DataStream.FromBytes(data));
                    Assert.That(count, Is.EqualTo(1024 * 1024 + 15));
                }
            }
        }
示例#52
0
        public void SupportsHttpsGet(string uriFormat)
        {
            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
            {
                var listenPort = octopus.Listen();

                using (var webClient = new WebClient())
                {
                    try
                    {
                        // We need to ignore server certificate validation errors - the server certificate is self-signed
                        ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true;
                        var result = webClient.DownloadString(uriFormat.Replace("{machine}", Environment.MachineName).Replace("{port}", listenPort.ToString()));
                        Assert.That(result, Is.EqualTo("<html><body><p>Hello!</p></body></html>"));
                    }
                    finally
                    {
                        // And restore it back to default behaviour
                        ServicePointManager.ServerCertificateValidationCallback = null;
                    }
                }
            }
        }
示例#53
0
        public void SupportsDifferentServiceContractMethods()
        {
            services.Register<ISupportedServices>(() => new SupportedServices());
            using (var octopus = new HalibutRuntime(Certificates.Octopus))
            using (var tentacleListening = new HalibutRuntime(services, Certificates.TentacleListening))
            {
                tentacleListening.Trust(Certificates.OctopusPublicThumbprint);
                var tentaclePort = tentacleListening.Listen();

                var echo = octopus.CreateClient<ISupportedServices>("https://localhost:" + tentaclePort, Certificates.TentacleListeningPublicThumbprint);
                echo.MethodReturningVoid(12, 14);

                Assert.That(echo.Hello(), Is.EqualTo("Hello"));
                Assert.That(echo.Hello("a"), Is.EqualTo("Hello a"));
                Assert.That(echo.Hello("a", "b"), Is.EqualTo("Hello a b"));
                Assert.That(echo.Hello("a", "b", "c"), Is.EqualTo("Hello a b c"));
                Assert.That(echo.Hello("a", "b", "c", "d"), Is.EqualTo("Hello a b c d"));
                Assert.That(echo.Hello("a", "b", "c", "d", "e"), Is.EqualTo("Hello a b c d e"));
                Assert.That(echo.Hello("a", "b", "c", "d", "e", "f"), Is.EqualTo("Hello a b c d e f"));
                Assert.That(echo.Hello("a", "b", "c", "d", "e", "f", "g"), Is.EqualTo("Hello a b c d e f g"));
                Assert.That(echo.Hello("a", "b", "c", "d", "e", "f", "g", "h"), Is.EqualTo("Hello a b c d e f g h"));
                Assert.That(echo.Hello("a", "b", "c", "d", "e", "f", "g", "h", "i"), Is.EqualTo("Hello a b c d e f g h i"));
                Assert.That(echo.Hello("a", "b", "c", "d", "e", "f", "g", "h", "i", "j"), Is.EqualTo("Hello a b c d e f g h i j"));
                Assert.That(echo.Hello("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"), Is.EqualTo("Hello a b c d e f g h i j k"));

                Assert.That(echo.Add(1, 2), Is.EqualTo(3));
                Assert.That(echo.Add(1.00, 2.00), Is.EqualTo(3.00));
                Assert.That(echo.Add(1.10M, 2.10M), Is.EqualTo(3.20M));

                Assert.That(echo.Ambiguous("a", "b"), Is.EqualTo("Hello string"));
                Assert.That(echo.Ambiguous("a", new Tuple<string, string>("a", "b")), Is.EqualTo("Hello tuple"));

                var ex = Assert.Throws<HalibutClientException>(() => echo.Ambiguous("a", (string)null));
                Assert.That(ex.Message, Is.StringContaining("Ambiguous"));
            }
        }