diff --git a/src/Servers/Kestrel/Core/test/AddressBinderTests.cs b/src/Servers/Kestrel/Core/test/AddressBinderTests.cs index 826cc0027c7c..ea34412975a8 100644 --- a/src/Servers/Kestrel/Core/test/AddressBinderTests.cs +++ b/src/Servers/Kestrel/Core/test/AddressBinderTests.cs @@ -2,15 +2,19 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections.Generic; using System.IO; using System.Net; using System.Net.Sockets; using System.Threading.Tasks; using Microsoft.AspNetCore.Connections; +using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; +using Microsoft.AspNetCore.Server.Kestrel.Https; using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing.xunit; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging.Abstractions; using Xunit; @@ -149,5 +153,39 @@ await AddressBinder.BindAsync(addresses, Assert.True(ipV6Attempt, "Should have attempted to bind to IPAddress.IPv6Any"); Assert.Contains(logger.Messages, f => f.Equals(CoreStrings.FormatFallbackToIPv4Any(80))); } + + [Fact] + public async Task DefaultAddressBinderWithoutDevCertButHttpsConfiguredBindsToHttpsPorts() + { + var x509Certificate2 = TestResources.GetTestCertificate(); + var logger = new MockLogger(); + var addresses = new ServerAddressesFeature(); + var services = new ServiceCollection(); + services.AddLogging(); + var options = new KestrelServerOptions() + { + // This stops the dev cert from being loaded + IsDevCertLoaded = true, + ApplicationServices = services.BuildServiceProvider() + }; + + options.ConfigureEndpointDefaults(e => + { + if (e.IPEndPoint.Port == 5001) + { + e.UseHttps(new HttpsConnectionAdapterOptions { ServerCertificate = x509Certificate2 }); + } + }); + + var endpoints = new List(); + await AddressBinder.BindAsync(addresses, options, logger, listenOptions => + { + endpoints.Add(listenOptions); + return Task.CompletedTask; + }); + + Assert.Contains(endpoints, e => e.IPEndPoint.Port == 5000 && !e.IsTls); + Assert.Contains(endpoints, e => e.IPEndPoint.Port == 5001 && e.IsTls); + } } } diff --git a/src/Servers/Kestrel/shared/test/PassThroughConnectionAdapter.cs b/src/Servers/Kestrel/shared/test/PassThroughConnectionMiddleware.cs similarity index 100% rename from src/Servers/Kestrel/shared/test/PassThroughConnectionAdapter.cs rename to src/Servers/Kestrel/shared/test/PassThroughConnectionMiddleware.cs diff --git a/src/Servers/Kestrel/shared/test/TestServiceContext.cs b/src/Servers/Kestrel/shared/test/TestServiceContext.cs index 9732bf1c8fdb..6b3ca5da959e 100644 --- a/src/Servers/Kestrel/shared/test/TestServiceContext.cs +++ b/src/Servers/Kestrel/shared/test/TestServiceContext.cs @@ -76,8 +76,6 @@ private void Initialize(ILoggerFactory loggerFactory, IKestrelTrace kestrelTrace public Func> MemoryPoolFactory { get; set; } = System.Buffers.SlabMemoryPoolFactory.Create; - public int ExpectedConnectionMiddlewareCount { get; set; } - public string DateHeaderValue => DateHeaderValueManager.GetDateHeaderValues().String; } } diff --git a/src/Servers/Kestrel/shared/test/TransportTestHelpers/TestServer.cs b/src/Servers/Kestrel/shared/test/TransportTestHelpers/TestServer.cs index 3db27b32ea7f..d79a6d905554 100644 --- a/src/Servers/Kestrel/shared/test/TransportTestHelpers/TestServer.cs +++ b/src/Servers/Kestrel/shared/test/TransportTestHelpers/TestServer.cs @@ -89,11 +89,6 @@ public TestServer(RequestDelegate app, TestServiceContext context, Action - Assert.Equal(context.ExpectedConnectionMiddlewareCount, lo._middleware.Count)); - return new KestrelServer(sp.GetRequiredService(), context); }); configureServices(services); diff --git a/src/Servers/Kestrel/test/FunctionalTests/ConnectionAdapterTests.cs b/src/Servers/Kestrel/test/FunctionalTests/ConnectionMiddlewareTests.cs similarity index 89% rename from src/Servers/Kestrel/test/FunctionalTests/ConnectionAdapterTests.cs rename to src/Servers/Kestrel/test/FunctionalTests/ConnectionMiddlewareTests.cs index eb2e9d493013..aa16d48a88f9 100644 --- a/src/Servers/Kestrel/test/FunctionalTests/ConnectionAdapterTests.cs +++ b/src/Servers/Kestrel/test/FunctionalTests/ConnectionMiddlewareTests.cs @@ -12,15 +12,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { - public class ConnectionAdapterTests : LoggedTest + public class ConnectionMiddlewareTests : LoggedTest { [Fact] - public async Task ThrowingSynchronousConnectionAdapterDoesNotCrashServer() + public async Task ThrowingSynchronousConnectionMiddlewareDoesNotCrashServer() { var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)); listenOptions.Use(next => context => throw new Exception()); - var serviceContext = new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = 1 }; + var serviceContext = new TestServiceContext(LoggerFactory); using (var server = new TestServer(TestApp.EchoApp, serviceContext, listenOptions)) { diff --git a/src/Servers/Kestrel/test/FunctionalTests/Http2/HandshakeTests.cs b/src/Servers/Kestrel/test/FunctionalTests/Http2/HandshakeTests.cs index 7d7717ba1337..eccfa17c2e0e 100644 --- a/src/Servers/Kestrel/test/FunctionalTests/Http2/HandshakeTests.cs +++ b/src/Servers/Kestrel/test/FunctionalTests/Http2/HandshakeTests.cs @@ -44,7 +44,7 @@ public void TlsAndHttp2NotSupportedOnMac() var ex = Assert.Throws(() => new TestServer(context => { throw new NotImplementedException(); - }, new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = 1 }, + }, new TestServiceContext(LoggerFactory), kestrelOptions => { kestrelOptions.Listen(IPAddress.Loopback, 0, listenOptions => @@ -71,7 +71,7 @@ public async Task TlsAlpnHandshakeSelectsHttp2From1and2() "ALPN: " + tlsFeature.ApplicationProtocol.Length); return context.Response.WriteAsync("hello world " + context.Request.Protocol); - }, new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = 1 }, + }, new TestServiceContext(LoggerFactory), kestrelOptions => { kestrelOptions.Listen(IPAddress.Loopback, 0, listenOptions => @@ -102,7 +102,7 @@ public async Task TlsAlpnHandshakeSelectsHttp2() "ALPN: " + tlsFeature.ApplicationProtocol.Length); return context.Response.WriteAsync("hello world " + context.Request.Protocol); - }, new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = 1 }, + }, new TestServiceContext(LoggerFactory), kestrelOptions => { kestrelOptions.Listen(IPAddress.Loopback, 0, listenOptions => diff --git a/src/Servers/Kestrel/test/FunctionalTests/Http2/ShutdownTests.cs b/src/Servers/Kestrel/test/FunctionalTests/Http2/ShutdownTests.cs index 28e662be3a96..03f7bb9f43fc 100644 --- a/src/Servers/Kestrel/test/FunctionalTests/Http2/ShutdownTests.cs +++ b/src/Servers/Kestrel/test/FunctionalTests/Http2/ShutdownTests.cs @@ -60,7 +60,7 @@ public async Task GracefulShutdownWaitsForRequestsToFinish() .Setup(m => m.Http2ConnectionClosing(It.IsAny())) .Callback(() => requestStopping.SetResult(null)); - var testContext = new TestServiceContext(LoggerFactory, mockKestrelTrace.Object) { ExpectedConnectionMiddlewareCount = 1 }; + var testContext = new TestServiceContext(LoggerFactory, mockKestrelTrace.Object); testContext.InitializeHeartbeat(); @@ -112,8 +112,7 @@ public async Task GracefulTurnsAbortiveIfRequestsDoNotFinish() var testContext = new TestServiceContext(LoggerFactory) { - MemoryPoolFactory = memoryPoolFactory.Create, - ExpectedConnectionMiddlewareCount = 1 + MemoryPoolFactory = memoryPoolFactory.Create }; TestApplicationErrorLogger.ThrowOnUngracefulShutdown = false; diff --git a/src/Servers/Kestrel/test/FunctionalTests/RequestTests.cs b/src/Servers/Kestrel/test/FunctionalTests/RequestTests.cs index cac39502328d..218a0db4088c 100644 --- a/src/Servers/Kestrel/test/FunctionalTests/RequestTests.cs +++ b/src/Servers/Kestrel/test/FunctionalTests/RequestTests.cs @@ -37,7 +37,7 @@ public class RequestTests : LoggedTest private const int _connectionResetEventId = 19; private static readonly int _semaphoreWaitTimeout = Debugger.IsAttached ? 10000 : 2500; - public static TheoryData ConnectionAdapterData => new TheoryData + public static TheoryData ConnectionMiddlewareData => new TheoryData { new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)), new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)).UsePassThrough() @@ -503,10 +503,10 @@ public async Task AbortingTheConnectionSendsFIN() } [Theory] - [MemberData(nameof(ConnectionAdapterData))] + [MemberData(nameof(ConnectionMiddlewareData))] public async Task ConnectionClosedTokenFiresOnClientFIN(ListenOptions listenOptions) { - var testContext = new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = listenOptions._middleware.Count }; + var testContext = new TestServiceContext(LoggerFactory); var appStartedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var connectionClosedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); @@ -540,10 +540,10 @@ await connection.Send( [Theory] [Flaky("https://github.com/aspnet/AspNetCore-Internal/issues/2181", FlakyOn.Helix.All)] - [MemberData(nameof(ConnectionAdapterData))] + [MemberData(nameof(ConnectionMiddlewareData))] public async Task ConnectionClosedTokenFiresOnServerFIN(ListenOptions listenOptions) { - var testContext = new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = listenOptions._middleware.Count }; + var testContext = new TestServiceContext(LoggerFactory); var connectionClosedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); using (var server = new TestServer(context => @@ -577,10 +577,10 @@ await connection.ReceiveEnd($"HTTP/1.1 200 OK", } [Theory] - [MemberData(nameof(ConnectionAdapterData))] + [MemberData(nameof(ConnectionMiddlewareData))] public async Task ConnectionClosedTokenFiresOnServerAbort(ListenOptions listenOptions) { - var testContext = new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = listenOptions._middleware.Count }; + var testContext = new TestServiceContext(LoggerFactory); var connectionClosedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); using (var server = new TestServer(context => @@ -619,13 +619,13 @@ await connection.Send( } [Theory] - [MemberData(nameof(ConnectionAdapterData))] + [MemberData(nameof(ConnectionMiddlewareData))] public async Task RequestsCanBeAbortedMidRead(ListenOptions listenOptions) { // This needs a timeout. const int applicationAbortedConnectionId = 34; - var testContext = new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = listenOptions._middleware.Count }; + var testContext = new TestServiceContext(LoggerFactory); var readTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var registrationTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); @@ -710,7 +710,7 @@ await connection.Send("POST / HTTP/1.1", } [Theory] - [MemberData(nameof(ConnectionAdapterData))] + [MemberData(nameof(ConnectionMiddlewareData))] public async Task ServerCanAbortConnectionAfterUnobservedClose(ListenOptions listenOptions) { const int connectionPausedEventId = 4; @@ -743,7 +743,6 @@ public async Task ServerCanAbortConnectionAfterUnobservedClose(ListenOptions lis var mockKestrelTrace = new Mock(); var testContext = new TestServiceContext(LoggerFactory, mockKestrelTrace.Object) { - ExpectedConnectionMiddlewareCount = listenOptions._middleware.Count, ServerOptions = { Limits = @@ -796,14 +795,14 @@ await connection.Send( #if LIBUV [Flaky("https://github.com/aspnet/AspNetCore-Internal/issues/1971", FlakyOn.Helix.All)] #endif - [MemberData(nameof(ConnectionAdapterData))] + [MemberData(nameof(ConnectionMiddlewareData))] public async Task AppCanHandleClientAbortingConnectionMidRequest(ListenOptions listenOptions) { var readTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var appStartedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var mockKestrelTrace = new Mock(); - var testContext = new TestServiceContext(LoggerFactory, mockKestrelTrace.Object) { ExpectedConnectionMiddlewareCount = listenOptions._middleware.Count }; + var testContext = new TestServiceContext(LoggerFactory, mockKestrelTrace.Object); var scratchBuffer = new byte[4096]; diff --git a/src/Servers/Kestrel/test/FunctionalTests/ResponseTests.cs b/src/Servers/Kestrel/test/FunctionalTests/ResponseTests.cs index 3958bcd97c4b..6e20f3e71a8a 100644 --- a/src/Servers/Kestrel/test/FunctionalTests/ResponseTests.cs +++ b/src/Servers/Kestrel/test/FunctionalTests/ResponseTests.cs @@ -33,7 +33,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public class ResponseTests : TestApplicationErrorLoggerLoggedTest { - public static TheoryData ConnectionAdapterData => new TheoryData + public static TheoryData ConnectionMiddlewareData => new TheoryData { new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)), new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)).UsePassThrough() @@ -136,7 +136,7 @@ public async Task IgnoreNullHeaderValues(string headerName, StringValues headerV } [Theory] - [MemberData(nameof(ConnectionAdapterData))] + [MemberData(nameof(ConnectionMiddlewareData))] public async Task WriteAfterConnectionCloseNoops(ListenOptions listenOptions) { var connectionClosed = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); @@ -157,7 +157,7 @@ public async Task WriteAfterConnectionCloseNoops(ListenOptions listenOptions) { appCompleted.TrySetException(ex); } - }, new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = listenOptions._middleware.Count }, listenOptions)) + }, new TestServiceContext(LoggerFactory), listenOptions)) { using (var connection = server.CreateConnection()) { @@ -180,7 +180,7 @@ await connection.Send( } [Theory] - [MemberData(nameof(ConnectionAdapterData))] + [MemberData(nameof(ConnectionMiddlewareData))] public async Task ThrowsOnWriteWithRequestAbortedTokenAfterRequestIsAborted(ListenOptions listenOptions) { // This should match _maxBytesPreCompleted in SocketOutput @@ -219,7 +219,7 @@ public async Task ThrowsOnWriteWithRequestAbortedTokenAfterRequestIsAborted(List } writeTcs.SetException(new Exception("This shouldn't be reached.")); - }, new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = listenOptions._middleware.Count }, listenOptions)) + }, new TestServiceContext(LoggerFactory), listenOptions)) { using (var connection = server.CreateConnection()) { @@ -244,7 +244,7 @@ await connection.Send( } [Theory] - [MemberData(nameof(ConnectionAdapterData))] + [MemberData(nameof(ConnectionMiddlewareData))] public async Task WritingToConnectionAfterUnobservedCloseTriggersRequestAbortedToken(ListenOptions listenOptions) { const int connectionPausedEventId = 4; @@ -273,7 +273,6 @@ public async Task WritingToConnectionAfterUnobservedCloseTriggersRequestAbortedT var testContext = new TestServiceContext(LoggerFactory, mockKestrelTrace.Object) { - ExpectedConnectionMiddlewareCount = listenOptions._middleware.Count, ServerOptions = { Limits = @@ -341,7 +340,7 @@ await connection.Send( [Theory] [Flaky("https://github.com/aspnet/AspNetCore-Internal/issues/1972", FlakyOn.All)] - [MemberData(nameof(ConnectionAdapterData))] + [MemberData(nameof(ConnectionMiddlewareData))] public async Task AppCanHandleClientAbortingConnectionMidResponse(ListenOptions listenOptions) { const int connectionResetEventId = 19; @@ -368,7 +367,7 @@ public async Task AppCanHandleClientAbortingConnectionMidResponse(ListenOptions await requestAborted.Task.DefaultTimeout(); appCompletedTcs.SetResult(null); - }, new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = listenOptions._middleware.Count }, listenOptions)) + }, new TestServiceContext(LoggerFactory), listenOptions)) { using (var connection = server.CreateConnection()) { @@ -414,7 +413,7 @@ await connection.Send( } [Theory] - [MemberData(nameof(ConnectionAdapterData))] + [MemberData(nameof(ConnectionMiddlewareData))] public async Task ClientAbortingConnectionImmediatelyIsNotLoggedHigherThanDebug(ListenOptions listenOptions) { // Attempt multiple connections to be extra sure the resets are consistently logged appropriately. @@ -422,7 +421,7 @@ public async Task ClientAbortingConnectionImmediatelyIsNotLoggedHigherThanDebug( // There's not guarantee that the app even gets invoked in this test. The connection reset can be observed // as early as accept. - var testServiceContext = new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = listenOptions._middleware.Count }; + var testServiceContext = new TestServiceContext(LoggerFactory); using (var server = new TestServer(context => Task.CompletedTask, testServiceContext, listenOptions)) { for (var i = 0; i < numConnections; i++) @@ -582,8 +581,7 @@ public async Task HttpsConnectionClosedWhenResponseDoesNotSatisfyMinimumDataRate { MinResponseDataRate = new MinDataRate(bytesPerSecond: 1024 * 1024, gracePeriod: TimeSpan.FromSeconds(2)) } - }, - ExpectedConnectionMiddlewareCount = 1 + } }; testContext.InitializeHeartbeat(); diff --git a/src/Servers/Kestrel/test/InMemory.FunctionalTests/ConnectionLimitTests.cs b/src/Servers/Kestrel/test/InMemory.FunctionalTests/ConnectionLimitTests.cs index 6c1aa25d53f5..e08fffc659f0 100644 --- a/src/Servers/Kestrel/test/InMemory.FunctionalTests/ConnectionLimitTests.cs +++ b/src/Servers/Kestrel/test/InMemory.FunctionalTests/ConnectionLimitTests.cs @@ -207,10 +207,7 @@ private TestServer CreateServerWithMaxConnections(RequestDelegate app, long max) private TestServer CreateServerWithMaxConnections(RequestDelegate app, ResourceCounter concurrentConnectionCounter) { - var serviceContext = new TestServiceContext(LoggerFactory) - { - ExpectedConnectionMiddlewareCount = 1 - }; + var serviceContext = new TestServiceContext(LoggerFactory); var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)); listenOptions.Use(next => diff --git a/src/Servers/Kestrel/test/InMemory.FunctionalTests/ConnectionAdapterTests.cs b/src/Servers/Kestrel/test/InMemory.FunctionalTests/ConnectionMiddlewareTests.cs similarity index 94% rename from src/Servers/Kestrel/test/InMemory.FunctionalTests/ConnectionAdapterTests.cs rename to src/Servers/Kestrel/test/InMemory.FunctionalTests/ConnectionMiddlewareTests.cs index b7f5b02de227..f73c96c6e754 100644 --- a/src/Servers/Kestrel/test/InMemory.FunctionalTests/ConnectionAdapterTests.cs +++ b/src/Servers/Kestrel/test/InMemory.FunctionalTests/ConnectionMiddlewareTests.cs @@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests { - public class ConnectionAdapterTests : TestApplicationErrorLoggerLoggedTest + public class ConnectionMiddlewareTests : TestApplicationErrorLoggerLoggedTest { public static TheoryData EchoAppRequestDelegates => new TheoryData @@ -40,7 +40,7 @@ public async Task CanReadAndWriteWithRewritingConnectionAdapter(RequestDelegate return middleware.OnConnectionAsync; }); - var serviceContext = new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = 1 }; + var serviceContext = new TestServiceContext(LoggerFactory); var sendString = "POST / HTTP/1.0\r\nContent-Length: 12\r\n\r\nHello World?"; @@ -64,12 +64,12 @@ await connection.ReceiveEnd( [Theory] [MemberData(nameof(EchoAppRequestDelegates))] - public async Task CanReadAndWriteWithAsyncConnectionAdapter(RequestDelegate requestDelegate) + public async Task CanReadAndWriteWithAsyncConnectionMiddleware(RequestDelegate requestDelegate) { var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)); listenOptions.Use(next => new AsyncConnectionMiddleware(next).OnConnectionAsync); - var serviceContext = new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = 1 }; + var serviceContext = new TestServiceContext(LoggerFactory); await using (var server = new TestServer(requestDelegate, serviceContext, listenOptions)) { @@ -97,7 +97,7 @@ public async Task ImmediateFinAfterOnConnectionAsyncClosesGracefully(RequestDele var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)); listenOptions.Use(next => new AsyncConnectionMiddleware(next).OnConnectionAsync); - var serviceContext = new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = 1 }; + var serviceContext = new TestServiceContext(LoggerFactory); await using (var server = new TestServer(requestDelegate, serviceContext, listenOptions)) { @@ -117,7 +117,7 @@ public async Task ImmediateFinAfterThrowingClosesGracefully(RequestDelegate requ var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)); listenOptions.Use(next => context => throw new InvalidOperationException()); - var serviceContext = new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = 1 }; + var serviceContext = new TestServiceContext(LoggerFactory); await using (var server = new TestServer(requestDelegate, serviceContext, listenOptions)) { @@ -138,7 +138,7 @@ public async Task ImmediateShutdownAfterOnConnectionAsyncDoesNotCrash(RequestDel var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)); listenOptions.Use(next => new AsyncConnectionMiddleware(next).OnConnectionAsync); - var serviceContext = new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = 1 }; + var serviceContext = new TestServiceContext(LoggerFactory); TestApplicationErrorLogger.ThrowOnUngracefulShutdown = false; @@ -172,7 +172,7 @@ public async Task ImmediateShutdownDuringOnConnectionAsyncDoesNotCrash() }; }); - var serviceContext = new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = 1 }; + var serviceContext = new TestServiceContext(LoggerFactory); await using (var server = new TestServer(TestApp.EchoApp, serviceContext, listenOptions)) { @@ -191,7 +191,7 @@ public async Task ImmediateShutdownDuringOnConnectionAsyncDoesNotCrash() [Theory] [MemberData(nameof(EchoAppRequestDelegates))] - public async Task ThrowingSynchronousConnectionAdapterDoesNotCrashServer(RequestDelegate requestDelegate) + public async Task ThrowingSynchronousConnectionMiddlewareDoesNotCrashServer(RequestDelegate requestDelegate) { var connectionId = ""; var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)); @@ -201,7 +201,7 @@ public async Task ThrowingSynchronousConnectionAdapterDoesNotCrashServer(Request throw new InvalidOperationException(); }); - var serviceContext = new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = 1 }; + var serviceContext = new TestServiceContext(LoggerFactory); await using (var server = new TestServer(requestDelegate, serviceContext, listenOptions)) { @@ -220,12 +220,12 @@ await connection.Send( } [Fact] - public async Task CanFlushAsyncWithConnectionAdapter() + public async Task CanFlushAsyncWithConnectionMiddleware() { var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) .UsePassThrough(); - var serviceContext = new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = 1 }; + var serviceContext = new TestServiceContext(LoggerFactory); await using (var server = new TestServer(async context => { @@ -251,12 +251,12 @@ await connection.ReceiveEnd( } [Fact] - public async Task CanFlushAsyncWithConnectionAdapterPipeWriter() + public async Task CanFlushAsyncWithConnectionMiddlewarePipeWriter() { var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)) .UsePassThrough(); - var serviceContext = new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = 1 }; + var serviceContext = new TestServiceContext(LoggerFactory); await using (var server = new TestServer(async context => { diff --git a/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/TlsTests.cs b/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/TlsTests.cs index 275fcb999767..91faea078601 100644 --- a/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/TlsTests.cs +++ b/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/TlsTests.cs @@ -41,7 +41,7 @@ public async Task TlsHandshakeRejectsTlsLessThan12() return context.Response.WriteAsync("hello world " + context.Request.Protocol); }, - new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = 1}, + new TestServiceContext(LoggerFactory), listenOptions => { listenOptions.Protocols = HttpProtocols.Http2; diff --git a/src/Servers/Kestrel/test/InMemory.FunctionalTests/HttpsConnectionMiddlewareTests.cs b/src/Servers/Kestrel/test/InMemory.FunctionalTests/HttpsConnectionMiddlewareTests.cs index cd06d0a3d1a3..fd35fa722efe 100644 --- a/src/Servers/Kestrel/test/InMemory.FunctionalTests/HttpsConnectionMiddlewareTests.cs +++ b/src/Servers/Kestrel/test/InMemory.FunctionalTests/HttpsConnectionMiddlewareTests.cs @@ -17,8 +17,8 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core; -using Microsoft.AspNetCore.Server.Kestrel.Https.Internal; using Microsoft.AspNetCore.Server.Kestrel.Https; +using Microsoft.AspNetCore.Server.Kestrel.Https.Internal; using Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests.TestTransport; using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing.xunit; @@ -27,20 +27,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests { - public class HttpsConnectionAdapterTests : LoggedTest + public class HttpsConnectionMiddlewareTests : LoggedTest { private static X509Certificate2 _x509Certificate2 = TestResources.GetTestCertificate(); private static X509Certificate2 _x509Certificate2NoExt = TestResources.GetTestCertificate("no_extensions.pfx"); [Fact] - public async Task CanReadAndWriteWithHttpsConnectionAdapter() + public async Task CanReadAndWriteWithHttpsConnectionMiddleware() { void ConfigureListenOptions(ListenOptions listenOptions) { listenOptions.UseHttps(new HttpsConnectionAdapterOptions { ServerCertificate = _x509Certificate2 }); }; - await using (var server = new TestServer(App, new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = 1 }, ConfigureListenOptions)) + await using (var server = new TestServer(App, new TestServiceContext(LoggerFactory), ConfigureListenOptions)) { var result = await server.HttpClientSlim.PostAsync($"https://localhost:{server.Port}/", new FormUrlEncodedContent(new[] { @@ -73,7 +73,7 @@ void ConfigureListenOptions(ListenOptions listenOptions) Assert.True(tlsFeature.KeyExchangeStrength >= 0, "KeyExchangeStrength"); // May be 0 on mac return context.Response.WriteAsync("hello world"); - }, new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = 1 }, ConfigureListenOptions)) + }, new TestServiceContext(LoggerFactory), ConfigureListenOptions)) { var result = await server.HttpClientSlim.GetStringAsync($"https://localhost:{server.Port}/", validateCertificate: false); Assert.Equal("hello world", result); @@ -90,7 +90,7 @@ public async Task RequireCertificateFailsWhenNoCertificate() ClientCertificateMode = ClientCertificateMode.RequireCertificate }); - await using (var server = new TestServer(App, new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = 1 }, listenOptions)) + await using (var server = new TestServer(App, new TestServiceContext(LoggerFactory), listenOptions)) { await Assert.ThrowsAnyAsync( () => server.HttpClientSlim.GetStringAsync($"https://localhost:{server.Port}/")); @@ -115,7 +115,7 @@ void ConfigureListenOptions(ListenOptions listenOptions) Assert.NotNull(tlsFeature); Assert.Null(tlsFeature.ClientCertificate); return context.Response.WriteAsync("hello world"); - }, new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = 1 }, ConfigureListenOptions)) + }, new TestServiceContext(LoggerFactory), ConfigureListenOptions)) { var result = await server.HttpClientSlim.GetStringAsync($"https://localhost:{server.Port}/", validateCertificate: false); Assert.Equal("hello world", result); @@ -138,13 +138,10 @@ void ConfigureListenOptions(ListenOptions listenOptions) listenOptions.UseHttps(new HttpsConnectionAdapterOptions { ServerCertificate = _x509Certificate2 }); }; - await using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = 1 }, ConfigureListenOptions)) + await using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory), ConfigureListenOptions)) { using (var connection = server.CreateConnection()) { - // SslStream is used to ensure the certificate is actually passed to the server - // HttpClient might not send the certificate because it is invalid or it doesn't match any - // of the certificate authorities sent by the server in the SSL handshake. var stream = OpenSslStream(connection.Stream); await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false); Assert.True(stream.RemoteCertificate.Equals(_x509Certificate2)); @@ -171,13 +168,10 @@ void ConfigureListenOptions(ListenOptions listenOptions) }); } - await using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = 1 }, ConfigureListenOptions)) + await using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory), ConfigureListenOptions)) { using (var connection = server.CreateConnection()) { - // SslStream is used to ensure the certificate is actually passed to the server - // HttpClient might not send the certificate because it is invalid or it doesn't match any - // of the certificate authorities sent by the server in the SSL handshake. var stream = OpenSslStream(connection.Stream); await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false); Assert.True(stream.RemoteCertificate.Equals(_x509Certificate2)); @@ -209,13 +203,10 @@ void ConfigureListenOptions(ListenOptions listenOptions) }); } - await using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = 1 }, ConfigureListenOptions)) + await using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory), ConfigureListenOptions)) { using (var connection = server.CreateConnection()) { - // SslStream is used to ensure the certificate is actually passed to the server - // HttpClient might not send the certificate because it is invalid or it doesn't match any - // of the certificate authorities sent by the server in the SSL handshake. var stream = OpenSslStream(connection.Stream); await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false); Assert.True(stream.RemoteCertificate.Equals(_x509Certificate2)); @@ -223,9 +214,6 @@ void ConfigureListenOptions(ListenOptions listenOptions) } using (var connection = server.CreateConnection()) { - // SslStream is used to ensure the certificate is actually passed to the server - // HttpClient might not send the certificate because it is invalid or it doesn't match any - // of the certificate authorities sent by the server in the SSL handshake. var stream = OpenSslStream(connection.Stream); await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false); Assert.True(stream.RemoteCertificate.Equals(_x509Certificate2NoExt)); @@ -250,13 +238,10 @@ void ConfigureListenOptions(ListenOptions listenOptions) }); } - await using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = 1 }, ConfigureListenOptions)) + await using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory), ConfigureListenOptions)) { using (var connection = server.CreateConnection()) { - // SslStream is used to ensure the certificate is actually passed to the server - // HttpClient might not send the certificate because it is invalid or it doesn't match any - // of the certificate authorities sent by the server in the SSL handshake. var stream = OpenSslStream(connection.Stream); await Assert.ThrowsAsync(() => stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false)); @@ -285,13 +270,10 @@ void ConfigureListenOptions(ListenOptions listenOptions) }); } - await using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = 1 }, ConfigureListenOptions)) + await using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory), ConfigureListenOptions)) { using (var connection = server.CreateConnection()) { - // SslStream is used to ensure the certificate is actually passed to the server - // HttpClient might not send the certificate because it is invalid or it doesn't match any - // of the certificate authorities sent by the server in the SSL handshake. var stream = OpenSslStream(connection.Stream); await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false); Assert.True(stream.RemoteCertificate.Equals(_x509Certificate2)); @@ -316,13 +298,10 @@ void ConfigureListenOptions(ListenOptions listenOptions) }); } - await using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = 1 }, ConfigureListenOptions)) + await using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory), ConfigureListenOptions)) { using (var connection = server.CreateConnection()) { - // SslStream is used to ensure the certificate is actually passed to the server - // HttpClient might not send the certificate because it is invalid or it doesn't match any - // of the certificate authorities sent by the server in the SSL handshake. var stream = OpenSslStream(connection.Stream); await Assert.ThrowsAsync(() => stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false)); @@ -354,14 +333,14 @@ void ConfigureListenOptions(ListenOptions listenOptions) Assert.NotNull(tlsFeature.ClientCertificate); Assert.NotNull(context.Connection.ClientCertificate); return context.Response.WriteAsync("hello world"); - }, new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = 1 }, ConfigureListenOptions)) + }, new TestServiceContext(LoggerFactory), ConfigureListenOptions)) { using (var connection = server.CreateConnection()) { // SslStream is used to ensure the certificate is actually passed to the server // HttpClient might not send the certificate because it is invalid or it doesn't match any // of the certificate authorities sent by the server in the SSL handshake. - var stream = OpenSslStream(connection.Stream); + var stream = OpenSslStreamWithCert(connection.Stream); await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false); await AssertConnectionResult(stream, true); } @@ -376,7 +355,7 @@ void ConfigureListenOptions(ListenOptions listenOptions) listenOptions.UseHttps(new HttpsConnectionAdapterOptions { ServerCertificate = _x509Certificate2 }); } - await using (var server = new TestServer(context => context.Response.WriteAsync(context.Request.Scheme), new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = 1 }, ConfigureListenOptions)) + await using (var server = new TestServer(context => context.Response.WriteAsync(context.Request.Scheme), new TestServiceContext(LoggerFactory), ConfigureListenOptions)) { var result = await server.HttpClientSlim.GetStringAsync($"https://localhost:{server.Port}/", validateCertificate: false); Assert.Equal("https", result); @@ -397,14 +376,14 @@ void ConfigureListenOptions(ListenOptions listenOptions) } - await using (var server = new TestServer(context => context.Response.WriteAsync("hello world"), new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = 1 }, ConfigureListenOptions)) + await using (var server = new TestServer(context => context.Response.WriteAsync("hello world"), new TestServiceContext(LoggerFactory), ConfigureListenOptions)) { // SslStream is used to ensure the certificate is actually passed to the server // HttpClient might not send the certificate because it is invalid or it doesn't match any // of the certificate authorities sent by the server in the SSL handshake. using (var connection = server.CreateConnection()) { - var stream = OpenSslStream(connection.Stream); + var stream = OpenSslStreamWithCert(connection.Stream); var ex = await Assert.ThrowsAsync( async () => await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls, false)); } @@ -434,11 +413,11 @@ void ConfigureListenOptions(ListenOptions listenOptions) }); } - await using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = 1 }, ConfigureListenOptions)) + await using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory), ConfigureListenOptions)) { using (var connection = server.CreateConnection()) { - var stream = OpenSslStream(connection.Stream); + var stream = OpenSslStreamWithCert(connection.Stream); await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false); await AssertConnectionResult(stream, true); Assert.True(clientCertificateValidationCalled); @@ -462,11 +441,11 @@ void ConfigureListenOptions(ListenOptions listenOptions) }); } - await using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = 1 }, ConfigureListenOptions)) + await using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory), ConfigureListenOptions)) { using (var connection = server.CreateConnection()) { - var stream = OpenSslStream(connection.Stream); + var stream = OpenSslStreamWithCert(connection.Stream); await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false); await AssertConnectionResult(stream, false); } @@ -487,11 +466,11 @@ void ConfigureListenOptions(ListenOptions listenOptions) }); } - await using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = 1 }, ConfigureListenOptions)) + await using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory), ConfigureListenOptions)) { using (var connection = server.CreateConnection()) { - var stream = OpenSslStream(connection.Stream); + var stream = OpenSslStreamWithCert(connection.Stream); await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false); await AssertConnectionResult(stream, false); } @@ -512,11 +491,11 @@ void ConfigureListenOptions(ListenOptions listenOptions) }); } - await using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = 1 }, ConfigureListenOptions)) + await using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory), ConfigureListenOptions)) { using (var connection = server.CreateConnection()) { - var stream = OpenSslStream(connection.Stream); + var stream = OpenSslStreamWithCert(connection.Stream); await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false); await AssertConnectionResult(stream, true); } @@ -546,14 +525,11 @@ void ConfigureListenOptions(ListenOptions listenOptions) return context.Response.WriteAsync("hello world"); }; - await using (var server = new TestServer(app, new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = 1 }, ConfigureListenOptions)) + await using (var server = new TestServer(app, new TestServiceContext(LoggerFactory), ConfigureListenOptions)) { - // SslStream is used to ensure the certificate is actually passed to the server - // HttpClient might not send the certificate because it is invalid or it doesn't match any - // of the certificate authorities sent by the server in the SSL handshake. using (var connection = server.CreateConnection()) { - var stream = OpenSslStream(connection.Stream); + var stream = OpenSslStreamWithCert(connection.Stream); await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls12 | SslProtocols.Tls11, false); await AssertConnectionResult(stream, true); } @@ -630,7 +606,17 @@ private static async Task App(HttpContext httpContext) } } - private static SslStream OpenSslStream(Stream rawStream, X509Certificate2 clientCertificate = null) + private static SslStream OpenSslStream(Stream rawStream) + { + return new SslStream(rawStream, false, (sender, certificate, chain, errors) => true); + } + + /// + /// SslStream is used to ensure the certificate is actually passed to the server + /// HttpClient might not send the certificate because it is invalid or it doesn't match any + /// of the certificate authorities sent by the server in the SSL handshake. + /// + private static SslStream OpenSslStreamWithCert(Stream rawStream, X509Certificate2 clientCertificate = null) { return new SslStream(rawStream, false, (sender, certificate, chain, errors) => true, (sender, host, certificates, certificate, issuers) => clientCertificate ?? _x509Certificate2); diff --git a/src/Servers/Kestrel/test/InMemory.FunctionalTests/HttpsTests.cs b/src/Servers/Kestrel/test/InMemory.FunctionalTests/HttpsTests.cs index 87d0316d7aa9..453c8f538558 100644 --- a/src/Servers/Kestrel/test/InMemory.FunctionalTests/HttpsTests.cs +++ b/src/Servers/Kestrel/test/InMemory.FunctionalTests/HttpsTests.cs @@ -122,7 +122,7 @@ public async Task EmptyRequestLoggedAsDebug() LoggerFactory.AddProvider(loggerProvider); await using (var server = new TestServer(context => Task.CompletedTask, - new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = 1 }, + new TestServiceContext(LoggerFactory), listenOptions => { listenOptions.UseHttps(TestResources.GetTestCertificate()); @@ -149,7 +149,7 @@ public async Task ClientHandshakeFailureLoggedAsDebug() LoggerFactory.AddProvider(loggerProvider); await using (var server = new TestServer(context => Task.CompletedTask, - new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = 1 }, + new TestServiceContext(LoggerFactory), listenOptions => { listenOptions.UseHttps(TestResources.GetTestCertificate()); @@ -193,7 +193,7 @@ public async Task DoesNotThrowObjectDisposedExceptionOnConnectionAbort() } } }, - new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = 1 }, + new TestServiceContext(LoggerFactory), listenOptions => { listenOptions.UseHttps(TestResources.GetTestCertificate()); @@ -237,7 +237,7 @@ public async Task DoesNotThrowObjectDisposedExceptionFromWriteAsyncAfterConnecti tcs.SetException(ex); } }, - new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = 1 }, + new TestServiceContext(LoggerFactory), listenOptions => { listenOptions.UseHttps(TestResources.GetTestCertificate()); @@ -268,7 +268,7 @@ public async Task DoesNotThrowObjectDisposedExceptionOnEmptyConnection() LoggerFactory.AddProvider(loggerProvider); await using (var server = new TestServer(context => Task.CompletedTask, - new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = 1 }, + new TestServiceContext(LoggerFactory), listenOptions => { listenOptions.UseHttps(TestResources.GetTestCertificate()); @@ -294,7 +294,7 @@ public async Task ConnectionFilterDoesNotLeakBlock() LoggerFactory.AddProvider(loggerProvider); await using (var server = new TestServer(context => Task.CompletedTask, - new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = 1 }, + new TestServiceContext(LoggerFactory), listenOptions => { listenOptions.UseHttps(TestResources.GetTestCertificate()); @@ -313,7 +313,7 @@ public async Task HandshakeTimesOutAndIsLoggedAsDebug() var loggerProvider = new HandshakeErrorLoggerProvider(); LoggerFactory.AddProvider(loggerProvider); - var testContext = new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = 1 }; + var testContext = new TestServiceContext(LoggerFactory); var heartbeatManager = new HeartbeatManager(testContext.ConnectionManager); var handshakeStartedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); @@ -361,7 +361,7 @@ public async Task ClientAttemptingToUseUnsupportedProtocolIsLoggedAsDebug() LoggerFactory.AddProvider(loggerProvider); await using (var server = new TestServer(context => Task.CompletedTask, - new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = 1 }, + new TestServiceContext(LoggerFactory), listenOptions => { listenOptions.UseHttps(TestResources.GetTestCertificate()); @@ -393,7 +393,7 @@ public async Task OnAuthenticate_SeesOtherSettings() var onAuthenticateCalled = false; await using (var server = new TestServer(context => Task.CompletedTask, - new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = 1 }, + new TestServiceContext(LoggerFactory), listenOptions => { listenOptions.UseHttps(httpsOptions => @@ -429,7 +429,7 @@ public async Task OnAuthenticate_CanSetSettings() var onAuthenticateCalled = false; await using (var server = new TestServer(context => Task.CompletedTask, - new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = 1 }, + new TestServiceContext(LoggerFactory), listenOptions => { listenOptions.UseHttps(httpsOptions => diff --git a/src/Servers/Kestrel/test/InMemory.FunctionalTests/LoggingConnectionAdapterTests.cs b/src/Servers/Kestrel/test/InMemory.FunctionalTests/LoggingConnectionMiddlewareTests.cs similarity index 86% rename from src/Servers/Kestrel/test/InMemory.FunctionalTests/LoggingConnectionAdapterTests.cs rename to src/Servers/Kestrel/test/InMemory.FunctionalTests/LoggingConnectionMiddlewareTests.cs index 42e98c878ab3..a93bf2b8a0f1 100644 --- a/src/Servers/Kestrel/test/InMemory.FunctionalTests/LoggingConnectionAdapterTests.cs +++ b/src/Servers/Kestrel/test/InMemory.FunctionalTests/LoggingConnectionMiddlewareTests.cs @@ -12,18 +12,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests { - public class LoggingConnectionAdapterTests : LoggedTest + public class LoggingConnectionMiddlewareTests : LoggedTest { [Fact] [Flaky("https://github.com/aspnet/AspNetCore-Internal/issues/2276", FlakyOn.Helix.All)] - public async Task LoggingConnectionAdapterCanBeAddedBeforeAndAfterHttpsAdapter() + public async Task LoggingConnectionMiddlewareCanBeAddedBeforeAndAfterHttps() { await using (var server = new TestServer(context => { context.Response.ContentLength = 12; return context.Response.WriteAsync("Hello World!"); }, - new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = 3 }, + new TestServiceContext(LoggerFactory), listenOptions => { listenOptions.UseConnectionLogging(); diff --git a/src/Servers/Kestrel/test/InMemory.FunctionalTests/ResponseDrainingTests.cs b/src/Servers/Kestrel/test/InMemory.FunctionalTests/ResponseDrainingTests.cs index f01dd716338d..183ac9e731b1 100644 --- a/src/Servers/Kestrel/test/InMemory.FunctionalTests/ResponseDrainingTests.cs +++ b/src/Servers/Kestrel/test/InMemory.FunctionalTests/ResponseDrainingTests.cs @@ -15,17 +15,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { public class ResponseDrainingTests : TestApplicationErrorLoggerLoggedTest { - public static TheoryData ConnectionAdapterData => new TheoryData + public static TheoryData ConnectionMiddlewareData => new TheoryData { new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)), new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)).UsePassThrough() }; [Theory] - [MemberData(nameof(ConnectionAdapterData))] + [MemberData(nameof(ConnectionMiddlewareData))] public async Task ConnectionClosedWhenResponseNotDrainedAtMinimumDataRate(ListenOptions listenOptions) { - var testContext = new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = listenOptions._middleware.Count }; + var testContext = new TestServiceContext(LoggerFactory); var heartbeatManager = new HeartbeatManager(testContext.ConnectionManager); var minRate = new MinDataRate(16384, TimeSpan.FromSeconds(2)); diff --git a/src/Servers/Kestrel/test/InMemory.FunctionalTests/TestTransport/TestServer.cs b/src/Servers/Kestrel/test/InMemory.FunctionalTests/TestTransport/TestServer.cs index c7bab027d888..1c76309881a1 100644 --- a/src/Servers/Kestrel/test/InMemory.FunctionalTests/TestTransport/TestServer.cs +++ b/src/Servers/Kestrel/test/InMemory.FunctionalTests/TestTransport/TestServer.cs @@ -80,12 +80,6 @@ public TestServer(RequestDelegate app, TestServiceContext context, Action - Assert.Equal(context.ExpectedConnectionMiddlewareCount, lo._middleware.Count)); - return new KestrelServer(_transportFactory, context); }); });