public async Task Http1And2And3_NoUseHttps_MultiplexBindNotCalled() { var serverOptions = CreateServerOptions(); serverOptions.DefaultCertificate = _x509Certificate2; var bindCalled = false; var multiplexedConnectionListenerFactory = new MockMultiplexedConnectionListenerFactory(); multiplexedConnectionListenerFactory.OnBindAsync = (ep, features) => { bindCalled = true; }; var testContext = new TestServiceContext(LoggerFactory); testContext.ServerOptions = serverOptions; await using (var server = new TestServer(context => Task.CompletedTask, testContext, serverOptions => { serverOptions.ListenLocalhost(5001, listenOptions => { listenOptions.Protocols = HttpProtocols.Http1AndHttp2AndHttp3; }); }, services => { services.AddSingleton <IMultiplexedConnectionListenerFactory>(multiplexedConnectionListenerFactory); })) { } Assert.False(bindCalled); }
public async Task Http3_TlsHandshakeCallbackOptions_Works() { var serverOptions = CreateServerOptions(); serverOptions.DefaultCertificate = _x509Certificate2; IFeatureCollection bindFeatures = null; var multiplexedConnectionListenerFactory = new MockMultiplexedConnectionListenerFactory(); multiplexedConnectionListenerFactory.OnBindAsync = (ep, features) => { bindFeatures = features; }; var testState = new object(); var testContext = new TestServiceContext(LoggerFactory); testContext.ServerOptions = serverOptions; await using (var server = new TestServer(context => Task.CompletedTask, testContext, serverOptions => { serverOptions.ListenLocalhost(5001, listenOptions => { listenOptions.Protocols = HttpProtocols.Http3; listenOptions.UseHttps(new TlsHandshakeCallbackOptions() { OnConnection = context => { return(ValueTask.FromResult(new SslServerAuthenticationOptions())); }, OnConnectionState = testState }); }); }, services => { services.AddSingleton <IMultiplexedConnectionListenerFactory>(multiplexedConnectionListenerFactory); })) { } Assert.NotNull(bindFeatures); var tlsOptions = bindFeatures.Get <TlsConnectionCallbackOptions>(); Assert.Collection(tlsOptions.ApplicationProtocols, p => Assert.Equal(SslApplicationProtocol.Http3, p)); Assert.NotNull(tlsOptions.OnConnection); Assert.Equal(testState, tlsOptions.OnConnectionState); }
public async Task Http3_ConfigureHttpsDefaults_Works() { var serverOptions = CreateServerOptions(); IFeatureCollection bindFeatures = null; var multiplexedConnectionListenerFactory = new MockMultiplexedConnectionListenerFactory(); multiplexedConnectionListenerFactory.OnBindAsync = (ep, features) => { bindFeatures = features; }; var testContext = new TestServiceContext(LoggerFactory); testContext.ServerOptions = serverOptions; await using (var server = new TestServer(context => Task.CompletedTask, testContext, serverOptions => { serverOptions.ConfigureHttpsDefaults(https => { https.ServerCertificate = _x509Certificate2; }); serverOptions.ListenLocalhost(5001, listenOptions => { listenOptions.Protocols = HttpProtocols.Http3; listenOptions.UseHttps(); }); }, services => { services.AddSingleton <IMultiplexedConnectionListenerFactory>(multiplexedConnectionListenerFactory); })) { } Assert.NotNull(bindFeatures); var tlsOptions = bindFeatures.Get <TlsConnectionCallbackOptions>(); Assert.NotNull(tlsOptions); var sslServerAuthenticationOptions = await tlsOptions.OnConnection(new TlsConnectionCallbackContext(), CancellationToken.None); Assert.Equal(_x509Certificate2, sslServerAuthenticationOptions.ServerCertificate); }
public async Task Http3_UseHttp3Callback_NoSslServerOptions() { var serverOptions = CreateServerOptions(); serverOptions.DefaultCertificate = _x509Certificate2; IFeatureCollection bindFeatures = null; var multiplexedConnectionListenerFactory = new MockMultiplexedConnectionListenerFactory(); multiplexedConnectionListenerFactory.OnBindAsync = (ep, features) => { bindFeatures = features; }; var testContext = new TestServiceContext(LoggerFactory); testContext.ServerOptions = serverOptions; await using (var server = new TestServer(context => Task.CompletedTask, testContext, serverOptions => { serverOptions.ListenLocalhost(5001, listenOptions => { listenOptions.Protocols = HttpProtocols.Http3; listenOptions.UseHttps((SslStream stream, SslClientHelloInfo clientHelloInfo, object state, CancellationToken cancellationToken) => { return(ValueTask.FromResult((new SslServerAuthenticationOptions()))); }, state: null); }); }, services => { services.AddSingleton <IMultiplexedConnectionListenerFactory>(multiplexedConnectionListenerFactory); })) { } Assert.NotNull(bindFeatures); var sslOptions = bindFeatures.Get <SslServerAuthenticationOptions>(); Assert.Null(sslOptions); }
public async Task Http3_UseHttpsNoArgsWithDefaultCertificate_UseDefaultCertificate() { var serverOptions = CreateServerOptions(); serverOptions.DefaultCertificate = _x509Certificate2; IFeatureCollection bindFeatures = null; var multiplexedConnectionListenerFactory = new MockMultiplexedConnectionListenerFactory(); multiplexedConnectionListenerFactory.OnBindAsync = (ep, features) => { bindFeatures = features; }; var testContext = new TestServiceContext(LoggerFactory); testContext.ServerOptions = serverOptions; await using (var server = new TestServer(context => Task.CompletedTask, testContext, serverOptions => { serverOptions.ListenLocalhost(5001, listenOptions => { listenOptions.Protocols = HttpProtocols.Http3; listenOptions.UseHttps(); }); }, services => { services.AddSingleton <IMultiplexedConnectionListenerFactory>(multiplexedConnectionListenerFactory); })) { } Assert.NotNull(bindFeatures); var sslOptions = bindFeatures.Get <SslServerAuthenticationOptions>(); Assert.NotNull(sslOptions); Assert.Equal(_x509Certificate2, sslOptions.ServerCertificate); }
public async Task Http3_NoUseHttps_Throws() { var serverOptions = CreateServerOptions(); serverOptions.DefaultCertificate = _x509Certificate2; var bindCalled = false; var multiplexedConnectionListenerFactory = new MockMultiplexedConnectionListenerFactory(); multiplexedConnectionListenerFactory.OnBindAsync = (ep, features) => { bindCalled = true; }; var testContext = new TestServiceContext(LoggerFactory); testContext.ServerOptions = serverOptions; var ex = await Assert.ThrowsAsync <IOException>(async() => { await using var server = new TestServer(context => Task.CompletedTask, testContext, serverOptions => { serverOptions.ListenLocalhost(5001, listenOptions => { listenOptions.Protocols = HttpProtocols.Http3; }); }, services => { services.AddSingleton <IMultiplexedConnectionListenerFactory>(multiplexedConnectionListenerFactory); }); }); Assert.False(bindCalled); Assert.Equal("HTTP/3 requires HTTPS.", ex.InnerException.InnerException.Message); }