Ejemplo n.º 1
0
        public static IServerHost Setup(Environment environment, GatewayConfiguration config,
                                        ushort port = 80, ushort securePort = 443)
        {
            var server = Host.Create()
                         .Bind(IPAddress.Any, port)
                         .Bind(IPAddress.IPv6Any, port)
                         .Defaults(secureUpgrade: false)
                         .Console();

            var certificateProvider = CertificateLoader.GetProvider(environment, config);

            if (certificateProvider != null)
            {
                server.Bind(IPAddress.Any, securePort, certificateProvider)
                .Bind(IPAddress.IPv6Any, securePort, certificateProvider);
            }

#if DEBUG
            server.Development();
#endif

            return(server);
        }
        public async Task TestLoader()
        {
            var environment = TestEnvironment.Create();

            try
            {
                using (var stream = await Resource.FromAssembly("Certificate.pfx").Build().GetContentAsync())
                {
                    using (var cert = File.OpenWrite(Path.Combine(environment.Certificates, "host.pfx")))
                    {
                        stream.CopyTo(cert);
                    }
                }

                var config = @$ "
hosts:
  localhost:
    security:
      certificate:
        pfx: host.pfx";

                var parsed = GetConfiguration(config);

                var provider = CertificateLoader.GetProvider(environment, parsed);

                Assert.IsNotNull(provider?.Provide("localhost"));

                Assert.IsNull(provider?.Provide("anotherhost"));

                Engine.Setup(environment, parsed);
            }
            finally
            {
                environment.Cleanup();
            }
        }