Add file logging to functional tests
This commit is contained in:
parent
d57da6b71f
commit
2d51d23697
|
|
@ -17,6 +17,10 @@ This project is part of ASP.NET Core. You can find samples, documentation and ge
|
||||||
|
|
||||||
To run a complete build on command line only, execute `build.cmd` or `build.sh` without arguments. See [developer documentation](https://github.com/aspnet/Home/wiki) for more details.
|
To run a complete build on command line only, execute `build.cmd` or `build.sh` without arguments. See [developer documentation](https://github.com/aspnet/Home/wiki) for more details.
|
||||||
|
|
||||||
|
## File logging for functional test
|
||||||
|
|
||||||
|
Turn on file logging for Kestrel functional tests by specifying the environment variable ASPNETCORE_TEST_LOG_DIR to the log output directory.
|
||||||
|
|
||||||
## Packages
|
## Packages
|
||||||
|
|
||||||
Kestrel is available as a NuGet package.
|
Kestrel is available as a NuGet package.
|
||||||
|
|
|
||||||
|
|
@ -7,41 +7,41 @@
|
||||||
<BenchmarkDotNetPackageVersion>0.10.13</BenchmarkDotNetPackageVersion>
|
<BenchmarkDotNetPackageVersion>0.10.13</BenchmarkDotNetPackageVersion>
|
||||||
<InternalAspNetCoreSdkPackageVersion>2.1.0-preview3-17002</InternalAspNetCoreSdkPackageVersion>
|
<InternalAspNetCoreSdkPackageVersion>2.1.0-preview3-17002</InternalAspNetCoreSdkPackageVersion>
|
||||||
<LibuvPackageVersion>1.10.0</LibuvPackageVersion>
|
<LibuvPackageVersion>1.10.0</LibuvPackageVersion>
|
||||||
<MicrosoftAspNetCoreAllPackageVersion>2.1.0-preview3-32110</MicrosoftAspNetCoreAllPackageVersion>
|
<MicrosoftAspNetCoreAllPackageVersion>2.1.0-preview3-32196</MicrosoftAspNetCoreAllPackageVersion>
|
||||||
<MicrosoftAspNetCoreBenchmarkRunnerSourcesPackageVersion>2.1.0-preview3-32110</MicrosoftAspNetCoreBenchmarkRunnerSourcesPackageVersion>
|
<MicrosoftAspNetCoreBenchmarkRunnerSourcesPackageVersion>2.1.0-preview3-32196</MicrosoftAspNetCoreBenchmarkRunnerSourcesPackageVersion>
|
||||||
<MicrosoftAspNetCoreCertificatesGenerationSourcesPackageVersion>2.1.0-preview3-32110</MicrosoftAspNetCoreCertificatesGenerationSourcesPackageVersion>
|
<MicrosoftAspNetCoreCertificatesGenerationSourcesPackageVersion>2.1.0-preview3-32196</MicrosoftAspNetCoreCertificatesGenerationSourcesPackageVersion>
|
||||||
<MicrosoftAspNetCoreHostingAbstractionsPackageVersion>2.1.0-preview3-32110</MicrosoftAspNetCoreHostingAbstractionsPackageVersion>
|
<MicrosoftAspNetCoreHostingAbstractionsPackageVersion>2.1.0-a-preview3-file-logger-16960</MicrosoftAspNetCoreHostingAbstractionsPackageVersion>
|
||||||
<MicrosoftAspNetCoreHostingPackageVersion>2.1.0-preview3-32110</MicrosoftAspNetCoreHostingPackageVersion>
|
<MicrosoftAspNetCoreHostingPackageVersion>2.1.0-a-preview3-file-logger-16960</MicrosoftAspNetCoreHostingPackageVersion>
|
||||||
<MicrosoftAspNetCoreHttpAbstractionsPackageVersion>2.1.0-preview3-32110</MicrosoftAspNetCoreHttpAbstractionsPackageVersion>
|
<MicrosoftAspNetCoreHttpAbstractionsPackageVersion>2.1.0-preview3-32196</MicrosoftAspNetCoreHttpAbstractionsPackageVersion>
|
||||||
<MicrosoftAspNetCoreHttpFeaturesPackageVersion>2.1.0-preview3-32110</MicrosoftAspNetCoreHttpFeaturesPackageVersion>
|
<MicrosoftAspNetCoreHttpFeaturesPackageVersion>2.1.0-preview3-32196</MicrosoftAspNetCoreHttpFeaturesPackageVersion>
|
||||||
<MicrosoftAspNetCoreHttpPackageVersion>2.1.0-preview3-32110</MicrosoftAspNetCoreHttpPackageVersion>
|
<MicrosoftAspNetCoreHttpPackageVersion>2.1.0-preview3-32196</MicrosoftAspNetCoreHttpPackageVersion>
|
||||||
<MicrosoftAspNetCoreTestingPackageVersion>2.1.0-preview3-32110</MicrosoftAspNetCoreTestingPackageVersion>
|
<MicrosoftAspNetCoreTestingPackageVersion>2.1.0-preview3-32196</MicrosoftAspNetCoreTestingPackageVersion>
|
||||||
<MicrosoftAspNetCoreWebUtilitiesPackageVersion>2.1.0-preview3-32110</MicrosoftAspNetCoreWebUtilitiesPackageVersion>
|
<MicrosoftAspNetCoreWebUtilitiesPackageVersion>2.1.0-preview3-32196</MicrosoftAspNetCoreWebUtilitiesPackageVersion>
|
||||||
<MicrosoftExtensionsActivatorUtilitiesSourcesPackageVersion>2.1.0-preview3-32110</MicrosoftExtensionsActivatorUtilitiesSourcesPackageVersion>
|
<MicrosoftExtensionsActivatorUtilitiesSourcesPackageVersion>2.1.0-preview3-32196</MicrosoftExtensionsActivatorUtilitiesSourcesPackageVersion>
|
||||||
<MicrosoftExtensionsBuffersSourcesPackageVersion>2.1.0-preview3-32110</MicrosoftExtensionsBuffersSourcesPackageVersion>
|
<MicrosoftExtensionsBuffersSourcesPackageVersion>2.1.0-preview3-32196</MicrosoftExtensionsBuffersSourcesPackageVersion>
|
||||||
<MicrosoftExtensionsBuffersTestingSourcesPackageVersion>2.1.0-preview3-32110</MicrosoftExtensionsBuffersTestingSourcesPackageVersion>
|
<MicrosoftExtensionsBuffersTestingSourcesPackageVersion>2.1.0-preview3-32196</MicrosoftExtensionsBuffersTestingSourcesPackageVersion>
|
||||||
<MicrosoftExtensionsConfigurationBinderPackageVersion>2.1.0-preview3-32110</MicrosoftExtensionsConfigurationBinderPackageVersion>
|
<MicrosoftExtensionsConfigurationBinderPackageVersion>2.1.0-preview3-32196</MicrosoftExtensionsConfigurationBinderPackageVersion>
|
||||||
<MicrosoftExtensionsConfigurationCommandLinePackageVersion>2.1.0-preview3-32037</MicrosoftExtensionsConfigurationCommandLinePackageVersion>
|
<MicrosoftExtensionsConfigurationCommandLinePackageVersion>2.1.0-preview3-32196</MicrosoftExtensionsConfigurationCommandLinePackageVersion>
|
||||||
<MicrosoftExtensionsConfigurationJsonPackageVersion>2.1.0-preview3-32110</MicrosoftExtensionsConfigurationJsonPackageVersion>
|
<MicrosoftExtensionsConfigurationJsonPackageVersion>2.1.0-preview3-32196</MicrosoftExtensionsConfigurationJsonPackageVersion>
|
||||||
<MicrosoftExtensionsDependencyInjectionPackageVersion>2.1.0-preview3-32110</MicrosoftExtensionsDependencyInjectionPackageVersion>
|
<MicrosoftExtensionsDependencyInjectionPackageVersion>2.1.0-preview3-32196</MicrosoftExtensionsDependencyInjectionPackageVersion>
|
||||||
<MicrosoftExtensionsLoggingAbstractionsPackageVersion>2.1.0-preview3-32110</MicrosoftExtensionsLoggingAbstractionsPackageVersion>
|
<MicrosoftExtensionsLoggingAbstractionsPackageVersion>2.1.0-a-preview3-file-logger-16474</MicrosoftExtensionsLoggingAbstractionsPackageVersion>
|
||||||
<MicrosoftExtensionsLoggingConsolePackageVersion>2.1.0-preview3-32110</MicrosoftExtensionsLoggingConsolePackageVersion>
|
<MicrosoftExtensionsLoggingConsolePackageVersion>2.1.0-a-preview3-file-logger-16474</MicrosoftExtensionsLoggingConsolePackageVersion>
|
||||||
<MicrosoftExtensionsLoggingPackageVersion>2.1.0-preview3-32110</MicrosoftExtensionsLoggingPackageVersion>
|
<MicrosoftExtensionsLoggingPackageVersion>2.1.0-a-preview3-file-logger-16474</MicrosoftExtensionsLoggingPackageVersion>
|
||||||
<MicrosoftExtensionsLoggingTestingPackageVersion>2.1.0-preview3-32110</MicrosoftExtensionsLoggingTestingPackageVersion>
|
<MicrosoftExtensionsLoggingTestingPackageVersion>2.1.0-a-preview3-file-logger-16474</MicrosoftExtensionsLoggingTestingPackageVersion>
|
||||||
<MicrosoftExtensionsOptionsPackageVersion>2.1.0-preview3-32110</MicrosoftExtensionsOptionsPackageVersion>
|
<MicrosoftExtensionsOptionsPackageVersion>2.1.0-preview3-32196</MicrosoftExtensionsOptionsPackageVersion>
|
||||||
<MicrosoftNETCoreApp20PackageVersion>2.0.0</MicrosoftNETCoreApp20PackageVersion>
|
<MicrosoftNETCoreApp20PackageVersion>2.0.0</MicrosoftNETCoreApp20PackageVersion>
|
||||||
<MicrosoftNETCoreApp21PackageVersion>2.1.0-preview3-26331-01</MicrosoftNETCoreApp21PackageVersion>
|
<MicrosoftNETCoreApp21PackageVersion>2.1.0-preview2-26406-04</MicrosoftNETCoreApp21PackageVersion>
|
||||||
<MicrosoftNetHttpHeadersPackageVersion>2.1.0-preview3-32110</MicrosoftNetHttpHeadersPackageVersion>
|
<MicrosoftNetHttpHeadersPackageVersion>2.1.0-preview3-32196</MicrosoftNetHttpHeadersPackageVersion>
|
||||||
<MicrosoftNETTestSdkPackageVersion>15.6.1</MicrosoftNETTestSdkPackageVersion>
|
<MicrosoftNETTestSdkPackageVersion>15.6.1</MicrosoftNETTestSdkPackageVersion>
|
||||||
<MoqPackageVersion>4.7.49</MoqPackageVersion>
|
<MoqPackageVersion>4.7.49</MoqPackageVersion>
|
||||||
<NewtonsoftJsonPackageVersion>11.0.2</NewtonsoftJsonPackageVersion>
|
<NewtonsoftJsonPackageVersion>11.0.2</NewtonsoftJsonPackageVersion>
|
||||||
<SystemBuffersPackageVersion>4.5.0-preview3-26331-02</SystemBuffersPackageVersion>
|
<SystemBuffersPackageVersion>4.5.0-preview2-26406-04</SystemBuffersPackageVersion>
|
||||||
<SystemIOPipelinesPackageVersion>4.5.0-preview3-26331-02</SystemIOPipelinesPackageVersion>
|
<SystemIOPipelinesPackageVersion>4.5.0-preview2-26406-04</SystemIOPipelinesPackageVersion>
|
||||||
<SystemMemoryPackageVersion>4.5.0-preview3-26331-02</SystemMemoryPackageVersion>
|
<SystemMemoryPackageVersion>4.5.0-preview2-26406-04</SystemMemoryPackageVersion>
|
||||||
<SystemNumericsVectorsPackageVersion>4.5.0-preview3-26331-02</SystemNumericsVectorsPackageVersion>
|
<SystemNumericsVectorsPackageVersion>4.5.0-preview2-26406-04</SystemNumericsVectorsPackageVersion>
|
||||||
<SystemRuntimeCompilerServicesUnsafePackageVersion>4.5.0-preview3-26331-02</SystemRuntimeCompilerServicesUnsafePackageVersion>
|
<SystemRuntimeCompilerServicesUnsafePackageVersion>4.5.0-preview2-26406-04</SystemRuntimeCompilerServicesUnsafePackageVersion>
|
||||||
<SystemSecurityCryptographyCngPackageVersion>4.5.0-preview3-26331-02</SystemSecurityCryptographyCngPackageVersion>
|
<SystemSecurityCryptographyCngPackageVersion>4.5.0-preview2-26406-04</SystemSecurityCryptographyCngPackageVersion>
|
||||||
<SystemThreadingTasksExtensionsPackageVersion>4.5.0-preview3-26331-02</SystemThreadingTasksExtensionsPackageVersion>
|
<SystemThreadingTasksExtensionsPackageVersion>4.5.0-preview2-26406-04</SystemThreadingTasksExtensionsPackageVersion>
|
||||||
<Utf8JsonPackageVersion>1.3.7</Utf8JsonPackageVersion>
|
<Utf8JsonPackageVersion>1.3.7</Utf8JsonPackageVersion>
|
||||||
<XunitAnalyzersPackageVersion>0.8.0</XunitAnalyzersPackageVersion>
|
<XunitAnalyzersPackageVersion>0.8.0</XunitAnalyzersPackageVersion>
|
||||||
<XunitPackageVersion>2.3.1</XunitPackageVersion>
|
<XunitPackageVersion>2.3.1</XunitPackageVersion>
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
|
[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
|
||||||
[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.FunctionalTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
|
[assembly: InternalsVisibleTo("Libuv.FunctionalTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
|
||||||
[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.FunctionalTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
|
[assembly: InternalsVisibleTo("Sockets.FunctionalTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
|
||||||
[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Core.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
|
[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Core.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
|
||||||
[assembly: InternalsVisibleTo("Kestrel.Performance, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
|
[assembly: InternalsVisibleTo("Kestrel.Performance, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
|
||||||
[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
|
[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
|
||||||
|
|
|
||||||
|
|
@ -23,22 +23,14 @@ using Microsoft.AspNetCore.Testing.xunit;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using Xunit.Abstractions;
|
|
||||||
using Xunit.Sdk;
|
using Xunit.Sdk;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
public class AddressRegistrationTests
|
public class AddressRegistrationTests : TestApplicationErrorLoggerLoggedTest
|
||||||
{
|
{
|
||||||
private const int MaxRetries = 10;
|
private const int MaxRetries = 10;
|
||||||
|
|
||||||
private readonly Action<ILoggingBuilder> _configureLoggingDelegate;
|
|
||||||
|
|
||||||
public AddressRegistrationTests(ITestOutputHelper output)
|
|
||||||
{
|
|
||||||
_configureLoggingDelegate = builder => builder.AddXunit(output);
|
|
||||||
}
|
|
||||||
|
|
||||||
[ConditionalFact]
|
[ConditionalFact]
|
||||||
[HostNameIsReachable]
|
[HostNameIsReachable]
|
||||||
public async Task RegisterAddresses_HostName_Success()
|
public async Task RegisterAddresses_HostName_Success()
|
||||||
|
|
@ -165,7 +157,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||||
.UseKestrel()
|
.UseKestrel()
|
||||||
.ConfigureLogging(_configureLoggingDelegate)
|
.ConfigureServices(AddTestLogging)
|
||||||
.UseUrls(addressInput)
|
.UseUrls(addressInput)
|
||||||
.Configure(ConfigureEchoAddress);
|
.Configure(ConfigureEchoAddress);
|
||||||
|
|
||||||
|
|
@ -201,7 +193,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
listenOptions.UseHttps(TestResources.GetTestCertificate());
|
listenOptions.UseHttps(TestResources.GetTestCertificate());
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.ConfigureLogging(_configureLoggingDelegate)
|
.ConfigureServices(AddTestLogging)
|
||||||
.UseUrls("http://127.0.0.1:0")
|
.UseUrls("http://127.0.0.1:0")
|
||||||
.Configure(app =>
|
.Configure(app =>
|
||||||
{
|
{
|
||||||
|
|
@ -261,7 +253,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
private async Task RegisterIPEndPoint_Success(IPEndPoint endPoint, string testUrl, int testPort = 0)
|
private async Task RegisterIPEndPoint_Success(IPEndPoint endPoint, string testUrl, int testPort = 0)
|
||||||
{
|
{
|
||||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||||
.ConfigureLogging(_configureLoggingDelegate)
|
.ConfigureServices(AddTestLogging)
|
||||||
.UseKestrel(options =>
|
.UseKestrel(options =>
|
||||||
{
|
{
|
||||||
options.Listen(endPoint, listenOptions =>
|
options.Listen(endPoint, listenOptions =>
|
||||||
|
|
@ -322,7 +314,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
options.ListenAnyIP(testPort);
|
options.ListenAnyIP(testPort);
|
||||||
})
|
})
|
||||||
.ConfigureLogging(_configureLoggingDelegate)
|
.ConfigureServices(AddTestLogging)
|
||||||
.Configure(ConfigureEchoAddress);
|
.Configure(ConfigureEchoAddress);
|
||||||
|
|
||||||
using (var host = hostBuilder.Build())
|
using (var host = hostBuilder.Build())
|
||||||
|
|
@ -363,7 +355,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
options.ListenLocalhost(testPort);
|
options.ListenLocalhost(testPort);
|
||||||
})
|
})
|
||||||
.ConfigureLogging(_configureLoggingDelegate)
|
.ConfigureServices(AddTestLogging)
|
||||||
.Configure(ConfigureEchoAddress);
|
.Configure(ConfigureEchoAddress);
|
||||||
|
|
||||||
using (var host = hostBuilder.Build())
|
using (var host = hostBuilder.Build())
|
||||||
|
|
@ -419,10 +411,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
|
|
||||||
private async Task RegisterDefaultServerAddresses_Success(IEnumerable<string> addresses, bool mockHttps = false)
|
private async Task RegisterDefaultServerAddresses_Success(IEnumerable<string> addresses, bool mockHttps = false)
|
||||||
{
|
{
|
||||||
var testLogger = new TestApplicationErrorLogger();
|
|
||||||
|
|
||||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||||
.ConfigureLogging(_configureLoggingDelegate)
|
.ConfigureServices(AddTestLogging)
|
||||||
.UseKestrel(options =>
|
.UseKestrel(options =>
|
||||||
{
|
{
|
||||||
if (mockHttps)
|
if (mockHttps)
|
||||||
|
|
@ -430,9 +420,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
options.DefaultCertificate = new X509Certificate2(TestResources.TestCertificatePath, "testPassword");
|
options.DefaultCertificate = new X509Certificate2(TestResources.TestCertificatePath, "testPassword");
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.ConfigureLogging(builder => builder
|
|
||||||
.AddProvider(new KestrelTestLoggerProvider(testLogger))
|
|
||||||
.SetMinimumLevel(LogLevel.Debug))
|
|
||||||
.Configure(ConfigureEchoAddress);
|
.Configure(ConfigureEchoAddress);
|
||||||
|
|
||||||
using (var host = hostBuilder.Build())
|
using (var host = hostBuilder.Build())
|
||||||
|
|
@ -446,7 +433,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
Assert.Contains(5001, host.GetPorts());
|
Assert.Contains(5001, host.GetPorts());
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.Single(testLogger.Messages, log => log.LogLevel == LogLevel.Debug &&
|
Assert.Single(TestApplicationErrorLogger.Messages, log => log.LogLevel == LogLevel.Debug &&
|
||||||
(string.Equals(CoreStrings.FormatBindingToDefaultAddresses(Constants.DefaultServerAddress, Constants.DefaultServerHttpsAddress), log.Message, StringComparison.Ordinal)
|
(string.Equals(CoreStrings.FormatBindingToDefaultAddresses(Constants.DefaultServerAddress, Constants.DefaultServerHttpsAddress), log.Message, StringComparison.Ordinal)
|
||||||
|| string.Equals(CoreStrings.FormatBindingToDefaultAddress(Constants.DefaultServerAddress), log.Message, StringComparison.Ordinal)));
|
|| string.Equals(CoreStrings.FormatBindingToDefaultAddress(Constants.DefaultServerAddress), log.Message, StringComparison.Ordinal)));
|
||||||
|
|
||||||
|
|
@ -467,7 +454,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
var port = ((IPEndPoint)socket.LocalEndPoint).Port;
|
var port = ((IPEndPoint)socket.LocalEndPoint).Port;
|
||||||
|
|
||||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||||
.ConfigureLogging(_configureLoggingDelegate)
|
|
||||||
.UseKestrel()
|
.UseKestrel()
|
||||||
.UseUrls($"http://127.0.0.1:{port}")
|
.UseUrls($"http://127.0.0.1:{port}")
|
||||||
.Configure(ConfigureEchoAddress);
|
.Configure(ConfigureEchoAddress);
|
||||||
|
|
@ -484,6 +470,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[IPv6SupportedCondition]
|
[IPv6SupportedCondition]
|
||||||
public void ThrowsWhenBindingToIPv6AddressInUse()
|
public void ThrowsWhenBindingToIPv6AddressInUse()
|
||||||
{
|
{
|
||||||
|
TestApplicationErrorLogger.IgnoredExceptions.Add(typeof(IOException));
|
||||||
|
|
||||||
using (var socket = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp))
|
using (var socket = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp))
|
||||||
{
|
{
|
||||||
socket.Bind(new IPEndPoint(IPAddress.IPv6Loopback, 0));
|
socket.Bind(new IPEndPoint(IPAddress.IPv6Loopback, 0));
|
||||||
|
|
@ -491,7 +479,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
var port = ((IPEndPoint)socket.LocalEndPoint).Port;
|
var port = ((IPEndPoint)socket.LocalEndPoint).Port;
|
||||||
|
|
||||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||||
.ConfigureLogging(_configureLoggingDelegate)
|
.ConfigureServices(AddTestLogging)
|
||||||
.UseKestrel()
|
.UseKestrel()
|
||||||
.UseUrls($"http://[::1]:{port}")
|
.UseUrls($"http://[::1]:{port}")
|
||||||
.Configure(ConfigureEchoAddress);
|
.Configure(ConfigureEchoAddress);
|
||||||
|
|
@ -508,7 +496,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
public async Task OverrideDirectConfigurationWithIServerAddressesFeature_Succeeds()
|
public async Task OverrideDirectConfigurationWithIServerAddressesFeature_Succeeds()
|
||||||
{
|
{
|
||||||
var useUrlsAddress = $"http://127.0.0.1:0";
|
var useUrlsAddress = $"http://127.0.0.1:0";
|
||||||
var testLogger = new TestApplicationErrorLogger();
|
|
||||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||||
.UseKestrel(options =>
|
.UseKestrel(options =>
|
||||||
{
|
{
|
||||||
|
|
@ -519,7 +506,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
})
|
})
|
||||||
.UseUrls(useUrlsAddress)
|
.UseUrls(useUrlsAddress)
|
||||||
.PreferHostingUrls(true)
|
.PreferHostingUrls(true)
|
||||||
.ConfigureLogging(builder => builder.AddProvider(new KestrelTestLoggerProvider(testLogger)))
|
.ConfigureServices(AddTestLogging)
|
||||||
.Configure(ConfigureEchoAddress);
|
.Configure(ConfigureEchoAddress);
|
||||||
|
|
||||||
using (var host = hostBuilder.Build())
|
using (var host = hostBuilder.Build())
|
||||||
|
|
@ -535,7 +522,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
var useUrlsAddressWithPort = $"http://127.0.0.1:{port}";
|
var useUrlsAddressWithPort = $"http://127.0.0.1:{port}";
|
||||||
Assert.Equal(serverAddresses.First(), useUrlsAddressWithPort);
|
Assert.Equal(serverAddresses.First(), useUrlsAddressWithPort);
|
||||||
|
|
||||||
Assert.Single(testLogger.Messages, log => log.LogLevel == LogLevel.Information &&
|
Assert.Single(TestApplicationErrorLogger.Messages, log => log.LogLevel == LogLevel.Information &&
|
||||||
string.Equals(CoreStrings.FormatOverridingWithPreferHostingUrls(nameof(IServerAddressesFeature.PreferHostingUrls), useUrlsAddress),
|
string.Equals(CoreStrings.FormatOverridingWithPreferHostingUrls(nameof(IServerAddressesFeature.PreferHostingUrls), useUrlsAddress),
|
||||||
log.Message, StringComparison.Ordinal));
|
log.Message, StringComparison.Ordinal));
|
||||||
|
|
||||||
|
|
@ -547,9 +534,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
public async Task DoesNotOverrideDirectConfigurationWithIServerAddressesFeature_IfPreferHostingUrlsFalse()
|
public async Task DoesNotOverrideDirectConfigurationWithIServerAddressesFeature_IfPreferHostingUrlsFalse()
|
||||||
{
|
{
|
||||||
var useUrlsAddress = $"http://127.0.0.1:0";
|
var useUrlsAddress = $"http://127.0.0.1:0";
|
||||||
var testLogger = new TestApplicationErrorLogger();
|
|
||||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||||
.ConfigureLogging(_configureLoggingDelegate)
|
.ConfigureServices(AddTestLogging)
|
||||||
.UseKestrel(options =>
|
.UseKestrel(options =>
|
||||||
{
|
{
|
||||||
options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions =>
|
options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions =>
|
||||||
|
|
@ -559,7 +546,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
})
|
})
|
||||||
.UseUrls($"http://127.0.0.1:0")
|
.UseUrls($"http://127.0.0.1:0")
|
||||||
.PreferHostingUrls(false)
|
.PreferHostingUrls(false)
|
||||||
.ConfigureLogging(builder => builder.AddProvider(new KestrelTestLoggerProvider(testLogger)))
|
|
||||||
.Configure(ConfigureEchoAddress);
|
.Configure(ConfigureEchoAddress);
|
||||||
|
|
||||||
using (var host = hostBuilder.Build())
|
using (var host = hostBuilder.Build())
|
||||||
|
|
@ -575,7 +561,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
var endPointAddress = $"https://127.0.0.1:{port}";
|
var endPointAddress = $"https://127.0.0.1:{port}";
|
||||||
Assert.Equal(serverAddresses.First(), endPointAddress);
|
Assert.Equal(serverAddresses.First(), endPointAddress);
|
||||||
|
|
||||||
Assert.Single(testLogger.Messages, log => log.LogLevel == LogLevel.Warning &&
|
Assert.Single(TestApplicationErrorLogger.Messages, log => log.LogLevel == LogLevel.Warning &&
|
||||||
string.Equals(CoreStrings.FormatOverridingWithKestrelOptions(useUrlsAddress, "UseKestrel()"),
|
string.Equals(CoreStrings.FormatOverridingWithKestrelOptions(useUrlsAddress, "UseKestrel()"),
|
||||||
log.Message, StringComparison.Ordinal));
|
log.Message, StringComparison.Ordinal));
|
||||||
|
|
||||||
|
|
@ -587,7 +573,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
public async Task DoesNotOverrideDirectConfigurationWithIServerAddressesFeature_IfAddressesEmpty()
|
public async Task DoesNotOverrideDirectConfigurationWithIServerAddressesFeature_IfAddressesEmpty()
|
||||||
{
|
{
|
||||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||||
.ConfigureLogging(_configureLoggingDelegate)
|
.ConfigureServices(AddTestLogging)
|
||||||
.UseKestrel(options =>
|
.UseKestrel(options =>
|
||||||
{
|
{
|
||||||
options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions =>
|
options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions =>
|
||||||
|
|
@ -630,7 +616,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ThrowsWhenBindingLocalhostToDynamicPort()
|
public void ThrowsWhenBindingLocalhostToDynamicPort()
|
||||||
{
|
{
|
||||||
|
TestApplicationErrorLogger.IgnoredExceptions.Add(typeof(InvalidOperationException));
|
||||||
|
|
||||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||||
|
.ConfigureServices(AddTestLogging)
|
||||||
.UseKestrel()
|
.UseKestrel()
|
||||||
.UseUrls("http://localhost:0")
|
.UseUrls("http://localhost:0")
|
||||||
.Configure(ConfigureEchoAddress);
|
.Configure(ConfigureEchoAddress);
|
||||||
|
|
@ -646,7 +635,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[InlineData("ssh://localhost")]
|
[InlineData("ssh://localhost")]
|
||||||
public void ThrowsForUnsupportedAddressFromHosting(string addr)
|
public void ThrowsForUnsupportedAddressFromHosting(string addr)
|
||||||
{
|
{
|
||||||
|
TestApplicationErrorLogger.IgnoredExceptions.Add(typeof(InvalidOperationException));
|
||||||
|
|
||||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||||
|
.ConfigureServices(AddTestLogging)
|
||||||
.UseKestrel()
|
.UseKestrel()
|
||||||
.UseUrls(addr)
|
.UseUrls(addr)
|
||||||
.Configure(ConfigureEchoAddress);
|
.Configure(ConfigureEchoAddress);
|
||||||
|
|
@ -664,7 +656,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
var endPointAddress = $"http://127.0.0.1:{port}/";
|
var endPointAddress = $"http://127.0.0.1:{port}/";
|
||||||
|
|
||||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||||
.ConfigureLogging(_configureLoggingDelegate)
|
.ConfigureServices(AddTestLogging)
|
||||||
.UseKestrel(options =>
|
.UseKestrel(options =>
|
||||||
{
|
{
|
||||||
options.Listen(IPAddress.Loopback, port);
|
options.Listen(IPAddress.Loopback, port);
|
||||||
|
|
@ -679,7 +671,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
}
|
}
|
||||||
|
|
||||||
hostBuilder = TransportSelector.GetWebHostBuilder()
|
hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||||
.ConfigureLogging(_configureLoggingDelegate)
|
|
||||||
.UseKestrel(options =>
|
.UseKestrel(options =>
|
||||||
{
|
{
|
||||||
options.Listen(IPAddress.Loopback, port);
|
options.Listen(IPAddress.Loopback, port);
|
||||||
|
|
@ -703,7 +694,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
var ipv6endPointAddress = $"http://[::1]:{port}/";
|
var ipv6endPointAddress = $"http://[::1]:{port}/";
|
||||||
|
|
||||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||||
.ConfigureLogging(_configureLoggingDelegate)
|
.ConfigureServices(AddTestLogging)
|
||||||
.UseKestrel(options =>
|
.UseKestrel(options =>
|
||||||
{
|
{
|
||||||
options.Listen(IPAddress.Loopback, port);
|
options.Listen(IPAddress.Loopback, port);
|
||||||
|
|
@ -720,7 +711,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
}
|
}
|
||||||
|
|
||||||
hostBuilder = TransportSelector.GetWebHostBuilder()
|
hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||||
.ConfigureLogging(_configureLoggingDelegate)
|
|
||||||
.UseKestrel(options =>
|
.UseKestrel(options =>
|
||||||
{
|
{
|
||||||
options.Listen(IPAddress.Loopback, port);
|
options.Listen(IPAddress.Loopback, port);
|
||||||
|
|
@ -739,6 +729,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
|
|
||||||
private void ThrowsWhenBindingLocalhostToAddressInUse(AddressFamily addressFamily)
|
private void ThrowsWhenBindingLocalhostToAddressInUse(AddressFamily addressFamily)
|
||||||
{
|
{
|
||||||
|
TestApplicationErrorLogger.IgnoredExceptions.Add(typeof(IOException));
|
||||||
|
|
||||||
var addressInUseCount = 0;
|
var addressInUseCount = 0;
|
||||||
var wrongMessageCount = 0;
|
var wrongMessageCount = 0;
|
||||||
|
|
||||||
|
|
@ -771,7 +763,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
}
|
}
|
||||||
|
|
||||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||||
.ConfigureLogging(_configureLoggingDelegate)
|
.ConfigureServices(AddTestLogging)
|
||||||
.UseKestrel()
|
.UseKestrel()
|
||||||
.UseUrls($"http://localhost:{port}")
|
.UseUrls($"http://localhost:{port}")
|
||||||
.Configure(ConfigureEchoAddress);
|
.Configure(ConfigureEchoAddress);
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
public class BadHttpRequestTests
|
public class BadHttpRequestTests : LoggedTest
|
||||||
{
|
{
|
||||||
[Theory]
|
[Theory]
|
||||||
[MemberData(nameof(InvalidRequestLineData))]
|
[MemberData(nameof(InvalidRequestLineData))]
|
||||||
|
|
@ -153,13 +153,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task BadRequestLogsAreNotHigherThanInformation()
|
public async Task BadRequestLogsAreNotHigherThanInformation()
|
||||||
{
|
{
|
||||||
var sink = new TestSink();
|
|
||||||
var logger = new TestLogger("TestLogger", sink, enabled: true);
|
|
||||||
|
|
||||||
using (var server = new TestServer(async context =>
|
using (var server = new TestServer(async context =>
|
||||||
{
|
{
|
||||||
await context.Request.Body.ReadAsync(new byte[1], 0, 1);
|
await context.Request.Body.ReadAsync(new byte[1], 0, 1);
|
||||||
}, new TestServiceContext { Log = new KestrelTrace(logger) }))
|
}, new TestServiceContext(LoggerFactory)))
|
||||||
{
|
{
|
||||||
using (var connection = new TestConnection(server.Port))
|
using (var connection = new TestConnection(server.Port))
|
||||||
{
|
{
|
||||||
|
|
@ -171,14 +168,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.All(sink.Writes, w => Assert.InRange(w.LogLevel, LogLevel.Trace, LogLevel.Information));
|
Assert.All(TestSink.Writes, w => Assert.InRange(w.LogLevel, LogLevel.Trace, LogLevel.Information));
|
||||||
Assert.Contains(sink.Writes, w => w.EventId.Id == 17 && w.LogLevel == LogLevel.Information);
|
Assert.Contains(TestSink.Writes, w => w.EventId.Id == 17 && w.LogLevel == LogLevel.Information);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task TestRequestSplitting()
|
public async Task TestRequestSplitting()
|
||||||
{
|
{
|
||||||
using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext { Log = Mock.Of<IKestrelTrace>() }))
|
using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory, Mock.Of<IKestrelTrace>())))
|
||||||
{
|
{
|
||||||
using (var client = server.CreateConnection())
|
using (var client = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
@ -202,7 +199,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
.Setup(trace => trace.ConnectionBadRequest(It.IsAny<string>(), It.IsAny<BadHttpRequestException>()))
|
.Setup(trace => trace.ConnectionBadRequest(It.IsAny<string>(), It.IsAny<BadHttpRequestException>()))
|
||||||
.Callback<string, BadHttpRequestException>((connectionId, exception) => loggedException = exception);
|
.Callback<string, BadHttpRequestException>((connectionId, exception) => loggedException = exception);
|
||||||
|
|
||||||
using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext { Log = mockKestrelTrace.Object }))
|
using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory, mockKestrelTrace.Object)))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -5,26 +5,19 @@ using System.Linq;
|
||||||
using System.Security.Cryptography.X509Certificates;
|
using System.Security.Cryptography.X509Certificates;
|
||||||
using Microsoft.AspNetCore.Server.Kestrel.Https.Internal;
|
using Microsoft.AspNetCore.Server.Kestrel.Https.Internal;
|
||||||
using Microsoft.AspNetCore.Testing;
|
using Microsoft.AspNetCore.Testing;
|
||||||
|
using Microsoft.Extensions.Logging.Testing;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using Xunit.Abstractions;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
public class CertificateLoaderTests
|
public class CertificateLoaderTests : LoggedTest
|
||||||
{
|
{
|
||||||
private readonly ITestOutputHelper _output;
|
|
||||||
|
|
||||||
public CertificateLoaderTests(ITestOutputHelper output)
|
|
||||||
{
|
|
||||||
_output = output;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("no_extensions.pfx")]
|
[InlineData("no_extensions.pfx")]
|
||||||
public void IsCertificateAllowedForServerAuth_AllowWithNoExtensions(string testCertName)
|
public void IsCertificateAllowedForServerAuth_AllowWithNoExtensions(string testCertName)
|
||||||
{
|
{
|
||||||
var certPath = TestResources.GetCertPath(testCertName);
|
var certPath = TestResources.GetCertPath(testCertName);
|
||||||
_output.WriteLine("Loading " + certPath);
|
TestOutputHelper.WriteLine("Loading " + certPath);
|
||||||
var cert = new X509Certificate2(certPath, "testPassword");
|
var cert = new X509Certificate2(certPath, "testPassword");
|
||||||
Assert.Empty(cert.Extensions.OfType<X509EnhancedKeyUsageExtension>());
|
Assert.Empty(cert.Extensions.OfType<X509EnhancedKeyUsageExtension>());
|
||||||
|
|
||||||
|
|
@ -37,7 +30,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
public void IsCertificateAllowedForServerAuth_ValidatesEnhancedKeyUsageOnCertificate(string testCertName)
|
public void IsCertificateAllowedForServerAuth_ValidatesEnhancedKeyUsageOnCertificate(string testCertName)
|
||||||
{
|
{
|
||||||
var certPath = TestResources.GetCertPath(testCertName);
|
var certPath = TestResources.GetCertPath(testCertName);
|
||||||
_output.WriteLine("Loading " + certPath);
|
TestOutputHelper.WriteLine("Loading " + certPath);
|
||||||
var cert = new X509Certificate2(certPath, "testPassword");
|
var cert = new X509Certificate2(certPath, "testPassword");
|
||||||
Assert.NotEmpty(cert.Extensions);
|
Assert.NotEmpty(cert.Extensions);
|
||||||
var eku = Assert.Single(cert.Extensions.OfType<X509EnhancedKeyUsageExtension>());
|
var eku = Assert.Single(cert.Extensions.OfType<X509EnhancedKeyUsageExtension>());
|
||||||
|
|
@ -52,7 +45,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
public void IsCertificateAllowedForServerAuth_RejectsCertificatesMissingServerEku(string testCertName)
|
public void IsCertificateAllowedForServerAuth_RejectsCertificatesMissingServerEku(string testCertName)
|
||||||
{
|
{
|
||||||
var certPath = TestResources.GetCertPath(testCertName);
|
var certPath = TestResources.GetCertPath(testCertName);
|
||||||
_output.WriteLine("Loading " + certPath);
|
TestOutputHelper.WriteLine("Loading " + certPath);
|
||||||
var cert = new X509Certificate2(certPath, "testPassword");
|
var cert = new X509Certificate2(certPath, "testPassword");
|
||||||
Assert.NotEmpty(cert.Extensions);
|
Assert.NotEmpty(cert.Extensions);
|
||||||
var eku = Assert.Single(cert.Extensions.OfType<X509EnhancedKeyUsageExtension>());
|
var eku = Assert.Single(cert.Extensions.OfType<X509EnhancedKeyUsageExtension>());
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,12 @@ using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
||||||
using Microsoft.AspNetCore.Testing;
|
using Microsoft.AspNetCore.Testing;
|
||||||
|
using Microsoft.Extensions.Logging.Testing;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
public class ChunkedRequestTests
|
public class ChunkedRequestTests : LoggedTest
|
||||||
{
|
{
|
||||||
public static TheoryData<ListenOptions> ConnectionAdapterData => new TheoryData<ListenOptions>
|
public static TheoryData<ListenOptions> ConnectionAdapterData => new TheoryData<ListenOptions>
|
||||||
{
|
{
|
||||||
|
|
@ -57,7 +58,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[MemberData(nameof(ConnectionAdapterData))]
|
[MemberData(nameof(ConnectionAdapterData))]
|
||||||
public async Task Http10TransferEncoding(ListenOptions listenOptions)
|
public async Task Http10TransferEncoding(ListenOptions listenOptions)
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext();
|
var testContext = new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
using (var server = new TestServer(App, testContext, listenOptions))
|
using (var server = new TestServer(App, testContext, listenOptions))
|
||||||
{
|
{
|
||||||
|
|
@ -87,7 +88,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[MemberData(nameof(ConnectionAdapterData))]
|
[MemberData(nameof(ConnectionAdapterData))]
|
||||||
public async Task Http10KeepAliveTransferEncoding(ListenOptions listenOptions)
|
public async Task Http10KeepAliveTransferEncoding(ListenOptions listenOptions)
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext();
|
var testContext = new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
using (var server = new TestServer(AppChunked, testContext, listenOptions))
|
using (var server = new TestServer(AppChunked, testContext, listenOptions))
|
||||||
{
|
{
|
||||||
|
|
@ -129,7 +130,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[MemberData(nameof(ConnectionAdapterData))]
|
[MemberData(nameof(ConnectionAdapterData))]
|
||||||
public async Task RequestBodyIsConsumedAutomaticallyIfAppDoesntConsumeItFully(ListenOptions listenOptions)
|
public async Task RequestBodyIsConsumedAutomaticallyIfAppDoesntConsumeItFully(ListenOptions listenOptions)
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext();
|
var testContext = new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
using (var server = new TestServer(async httpContext =>
|
using (var server = new TestServer(async httpContext =>
|
||||||
{
|
{
|
||||||
|
|
@ -213,7 +214,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
response.Headers["Content-Length"] = new[] { "11" };
|
response.Headers["Content-Length"] = new[] { "11" };
|
||||||
|
|
||||||
await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11);
|
await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11);
|
||||||
}, new TestServiceContext(), listenOptions))
|
}, new TestServiceContext(LoggerFactory), listenOptions))
|
||||||
{
|
{
|
||||||
var response = string.Join("\r\n", new string[] {
|
var response = string.Join("\r\n", new string[] {
|
||||||
"HTTP/1.1 200 OK",
|
"HTTP/1.1 200 OK",
|
||||||
|
|
@ -274,7 +275,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
const string headerLine = "Header: value";
|
const string headerLine = "Header: value";
|
||||||
const string trailingHeaderLine = "Trailing-Header: trailing-value";
|
const string trailingHeaderLine = "Trailing-Header: trailing-value";
|
||||||
|
|
||||||
var testContext = new TestServiceContext();
|
var testContext = new TestServiceContext(LoggerFactory);
|
||||||
testContext.ServerOptions.Limits.MaxRequestHeadersTotalSize =
|
testContext.ServerOptions.Limits.MaxRequestHeadersTotalSize =
|
||||||
transferEncodingHeaderLine.Length + 2 +
|
transferEncodingHeaderLine.Length + 2 +
|
||||||
headerLine.Length + 2 +
|
headerLine.Length + 2 +
|
||||||
|
|
@ -319,7 +320,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
const string headerLine = "Header: value";
|
const string headerLine = "Header: value";
|
||||||
const string trailingHeaderLine = "Trailing-Header: trailing-value";
|
const string trailingHeaderLine = "Trailing-Header: trailing-value";
|
||||||
|
|
||||||
var testContext = new TestServiceContext();
|
var testContext = new TestServiceContext(LoggerFactory);
|
||||||
testContext.ServerOptions.Limits.MaxRequestHeaderCount = 2;
|
testContext.ServerOptions.Limits.MaxRequestHeaderCount = 2;
|
||||||
|
|
||||||
using (var server = new TestServer(async context =>
|
using (var server = new TestServer(async context =>
|
||||||
|
|
@ -357,7 +358,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[MemberData(nameof(ConnectionAdapterData))]
|
[MemberData(nameof(ConnectionAdapterData))]
|
||||||
public async Task ExtensionsAreIgnored(ListenOptions listenOptions)
|
public async Task ExtensionsAreIgnored(ListenOptions listenOptions)
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext();
|
var testContext = new TestServiceContext(LoggerFactory);
|
||||||
var requestCount = 10;
|
var requestCount = 10;
|
||||||
var requestsReceived = 0;
|
var requestsReceived = 0;
|
||||||
|
|
||||||
|
|
@ -444,7 +445,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[MemberData(nameof(ConnectionAdapterData))]
|
[MemberData(nameof(ConnectionAdapterData))]
|
||||||
public async Task InvalidLengthResultsIn400(ListenOptions listenOptions)
|
public async Task InvalidLengthResultsIn400(ListenOptions listenOptions)
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext();
|
var testContext = new TestServiceContext(LoggerFactory);
|
||||||
using (var server = new TestServer(async httpContext =>
|
using (var server = new TestServer(async httpContext =>
|
||||||
{
|
{
|
||||||
var response = httpContext.Response;
|
var response = httpContext.Response;
|
||||||
|
|
@ -488,7 +489,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[MemberData(nameof(ConnectionAdapterData))]
|
[MemberData(nameof(ConnectionAdapterData))]
|
||||||
public async Task InvalidSizedDataResultsIn400(ListenOptions listenOptions)
|
public async Task InvalidSizedDataResultsIn400(ListenOptions listenOptions)
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext();
|
var testContext = new TestServiceContext(LoggerFactory);
|
||||||
using (var server = new TestServer(async httpContext =>
|
using (var server = new TestServer(async httpContext =>
|
||||||
{
|
{
|
||||||
var response = httpContext.Response;
|
var response = httpContext.Response;
|
||||||
|
|
@ -534,7 +535,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[MemberData(nameof(ConnectionAdapterData))]
|
[MemberData(nameof(ConnectionAdapterData))]
|
||||||
public async Task ChunkedNotFinalTransferCodingResultsIn400(ListenOptions listenOptions)
|
public async Task ChunkedNotFinalTransferCodingResultsIn400(ListenOptions listenOptions)
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext();
|
var testContext = new TestServiceContext(LoggerFactory);
|
||||||
using (var server = new TestServer(httpContext =>
|
using (var server = new TestServer(httpContext =>
|
||||||
{
|
{
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,12 @@ using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
||||||
using Microsoft.AspNetCore.Testing;
|
using Microsoft.AspNetCore.Testing;
|
||||||
|
using Microsoft.Extensions.Logging.Testing;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
public class ChunkedResponseTests
|
public class ChunkedResponseTests : LoggedTest
|
||||||
{
|
{
|
||||||
public static TheoryData<ListenOptions> ConnectionAdapterData => new TheoryData<ListenOptions>
|
public static TheoryData<ListenOptions> ConnectionAdapterData => new TheoryData<ListenOptions>
|
||||||
{
|
{
|
||||||
|
|
@ -28,7 +29,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[MemberData(nameof(ConnectionAdapterData))]
|
[MemberData(nameof(ConnectionAdapterData))]
|
||||||
public async Task ResponsesAreChunkedAutomatically(ListenOptions listenOptions)
|
public async Task ResponsesAreChunkedAutomatically(ListenOptions listenOptions)
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext();
|
var testContext = new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
using (var server = new TestServer(async httpContext =>
|
using (var server = new TestServer(async httpContext =>
|
||||||
{
|
{
|
||||||
|
|
@ -64,7 +65,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[MemberData(nameof(ConnectionAdapterData))]
|
[MemberData(nameof(ConnectionAdapterData))]
|
||||||
public async Task ResponsesAreNotChunkedAutomaticallyForHttp10Requests(ListenOptions listenOptions)
|
public async Task ResponsesAreNotChunkedAutomaticallyForHttp10Requests(ListenOptions listenOptions)
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext();
|
var testContext = new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
using (var server = new TestServer(async httpContext =>
|
using (var server = new TestServer(async httpContext =>
|
||||||
{
|
{
|
||||||
|
|
@ -93,7 +94,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[MemberData(nameof(ConnectionAdapterData))]
|
[MemberData(nameof(ConnectionAdapterData))]
|
||||||
public async Task ResponsesAreChunkedAutomaticallyForHttp11NonKeepAliveRequests(ListenOptions listenOptions)
|
public async Task ResponsesAreChunkedAutomaticallyForHttp11NonKeepAliveRequests(ListenOptions listenOptions)
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext();
|
var testContext = new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
using (var server = new TestServer(async httpContext =>
|
using (var server = new TestServer(async httpContext =>
|
||||||
{
|
{
|
||||||
|
|
@ -130,7 +131,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[MemberData(nameof(ConnectionAdapterData))]
|
[MemberData(nameof(ConnectionAdapterData))]
|
||||||
public async Task SettingConnectionCloseHeaderInAppDoesNotDisableChunking(ListenOptions listenOptions)
|
public async Task SettingConnectionCloseHeaderInAppDoesNotDisableChunking(ListenOptions listenOptions)
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext();
|
var testContext = new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
using (var server = new TestServer(async httpContext =>
|
using (var server = new TestServer(async httpContext =>
|
||||||
{
|
{
|
||||||
|
|
@ -167,7 +168,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[MemberData(nameof(ConnectionAdapterData))]
|
[MemberData(nameof(ConnectionAdapterData))]
|
||||||
public async Task ZeroLengthWritesAreIgnored(ListenOptions listenOptions)
|
public async Task ZeroLengthWritesAreIgnored(ListenOptions listenOptions)
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext();
|
var testContext = new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
using (var server = new TestServer(async httpContext =>
|
using (var server = new TestServer(async httpContext =>
|
||||||
{
|
{
|
||||||
|
|
@ -204,7 +205,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[MemberData(nameof(ConnectionAdapterData))]
|
[MemberData(nameof(ConnectionAdapterData))]
|
||||||
public async Task ZeroLengthWritesFlushHeaders(ListenOptions listenOptions)
|
public async Task ZeroLengthWritesFlushHeaders(ListenOptions listenOptions)
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext();
|
var testContext = new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
var flushed = new SemaphoreSlim(0, 1);
|
var flushed = new SemaphoreSlim(0, 1);
|
||||||
|
|
||||||
|
|
@ -249,7 +250,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[MemberData(nameof(ConnectionAdapterData))]
|
[MemberData(nameof(ConnectionAdapterData))]
|
||||||
public async Task EmptyResponseBodyHandledCorrectlyWithZeroLengthWrite(ListenOptions listenOptions)
|
public async Task EmptyResponseBodyHandledCorrectlyWithZeroLengthWrite(ListenOptions listenOptions)
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext();
|
var testContext = new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
using (var server = new TestServer(async httpContext =>
|
using (var server = new TestServer(async httpContext =>
|
||||||
{
|
{
|
||||||
|
|
@ -280,7 +281,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[MemberData(nameof(ConnectionAdapterData))]
|
[MemberData(nameof(ConnectionAdapterData))]
|
||||||
public async Task ConnectionClosedIfExceptionThrownAfterWrite(ListenOptions listenOptions)
|
public async Task ConnectionClosedIfExceptionThrownAfterWrite(ListenOptions listenOptions)
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext();
|
var testContext = new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
using (var server = new TestServer(async httpContext =>
|
using (var server = new TestServer(async httpContext =>
|
||||||
{
|
{
|
||||||
|
|
@ -314,7 +315,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[MemberData(nameof(ConnectionAdapterData))]
|
[MemberData(nameof(ConnectionAdapterData))]
|
||||||
public async Task ConnectionClosedIfExceptionThrownAfterZeroLengthWrite(ListenOptions listenOptions)
|
public async Task ConnectionClosedIfExceptionThrownAfterZeroLengthWrite(ListenOptions listenOptions)
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext();
|
var testContext = new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
using (var server = new TestServer(async httpContext =>
|
using (var server = new TestServer(async httpContext =>
|
||||||
{
|
{
|
||||||
|
|
@ -347,7 +348,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[MemberData(nameof(ConnectionAdapterData))]
|
[MemberData(nameof(ConnectionAdapterData))]
|
||||||
public async Task WritesAreFlushedPriorToResponseCompletion(ListenOptions listenOptions)
|
public async Task WritesAreFlushedPriorToResponseCompletion(ListenOptions listenOptions)
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext();
|
var testContext = new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
var flushWh = new ManualResetEventSlim();
|
var flushWh = new ManualResetEventSlim();
|
||||||
|
|
||||||
|
|
@ -394,7 +395,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[MemberData(nameof(ConnectionAdapterData))]
|
[MemberData(nameof(ConnectionAdapterData))]
|
||||||
public async Task ChunksCanBeWrittenManually(ListenOptions listenOptions)
|
public async Task ChunksCanBeWrittenManually(ListenOptions listenOptions)
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext();
|
var testContext = new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
using (var server = new TestServer(async httpContext =>
|
using (var server = new TestServer(async httpContext =>
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,12 @@ using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
||||||
using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal;
|
using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal;
|
||||||
using Microsoft.AspNetCore.Testing;
|
using Microsoft.AspNetCore.Testing;
|
||||||
|
using Microsoft.Extensions.Logging.Testing;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
public class ConnectionAdapterTests
|
public class ConnectionAdapterTests : LoggedTest
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task CanReadAndWriteWithRewritingConnectionAdapter()
|
public async Task CanReadAndWriteWithRewritingConnectionAdapter()
|
||||||
|
|
@ -26,7 +27,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
ConnectionAdapters = { adapter }
|
ConnectionAdapters = { adapter }
|
||||||
};
|
};
|
||||||
|
|
||||||
var serviceContext = new TestServiceContext();
|
var serviceContext = new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
var sendString = "POST / HTTP/1.0\r\nContent-Length: 12\r\n\r\nHello World?";
|
var sendString = "POST / HTTP/1.0\r\nContent-Length: 12\r\n\r\nHello World?";
|
||||||
|
|
||||||
|
|
@ -56,7 +57,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
ConnectionAdapters = { new AsyncConnectionAdapter() }
|
ConnectionAdapters = { new AsyncConnectionAdapter() }
|
||||||
};
|
};
|
||||||
|
|
||||||
var serviceContext = new TestServiceContext();
|
var serviceContext = new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
using (var server = new TestServer(TestApp.EchoApp, serviceContext, listenOptions))
|
using (var server = new TestServer(TestApp.EchoApp, serviceContext, listenOptions))
|
||||||
{
|
{
|
||||||
|
|
@ -85,7 +86,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
ConnectionAdapters = { new AsyncConnectionAdapter() }
|
ConnectionAdapters = { new AsyncConnectionAdapter() }
|
||||||
};
|
};
|
||||||
|
|
||||||
var serviceContext = new TestServiceContext();
|
var serviceContext = new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
using (var server = new TestServer(TestApp.EchoApp, serviceContext, listenOptions))
|
using (var server = new TestServer(TestApp.EchoApp, serviceContext, listenOptions))
|
||||||
{
|
{
|
||||||
|
|
@ -106,7 +107,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
ConnectionAdapters = { new ThrowingConnectionAdapter() }
|
ConnectionAdapters = { new ThrowingConnectionAdapter() }
|
||||||
};
|
};
|
||||||
|
|
||||||
var serviceContext = new TestServiceContext();
|
var serviceContext = new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
using (var server = new TestServer(TestApp.EchoApp, serviceContext, listenOptions))
|
using (var server = new TestServer(TestApp.EchoApp, serviceContext, listenOptions))
|
||||||
{
|
{
|
||||||
|
|
@ -127,7 +128,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
ConnectionAdapters = { new AsyncConnectionAdapter() }
|
ConnectionAdapters = { new AsyncConnectionAdapter() }
|
||||||
};
|
};
|
||||||
|
|
||||||
var serviceContext = new TestServiceContext();
|
var serviceContext = new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
var stopTask = Task.CompletedTask;
|
var stopTask = Task.CompletedTask;
|
||||||
using (var server = new TestServer(TestApp.EchoApp, serviceContext, listenOptions))
|
using (var server = new TestServer(TestApp.EchoApp, serviceContext, listenOptions))
|
||||||
|
|
@ -149,7 +150,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
ConnectionAdapters = { new ThrowingConnectionAdapter() }
|
ConnectionAdapters = { new ThrowingConnectionAdapter() }
|
||||||
};
|
};
|
||||||
|
|
||||||
var serviceContext = new TestServiceContext();
|
var serviceContext = new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
using (var server = new TestServer(TestApp.EchoApp, serviceContext, listenOptions))
|
using (var server = new TestServer(TestApp.EchoApp, serviceContext, listenOptions))
|
||||||
{
|
{
|
||||||
|
|
@ -181,7 +182,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
ConnectionAdapters = { new PassThroughConnectionAdapter() }
|
ConnectionAdapters = { new PassThroughConnectionAdapter() }
|
||||||
};
|
};
|
||||||
|
|
||||||
var serviceContext = new TestServiceContext();
|
var serviceContext = new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
using (var server = new TestServer(async context =>
|
using (var server = new TestServer(async context =>
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,12 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal;
|
||||||
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
|
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Server.Kestrel.Tests;
|
using Microsoft.AspNetCore.Server.Kestrel.Tests;
|
||||||
using Microsoft.AspNetCore.Testing;
|
using Microsoft.AspNetCore.Testing;
|
||||||
|
using Microsoft.Extensions.Logging.Testing;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
public class ConnectionLimitTests
|
public class ConnectionLimitTests : LoggedTest
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task ResetsCountWhenConnectionClosed()
|
public async Task ResetsCountWhenConnectionClosed()
|
||||||
|
|
@ -190,14 +191,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
|
|
||||||
private TestServer CreateServerWithMaxConnections(RequestDelegate app, long max)
|
private TestServer CreateServerWithMaxConnections(RequestDelegate app, long max)
|
||||||
{
|
{
|
||||||
var serviceContext = new TestServiceContext();
|
var serviceContext = new TestServiceContext(LoggerFactory);
|
||||||
serviceContext.ServerOptions.Limits.MaxConcurrentConnections = max;
|
serviceContext.ServerOptions.Limits.MaxConcurrentConnections = max;
|
||||||
return new TestServer(app, serviceContext);
|
return new TestServer(app, serviceContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
private TestServer CreateServerWithMaxConnections(RequestDelegate app, ResourceCounter concurrentConnectionCounter)
|
private TestServer CreateServerWithMaxConnections(RequestDelegate app, ResourceCounter concurrentConnectionCounter)
|
||||||
{
|
{
|
||||||
var serviceContext = new TestServiceContext();
|
var serviceContext = new TestServiceContext(LoggerFactory);
|
||||||
var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0));
|
var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0));
|
||||||
listenOptions.Use(next =>
|
listenOptions.Use(next =>
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -3,16 +3,17 @@
|
||||||
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Testing;
|
using Microsoft.AspNetCore.Testing;
|
||||||
|
using Microsoft.Extensions.Logging.Testing;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
public class DefaultHeaderTests
|
public class DefaultHeaderTests : LoggedTest
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task TestDefaultHeaders()
|
public async Task TestDefaultHeaders()
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext()
|
var testContext = new TestServiceContext(LoggerFactory)
|
||||||
{
|
{
|
||||||
ServerOptions = { AddServerHeader = true }
|
ServerOptions = { AddServerHeader = true }
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,12 @@ using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http.Features;
|
using Microsoft.AspNetCore.Http.Features;
|
||||||
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
|
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Testing;
|
using Microsoft.AspNetCore.Testing;
|
||||||
|
using Microsoft.Extensions.Logging.Testing;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
public class EventSourceTests : IDisposable
|
public class EventSourceTests : LoggedTest, IDisposable
|
||||||
{
|
{
|
||||||
private readonly TestEventListener _listener = new TestEventListener();
|
private readonly TestEventListener _listener = new TestEventListener();
|
||||||
|
|
||||||
|
|
@ -34,7 +35,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
connectionId = context.Features.Get<IHttpConnectionFeature>().ConnectionId;
|
connectionId = context.Features.Get<IHttpConnectionFeature>().ConnectionId;
|
||||||
requestId = context.TraceIdentifier;
|
requestId = context.TraceIdentifier;
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}))
|
}, new TestServiceContext(LoggerFactory)))
|
||||||
{
|
{
|
||||||
port = server.Port;
|
port = server.Port;
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,13 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Testing;
|
using Microsoft.AspNetCore.Testing;
|
||||||
using Microsoft.AspNetCore.Testing.xunit;
|
using Microsoft.AspNetCore.Testing.xunit;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.Extensions.Logging.Testing;
|
||||||
using Moq;
|
using Moq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
public class HttpConnectionManagerTests
|
public class HttpConnectionManagerTests : LoggedTest
|
||||||
{
|
{
|
||||||
// This test causes MemoryPoolBlocks to be finalized which in turn causes an assert failure in debug builds.
|
// This test causes MemoryPoolBlocks to be finalized which in turn causes an assert failure in debug builds.
|
||||||
#if !DEBUG
|
#if !DEBUG
|
||||||
|
|
|
||||||
|
|
@ -11,12 +11,12 @@ using Microsoft.AspNetCore.Server.Kestrel.Core;
|
||||||
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2;
|
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2;
|
||||||
using Microsoft.AspNetCore.Testing;
|
using Microsoft.AspNetCore.Testing;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Moq;
|
using Microsoft.Extensions.Logging.Testing;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
public class HttpProtocolSelectionTests
|
public class HttpProtocolSelectionTests : TestApplicationErrorLoggerLoggedTest
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public Task Server_NoProtocols_Error()
|
public Task Server_NoProtocols_Error()
|
||||||
|
|
@ -46,6 +46,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
private async Task TestSuccess(HttpProtocols serverProtocols, string request, string expectedResponse)
|
private async Task TestSuccess(HttpProtocols serverProtocols, string request, string expectedResponse)
|
||||||
{
|
{
|
||||||
var builder = TransportSelector.GetWebHostBuilder()
|
var builder = TransportSelector.GetWebHostBuilder()
|
||||||
|
.ConfigureServices(AddTestLogging)
|
||||||
.UseKestrel(options =>
|
.UseKestrel(options =>
|
||||||
{
|
{
|
||||||
options.Listen(IPAddress.Loopback, 0, listenOptions =>
|
options.Listen(IPAddress.Loopback, 0, listenOptions =>
|
||||||
|
|
@ -70,14 +71,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
private async Task TestError<TException>(HttpProtocols serverProtocols, string expectedErrorMessage)
|
private async Task TestError<TException>(HttpProtocols serverProtocols, string expectedErrorMessage)
|
||||||
where TException : Exception
|
where TException : Exception
|
||||||
{
|
{
|
||||||
var logger = new TestApplicationErrorLogger();
|
|
||||||
var loggerProvider = new Mock<ILoggerProvider>();
|
|
||||||
loggerProvider
|
|
||||||
.Setup(provider => provider.CreateLogger(It.IsAny<string>()))
|
|
||||||
.Returns(logger);
|
|
||||||
|
|
||||||
var builder = TransportSelector.GetWebHostBuilder()
|
var builder = TransportSelector.GetWebHostBuilder()
|
||||||
.ConfigureLogging(loggingBuilder => loggingBuilder.AddProvider(loggerProvider.Object))
|
.ConfigureServices(AddTestLogging)
|
||||||
.UseKestrel(options => options.Listen(IPAddress.Loopback, 0, listenOptions =>
|
.UseKestrel(options => options.Listen(IPAddress.Loopback, 0, listenOptions =>
|
||||||
{
|
{
|
||||||
listenOptions.Protocols = serverProtocols;
|
listenOptions.Protocols = serverProtocols;
|
||||||
|
|
@ -94,7 +89,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.Single(logger.Messages, message => message.LogLevel == LogLevel.Error
|
Assert.Single(TestApplicationErrorLogger.Messages, message => message.LogLevel == LogLevel.Error
|
||||||
&& message.EventId.Id == 0
|
&& message.EventId.Id == 0
|
||||||
&& message.Message == expectedErrorMessage);
|
&& message.Message == expectedErrorMessage);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,28 +19,21 @@ using Microsoft.AspNetCore.Server.Kestrel.Core;
|
||||||
using Microsoft.AspNetCore.Server.Kestrel.Https;
|
using Microsoft.AspNetCore.Server.Kestrel.Https;
|
||||||
using Microsoft.AspNetCore.Server.Kestrel.Https.Internal;
|
using Microsoft.AspNetCore.Server.Kestrel.Https.Internal;
|
||||||
using Microsoft.AspNetCore.Testing;
|
using Microsoft.AspNetCore.Testing;
|
||||||
|
using Microsoft.Extensions.Logging.Testing;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using Xunit.Abstractions;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
public class HttpsConnectionAdapterTests
|
public class HttpsConnectionAdapterTests : LoggedTest
|
||||||
{
|
{
|
||||||
private static X509Certificate2 _x509Certificate2 = TestResources.GetTestCertificate();
|
private static X509Certificate2 _x509Certificate2 = TestResources.GetTestCertificate();
|
||||||
private static X509Certificate2 _x509Certificate2NoExt = TestResources.GetTestCertificate("no_extensions.pfx");
|
private static X509Certificate2 _x509Certificate2NoExt = TestResources.GetTestCertificate("no_extensions.pfx");
|
||||||
private readonly ITestOutputHelper _output;
|
|
||||||
|
|
||||||
public HttpsConnectionAdapterTests(ITestOutputHelper output)
|
|
||||||
{
|
|
||||||
_output = output;
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://github.com/aspnet/KestrelHttpServer/issues/240
|
// https://github.com/aspnet/KestrelHttpServer/issues/240
|
||||||
// This test currently fails on mono because of an issue with SslStream.
|
// This test currently fails on mono because of an issue with SslStream.
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task CanReadAndWriteWithHttpsConnectionAdapter()
|
public async Task CanReadAndWriteWithHttpsConnectionAdapter()
|
||||||
{
|
{
|
||||||
var serviceContext = new TestServiceContext();
|
|
||||||
var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0))
|
var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0))
|
||||||
{
|
{
|
||||||
ConnectionAdapters =
|
ConnectionAdapters =
|
||||||
|
|
@ -49,7 +42,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
using (var server = new TestServer(App, serviceContext, listenOptions))
|
using (var server = new TestServer(App, new TestServiceContext(LoggerFactory), listenOptions))
|
||||||
{
|
{
|
||||||
var result = await HttpClientSlim.PostAsync($"https://localhost:{server.Port}/",
|
var result = await HttpClientSlim.PostAsync($"https://localhost:{server.Port}/",
|
||||||
new FormUrlEncodedContent(new[] {
|
new FormUrlEncodedContent(new[] {
|
||||||
|
|
@ -64,7 +57,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task RequireCertificateFailsWhenNoCertificate()
|
public async Task RequireCertificateFailsWhenNoCertificate()
|
||||||
{
|
{
|
||||||
var serviceContext = new TestServiceContext();
|
|
||||||
var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0))
|
var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0))
|
||||||
{
|
{
|
||||||
ConnectionAdapters =
|
ConnectionAdapters =
|
||||||
|
|
@ -78,7 +70,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
using (var server = new TestServer(App, serviceContext, listenOptions))
|
using (var server = new TestServer(App, new TestServiceContext(LoggerFactory), listenOptions))
|
||||||
{
|
{
|
||||||
await Assert.ThrowsAnyAsync<Exception>(
|
await Assert.ThrowsAnyAsync<Exception>(
|
||||||
() => HttpClientSlim.GetStringAsync($"https://localhost:{server.Port}/"));
|
() => HttpClientSlim.GetStringAsync($"https://localhost:{server.Port}/"));
|
||||||
|
|
@ -88,7 +80,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task AllowCertificateContinuesWhenNoCertificate()
|
public async Task AllowCertificateContinuesWhenNoCertificate()
|
||||||
{
|
{
|
||||||
var serviceContext = new TestServiceContext();
|
|
||||||
var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0))
|
var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0))
|
||||||
{
|
{
|
||||||
ConnectionAdapters =
|
ConnectionAdapters =
|
||||||
|
|
@ -107,8 +98,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
Assert.NotNull(tlsFeature);
|
Assert.NotNull(tlsFeature);
|
||||||
Assert.Null(tlsFeature.ClientCertificate);
|
Assert.Null(tlsFeature.ClientCertificate);
|
||||||
return context.Response.WriteAsync("hello world");
|
return context.Response.WriteAsync("hello world");
|
||||||
},
|
}, new TestServiceContext(LoggerFactory), listenOptions))
|
||||||
serviceContext, listenOptions))
|
|
||||||
{
|
{
|
||||||
var result = await HttpClientSlim.GetStringAsync($"https://localhost:{server.Port}/", validateCertificate: false);
|
var result = await HttpClientSlim.GetStringAsync($"https://localhost:{server.Port}/", validateCertificate: false);
|
||||||
Assert.Equal("hello world", result);
|
Assert.Equal("hello world", result);
|
||||||
|
|
@ -126,7 +116,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task UsesProvidedServerCertificate()
|
public async Task UsesProvidedServerCertificate()
|
||||||
{
|
{
|
||||||
var serviceContext = new TestServiceContext();
|
|
||||||
var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0))
|
var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0))
|
||||||
{
|
{
|
||||||
ConnectionAdapters =
|
ConnectionAdapters =
|
||||||
|
|
@ -135,7 +124,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
using (var server = new TestServer(context => Task.CompletedTask, serviceContext, listenOptions))
|
using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory), listenOptions))
|
||||||
{
|
{
|
||||||
using (var client = new TcpClient())
|
using (var client = new TcpClient())
|
||||||
{
|
{
|
||||||
|
|
@ -153,7 +142,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
public async Task UsesProvidedServerCertificateSelector()
|
public async Task UsesProvidedServerCertificateSelector()
|
||||||
{
|
{
|
||||||
var selectorCalled = 0;
|
var selectorCalled = 0;
|
||||||
var serviceContext = new TestServiceContext();
|
|
||||||
var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0))
|
var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0))
|
||||||
{
|
{
|
||||||
ConnectionAdapters =
|
ConnectionAdapters =
|
||||||
|
|
@ -175,7 +163,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
using (var server = new TestServer(context => Task.CompletedTask, serviceContext, listenOptions))
|
using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory), listenOptions))
|
||||||
{
|
{
|
||||||
using (var client = new TcpClient())
|
using (var client = new TcpClient())
|
||||||
{
|
{
|
||||||
|
|
@ -194,7 +182,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
public async Task UsesProvidedServerCertificateSelectorEachTime()
|
public async Task UsesProvidedServerCertificateSelectorEachTime()
|
||||||
{
|
{
|
||||||
var selectorCalled = 0;
|
var selectorCalled = 0;
|
||||||
var serviceContext = new TestServiceContext();
|
|
||||||
var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0))
|
var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0))
|
||||||
{
|
{
|
||||||
ConnectionAdapters =
|
ConnectionAdapters =
|
||||||
|
|
@ -220,7 +207,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
using (var server = new TestServer(context => Task.CompletedTask, serviceContext, listenOptions))
|
using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory), listenOptions))
|
||||||
{
|
{
|
||||||
using (var client = new TcpClient())
|
using (var client = new TcpClient())
|
||||||
{
|
{
|
||||||
|
|
@ -249,7 +236,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
public async Task UsesProvidedServerCertificateSelectorValidatesEkus()
|
public async Task UsesProvidedServerCertificateSelectorValidatesEkus()
|
||||||
{
|
{
|
||||||
var selectorCalled = 0;
|
var selectorCalled = 0;
|
||||||
var serviceContext = new TestServiceContext();
|
|
||||||
var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0))
|
var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0))
|
||||||
{
|
{
|
||||||
ConnectionAdapters =
|
ConnectionAdapters =
|
||||||
|
|
@ -264,7 +250,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
using (var server = new TestServer(context => Task.CompletedTask, serviceContext, listenOptions))
|
using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory), listenOptions))
|
||||||
{
|
{
|
||||||
using (var client = new TcpClient())
|
using (var client = new TcpClient())
|
||||||
{
|
{
|
||||||
|
|
@ -283,7 +269,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
public async Task UsesProvidedServerCertificateSelectorOverridesServerCertificate()
|
public async Task UsesProvidedServerCertificateSelectorOverridesServerCertificate()
|
||||||
{
|
{
|
||||||
var selectorCalled = 0;
|
var selectorCalled = 0;
|
||||||
var serviceContext = new TestServiceContext();
|
|
||||||
var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0))
|
var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0))
|
||||||
{
|
{
|
||||||
ConnectionAdapters =
|
ConnectionAdapters =
|
||||||
|
|
@ -306,7 +291,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
using (var server = new TestServer(context => Task.CompletedTask, serviceContext, listenOptions))
|
using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory), listenOptions))
|
||||||
{
|
{
|
||||||
using (var client = new TcpClient())
|
using (var client = new TcpClient())
|
||||||
{
|
{
|
||||||
|
|
@ -325,7 +310,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
public async Task UsesProvidedServerCertificateSelectorFailsIfYouReturnNull()
|
public async Task UsesProvidedServerCertificateSelectorFailsIfYouReturnNull()
|
||||||
{
|
{
|
||||||
var selectorCalled = 0;
|
var selectorCalled = 0;
|
||||||
var serviceContext = new TestServiceContext();
|
|
||||||
var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0))
|
var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0))
|
||||||
{
|
{
|
||||||
ConnectionAdapters =
|
ConnectionAdapters =
|
||||||
|
|
@ -340,7 +324,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
using (var server = new TestServer(context => Task.CompletedTask, serviceContext, listenOptions))
|
using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory), listenOptions))
|
||||||
{
|
{
|
||||||
using (var client = new TcpClient())
|
using (var client = new TcpClient())
|
||||||
{
|
{
|
||||||
|
|
@ -358,7 +342,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task CertificatePassedToHttpContext()
|
public async Task CertificatePassedToHttpContext()
|
||||||
{
|
{
|
||||||
var serviceContext = new TestServiceContext();
|
|
||||||
var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0))
|
var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0))
|
||||||
{
|
{
|
||||||
ConnectionAdapters =
|
ConnectionAdapters =
|
||||||
|
|
@ -379,8 +362,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
Assert.NotNull(tlsFeature.ClientCertificate);
|
Assert.NotNull(tlsFeature.ClientCertificate);
|
||||||
Assert.NotNull(context.Connection.ClientCertificate);
|
Assert.NotNull(context.Connection.ClientCertificate);
|
||||||
return context.Response.WriteAsync("hello world");
|
return context.Response.WriteAsync("hello world");
|
||||||
},
|
}, new TestServiceContext(LoggerFactory), listenOptions))
|
||||||
serviceContext, listenOptions))
|
|
||||||
{
|
{
|
||||||
using (var client = new TcpClient())
|
using (var client = new TcpClient())
|
||||||
{
|
{
|
||||||
|
|
@ -404,9 +386,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
new HttpsConnectionAdapter(new HttpsConnectionAdapterOptions { ServerCertificate = _x509Certificate2 })
|
new HttpsConnectionAdapter(new HttpsConnectionAdapterOptions { ServerCertificate = _x509Certificate2 })
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var serviceContext = new TestServiceContext();
|
|
||||||
|
|
||||||
using (var server = new TestServer(context => context.Response.WriteAsync(context.Request.Scheme), serviceContext, listenOptions))
|
using (var server = new TestServer(context => context.Response.WriteAsync(context.Request.Scheme), new TestServiceContext(LoggerFactory), listenOptions))
|
||||||
{
|
{
|
||||||
var result = await HttpClientSlim.GetStringAsync($"https://localhost:{server.Port}/", validateCertificate: false);
|
var result = await HttpClientSlim.GetStringAsync($"https://localhost:{server.Port}/", validateCertificate: false);
|
||||||
Assert.Equal("https", result);
|
Assert.Equal("https", result);
|
||||||
|
|
@ -416,7 +397,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task DoesNotSupportTls10()
|
public async Task DoesNotSupportTls10()
|
||||||
{
|
{
|
||||||
var serviceContext = new TestServiceContext();
|
|
||||||
var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0))
|
var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0))
|
||||||
{
|
{
|
||||||
ConnectionAdapters =
|
ConnectionAdapters =
|
||||||
|
|
@ -430,7 +410,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
using (var server = new TestServer(context => context.Response.WriteAsync("hello world"), serviceContext, listenOptions))
|
using (var server = new TestServer(context => context.Response.WriteAsync("hello world"), new TestServiceContext(LoggerFactory), listenOptions))
|
||||||
{
|
{
|
||||||
// SslStream is used to ensure the certificate is actually passed to the server
|
// 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
|
// HttpClient might not send the certificate because it is invalid or it doesn't match any
|
||||||
|
|
@ -450,7 +430,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
public async Task ClientCertificateValidationGetsCalledWithNotNullParameters(ClientCertificateMode mode)
|
public async Task ClientCertificateValidationGetsCalledWithNotNullParameters(ClientCertificateMode mode)
|
||||||
{
|
{
|
||||||
var clientCertificateValidationCalled = false;
|
var clientCertificateValidationCalled = false;
|
||||||
var serviceContext = new TestServiceContext();
|
|
||||||
var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0))
|
var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0))
|
||||||
{
|
{
|
||||||
ConnectionAdapters =
|
ConnectionAdapters =
|
||||||
|
|
@ -470,7 +449,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
using (var server = new TestServer(context => Task.CompletedTask, serviceContext, listenOptions))
|
using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory), listenOptions))
|
||||||
{
|
{
|
||||||
using (var client = new TcpClient())
|
using (var client = new TcpClient())
|
||||||
{
|
{
|
||||||
|
|
@ -487,7 +466,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[InlineData(ClientCertificateMode.RequireCertificate)]
|
[InlineData(ClientCertificateMode.RequireCertificate)]
|
||||||
public async Task ValidationFailureRejectsConnection(ClientCertificateMode mode)
|
public async Task ValidationFailureRejectsConnection(ClientCertificateMode mode)
|
||||||
{
|
{
|
||||||
var serviceContext = new TestServiceContext();
|
|
||||||
var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0))
|
var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0))
|
||||||
{
|
{
|
||||||
ConnectionAdapters =
|
ConnectionAdapters =
|
||||||
|
|
@ -501,7 +479,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
using (var server = new TestServer(context => Task.CompletedTask, serviceContext, listenOptions))
|
using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory), listenOptions))
|
||||||
{
|
{
|
||||||
using (var client = new TcpClient())
|
using (var client = new TcpClient())
|
||||||
{
|
{
|
||||||
|
|
@ -517,7 +495,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[InlineData(ClientCertificateMode.RequireCertificate)]
|
[InlineData(ClientCertificateMode.RequireCertificate)]
|
||||||
public async Task RejectsConnectionOnSslPolicyErrorsWhenNoValidation(ClientCertificateMode mode)
|
public async Task RejectsConnectionOnSslPolicyErrorsWhenNoValidation(ClientCertificateMode mode)
|
||||||
{
|
{
|
||||||
var serviceContext = new TestServiceContext();
|
|
||||||
var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0))
|
var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0))
|
||||||
{
|
{
|
||||||
ConnectionAdapters =
|
ConnectionAdapters =
|
||||||
|
|
@ -530,7 +507,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
using (var server = new TestServer(context => Task.CompletedTask, serviceContext, listenOptions))
|
using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory), listenOptions))
|
||||||
{
|
{
|
||||||
using (var client = new TcpClient())
|
using (var client = new TcpClient())
|
||||||
{
|
{
|
||||||
|
|
@ -544,7 +521,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task CertificatePassedToHttpContextIsNotDisposed()
|
public async Task CertificatePassedToHttpContextIsNotDisposed()
|
||||||
{
|
{
|
||||||
var serviceContext = new TestServiceContext();
|
|
||||||
var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0))
|
var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0))
|
||||||
{
|
{
|
||||||
ConnectionAdapters =
|
ConnectionAdapters =
|
||||||
|
|
@ -568,7 +544,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
return context.Response.WriteAsync("hello world");
|
return context.Response.WriteAsync("hello world");
|
||||||
};
|
};
|
||||||
|
|
||||||
using (var server = new TestServer(app, serviceContext, listenOptions))
|
using (var server = new TestServer(app, new TestServiceContext(LoggerFactory), listenOptions))
|
||||||
{
|
{
|
||||||
// SslStream is used to ensure the certificate is actually passed to the server
|
// 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
|
// HttpClient might not send the certificate because it is invalid or it doesn't match any
|
||||||
|
|
@ -587,7 +563,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
public void AcceptsCertificateWithoutExtensions(string testCertName)
|
public void AcceptsCertificateWithoutExtensions(string testCertName)
|
||||||
{
|
{
|
||||||
var certPath = TestResources.GetCertPath(testCertName);
|
var certPath = TestResources.GetCertPath(testCertName);
|
||||||
_output.WriteLine("Loading " + certPath);
|
TestOutputHelper.WriteLine("Loading " + certPath);
|
||||||
var cert = new X509Certificate2(certPath, "testPassword");
|
var cert = new X509Certificate2(certPath, "testPassword");
|
||||||
Assert.Empty(cert.Extensions.OfType<X509EnhancedKeyUsageExtension>());
|
Assert.Empty(cert.Extensions.OfType<X509EnhancedKeyUsageExtension>());
|
||||||
|
|
||||||
|
|
@ -603,7 +579,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
public void ValidatesEnhancedKeyUsageOnCertificate(string testCertName)
|
public void ValidatesEnhancedKeyUsageOnCertificate(string testCertName)
|
||||||
{
|
{
|
||||||
var certPath = TestResources.GetCertPath(testCertName);
|
var certPath = TestResources.GetCertPath(testCertName);
|
||||||
_output.WriteLine("Loading " + certPath);
|
TestOutputHelper.WriteLine("Loading " + certPath);
|
||||||
var cert = new X509Certificate2(certPath, "testPassword");
|
var cert = new X509Certificate2(certPath, "testPassword");
|
||||||
Assert.NotEmpty(cert.Extensions);
|
Assert.NotEmpty(cert.Extensions);
|
||||||
var eku = Assert.Single(cert.Extensions.OfType<X509EnhancedKeyUsageExtension>());
|
var eku = Assert.Single(cert.Extensions.OfType<X509EnhancedKeyUsageExtension>());
|
||||||
|
|
@ -621,7 +597,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
public void ThrowsForCertificatesMissingServerEku(string testCertName)
|
public void ThrowsForCertificatesMissingServerEku(string testCertName)
|
||||||
{
|
{
|
||||||
var certPath = TestResources.GetCertPath(testCertName);
|
var certPath = TestResources.GetCertPath(testCertName);
|
||||||
_output.WriteLine("Loading " + certPath);
|
TestOutputHelper.WriteLine("Loading " + certPath);
|
||||||
var cert = new X509Certificate2(certPath, "testPassword");
|
var cert = new X509Certificate2(certPath, "testPassword");
|
||||||
Assert.NotEmpty(cert.Extensions);
|
Assert.NotEmpty(cert.Extensions);
|
||||||
var eku = Assert.Single(cert.Extensions.OfType<X509EnhancedKeyUsageExtension>());
|
var eku = Assert.Single(cert.Extensions.OfType<X509EnhancedKeyUsageExtension>());
|
||||||
|
|
|
||||||
|
|
@ -20,11 +20,12 @@ using Microsoft.AspNetCore.Testing;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Logging.Abstractions.Internal;
|
using Microsoft.Extensions.Logging.Abstractions.Internal;
|
||||||
|
using Microsoft.Extensions.Logging.Testing;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
public class HttpsTests
|
public class HttpsTests : LoggedTest
|
||||||
{
|
{
|
||||||
private KestrelServerOptions CreateServerOptions()
|
private KestrelServerOptions CreateServerOptions()
|
||||||
{
|
{
|
||||||
|
|
@ -117,6 +118,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
public async Task EmptyRequestLoggedAsDebug()
|
public async Task EmptyRequestLoggedAsDebug()
|
||||||
{
|
{
|
||||||
var loggerProvider = new HandshakeErrorLoggerProvider();
|
var loggerProvider = new HandshakeErrorLoggerProvider();
|
||||||
|
LoggerFactory.AddProvider(loggerProvider);
|
||||||
|
|
||||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||||
.UseKestrel(options =>
|
.UseKestrel(options =>
|
||||||
|
|
@ -126,11 +128,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword");
|
listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword");
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.ConfigureLogging(builder =>
|
.ConfigureServices(AddTestLogging)
|
||||||
{
|
.ConfigureLogging(builder => builder.AddProvider(loggerProvider))
|
||||||
builder.AddProvider(loggerProvider);
|
|
||||||
builder.SetMinimumLevel(LogLevel.Debug);
|
|
||||||
})
|
|
||||||
.Configure(app => { });
|
.Configure(app => { });
|
||||||
|
|
||||||
using (var host = hostBuilder.Build())
|
using (var host = hostBuilder.Build())
|
||||||
|
|
@ -155,6 +154,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
public async Task ClientHandshakeFailureLoggedAsDebug()
|
public async Task ClientHandshakeFailureLoggedAsDebug()
|
||||||
{
|
{
|
||||||
var loggerProvider = new HandshakeErrorLoggerProvider();
|
var loggerProvider = new HandshakeErrorLoggerProvider();
|
||||||
|
LoggerFactory.AddProvider(loggerProvider);
|
||||||
|
|
||||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||||
.UseKestrel(options =>
|
.UseKestrel(options =>
|
||||||
|
|
@ -164,11 +164,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword");
|
listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword");
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.ConfigureLogging(builder =>
|
.ConfigureServices(AddTestLogging)
|
||||||
{
|
|
||||||
builder.AddProvider(loggerProvider);
|
|
||||||
builder.SetMinimumLevel(LogLevel.Debug);
|
|
||||||
})
|
|
||||||
.Configure(app => { });
|
.Configure(app => { });
|
||||||
|
|
||||||
using (var host = hostBuilder.Build())
|
using (var host = hostBuilder.Build())
|
||||||
|
|
@ -196,6 +192,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
public async Task DoesNotThrowObjectDisposedExceptionOnConnectionAbort()
|
public async Task DoesNotThrowObjectDisposedExceptionOnConnectionAbort()
|
||||||
{
|
{
|
||||||
var loggerProvider = new HandshakeErrorLoggerProvider();
|
var loggerProvider = new HandshakeErrorLoggerProvider();
|
||||||
|
LoggerFactory.AddProvider(loggerProvider);
|
||||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||||
.UseKestrel(options =>
|
.UseKestrel(options =>
|
||||||
{
|
{
|
||||||
|
|
@ -204,6 +201,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword");
|
listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword");
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
.ConfigureServices(AddTestLogging)
|
||||||
.ConfigureLogging(builder => builder.AddProvider(loggerProvider))
|
.ConfigureLogging(builder => builder.AddProvider(loggerProvider))
|
||||||
.Configure(app => app.Run(async httpContext =>
|
.Configure(app => app.Run(async httpContext =>
|
||||||
{
|
{
|
||||||
|
|
@ -248,6 +246,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
var tcs = new TaskCompletionSource<object>();
|
var tcs = new TaskCompletionSource<object>();
|
||||||
var loggerProvider = new HandshakeErrorLoggerProvider();
|
var loggerProvider = new HandshakeErrorLoggerProvider();
|
||||||
|
LoggerFactory.AddProvider(loggerProvider);
|
||||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||||
.UseKestrel(options =>
|
.UseKestrel(options =>
|
||||||
{
|
{
|
||||||
|
|
@ -256,6 +255,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword");
|
listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword");
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
.ConfigureServices(AddTestLogging)
|
||||||
.ConfigureLogging(builder => builder.AddProvider(loggerProvider))
|
.ConfigureLogging(builder => builder.AddProvider(loggerProvider))
|
||||||
.Configure(app => app.Run(async httpContext =>
|
.Configure(app => app.Run(async httpContext =>
|
||||||
{
|
{
|
||||||
|
|
@ -297,6 +297,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
public async Task DoesNotThrowObjectDisposedExceptionOnEmptyConnection()
|
public async Task DoesNotThrowObjectDisposedExceptionOnEmptyConnection()
|
||||||
{
|
{
|
||||||
var loggerProvider = new HandshakeErrorLoggerProvider();
|
var loggerProvider = new HandshakeErrorLoggerProvider();
|
||||||
|
LoggerFactory.AddProvider(loggerProvider);
|
||||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||||
.UseKestrel(options =>
|
.UseKestrel(options =>
|
||||||
{
|
{
|
||||||
|
|
@ -305,6 +306,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword");
|
listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword");
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
.ConfigureServices(AddTestLogging)
|
||||||
.ConfigureLogging(builder => builder.AddProvider(loggerProvider))
|
.ConfigureLogging(builder => builder.AddProvider(loggerProvider))
|
||||||
.Configure(app => app.Run(httpContext => Task.CompletedTask));
|
.Configure(app => app.Run(httpContext => Task.CompletedTask));
|
||||||
|
|
||||||
|
|
@ -330,6 +332,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
public void ConnectionFilterDoesNotLeakBlock()
|
public void ConnectionFilterDoesNotLeakBlock()
|
||||||
{
|
{
|
||||||
var loggerProvider = new HandshakeErrorLoggerProvider();
|
var loggerProvider = new HandshakeErrorLoggerProvider();
|
||||||
|
LoggerFactory.AddProvider(loggerProvider);
|
||||||
|
|
||||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||||
.UseKestrel(options =>
|
.UseKestrel(options =>
|
||||||
|
|
@ -339,6 +342,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword");
|
listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword");
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
.ConfigureServices(AddTestLogging)
|
||||||
.ConfigureLogging(builder => builder.AddProvider(loggerProvider))
|
.ConfigureLogging(builder => builder.AddProvider(loggerProvider))
|
||||||
.Configure(app => { });
|
.Configure(app => { });
|
||||||
|
|
||||||
|
|
@ -360,6 +364,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
public async Task HandshakeTimesOutAndIsLoggedAsDebug()
|
public async Task HandshakeTimesOutAndIsLoggedAsDebug()
|
||||||
{
|
{
|
||||||
var loggerProvider = new HandshakeErrorLoggerProvider();
|
var loggerProvider = new HandshakeErrorLoggerProvider();
|
||||||
|
LoggerFactory.AddProvider(loggerProvider);
|
||||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||||
.UseKestrel(options =>
|
.UseKestrel(options =>
|
||||||
{
|
{
|
||||||
|
|
@ -372,11 +377,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.ConfigureLogging(builder =>
|
.ConfigureServices(AddTestLogging)
|
||||||
{
|
|
||||||
builder.AddProvider(loggerProvider);
|
|
||||||
builder.SetMinimumLevel(LogLevel.Debug);
|
|
||||||
})
|
|
||||||
.Configure(app => app.Run(httpContext => Task.CompletedTask));
|
.Configure(app => app.Run(httpContext => Task.CompletedTask));
|
||||||
|
|
||||||
using (var host = hostBuilder.Build())
|
using (var host = hostBuilder.Build())
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,12 @@ using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Http.Features;
|
using Microsoft.AspNetCore.Http.Features;
|
||||||
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
|
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Testing;
|
using Microsoft.AspNetCore.Testing;
|
||||||
|
using Microsoft.Extensions.Logging.Testing;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
public class KeepAliveTimeoutTests
|
public class KeepAliveTimeoutTests : LoggedTest
|
||||||
{
|
{
|
||||||
private static readonly TimeSpan _keepAliveTimeout = TimeSpan.FromSeconds(10);
|
private static readonly TimeSpan _keepAliveTimeout = TimeSpan.FromSeconds(10);
|
||||||
private static readonly TimeSpan _longDelay = TimeSpan.FromSeconds(30);
|
private static readonly TimeSpan _longDelay = TimeSpan.FromSeconds(30);
|
||||||
|
|
@ -185,7 +186,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
|
|
||||||
private TestServer CreateServer(CancellationToken longRunningCt, CancellationToken upgradeCt)
|
private TestServer CreateServer(CancellationToken longRunningCt, CancellationToken upgradeCt)
|
||||||
{
|
{
|
||||||
return new TestServer(httpContext => App(httpContext, longRunningCt, upgradeCt), new TestServiceContext
|
return new TestServer(httpContext => App(httpContext, longRunningCt, upgradeCt), new TestServiceContext(LoggerFactory)
|
||||||
{
|
{
|
||||||
// Use real SystemClock so timeouts trigger.
|
// Use real SystemClock so timeouts trigger.
|
||||||
SystemClock = new SystemClock(),
|
SystemClock = new SystemClock(),
|
||||||
|
|
|
||||||
|
|
@ -8,30 +8,18 @@ using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Testing;
|
using Microsoft.AspNetCore.Testing;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging.Testing;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using Xunit.Abstractions;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
public class LoggingConnectionAdapterTests
|
public class LoggingConnectionAdapterTests : LoggedTest
|
||||||
{
|
{
|
||||||
private readonly ITestOutputHelper _output;
|
|
||||||
|
|
||||||
public LoggingConnectionAdapterTests(ITestOutputHelper output)
|
|
||||||
{
|
|
||||||
_output = output;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task LoggingConnectionAdapterCanBeAddedBeforeAndAfterHttpsAdapter()
|
public async Task LoggingConnectionAdapterCanBeAddedBeforeAndAfterHttpsAdapter()
|
||||||
{
|
{
|
||||||
var host = TransportSelector.GetWebHostBuilder()
|
var host = TransportSelector.GetWebHostBuilder()
|
||||||
.ConfigureLogging(builder =>
|
.ConfigureServices(AddTestLogging)
|
||||||
{
|
|
||||||
builder.SetMinimumLevel(LogLevel.Trace);
|
|
||||||
builder.AddXunit(_output);
|
|
||||||
})
|
|
||||||
.UseKestrel(options =>
|
.UseKestrel(options =>
|
||||||
{
|
{
|
||||||
options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions =>
|
options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions =>
|
||||||
|
|
@ -41,15 +29,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
listenOptions.UseConnectionLogging();
|
listenOptions.UseConnectionLogging();
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.Configure(app =>
|
.Configure(app =>
|
||||||
{
|
|
||||||
app.Run(context =>
|
|
||||||
{
|
{
|
||||||
context.Response.ContentLength = 12;
|
app.Run(context =>
|
||||||
return context.Response.WriteAsync("Hello World!");
|
{
|
||||||
});
|
context.Response.ContentLength = 12;
|
||||||
})
|
return context.Response.WriteAsync("Hello World!");
|
||||||
.Build();
|
});
|
||||||
|
})
|
||||||
|
.Build();
|
||||||
|
|
||||||
using (host)
|
using (host)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,12 @@ using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http.Features;
|
using Microsoft.AspNetCore.Http.Features;
|
||||||
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
||||||
using Microsoft.AspNetCore.Testing;
|
using Microsoft.AspNetCore.Testing;
|
||||||
|
using Microsoft.Extensions.Logging.Testing;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
public class MaxRequestBodySizeTests
|
public class MaxRequestBodySizeTests : LoggedTest
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task RejectsRequestWithContentLengthHeaderExceedingGlobalLimit()
|
public async Task RejectsRequestWithContentLengthHeaderExceedingGlobalLimit()
|
||||||
|
|
@ -28,7 +29,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
async () => await context.Request.Body.ReadAsync(buffer, 0, 1));
|
async () => await context.Request.Body.ReadAsync(buffer, 0, 1));
|
||||||
throw requestRejectedEx;
|
throw requestRejectedEx;
|
||||||
},
|
},
|
||||||
new TestServiceContext { ServerOptions = { Limits = { MaxRequestBodySize = globalMaxRequestBodySize } } }))
|
new TestServiceContext(LoggerFactory) { ServerOptions = { Limits = { MaxRequestBodySize = globalMaxRequestBodySize } } }))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
@ -74,7 +75,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
async () => await context.Request.Body.ReadAsync(buffer, 0, 1));
|
async () => await context.Request.Body.ReadAsync(buffer, 0, 1));
|
||||||
throw requestRejectedEx;
|
throw requestRejectedEx;
|
||||||
},
|
},
|
||||||
new TestServiceContext { ServerOptions = { Limits = { MaxRequestBodySize = globalMaxRequestBodySize } } }))
|
new TestServiceContext(LoggerFactory) { ServerOptions = { Limits = { MaxRequestBodySize = globalMaxRequestBodySize } } }))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
@ -118,7 +119,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
context.Response.ContentLength = 1;
|
context.Response.ContentLength = 1;
|
||||||
await context.Response.Body.WriteAsync(buffer, 0, 1);
|
await context.Response.Body.WriteAsync(buffer, 0, 1);
|
||||||
},
|
},
|
||||||
new TestServiceContext { ServerOptions = { Limits = { MaxRequestBodySize = 0 } } }))
|
new TestServiceContext(LoggerFactory) { ServerOptions = { Limits = { MaxRequestBodySize = 0 } } }))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
@ -190,7 +191,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
invalidOpEx = Assert.Throws<InvalidOperationException>(() =>
|
invalidOpEx = Assert.Throws<InvalidOperationException>(() =>
|
||||||
feature.MaxRequestBodySize = perRequestMaxRequestBodySize);
|
feature.MaxRequestBodySize = perRequestMaxRequestBodySize);
|
||||||
throw invalidOpEx;
|
throw invalidOpEx;
|
||||||
}))
|
}, new TestServiceContext(LoggerFactory)))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
@ -230,7 +231,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
invalidOpEx = Assert.Throws<InvalidOperationException>(() =>
|
invalidOpEx = Assert.Throws<InvalidOperationException>(() =>
|
||||||
feature.MaxRequestBodySize = 0x10);
|
feature.MaxRequestBodySize = 0x10);
|
||||||
throw invalidOpEx;
|
throw invalidOpEx;
|
||||||
}))
|
}, new TestServiceContext(LoggerFactory)))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
@ -267,7 +268,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
async () => await context.Request.Body.ReadAsync(buffer, 0, 1));
|
async () => await context.Request.Body.ReadAsync(buffer, 0, 1));
|
||||||
throw requestRejectedEx2;
|
throw requestRejectedEx2;
|
||||||
},
|
},
|
||||||
new TestServiceContext { ServerOptions = { Limits = { MaxRequestBodySize = 0 } } }))
|
new TestServiceContext(LoggerFactory) { ServerOptions = { Limits = { MaxRequestBodySize = 0 } } }))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
@ -314,7 +315,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
|
|
||||||
throw requestRejectedEx;
|
throw requestRejectedEx;
|
||||||
},
|
},
|
||||||
new TestServiceContext { ServerOptions = { Limits = { MaxRequestBodySize = globalMaxRequestBodySize } } }))
|
new TestServiceContext(LoggerFactory) { ServerOptions = { Limits = { MaxRequestBodySize = globalMaxRequestBodySize } } }))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
@ -360,7 +361,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
Assert.Equal("Hello World", Encoding.ASCII.GetString(buffer));
|
Assert.Equal("Hello World", Encoding.ASCII.GetString(buffer));
|
||||||
Assert.Equal("trailing-value", context.Request.Headers["Trailing-Header"].ToString());
|
Assert.Equal("trailing-value", context.Request.Headers["Trailing-Header"].ToString());
|
||||||
},
|
},
|
||||||
new TestServiceContext { ServerOptions = { Limits = { MaxRequestBodySize = globalMaxRequestBodySize } } }))
|
new TestServiceContext(LoggerFactory) { ServerOptions = { Limits = { MaxRequestBodySize = globalMaxRequestBodySize } } }))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
@ -419,7 +420,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
throw requestRejectedEx;
|
throw requestRejectedEx;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
new TestServiceContext { ServerOptions = { Limits = { MaxRequestBodySize = globalMaxRequestBodySize } } }))
|
new TestServiceContext(LoggerFactory) { ServerOptions = { Limits = { MaxRequestBodySize = globalMaxRequestBodySize } } }))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
@ -466,7 +467,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
async () => await context.Request.Body.ReadAsync(buffer, 0, 1));
|
async () => await context.Request.Body.ReadAsync(buffer, 0, 1));
|
||||||
throw requestRejectedEx2;
|
throw requestRejectedEx2;
|
||||||
},
|
},
|
||||||
new TestServiceContext { ServerOptions = { Limits = { MaxRequestBodySize = 0 } } }))
|
new TestServiceContext(LoggerFactory) { ServerOptions = { Limits = { MaxRequestBodySize = 0 } } }))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -13,13 +13,12 @@ using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Testing;
|
using Microsoft.AspNetCore.Testing;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging.Testing;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using Xunit.Abstractions;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
public class MaxRequestBufferSizeTests
|
public class MaxRequestBufferSizeTests : LoggedTest
|
||||||
{
|
{
|
||||||
private const int _dataLength = 20 * 1024 * 1024;
|
private const int _dataLength = 20 * 1024 * 1024;
|
||||||
|
|
||||||
|
|
@ -30,13 +29,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
"\r\n"
|
"\r\n"
|
||||||
};
|
};
|
||||||
|
|
||||||
private readonly Action<ILoggingBuilder> _configureLoggingDelegate;
|
|
||||||
|
|
||||||
public MaxRequestBufferSizeTests(ITestOutputHelper output)
|
|
||||||
{
|
|
||||||
_configureLoggingDelegate = builder => builder.AddXunit(output);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IEnumerable<object[]> LargeUploadData
|
public static IEnumerable<object[]> LargeUploadData
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
|
@ -259,7 +251,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
TaskCompletionSource<object> clientFinishedSendingRequestBody)
|
TaskCompletionSource<object> clientFinishedSendingRequestBody)
|
||||||
{
|
{
|
||||||
var host = TransportSelector.GetWebHostBuilder()
|
var host = TransportSelector.GetWebHostBuilder()
|
||||||
.ConfigureLogging(_configureLoggingDelegate)
|
.ConfigureServices(AddTestLogging)
|
||||||
.UseKestrel(options =>
|
.UseKestrel(options =>
|
||||||
{
|
{
|
||||||
options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions =>
|
options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions =>
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,12 @@ using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
||||||
using Microsoft.AspNetCore.Testing;
|
using Microsoft.AspNetCore.Testing;
|
||||||
|
using Microsoft.Extensions.Logging.Testing;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
public class MaxRequestLineSizeTests
|
public class MaxRequestLineSizeTests : LoggedTest
|
||||||
{
|
{
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("GET / HTTP/1.1\r\nHost:\r\n\r\n", 16)]
|
[InlineData("GET / HTTP/1.1\r\nHost:\r\n\r\n", 16)]
|
||||||
|
|
@ -70,7 +71,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
|
|
||||||
private TestServer CreateServer(int maxRequestLineSize)
|
private TestServer CreateServer(int maxRequestLineSize)
|
||||||
{
|
{
|
||||||
return new TestServer(async httpContext => await httpContext.Response.WriteAsync("hello, world"), new TestServiceContext
|
return new TestServer(async httpContext => await httpContext.Response.WriteAsync("hello, world"), new TestServiceContext(LoggerFactory)
|
||||||
{
|
{
|
||||||
ServerOptions = new KestrelServerOptions
|
ServerOptions = new KestrelServerOptions
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,12 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using Microsoft.Extensions.Logging.Testing;
|
||||||
#if MACOS
|
#if MACOS
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
[assembly: ShortClassName]
|
||||||
|
#if MACOS
|
||||||
[assembly: CollectionBehavior(DisableTestParallelization = true)]
|
[assembly: CollectionBehavior(DisableTestParallelization = true)]
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -17,14 +17,14 @@ using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
public class RequestBodyTimeoutTests
|
public class RequestBodyTimeoutTests : LoggedTest
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task RequestTimesOutWhenRequestBodyNotReceivedAtSpecifiedMinimumRate()
|
public async Task RequestTimesOutWhenRequestBodyNotReceivedAtSpecifiedMinimumRate()
|
||||||
{
|
{
|
||||||
var gracePeriod = TimeSpan.FromSeconds(5);
|
var gracePeriod = TimeSpan.FromSeconds(5);
|
||||||
var systemClock = new MockSystemClock();
|
var systemClock = new MockSystemClock();
|
||||||
var serviceContext = new TestServiceContext
|
var serviceContext = new TestServiceContext(LoggerFactory)
|
||||||
{
|
{
|
||||||
SystemClock = systemClock,
|
SystemClock = systemClock,
|
||||||
DateHeaderValueManager = new DateHeaderValueManager(systemClock)
|
DateHeaderValueManager = new DateHeaderValueManager(systemClock)
|
||||||
|
|
@ -69,16 +69,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task RequestTimesOutWhenNotDrainedWithinDrainTimeoutPeriod()
|
public async Task RequestTimesOutWhenNotDrainedWithinDrainTimeoutPeriod()
|
||||||
{
|
{
|
||||||
var sink = new TestSink();
|
|
||||||
var logger = new TestLogger("TestLogger", sink, enabled: true);
|
|
||||||
|
|
||||||
// This test requires a real clock since we can't control when the drain timeout is set
|
// This test requires a real clock since we can't control when the drain timeout is set
|
||||||
var systemClock = new SystemClock();
|
var systemClock = new SystemClock();
|
||||||
var serviceContext = new TestServiceContext
|
var serviceContext = new TestServiceContext(LoggerFactory)
|
||||||
{
|
{
|
||||||
SystemClock = systemClock,
|
SystemClock = systemClock,
|
||||||
DateHeaderValueManager = new DateHeaderValueManager(systemClock),
|
DateHeaderValueManager = new DateHeaderValueManager(systemClock),
|
||||||
Log = new KestrelTrace(logger)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var appRunningEvent = new ManualResetEventSlim();
|
var appRunningEvent = new ManualResetEventSlim();
|
||||||
|
|
@ -115,7 +111,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.Contains(sink.Writes, w => w.EventId.Id == 17 && w.LogLevel == LogLevel.Information && w.Exception is BadHttpRequestException
|
Assert.Contains(TestSink.Writes, w => w.EventId.Id == 17 && w.LogLevel == LogLevel.Information && w.Exception is BadHttpRequestException
|
||||||
&& ((BadHttpRequestException)w.Exception).StatusCode == StatusCodes.Status408RequestTimeout);
|
&& ((BadHttpRequestException)w.Exception).StatusCode == StatusCodes.Status408RequestTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -124,7 +120,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
var gracePeriod = TimeSpan.FromSeconds(5);
|
var gracePeriod = TimeSpan.FromSeconds(5);
|
||||||
var systemClock = new MockSystemClock();
|
var systemClock = new MockSystemClock();
|
||||||
var serviceContext = new TestServiceContext
|
var serviceContext = new TestServiceContext(LoggerFactory)
|
||||||
{
|
{
|
||||||
SystemClock = systemClock,
|
SystemClock = systemClock,
|
||||||
DateHeaderValueManager = new DateHeaderValueManager(systemClock)
|
DateHeaderValueManager = new DateHeaderValueManager(systemClock)
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,12 @@ using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
||||||
using Microsoft.AspNetCore.Testing;
|
using Microsoft.AspNetCore.Testing;
|
||||||
|
using Microsoft.Extensions.Logging.Testing;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
public class RequestHeaderLimitsTests
|
public class RequestHeaderLimitsTests : LoggedTest
|
||||||
{
|
{
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(0, 1)]
|
[InlineData(0, 1)]
|
||||||
|
|
@ -148,7 +149,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
options.Limits.MaxRequestHeadersTotalSize = maxRequestHeadersTotalSize.Value;
|
options.Limits.MaxRequestHeadersTotalSize = maxRequestHeadersTotalSize.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new TestServer(async httpContext => await httpContext.Response.WriteAsync("hello, world"), new TestServiceContext
|
return new TestServer(async httpContext => await httpContext.Response.WriteAsync("hello, world"), new TestServiceContext(LoggerFactory)
|
||||||
{
|
{
|
||||||
ServerOptions = options
|
ServerOptions = options
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,12 @@ using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
|
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Testing;
|
using Microsoft.AspNetCore.Testing;
|
||||||
|
using Microsoft.Extensions.Logging.Testing;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
public class RequestHeadersTimeoutTests
|
public class RequestHeadersTimeoutTests : LoggedTest
|
||||||
{
|
{
|
||||||
private static readonly TimeSpan RequestHeadersTimeout = TimeSpan.FromSeconds(10);
|
private static readonly TimeSpan RequestHeadersTimeout = TimeSpan.FromSeconds(10);
|
||||||
private static readonly TimeSpan LongDelay = TimeSpan.FromSeconds(30);
|
private static readonly TimeSpan LongDelay = TimeSpan.FromSeconds(30);
|
||||||
|
|
@ -96,7 +97,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
await httpContext.Request.Body.ReadAsync(new byte[1], 0, 1);
|
await httpContext.Request.Body.ReadAsync(new byte[1], 0, 1);
|
||||||
await httpContext.Response.WriteAsync("hello, world");
|
await httpContext.Response.WriteAsync("hello, world");
|
||||||
},
|
},
|
||||||
new TestServiceContext
|
new TestServiceContext(LoggerFactory)
|
||||||
{
|
{
|
||||||
// Use real SystemClock so timeouts trigger.
|
// Use real SystemClock so timeouts trigger.
|
||||||
SystemClock = new SystemClock(),
|
SystemClock = new SystemClock(),
|
||||||
|
|
|
||||||
|
|
@ -9,16 +9,17 @@ using Microsoft.AspNetCore.Server.Kestrel.Core;
|
||||||
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http;
|
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http;
|
||||||
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
|
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Testing;
|
using Microsoft.AspNetCore.Testing;
|
||||||
|
using Microsoft.Extensions.Logging.Testing;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
public class RequestTargetProcessingTests
|
public class RequestTargetProcessingTests : LoggedTest
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task RequestPathIsNotNormalized()
|
public async Task RequestPathIsNotNormalized()
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext();
|
var testContext = new TestServiceContext(LoggerFactory);
|
||||||
var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0));
|
var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0));
|
||||||
|
|
||||||
using (var server = new TestServer(async context =>
|
using (var server = new TestServer(async context =>
|
||||||
|
|
@ -64,7 +65,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[InlineData("/base/hello%20world?foo=1&bar=2")]
|
[InlineData("/base/hello%20world?foo=1&bar=2")]
|
||||||
public async Task RequestFeatureContainsRawTarget(string requestTarget)
|
public async Task RequestFeatureContainsRawTarget(string requestTarget)
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext();
|
var testContext = new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
using (var server = new TestServer(async context =>
|
using (var server = new TestServer(async context =>
|
||||||
{
|
{
|
||||||
|
|
@ -96,7 +97,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[InlineData(HttpMethod.Connect, "host")]
|
[InlineData(HttpMethod.Connect, "host")]
|
||||||
public async Task NonPathRequestTargetSetInRawTarget(HttpMethod method, string requestTarget)
|
public async Task NonPathRequestTargetSetInRawTarget(HttpMethod method, string requestTarget)
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext();
|
var testContext = new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
using (var server = new TestServer(async context =>
|
using (var server = new TestServer(async context =>
|
||||||
{
|
{
|
||||||
|
|
@ -111,8 +112,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
var host = method == HttpMethod.Connect
|
var host = method == HttpMethod.Connect
|
||||||
? requestTarget
|
? requestTarget
|
||||||
: string.Empty;
|
: string.Empty;
|
||||||
|
|
||||||
await connection.Send(
|
await connection.Send(
|
||||||
|
|
|
||||||
|
|
@ -26,27 +26,20 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Testing;
|
using Microsoft.AspNetCore.Testing;
|
||||||
using Microsoft.AspNetCore.Testing.xunit;
|
using Microsoft.AspNetCore.Testing.xunit;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.Extensions.Logging.Testing;
|
||||||
using Moq;
|
using Moq;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using Xunit.Abstractions;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
public class RequestTests
|
public class RequestTests : LoggedTest
|
||||||
{
|
{
|
||||||
private const int _connectionStartedEventId = 1;
|
private const int _connectionStartedEventId = 1;
|
||||||
private const int _connectionResetEventId = 19;
|
private const int _connectionResetEventId = 19;
|
||||||
private static readonly int _semaphoreWaitTimeout = Debugger.IsAttached ? 10000 : 2500;
|
private static readonly int _semaphoreWaitTimeout = Debugger.IsAttached ? 10000 : 2500;
|
||||||
|
|
||||||
private readonly ITestOutputHelper _output;
|
|
||||||
|
|
||||||
public RequestTests(ITestOutputHelper output)
|
|
||||||
{
|
|
||||||
_output = output;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static TheoryData<ListenOptions> ConnectionAdapterData => new TheoryData<ListenOptions>
|
public static TheoryData<ListenOptions> ConnectionAdapterData => new TheoryData<ListenOptions>
|
||||||
{
|
{
|
||||||
new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)),
|
new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)),
|
||||||
|
|
@ -70,6 +63,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
Assert.True(bufferLength % 256 == 0, $"{nameof(bufferLength)} must be evenly divisible by 256");
|
Assert.True(bufferLength % 256 == 0, $"{nameof(bufferLength)} must be evenly divisible by 256");
|
||||||
|
|
||||||
var builder = TransportSelector.GetWebHostBuilder()
|
var builder = TransportSelector.GetWebHostBuilder()
|
||||||
|
.ConfigureServices(AddTestLogging)
|
||||||
.UseKestrel(options =>
|
.UseKestrel(options =>
|
||||||
{
|
{
|
||||||
options.Limits.MaxRequestBodySize = contentLength;
|
options.Limits.MaxRequestBodySize = contentLength;
|
||||||
|
|
@ -158,6 +152,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
var builder = TransportSelector.GetWebHostBuilder()
|
var builder = TransportSelector.GetWebHostBuilder()
|
||||||
.UseKestrel()
|
.UseKestrel()
|
||||||
.UseUrls("http://127.0.0.1:0")
|
.UseUrls("http://127.0.0.1:0")
|
||||||
|
.ConfigureServices(AddTestLogging)
|
||||||
.Configure(app =>
|
.Configure(app =>
|
||||||
{
|
{
|
||||||
app.Run(async context =>
|
app.Run(async context =>
|
||||||
|
|
@ -186,28 +181,29 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
var responseBodyPersisted = false;
|
var responseBodyPersisted = false;
|
||||||
|
|
||||||
var builder = TransportSelector.GetWebHostBuilder()
|
var builder = TransportSelector.GetWebHostBuilder()
|
||||||
.UseKestrel()
|
.UseKestrel()
|
||||||
.UseUrls("http://127.0.0.1:0")
|
.UseUrls("http://127.0.0.1:0")
|
||||||
.Configure(app =>
|
.ConfigureServices(AddTestLogging)
|
||||||
{
|
.Configure(app =>
|
||||||
app.Run(async context =>
|
{
|
||||||
{
|
app.Run(async context =>
|
||||||
if (context.Request.Body is MemoryStream)
|
{
|
||||||
{
|
if (context.Request.Body is MemoryStream)
|
||||||
requestBodyPersisted = true;
|
{
|
||||||
}
|
requestBodyPersisted = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (context.Response.Body is MemoryStream)
|
if (context.Response.Body is MemoryStream)
|
||||||
{
|
{
|
||||||
responseBodyPersisted = true;
|
responseBodyPersisted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
context.Request.Body = new MemoryStream();
|
context.Request.Body = new MemoryStream();
|
||||||
context.Response.Body = new MemoryStream();
|
context.Response.Body = new MemoryStream();
|
||||||
|
|
||||||
await context.Response.WriteAsync("hello, world");
|
await context.Response.WriteAsync("hello, world");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
using (var host = builder.Build())
|
using (var host = builder.Build())
|
||||||
{
|
{
|
||||||
|
|
@ -229,24 +225,25 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
var dataRead = false;
|
var dataRead = false;
|
||||||
var builder = TransportSelector.GetWebHostBuilder()
|
var builder = TransportSelector.GetWebHostBuilder()
|
||||||
.UseKestrel()
|
.UseKestrel()
|
||||||
.UseUrls("http://127.0.0.1:0")
|
.UseUrls("http://127.0.0.1:0")
|
||||||
.Configure(app =>
|
.ConfigureServices(AddTestLogging)
|
||||||
{
|
.Configure(app =>
|
||||||
app.Run(async context =>
|
{
|
||||||
{
|
app.Run(async context =>
|
||||||
var stream = await context.Features.Get<IHttpUpgradeFeature>().UpgradeAsync();
|
{
|
||||||
var data = new byte[3];
|
var stream = await context.Features.Get<IHttpUpgradeFeature>().UpgradeAsync();
|
||||||
var bytesRead = 0;
|
var data = new byte[3];
|
||||||
|
var bytesRead = 0;
|
||||||
|
|
||||||
while (bytesRead < 3)
|
while (bytesRead < 3)
|
||||||
{
|
{
|
||||||
bytesRead += await stream.ReadAsync(data, bytesRead, data.Length - bytesRead);
|
bytesRead += await stream.ReadAsync(data, bytesRead, data.Length - bytesRead);
|
||||||
}
|
}
|
||||||
|
|
||||||
dataRead = Encoding.ASCII.GetString(data, 0, 3) == "abc";
|
dataRead = Encoding.ASCII.GetString(data, 0, 3) == "abc";
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
using (var host = builder.Build())
|
using (var host = builder.Build())
|
||||||
{
|
{
|
||||||
|
|
@ -280,6 +277,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
.Setup(logger => logger.Log(It.IsAny<LogLevel>(), It.IsAny<EventId>(), It.IsAny<object>(), It.IsAny<Exception>(), It.IsAny<Func<object, Exception, string>>()))
|
.Setup(logger => logger.Log(It.IsAny<LogLevel>(), It.IsAny<EventId>(), It.IsAny<object>(), It.IsAny<Exception>(), It.IsAny<Func<object, Exception, string>>()))
|
||||||
.Callback<LogLevel, EventId, object, Exception, Func<object, Exception, string>>((logLevel, eventId, state, exception, formatter) =>
|
.Callback<LogLevel, EventId, object, Exception, Func<object, Exception, string>>((logLevel, eventId, state, exception, formatter) =>
|
||||||
{
|
{
|
||||||
|
Logger.Log(logLevel, eventId, state, exception, formatter);
|
||||||
if (eventId.Id == _connectionStartedEventId)
|
if (eventId.Id == _connectionStartedEventId)
|
||||||
{
|
{
|
||||||
connectionStarted.Release();
|
connectionStarted.Release();
|
||||||
|
|
@ -298,7 +296,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
var mockLoggerFactory = new Mock<ILoggerFactory>();
|
var mockLoggerFactory = new Mock<ILoggerFactory>();
|
||||||
mockLoggerFactory
|
mockLoggerFactory
|
||||||
.Setup(factory => factory.CreateLogger(It.IsAny<string>()))
|
.Setup(factory => factory.CreateLogger(It.IsAny<string>()))
|
||||||
.Returns(Mock.Of<ILogger>());
|
.Returns(Logger);
|
||||||
mockLoggerFactory
|
mockLoggerFactory
|
||||||
.Setup(factory => factory.CreateLogger(It.IsIn("Microsoft.AspNetCore.Server.Kestrel",
|
.Setup(factory => factory.CreateLogger(It.IsIn("Microsoft.AspNetCore.Server.Kestrel",
|
||||||
"Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv",
|
"Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv",
|
||||||
|
|
@ -340,6 +338,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
.Setup(logger => logger.Log(It.IsAny<LogLevel>(), It.IsAny<EventId>(), It.IsAny<object>(), It.IsAny<Exception>(), It.IsAny<Func<object, Exception, string>>()))
|
.Setup(logger => logger.Log(It.IsAny<LogLevel>(), It.IsAny<EventId>(), It.IsAny<object>(), It.IsAny<Exception>(), It.IsAny<Func<object, Exception, string>>()))
|
||||||
.Callback<LogLevel, EventId, object, Exception, Func<object, Exception, string>>((logLevel, eventId, state, exception, formatter) =>
|
.Callback<LogLevel, EventId, object, Exception, Func<object, Exception, string>>((logLevel, eventId, state, exception, formatter) =>
|
||||||
{
|
{
|
||||||
|
Logger.Log(logLevel, eventId, state, exception, formatter);
|
||||||
if (eventId.Id == _connectionResetEventId)
|
if (eventId.Id == _connectionResetEventId)
|
||||||
{
|
{
|
||||||
connectionReset.Release();
|
connectionReset.Release();
|
||||||
|
|
@ -354,7 +353,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
var mockLoggerFactory = new Mock<ILoggerFactory>();
|
var mockLoggerFactory = new Mock<ILoggerFactory>();
|
||||||
mockLoggerFactory
|
mockLoggerFactory
|
||||||
.Setup(factory => factory.CreateLogger(It.IsAny<string>()))
|
.Setup(factory => factory.CreateLogger(It.IsAny<string>()))
|
||||||
.Returns(Mock.Of<ILogger>());
|
.Returns(Logger);
|
||||||
mockLoggerFactory
|
mockLoggerFactory
|
||||||
.Setup(factory => factory.CreateLogger(It.IsIn("Microsoft.AspNetCore.Server.Kestrel",
|
.Setup(factory => factory.CreateLogger(It.IsIn("Microsoft.AspNetCore.Server.Kestrel",
|
||||||
"Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv",
|
"Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv",
|
||||||
|
|
@ -410,8 +409,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
.Setup(logger => logger.Log(It.IsAny<LogLevel>(), It.IsAny<EventId>(), It.IsAny<object>(), It.IsAny<Exception>(), It.IsAny<Func<object, Exception, string>>()))
|
.Setup(logger => logger.Log(It.IsAny<LogLevel>(), It.IsAny<EventId>(), It.IsAny<object>(), It.IsAny<Exception>(), It.IsAny<Func<object, Exception, string>>()))
|
||||||
.Callback<LogLevel, EventId, object, Exception, Func<object, Exception, string>>((logLevel, eventId, state, exception, formatter) =>
|
.Callback<LogLevel, EventId, object, Exception, Func<object, Exception, string>>((logLevel, eventId, state, exception, formatter) =>
|
||||||
{
|
{
|
||||||
|
Logger.Log(logLevel, eventId, state, exception, formatter);
|
||||||
var log = $"Log {logLevel}[{eventId}]: {formatter(state, exception)} {exception}";
|
var log = $"Log {logLevel}[{eventId}]: {formatter(state, exception)} {exception}";
|
||||||
_output.WriteLine(log);
|
TestOutputHelper.WriteLine(log);
|
||||||
|
|
||||||
if (eventId.Id == _connectionResetEventId)
|
if (eventId.Id == _connectionResetEventId)
|
||||||
{
|
{
|
||||||
|
|
@ -427,7 +427,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
var mockLoggerFactory = new Mock<ILoggerFactory>();
|
var mockLoggerFactory = new Mock<ILoggerFactory>();
|
||||||
mockLoggerFactory
|
mockLoggerFactory
|
||||||
.Setup(factory => factory.CreateLogger(It.IsAny<string>()))
|
.Setup(factory => factory.CreateLogger(It.IsAny<string>()))
|
||||||
.Returns(Mock.Of<ILogger>());
|
.Returns(Logger);
|
||||||
mockLoggerFactory
|
mockLoggerFactory
|
||||||
.Setup(factory => factory.CreateLogger(It.IsIn("Microsoft.AspNetCore.Server.Kestrel",
|
.Setup(factory => factory.CreateLogger(It.IsIn("Microsoft.AspNetCore.Server.Kestrel",
|
||||||
"Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv",
|
"Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv",
|
||||||
|
|
@ -472,6 +472,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
var expectedExceptionThrown = false;
|
var expectedExceptionThrown = false;
|
||||||
|
|
||||||
var builder = TransportSelector.GetWebHostBuilder()
|
var builder = TransportSelector.GetWebHostBuilder()
|
||||||
|
.ConfigureServices(AddTestLogging)
|
||||||
.UseKestrel()
|
.UseKestrel()
|
||||||
.UseUrls("http://127.0.0.1:0")
|
.UseUrls("http://127.0.0.1:0")
|
||||||
.Configure(app => app.Run(async context =>
|
.Configure(app => app.Run(async context =>
|
||||||
|
|
@ -518,6 +519,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
var builder = TransportSelector.GetWebHostBuilder()
|
var builder = TransportSelector.GetWebHostBuilder()
|
||||||
.UseKestrel()
|
.UseKestrel()
|
||||||
.UseUrls("http://127.0.0.1:0")
|
.UseUrls("http://127.0.0.1:0")
|
||||||
|
.ConfigureServices(AddTestLogging)
|
||||||
.Configure(app => app.Run(async context =>
|
.Configure(app => app.Run(async context =>
|
||||||
{
|
{
|
||||||
appStarted.Release();
|
appStarted.Release();
|
||||||
|
|
@ -548,6 +550,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
var builder = TransportSelector.GetWebHostBuilder()
|
var builder = TransportSelector.GetWebHostBuilder()
|
||||||
.UseKestrel()
|
.UseKestrel()
|
||||||
.UseUrls("http://127.0.0.1:0")
|
.UseUrls("http://127.0.0.1:0")
|
||||||
|
.ConfigureServices(AddTestLogging)
|
||||||
.Configure(app => app.Run(context =>
|
.Configure(app => app.Run(context =>
|
||||||
{
|
{
|
||||||
context.Abort();
|
context.Abort();
|
||||||
|
|
@ -597,7 +600,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
queryTcs.TrySetResult(context.Request.Query);
|
queryTcs.TrySetResult(context.Request.Query);
|
||||||
rawTargetTcs.TrySetResult(context.Features.Get<IHttpRequestFeature>().RawTarget);
|
rawTargetTcs.TrySetResult(context.Features.Get<IHttpRequestFeature>().RawTarget);
|
||||||
await context.Response.WriteAsync("Done");
|
await context.Response.WriteAsync("Done");
|
||||||
}))
|
}, new TestServiceContext(LoggerFactory)))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
@ -646,7 +649,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
context.TraceIdentifier = knownId;
|
context.TraceIdentifier = knownId;
|
||||||
await context.Response.WriteAsync(context.TraceIdentifier);
|
await context.Response.WriteAsync(context.TraceIdentifier);
|
||||||
}))
|
}, new TestServiceContext(LoggerFactory)))
|
||||||
{
|
{
|
||||||
var requestId = await HttpClientSlim.GetStringAsync($"http://{server.EndPoint}")
|
var requestId = await HttpClientSlim.GetStringAsync($"http://{server.EndPoint}")
|
||||||
.TimeoutAfter(TestConstants.DefaultTimeout);
|
.TimeoutAfter(TestConstants.DefaultTimeout);
|
||||||
|
|
@ -665,7 +668,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
Assert.Equal(identifierLength, Encoding.ASCII.GetByteCount(context.TraceIdentifier));
|
Assert.Equal(identifierLength, Encoding.ASCII.GetByteCount(context.TraceIdentifier));
|
||||||
context.Response.ContentLength = identifierLength;
|
context.Response.ContentLength = identifierLength;
|
||||||
await context.Response.WriteAsync(context.TraceIdentifier);
|
await context.Response.WriteAsync(context.TraceIdentifier);
|
||||||
}))
|
}, new TestServiceContext(LoggerFactory)))
|
||||||
{
|
{
|
||||||
var usedIds = new ConcurrentBag<string>();
|
var usedIds = new ConcurrentBag<string>();
|
||||||
var uri = $"http://{server.EndPoint}";
|
var uri = $"http://{server.EndPoint}";
|
||||||
|
|
@ -706,7 +709,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[MemberData(nameof(ConnectionAdapterData))]
|
[MemberData(nameof(ConnectionAdapterData))]
|
||||||
public async Task Http11KeptAliveByDefault(ListenOptions listenOptions)
|
public async Task Http11KeptAliveByDefault(ListenOptions listenOptions)
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext();
|
var testContext = new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
using (var server = new TestServer(TestApp.EchoAppChunked, testContext, listenOptions))
|
using (var server = new TestServer(TestApp.EchoAppChunked, testContext, listenOptions))
|
||||||
{
|
{
|
||||||
|
|
@ -741,7 +744,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[MemberData(nameof(ConnectionAdapterData))]
|
[MemberData(nameof(ConnectionAdapterData))]
|
||||||
public async Task Http10NotKeptAliveByDefault(ListenOptions listenOptions)
|
public async Task Http10NotKeptAliveByDefault(ListenOptions listenOptions)
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext();
|
var testContext = new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
using (var server = new TestServer(TestApp.EchoApp, testContext, listenOptions))
|
using (var server = new TestServer(TestApp.EchoApp, testContext, listenOptions))
|
||||||
{
|
{
|
||||||
|
|
@ -781,7 +784,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[MemberData(nameof(ConnectionAdapterData))]
|
[MemberData(nameof(ConnectionAdapterData))]
|
||||||
public async Task Http10KeepAlive(ListenOptions listenOptions)
|
public async Task Http10KeepAlive(ListenOptions listenOptions)
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext();
|
var testContext = new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
using (var server = new TestServer(TestApp.EchoAppChunked, testContext, listenOptions))
|
using (var server = new TestServer(TestApp.EchoAppChunked, testContext, listenOptions))
|
||||||
{
|
{
|
||||||
|
|
@ -816,7 +819,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[MemberData(nameof(ConnectionAdapterData))]
|
[MemberData(nameof(ConnectionAdapterData))]
|
||||||
public async Task Http10KeepAliveNotHonoredIfResponseContentLengthNotSet(ListenOptions listenOptions)
|
public async Task Http10KeepAliveNotHonoredIfResponseContentLengthNotSet(ListenOptions listenOptions)
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext();
|
var testContext = new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
using (var server = new TestServer(TestApp.EchoApp, testContext, listenOptions))
|
using (var server = new TestServer(TestApp.EchoApp, testContext, listenOptions))
|
||||||
{
|
{
|
||||||
|
|
@ -856,7 +859,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[MemberData(nameof(ConnectionAdapterData))]
|
[MemberData(nameof(ConnectionAdapterData))]
|
||||||
public async Task Http10KeepAliveHonoredIfResponseContentLengthSet(ListenOptions listenOptions)
|
public async Task Http10KeepAliveHonoredIfResponseContentLengthSet(ListenOptions listenOptions)
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext();
|
var testContext = new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
using (var server = new TestServer(TestApp.EchoAppChunked, testContext, listenOptions))
|
using (var server = new TestServer(TestApp.EchoAppChunked, testContext, listenOptions))
|
||||||
{
|
{
|
||||||
|
|
@ -913,7 +916,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[MemberData(nameof(ConnectionAdapterData))]
|
[MemberData(nameof(ConnectionAdapterData))]
|
||||||
public async Task Expect100ContinueHonored(ListenOptions listenOptions)
|
public async Task Expect100ContinueHonored(ListenOptions listenOptions)
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext();
|
var testContext = new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
using (var server = new TestServer(TestApp.EchoAppChunked, testContext, listenOptions))
|
using (var server = new TestServer(TestApp.EchoAppChunked, testContext, listenOptions))
|
||||||
{
|
{
|
||||||
|
|
@ -946,7 +949,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[MemberData(nameof(ConnectionAdapterData))]
|
[MemberData(nameof(ConnectionAdapterData))]
|
||||||
public async Task ZeroContentLengthAssumedOnNonKeepAliveRequestsWithoutContentLengthOrTransferEncodingHeader(ListenOptions listenOptions)
|
public async Task ZeroContentLengthAssumedOnNonKeepAliveRequestsWithoutContentLengthOrTransferEncodingHeader(ListenOptions listenOptions)
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext();
|
var testContext = new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
using (var server = new TestServer(async httpContext =>
|
using (var server = new TestServer(async httpContext =>
|
||||||
{
|
{
|
||||||
|
|
@ -996,7 +999,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[MemberData(nameof(ConnectionAdapterData))]
|
[MemberData(nameof(ConnectionAdapterData))]
|
||||||
public async Task ConnectionClosesWhenFinReceivedBeforeRequestCompletes(ListenOptions listenOptions)
|
public async Task ConnectionClosesWhenFinReceivedBeforeRequestCompletes(ListenOptions listenOptions)
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext();
|
var testContext = new TestServiceContext(LoggerFactory);
|
||||||
// FIN callbacks are scheduled so run inline to make this test more reliable
|
// FIN callbacks are scheduled so run inline to make this test more reliable
|
||||||
testContext.Scheduler = PipeScheduler.Inline;
|
testContext.Scheduler = PipeScheduler.Inline;
|
||||||
|
|
||||||
|
|
@ -1026,7 +1029,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[MemberData(nameof(ConnectionAdapterData))]
|
[MemberData(nameof(ConnectionAdapterData))]
|
||||||
public async Task RequestsCanBeAbortedMidRead(ListenOptions listenOptions)
|
public async Task RequestsCanBeAbortedMidRead(ListenOptions listenOptions)
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext();
|
var testContext = new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
var readTcs = new TaskCompletionSource<object>();
|
var readTcs = new TaskCompletionSource<object>();
|
||||||
var registrationTcs = new TaskCompletionSource<int>();
|
var registrationTcs = new TaskCompletionSource<int>();
|
||||||
|
|
@ -1106,7 +1109,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[MemberData(nameof(ConnectionAdapterData))]
|
[MemberData(nameof(ConnectionAdapterData))]
|
||||||
public async Task RequestHeadersAreResetOnEachRequest(ListenOptions listenOptions)
|
public async Task RequestHeadersAreResetOnEachRequest(ListenOptions listenOptions)
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext();
|
var testContext = new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
IHeaderDictionary originalRequestHeaders = null;
|
IHeaderDictionary originalRequestHeaders = null;
|
||||||
var firstRequest = true;
|
var firstRequest = true;
|
||||||
|
|
@ -1159,7 +1162,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
const string message = "Hello World";
|
const string message = "Hello World";
|
||||||
|
|
||||||
var testContext = new TestServiceContext();
|
var testContext = new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
using (var server = new TestServer(async context =>
|
using (var server = new TestServer(async context =>
|
||||||
{
|
{
|
||||||
|
|
@ -1197,7 +1200,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task HeadersAndStreamsAreReusedAcrossRequests()
|
public async Task HeadersAndStreamsAreReusedAcrossRequests()
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext();
|
var testContext = new TestServiceContext(LoggerFactory);
|
||||||
var streamCount = 0;
|
var streamCount = 0;
|
||||||
var requestHeadersCount = 0;
|
var requestHeadersCount = 0;
|
||||||
var responseHeadersCount = 0;
|
var responseHeadersCount = 0;
|
||||||
|
|
@ -1274,7 +1277,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[MemberData(nameof(HostHeaderData))]
|
[MemberData(nameof(HostHeaderData))]
|
||||||
public async Task MatchesValidRequestTargetAndHostHeader(string request, string hostHeader)
|
public async Task MatchesValidRequestTargetAndHostHeader(string request, string hostHeader)
|
||||||
{
|
{
|
||||||
using (var server = new TestServer(context => Task.CompletedTask))
|
using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory)))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
@ -1292,7 +1295,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
public async Task ServerConsumesKeepAliveContentLengthRequest()
|
public async Task ServerConsumesKeepAliveContentLengthRequest()
|
||||||
{
|
{
|
||||||
// The app doesn't read the request body, so it should be consumed by the server
|
// The app doesn't read the request body, so it should be consumed by the server
|
||||||
using (var server = new TestServer(context => Task.CompletedTask))
|
using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory)))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
@ -1333,7 +1336,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
public async Task ServerConsumesKeepAliveChunkedRequest()
|
public async Task ServerConsumesKeepAliveChunkedRequest()
|
||||||
{
|
{
|
||||||
// The app doesn't read the request body, so it should be consumed by the server
|
// The app doesn't read the request body, so it should be consumed by the server
|
||||||
using (var server = new TestServer(context => Task.CompletedTask))
|
using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory)))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
@ -1381,7 +1384,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
public async Task NonKeepAliveRequestNotConsumedByAppCompletes()
|
public async Task NonKeepAliveRequestNotConsumedByAppCompletes()
|
||||||
{
|
{
|
||||||
// The app doesn't read the request body, so it should be consumed by the server
|
// The app doesn't read the request body, so it should be consumed by the server
|
||||||
using (var server = new TestServer(context => Task.CompletedTask))
|
using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory)))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
@ -1414,7 +1417,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
|
|
||||||
var response = Encoding.ASCII.GetBytes("goodbye");
|
var response = Encoding.ASCII.GetBytes("goodbye");
|
||||||
await duplexStream.WriteAsync(response, 0, response.Length);
|
await duplexStream.WriteAsync(response, 0, response.Length);
|
||||||
}))
|
}, new TestServiceContext(LoggerFactory)))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
@ -1440,7 +1443,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
var appEvent = new ManualResetEventSlim();
|
var appEvent = new ManualResetEventSlim();
|
||||||
var delayEvent = new ManualResetEventSlim();
|
var delayEvent = new ManualResetEventSlim();
|
||||||
var serviceContext = new TestServiceContext
|
var serviceContext = new TestServiceContext(LoggerFactory)
|
||||||
{
|
{
|
||||||
SystemClock = new SystemClock()
|
SystemClock = new SystemClock()
|
||||||
};
|
};
|
||||||
|
|
@ -1545,7 +1548,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
|
|
||||||
context.Response.ContentLength = 6;
|
context.Response.ContentLength = 6;
|
||||||
await context.Response.Body.WriteAsync(buffer, 0, 6);
|
await context.Response.Body.WriteAsync(buffer, 0, 6);
|
||||||
}))
|
}, new TestServiceContext(LoggerFactory)))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
@ -1576,7 +1579,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task SynchronousReadsCanBeDisallowedGlobally()
|
public async Task SynchronousReadsCanBeDisallowedGlobally()
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext
|
var testContext = new TestServiceContext(LoggerFactory)
|
||||||
{
|
{
|
||||||
ServerOptions = { AllowSynchronousIO = false }
|
ServerOptions = { AllowSynchronousIO = false }
|
||||||
};
|
};
|
||||||
|
|
@ -1627,6 +1630,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
var builder = TransportSelector.GetWebHostBuilder()
|
var builder = TransportSelector.GetWebHostBuilder()
|
||||||
.UseKestrel()
|
.UseKestrel()
|
||||||
.UseUrls($"http://{registerAddress}:0")
|
.UseUrls($"http://{registerAddress}:0")
|
||||||
|
.ConfigureServices(AddTestLogging)
|
||||||
.Configure(app =>
|
.Configure(app =>
|
||||||
{
|
{
|
||||||
app.Run(async context =>
|
app.Run(async context =>
|
||||||
|
|
|
||||||
|
|
@ -33,11 +33,10 @@ using Microsoft.Extensions.Logging.Testing;
|
||||||
using Microsoft.Extensions.Primitives;
|
using Microsoft.Extensions.Primitives;
|
||||||
using Moq;
|
using Moq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using Xunit.Abstractions;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
public class ResponseTests : LoggedTest
|
public class ResponseTests : TestApplicationErrorLoggerLoggedTest
|
||||||
{
|
{
|
||||||
public static TheoryData<ListenOptions> ConnectionAdapterData => new TheoryData<ListenOptions>
|
public static TheoryData<ListenOptions> ConnectionAdapterData => new TheoryData<ListenOptions>
|
||||||
{
|
{
|
||||||
|
|
@ -48,14 +47,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public ResponseTests(ITestOutputHelper outputHelper) : base(outputHelper) { }
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task LargeDownload()
|
public async Task LargeDownload()
|
||||||
{
|
{
|
||||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||||
.UseKestrel()
|
.UseKestrel()
|
||||||
.UseUrls("http://127.0.0.1:0/")
|
.UseUrls("http://127.0.0.1:0/")
|
||||||
|
.ConfigureServices(AddTestLogging)
|
||||||
.Configure(app =>
|
.Configure(app =>
|
||||||
{
|
{
|
||||||
app.Run(async context =>
|
app.Run(async context =>
|
||||||
|
|
@ -108,6 +106,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||||
.UseKestrel()
|
.UseKestrel()
|
||||||
.UseUrls("http://127.0.0.1:0/")
|
.UseUrls("http://127.0.0.1:0/")
|
||||||
|
.ConfigureServices(AddTestLogging)
|
||||||
.Configure(app =>
|
.Configure(app =>
|
||||||
{
|
{
|
||||||
app.Run(async context =>
|
app.Run(async context =>
|
||||||
|
|
@ -151,6 +150,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||||
.UseKestrel()
|
.UseKestrel()
|
||||||
.UseUrls("http://127.0.0.1:0/")
|
.UseUrls("http://127.0.0.1:0/")
|
||||||
|
.ConfigureServices(AddTestLogging)
|
||||||
.Configure(app =>
|
.Configure(app =>
|
||||||
{
|
{
|
||||||
app.Run(context =>
|
app.Run(context =>
|
||||||
|
|
@ -189,6 +189,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||||
.UseKestrel()
|
.UseKestrel()
|
||||||
.UseUrls("http://127.0.0.1:0/")
|
.UseUrls("http://127.0.0.1:0/")
|
||||||
|
.ConfigureServices(AddTestLogging)
|
||||||
.Configure(app =>
|
.Configure(app =>
|
||||||
{
|
{
|
||||||
app.Run(async context =>
|
app.Run(async context =>
|
||||||
|
|
@ -218,6 +219,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
public Task ResponseStatusCodeSetBeforeHttpContextDisposeAppException()
|
public Task ResponseStatusCodeSetBeforeHttpContextDisposeAppException()
|
||||||
{
|
{
|
||||||
return ResponseStatusCodeSetBeforeHttpContextDispose(
|
return ResponseStatusCodeSetBeforeHttpContextDispose(
|
||||||
|
TestSink,
|
||||||
|
LoggerFactory,
|
||||||
context =>
|
context =>
|
||||||
{
|
{
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
|
|
@ -230,6 +233,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
public Task ResponseStatusCodeSetBeforeHttpContextDisposeRequestAborted()
|
public Task ResponseStatusCodeSetBeforeHttpContextDisposeRequestAborted()
|
||||||
{
|
{
|
||||||
return ResponseStatusCodeSetBeforeHttpContextDispose(
|
return ResponseStatusCodeSetBeforeHttpContextDispose(
|
||||||
|
TestSink,
|
||||||
|
LoggerFactory,
|
||||||
context =>
|
context =>
|
||||||
{
|
{
|
||||||
context.Abort();
|
context.Abort();
|
||||||
|
|
@ -243,6 +248,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
public Task ResponseStatusCodeSetBeforeHttpContextDisposeRequestAbortedAppException()
|
public Task ResponseStatusCodeSetBeforeHttpContextDisposeRequestAbortedAppException()
|
||||||
{
|
{
|
||||||
return ResponseStatusCodeSetBeforeHttpContextDispose(
|
return ResponseStatusCodeSetBeforeHttpContextDispose(
|
||||||
|
TestSink,
|
||||||
|
LoggerFactory,
|
||||||
context =>
|
context =>
|
||||||
{
|
{
|
||||||
context.Abort();
|
context.Abort();
|
||||||
|
|
@ -256,6 +263,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
public Task ResponseStatusCodeSetBeforeHttpContextDisposedRequestMalformed()
|
public Task ResponseStatusCodeSetBeforeHttpContextDisposedRequestMalformed()
|
||||||
{
|
{
|
||||||
return ResponseStatusCodeSetBeforeHttpContextDispose(
|
return ResponseStatusCodeSetBeforeHttpContextDispose(
|
||||||
|
TestSink,
|
||||||
|
LoggerFactory,
|
||||||
context =>
|
context =>
|
||||||
{
|
{
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
|
|
@ -269,6 +278,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
public Task ResponseStatusCodeSetBeforeHttpContextDisposedRequestMalformedRead()
|
public Task ResponseStatusCodeSetBeforeHttpContextDisposedRequestMalformedRead()
|
||||||
{
|
{
|
||||||
return ResponseStatusCodeSetBeforeHttpContextDispose(
|
return ResponseStatusCodeSetBeforeHttpContextDispose(
|
||||||
|
TestSink,
|
||||||
|
LoggerFactory,
|
||||||
async context =>
|
async context =>
|
||||||
{
|
{
|
||||||
await context.Request.Body.ReadAsync(new byte[1], 0, 1);
|
await context.Request.Body.ReadAsync(new byte[1], 0, 1);
|
||||||
|
|
@ -282,6 +293,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
public Task ResponseStatusCodeSetBeforeHttpContextDisposedRequestMalformedReadIgnored()
|
public Task ResponseStatusCodeSetBeforeHttpContextDisposedRequestMalformedReadIgnored()
|
||||||
{
|
{
|
||||||
return ResponseStatusCodeSetBeforeHttpContextDispose(
|
return ResponseStatusCodeSetBeforeHttpContextDispose(
|
||||||
|
TestSink,
|
||||||
|
LoggerFactory,
|
||||||
async context =>
|
async context =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
@ -303,6 +316,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||||
.UseKestrel()
|
.UseKestrel()
|
||||||
.UseUrls("http://127.0.0.1:0/")
|
.UseUrls("http://127.0.0.1:0/")
|
||||||
|
.ConfigureServices(AddTestLogging)
|
||||||
.Configure(app =>
|
.Configure(app =>
|
||||||
{
|
{
|
||||||
app.Run(async context =>
|
app.Run(async context =>
|
||||||
|
|
@ -331,6 +345,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||||
.UseKestrel()
|
.UseKestrel()
|
||||||
.UseUrls("http://127.0.0.1:0/")
|
.UseUrls("http://127.0.0.1:0/")
|
||||||
|
.ConfigureServices(AddTestLogging)
|
||||||
.Configure(app =>
|
.Configure(app =>
|
||||||
{
|
{
|
||||||
app.Run(async context =>
|
app.Run(async context =>
|
||||||
|
|
@ -368,7 +383,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
onCompletedTcs.SetResult(null);
|
onCompletedTcs.SetResult(null);
|
||||||
}));
|
}));
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}))
|
}, new TestServiceContext(LoggerFactory)))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
@ -391,6 +406,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task ResponseStatusCodeSetBeforeHttpContextDispose(
|
private static async Task ResponseStatusCodeSetBeforeHttpContextDispose(
|
||||||
|
ITestSink testSink,
|
||||||
|
ILoggerFactory loggerFactory,
|
||||||
RequestDelegate handler,
|
RequestDelegate handler,
|
||||||
HttpStatusCode? expectedClientStatusCode,
|
HttpStatusCode? expectedClientStatusCode,
|
||||||
HttpStatusCode expectedServerStatusCode,
|
HttpStatusCode expectedServerStatusCode,
|
||||||
|
|
@ -407,10 +424,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
disposedTcs.TrySetResult(c.Response.StatusCode);
|
disposedTcs.TrySetResult(c.Response.StatusCode);
|
||||||
});
|
});
|
||||||
|
|
||||||
var sink = new TestSink();
|
using (var server = new TestServer(handler, new TestServiceContext(loggerFactory),
|
||||||
var logger = new TestLogger("TestLogger", sink, enabled: true);
|
|
||||||
|
|
||||||
using (var server = new TestServer(handler, new TestServiceContext() { Log = new KestrelTrace(logger) },
|
|
||||||
new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)),
|
new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)),
|
||||||
services => services.AddSingleton(mockHttpContextFactory.Object)))
|
services => services.AddSingleton(mockHttpContextFactory.Object)))
|
||||||
{
|
{
|
||||||
|
|
@ -470,12 +484,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
|
|
||||||
if (sendMalformedRequest)
|
if (sendMalformedRequest)
|
||||||
{
|
{
|
||||||
Assert.Contains(sink.Writes, w => w.EventId.Id == 17 && w.LogLevel == LogLevel.Information && w.Exception is BadHttpRequestException
|
Assert.Contains(testSink.Writes, w => w.EventId.Id == 17 && w.LogLevel == LogLevel.Information && w.Exception is BadHttpRequestException
|
||||||
&& ((BadHttpRequestException)w.Exception).StatusCode == StatusCodes.Status400BadRequest);
|
&& ((BadHttpRequestException)w.Exception).StatusCode == StatusCodes.Status400BadRequest);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Assert.DoesNotContain(sink.Writes, w => w.EventId.Id == 17 && w.LogLevel == LogLevel.Information && w.Exception is BadHttpRequestException
|
Assert.DoesNotContain(testSink.Writes, w => w.EventId.Id == 17 && w.LogLevel == LogLevel.Information && w.Exception is BadHttpRequestException
|
||||||
&& ((BadHttpRequestException)w.Exception).StatusCode == StatusCodes.Status400BadRequest);
|
&& ((BadHttpRequestException)w.Exception).StatusCode == StatusCodes.Status400BadRequest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -485,14 +499,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
public async Task NoErrorResponseSentWhenAppSwallowsBadRequestException()
|
public async Task NoErrorResponseSentWhenAppSwallowsBadRequestException()
|
||||||
{
|
{
|
||||||
BadHttpRequestException readException = null;
|
BadHttpRequestException readException = null;
|
||||||
var sink = new TestSink();
|
|
||||||
var logger = new TestLogger("TestLogger", sink, enabled: true);
|
|
||||||
|
|
||||||
using (var server = new TestServer(async httpContext =>
|
using (var server = new TestServer(async httpContext =>
|
||||||
{
|
{
|
||||||
readException = await Assert.ThrowsAsync<BadHttpRequestException>(
|
readException = await Assert.ThrowsAsync<BadHttpRequestException>(
|
||||||
async () => await httpContext.Request.Body.ReadAsync(new byte[1], 0, 1));
|
async () => await httpContext.Request.Body.ReadAsync(new byte[1], 0, 1));
|
||||||
}, new TestServiceContext() { Log = new KestrelTrace(logger) }))
|
}, new TestServiceContext(LoggerFactory)))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
@ -513,7 +525,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
|
|
||||||
Assert.NotNull(readException);
|
Assert.NotNull(readException);
|
||||||
|
|
||||||
Assert.Contains(sink.Writes, w => w.EventId.Id == 17 && w.LogLevel == LogLevel.Information && w.Exception is BadHttpRequestException
|
Assert.Contains(TestSink.Writes, w => w.EventId.Id == 17 && w.LogLevel == LogLevel.Information && w.Exception is BadHttpRequestException
|
||||||
&& ((BadHttpRequestException)w.Exception).StatusCode == StatusCodes.Status400BadRequest);
|
&& ((BadHttpRequestException)w.Exception).StatusCode == StatusCodes.Status400BadRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -524,7 +536,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
await httpContext.Response.WriteAsync("hello, ");
|
await httpContext.Response.WriteAsync("hello, ");
|
||||||
await httpContext.Response.WriteAsync("world");
|
await httpContext.Response.WriteAsync("world");
|
||||||
}))
|
}, new TestServiceContext(LoggerFactory)))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
@ -559,7 +571,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
httpContext.Response.StatusCode = statusCode;
|
httpContext.Response.StatusCode = statusCode;
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}))
|
}, new TestServiceContext(LoggerFactory)))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
@ -583,7 +595,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
using (var server = new TestServer(httpContext =>
|
using (var server = new TestServer(httpContext =>
|
||||||
{
|
{
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}))
|
}, new TestServiceContext(LoggerFactory)))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
@ -616,7 +628,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
await httpContext.Response.WriteAsync(response);
|
await httpContext.Response.WriteAsync(response);
|
||||||
await httpContext.Response.Body.FlushAsync();
|
await httpContext.Response.Body.FlushAsync();
|
||||||
}, new TestServiceContext { Log = mockKestrelTrace.Object }))
|
}, new TestServiceContext(LoggerFactory, mockKestrelTrace.Object)))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
@ -645,10 +657,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task ThrowsAndClosesConnectionWhenAppWritesMoreThanContentLengthWrite()
|
public async Task ThrowsAndClosesConnectionWhenAppWritesMoreThanContentLengthWrite()
|
||||||
{
|
{
|
||||||
var testLogger = new TestApplicationErrorLogger();
|
var serviceContext = new TestServiceContext(LoggerFactory)
|
||||||
var serviceContext = new TestServiceContext
|
|
||||||
{
|
{
|
||||||
Log = new TestKestrelTrace(testLogger),
|
|
||||||
ServerOptions = { AllowSynchronousIO = true }
|
ServerOptions = { AllowSynchronousIO = true }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -678,7 +688,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var logMessage = Assert.Single(testLogger.Messages, message => message.LogLevel == LogLevel.Error);
|
var logMessage = Assert.Single(TestApplicationErrorLogger.Messages, message => message.LogLevel == LogLevel.Error);
|
||||||
|
|
||||||
Assert.Equal(
|
Assert.Equal(
|
||||||
$"Response Content-Length mismatch: too many bytes written (12 of 11).",
|
$"Response Content-Length mismatch: too many bytes written (12 of 11).",
|
||||||
|
|
@ -689,8 +699,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task ThrowsAndClosesConnectionWhenAppWritesMoreThanContentLengthWriteAsync()
|
public async Task ThrowsAndClosesConnectionWhenAppWritesMoreThanContentLengthWriteAsync()
|
||||||
{
|
{
|
||||||
var testLogger = new TestApplicationErrorLogger();
|
var serviceContext = new TestServiceContext(LoggerFactory);
|
||||||
var serviceContext = new TestServiceContext { Log = new TestKestrelTrace(testLogger) };
|
|
||||||
|
|
||||||
using (var server = new TestServer(async httpContext =>
|
using (var server = new TestServer(async httpContext =>
|
||||||
{
|
{
|
||||||
|
|
@ -715,7 +724,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var logMessage = Assert.Single(testLogger.Messages, message => message.LogLevel == LogLevel.Error);
|
var logMessage = Assert.Single(TestApplicationErrorLogger.Messages, message => message.LogLevel == LogLevel.Error);
|
||||||
Assert.Equal(
|
Assert.Equal(
|
||||||
$"Response Content-Length mismatch: too many bytes written (12 of 11).",
|
$"Response Content-Length mismatch: too many bytes written (12 of 11).",
|
||||||
logMessage.Exception.Message);
|
logMessage.Exception.Message);
|
||||||
|
|
@ -724,10 +733,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task InternalServerErrorAndConnectionClosedOnWriteWithMoreThanContentLengthAndResponseNotStarted()
|
public async Task InternalServerErrorAndConnectionClosedOnWriteWithMoreThanContentLengthAndResponseNotStarted()
|
||||||
{
|
{
|
||||||
var testLogger = new TestApplicationErrorLogger();
|
var serviceContext = new TestServiceContext(LoggerFactory)
|
||||||
var serviceContext = new TestServiceContext
|
|
||||||
{
|
{
|
||||||
Log = new TestKestrelTrace(testLogger),
|
|
||||||
ServerOptions = { AllowSynchronousIO = true }
|
ServerOptions = { AllowSynchronousIO = true }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -756,7 +763,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var logMessage = Assert.Single(testLogger.Messages, message => message.LogLevel == LogLevel.Error);
|
var logMessage = Assert.Single(TestApplicationErrorLogger.Messages, message => message.LogLevel == LogLevel.Error);
|
||||||
Assert.Equal(
|
Assert.Equal(
|
||||||
$"Response Content-Length mismatch: too many bytes written (12 of 5).",
|
$"Response Content-Length mismatch: too many bytes written (12 of 5).",
|
||||||
logMessage.Exception.Message);
|
logMessage.Exception.Message);
|
||||||
|
|
@ -765,8 +772,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task InternalServerErrorAndConnectionClosedOnWriteAsyncWithMoreThanContentLengthAndResponseNotStarted()
|
public async Task InternalServerErrorAndConnectionClosedOnWriteAsyncWithMoreThanContentLengthAndResponseNotStarted()
|
||||||
{
|
{
|
||||||
var testLogger = new TestApplicationErrorLogger();
|
var serviceContext = new TestServiceContext(LoggerFactory);
|
||||||
var serviceContext = new TestServiceContext { Log = new TestKestrelTrace(testLogger) };
|
|
||||||
|
|
||||||
using (var server = new TestServer(httpContext =>
|
using (var server = new TestServer(httpContext =>
|
||||||
{
|
{
|
||||||
|
|
@ -792,7 +798,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var logMessage = Assert.Single(testLogger.Messages, message => message.LogLevel == LogLevel.Error);
|
var logMessage = Assert.Single(TestApplicationErrorLogger.Messages, message => message.LogLevel == LogLevel.Error);
|
||||||
Assert.Equal(
|
Assert.Equal(
|
||||||
$"Response Content-Length mismatch: too many bytes written (12 of 5).",
|
$"Response Content-Length mismatch: too many bytes written (12 of 5).",
|
||||||
logMessage.Exception.Message);
|
logMessage.Exception.Message);
|
||||||
|
|
@ -814,7 +820,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
httpContext.Response.ContentLength = 13;
|
httpContext.Response.ContentLength = 13;
|
||||||
await httpContext.Response.WriteAsync("hello, world");
|
await httpContext.Response.WriteAsync("hello, world");
|
||||||
}, new TestServiceContext { Log = mockTrace.Object }))
|
}, new TestServiceContext(LoggerFactory, mockTrace.Object)))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
@ -869,7 +875,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
|
|
||||||
// Wait until the request is aborted so we know HttpProtocol will skip the response content length check.
|
// Wait until the request is aborted so we know HttpProtocol will skip the response content length check.
|
||||||
Assert.True(await requestAborted.WaitAsync(TestConstants.DefaultTimeout));
|
Assert.True(await requestAborted.WaitAsync(TestConstants.DefaultTimeout));
|
||||||
}, new TestServiceContext { Log = mockTrace.Object }))
|
}, new TestServiceContext(LoggerFactory, mockTrace.Object)))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
@ -902,8 +908,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task WhenAppSetsContentLengthButDoesNotWriteBody500ResponseSentAndConnectionDoesNotClose()
|
public async Task WhenAppSetsContentLengthButDoesNotWriteBody500ResponseSentAndConnectionDoesNotClose()
|
||||||
{
|
{
|
||||||
var testLogger = new TestApplicationErrorLogger();
|
var serviceContext = new TestServiceContext(LoggerFactory);
|
||||||
var serviceContext = new TestServiceContext { Log = new TestKestrelTrace(testLogger) };
|
|
||||||
|
|
||||||
using (var server = new TestServer(httpContext =>
|
using (var server = new TestServer(httpContext =>
|
||||||
{
|
{
|
||||||
|
|
@ -934,9 +939,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var error = testLogger.Messages.Where(message => message.LogLevel == LogLevel.Error);
|
var error = TestApplicationErrorLogger.Messages.Where(message => message.LogLevel == LogLevel.Error);
|
||||||
Assert.Equal(2, error.Count());
|
Assert.Equal(2, error.Count());
|
||||||
Assert.All(error, message => message.Equals("Response Content-Length mismatch: too few bytes written (0 of 5)."));
|
Assert.All(error, message => message.Message.Equals("Response Content-Length mismatch: too few bytes written (0 of 5)."));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
|
|
@ -944,8 +949,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[InlineData(true)]
|
[InlineData(true)]
|
||||||
public async Task WhenAppSetsContentLengthToZeroAndDoesNotWriteNoErrorIsThrown(bool flushResponse)
|
public async Task WhenAppSetsContentLengthToZeroAndDoesNotWriteNoErrorIsThrown(bool flushResponse)
|
||||||
{
|
{
|
||||||
var testLogger = new TestApplicationErrorLogger();
|
var serviceContext = new TestServiceContext(LoggerFactory);
|
||||||
var serviceContext = new TestServiceContext { Log = new TestKestrelTrace(testLogger) };
|
|
||||||
|
|
||||||
using (var server = new TestServer(async httpContext =>
|
using (var server = new TestServer(async httpContext =>
|
||||||
{
|
{
|
||||||
|
|
@ -973,7 +977,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.Equal(0, testLogger.ApplicationErrorsLogged);
|
Assert.Empty(TestApplicationErrorLogger.Messages.Where(message => message.LogLevel == LogLevel.Error));
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://tools.ietf.org/html/rfc7230#section-3.3.3
|
// https://tools.ietf.org/html/rfc7230#section-3.3.3
|
||||||
|
|
@ -983,8 +987,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task WhenAppSetsTransferEncodingAndContentLengthWritingLessIsNotAnError()
|
public async Task WhenAppSetsTransferEncodingAndContentLengthWritingLessIsNotAnError()
|
||||||
{
|
{
|
||||||
var testLogger = new TestApplicationErrorLogger();
|
var serviceContext = new TestServiceContext(LoggerFactory);
|
||||||
var serviceContext = new TestServiceContext { Log = new TestKestrelTrace(testLogger) };
|
|
||||||
|
|
||||||
using (var server = new TestServer(async httpContext =>
|
using (var server = new TestServer(async httpContext =>
|
||||||
{
|
{
|
||||||
|
|
@ -1010,7 +1013,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.Equal(0, testLogger.ApplicationErrorsLogged);
|
Assert.Empty(TestApplicationErrorLogger.Messages.Where(message => message.LogLevel == LogLevel.Error));
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://tools.ietf.org/html/rfc7230#section-3.3.3
|
// https://tools.ietf.org/html/rfc7230#section-3.3.3
|
||||||
|
|
@ -1020,8 +1023,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task WhenAppSetsTransferEncodingAndContentLengthWritingMoreIsNotAnError()
|
public async Task WhenAppSetsTransferEncodingAndContentLengthWritingMoreIsNotAnError()
|
||||||
{
|
{
|
||||||
var testLogger = new TestApplicationErrorLogger();
|
var serviceContext = new TestServiceContext(LoggerFactory);
|
||||||
var serviceContext = new TestServiceContext { Log = new TestKestrelTrace(testLogger) };
|
|
||||||
|
|
||||||
using (var server = new TestServer(async httpContext =>
|
using (var server = new TestServer(async httpContext =>
|
||||||
{
|
{
|
||||||
|
|
@ -1047,7 +1049,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.Equal(0, testLogger.ApplicationErrorsLogged);
|
Assert.Empty(TestApplicationErrorLogger.Messages.Where(message => message.LogLevel == LogLevel.Error));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -1057,7 +1059,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
httpContext.Response.ContentLength = 42;
|
httpContext.Response.ContentLength = 42;
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}))
|
}, new TestServiceContext(LoggerFactory)))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
@ -1086,7 +1088,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
httpContext.Response.ContentLength = 12;
|
httpContext.Response.ContentLength = 12;
|
||||||
await httpContext.Response.WriteAsync("hello, world");
|
await httpContext.Response.WriteAsync("hello, world");
|
||||||
await flushed.WaitAsync();
|
await flushed.WaitAsync();
|
||||||
}))
|
}, new TestServiceContext(LoggerFactory)))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
@ -1111,7 +1113,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
public async Task HeadResponseBodyNotWrittenWithSyncWrite()
|
public async Task HeadResponseBodyNotWrittenWithSyncWrite()
|
||||||
{
|
{
|
||||||
var flushed = new SemaphoreSlim(0, 1);
|
var flushed = new SemaphoreSlim(0, 1);
|
||||||
var serviceContext = new TestServiceContext { ServerOptions = { AllowSynchronousIO = true } };
|
var serviceContext = new TestServiceContext(LoggerFactory) { ServerOptions = { AllowSynchronousIO = true } };
|
||||||
|
|
||||||
using (var server = new TestServer(httpContext =>
|
using (var server = new TestServer(httpContext =>
|
||||||
{
|
{
|
||||||
|
|
@ -1151,7 +1153,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
await httpContext.Response.WriteAsync("");
|
await httpContext.Response.WriteAsync("");
|
||||||
flushed.Wait();
|
flushed.Wait();
|
||||||
await httpContext.Response.WriteAsync("hello, world");
|
await httpContext.Response.WriteAsync("hello, world");
|
||||||
}))
|
}, new TestServiceContext(LoggerFactory)))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
@ -1195,7 +1197,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
tcs.TrySetException(ex);
|
tcs.TrySetException(ex);
|
||||||
}
|
}
|
||||||
}))
|
}, new TestServiceContext(LoggerFactory)))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
@ -1236,7 +1238,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
await httpContext.Response.WriteAsync(ex.Message);
|
await httpContext.Response.WriteAsync(ex.Message);
|
||||||
responseWritten.Release();
|
responseWritten.Release();
|
||||||
}
|
}
|
||||||
}))
|
}, new TestServiceContext(LoggerFactory)))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
@ -1266,7 +1268,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
httpContext.Response.Headers["Transfer-Encoding"] = responseTransferEncoding;
|
httpContext.Response.Headers["Transfer-Encoding"] = responseTransferEncoding;
|
||||||
await httpContext.Response.WriteAsync("hello, world");
|
await httpContext.Response.WriteAsync("hello, world");
|
||||||
}))
|
}, new TestServiceContext(LoggerFactory)))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
@ -1312,7 +1314,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
httpContext.Response.Headers["Connection"] = "keep-alive";
|
httpContext.Response.Headers["Connection"] = "keep-alive";
|
||||||
httpContext.Response.Headers["Transfer-Encoding"] = responseTransferEncoding;
|
httpContext.Response.Headers["Transfer-Encoding"] = responseTransferEncoding;
|
||||||
await httpContext.Response.WriteAsync("hello, world");
|
await httpContext.Response.WriteAsync("hello, world");
|
||||||
}))
|
}, new TestServiceContext(LoggerFactory)))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
@ -1359,7 +1361,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
|
|
||||||
// App would have to chunk manually, but here we don't care
|
// App would have to chunk manually, but here we don't care
|
||||||
await httpContext.Response.WriteAsync("hello, world");
|
await httpContext.Response.WriteAsync("hello, world");
|
||||||
}))
|
}, new TestServiceContext(LoggerFactory)))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
@ -1394,7 +1396,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task FirstWriteVerifiedAfterOnStarting()
|
public async Task FirstWriteVerifiedAfterOnStarting()
|
||||||
{
|
{
|
||||||
var serviceContext = new TestServiceContext { ServerOptions = { AllowSynchronousIO = true } };
|
var serviceContext = new TestServiceContext(LoggerFactory) { ServerOptions = { AllowSynchronousIO = true } };
|
||||||
|
|
||||||
using (var server = new TestServer(httpContext =>
|
using (var server = new TestServer(httpContext =>
|
||||||
{
|
{
|
||||||
|
|
@ -1437,7 +1439,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task SubsequentWriteVerifiedAfterOnStarting()
|
public async Task SubsequentWriteVerifiedAfterOnStarting()
|
||||||
{
|
{
|
||||||
var serviceContext = new TestServiceContext { ServerOptions = { AllowSynchronousIO = true } };
|
var serviceContext = new TestServiceContext(LoggerFactory) { ServerOptions = { AllowSynchronousIO = true } };
|
||||||
|
|
||||||
using (var server = new TestServer(httpContext =>
|
using (var server = new TestServer(httpContext =>
|
||||||
{
|
{
|
||||||
|
|
@ -1497,7 +1499,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
|
|
||||||
// If OnStarting is not run before verifying writes, an error response will be sent.
|
// If OnStarting is not run before verifying writes, an error response will be sent.
|
||||||
return httpContext.Response.Body.WriteAsync(response, 0, response.Length);
|
return httpContext.Response.Body.WriteAsync(response, 0, response.Length);
|
||||||
}))
|
}, new TestServiceContext(LoggerFactory)))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
@ -1538,7 +1540,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
// If OnStarting is not run before verifying writes, an error response will be sent.
|
// If OnStarting is not run before verifying writes, an error response will be sent.
|
||||||
await httpContext.Response.Body.WriteAsync(response, 0, response.Length / 2);
|
await httpContext.Response.Body.WriteAsync(response, 0, response.Length / 2);
|
||||||
await httpContext.Response.Body.WriteAsync(response, response.Length / 2, response.Length - response.Length / 2);
|
await httpContext.Response.Body.WriteAsync(response, response.Length / 2, response.Length - response.Length / 2);
|
||||||
}))
|
}, new TestServiceContext(LoggerFactory)))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
@ -1569,7 +1571,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
using (var server = new TestServer(async httpContext =>
|
using (var server = new TestServer(async httpContext =>
|
||||||
{
|
{
|
||||||
await httpContext.Response.WriteAsync("hello, world");
|
await httpContext.Response.WriteAsync("hello, world");
|
||||||
}))
|
}, new TestServiceContext(LoggerFactory)))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
@ -1603,11 +1605,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task WhenResponseNotStartedResponseEndedBeforeConsumingRequestBody()
|
public async Task WhenResponseNotStartedResponseEndedBeforeConsumingRequestBody()
|
||||||
{
|
{
|
||||||
var sink = new TestSink();
|
|
||||||
var logger = new TestLogger("TestLogger", sink, enabled: true);
|
|
||||||
|
|
||||||
using (var server = new TestServer(httpContext => Task.CompletedTask,
|
using (var server = new TestServer(httpContext => Task.CompletedTask,
|
||||||
new TestServiceContext() { Log = new KestrelTrace(logger) }))
|
new TestServiceContext(LoggerFactory)))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
@ -1630,20 +1629,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.Contains(sink.Writes, w => w.EventId.Id == 17 && w.LogLevel == LogLevel.Information && w.Exception is BadHttpRequestException
|
Assert.Contains(TestApplicationErrorLogger.Messages, w => w.EventId.Id == 17 && w.LogLevel == LogLevel.Information && w.Exception is BadHttpRequestException
|
||||||
&& ((BadHttpRequestException)w.Exception).StatusCode == StatusCodes.Status400BadRequest);
|
&& ((BadHttpRequestException)w.Exception).StatusCode == StatusCodes.Status400BadRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task Sending100ContinueDoesNotStartResponse()
|
public async Task Sending100ContinueDoesNotStartResponse()
|
||||||
{
|
{
|
||||||
var sink = new TestSink();
|
|
||||||
var logger = new TestLogger("TestLogger", sink, enabled: true);
|
|
||||||
|
|
||||||
using (var server = new TestServer(httpContext =>
|
using (var server = new TestServer(httpContext =>
|
||||||
{
|
{
|
||||||
return httpContext.Request.Body.ReadAsync(new byte[1], 0, 1);
|
return httpContext.Request.Body.ReadAsync(new byte[1], 0, 1);
|
||||||
}, new TestServiceContext() { Log = new KestrelTrace(logger) }))
|
}, new TestServiceContext(LoggerFactory)))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
@ -1685,7 +1681,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.Contains(sink.Writes, w => w.EventId.Id == 17 && w.LogLevel == LogLevel.Information && w.Exception is BadHttpRequestException
|
Assert.Contains(TestApplicationErrorLogger.Messages, w => w.EventId.Id == 17 && w.LogLevel == LogLevel.Information && w.Exception is BadHttpRequestException
|
||||||
&& ((BadHttpRequestException)w.Exception).StatusCode == StatusCodes.Status400BadRequest);
|
&& ((BadHttpRequestException)w.Exception).StatusCode == StatusCodes.Status400BadRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1696,7 +1692,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
await httpContext.Request.Body.ReadAsync(new byte[1], 0, 1);
|
await httpContext.Request.Body.ReadAsync(new byte[1], 0, 1);
|
||||||
await httpContext.Response.WriteAsync("hello, world");
|
await httpContext.Response.WriteAsync("hello, world");
|
||||||
}))
|
}, new TestServiceContext(LoggerFactory)))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
@ -1740,7 +1736,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[MemberData(nameof(ConnectionAdapterData))]
|
[MemberData(nameof(ConnectionAdapterData))]
|
||||||
public async Task Http11ResponseSentToHttp10Request(ListenOptions listenOptions)
|
public async Task Http11ResponseSentToHttp10Request(ListenOptions listenOptions)
|
||||||
{
|
{
|
||||||
var serviceContext = new TestServiceContext();
|
var serviceContext = new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
using (var server = new TestServer(TestApp.EchoApp, serviceContext, listenOptions))
|
using (var server = new TestServer(TestApp.EchoApp, serviceContext, listenOptions))
|
||||||
{
|
{
|
||||||
|
|
@ -1765,7 +1761,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[MemberData(nameof(ConnectionAdapterData))]
|
[MemberData(nameof(ConnectionAdapterData))]
|
||||||
public async Task ZeroContentLengthSetAutomaticallyAfterNoWrites(ListenOptions listenOptions)
|
public async Task ZeroContentLengthSetAutomaticallyAfterNoWrites(ListenOptions listenOptions)
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext();
|
var testContext= new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
using (var server = new TestServer(TestApp.EmptyApp, testContext, listenOptions))
|
using (var server = new TestServer(TestApp.EmptyApp, testContext, listenOptions))
|
||||||
{
|
{
|
||||||
|
|
@ -1798,7 +1794,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[MemberData(nameof(ConnectionAdapterData))]
|
[MemberData(nameof(ConnectionAdapterData))]
|
||||||
public async Task ZeroContentLengthSetAutomaticallyForNonKeepAliveRequests(ListenOptions listenOptions)
|
public async Task ZeroContentLengthSetAutomaticallyForNonKeepAliveRequests(ListenOptions listenOptions)
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext();
|
var testContext= new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
using (var server = new TestServer(async httpContext =>
|
using (var server = new TestServer(async httpContext =>
|
||||||
{
|
{
|
||||||
|
|
@ -1843,7 +1839,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[MemberData(nameof(ConnectionAdapterData))]
|
[MemberData(nameof(ConnectionAdapterData))]
|
||||||
public async Task ZeroContentLengthNotSetAutomaticallyForHeadRequests(ListenOptions listenOptions)
|
public async Task ZeroContentLengthNotSetAutomaticallyForHeadRequests(ListenOptions listenOptions)
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext();
|
var testContext= new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
using (var server = new TestServer(TestApp.EmptyApp, testContext, listenOptions))
|
using (var server = new TestServer(TestApp.EmptyApp, testContext, listenOptions))
|
||||||
{
|
{
|
||||||
|
|
@ -1867,7 +1863,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[MemberData(nameof(ConnectionAdapterData))]
|
[MemberData(nameof(ConnectionAdapterData))]
|
||||||
public async Task ZeroContentLengthNotSetAutomaticallyForCertainStatusCodes(ListenOptions listenOptions)
|
public async Task ZeroContentLengthNotSetAutomaticallyForCertainStatusCodes(ListenOptions listenOptions)
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext();
|
var testContext= new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
using (var server = new TestServer(async httpContext =>
|
using (var server = new TestServer(async httpContext =>
|
||||||
{
|
{
|
||||||
|
|
@ -1924,7 +1920,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[MemberData(nameof(ConnectionAdapterData))]
|
[MemberData(nameof(ConnectionAdapterData))]
|
||||||
public async Task ConnectionClosedAfter101Response(ListenOptions listenOptions)
|
public async Task ConnectionClosedAfter101Response(ListenOptions listenOptions)
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext();
|
var testContext= new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
using (var server = new TestServer(async httpContext =>
|
using (var server = new TestServer(async httpContext =>
|
||||||
{
|
{
|
||||||
|
|
@ -1971,13 +1967,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[MemberData(nameof(ConnectionAdapterData))]
|
[MemberData(nameof(ConnectionAdapterData))]
|
||||||
public async Task ThrowingResultsIn500Response(ListenOptions listenOptions)
|
public async Task ThrowingResultsIn500Response(ListenOptions listenOptions)
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext();
|
var testContext= new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
bool onStartingCalled = false;
|
bool onStartingCalled = false;
|
||||||
|
|
||||||
var testLogger = new TestApplicationErrorLogger();
|
|
||||||
testContext.Log = new KestrelTrace(testLogger);
|
|
||||||
|
|
||||||
using (var server = new TestServer(httpContext =>
|
using (var server = new TestServer(httpContext =>
|
||||||
{
|
{
|
||||||
var response = httpContext.Response;
|
var response = httpContext.Response;
|
||||||
|
|
@ -2018,7 +2011,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.False(onStartingCalled);
|
Assert.False(onStartingCalled);
|
||||||
Assert.Equal(2, testLogger.ApplicationErrorsLogged);
|
Assert.Equal(2, TestApplicationErrorLogger.Messages.Where(message => message.LogLevel == LogLevel.Error).Count());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
|
|
@ -2028,9 +2021,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
var callback1Called = false;
|
var callback1Called = false;
|
||||||
var callback2CallCount = 0;
|
var callback2CallCount = 0;
|
||||||
|
|
||||||
var testContext = new TestServiceContext();
|
var testContext= new TestServiceContext(LoggerFactory);
|
||||||
var testLogger = new TestApplicationErrorLogger();
|
|
||||||
testContext.Log = new KestrelTrace(testLogger);
|
|
||||||
|
|
||||||
using (var server = new TestServer(async httpContext =>
|
using (var server = new TestServer(async httpContext =>
|
||||||
{
|
{
|
||||||
|
|
@ -2079,21 +2070,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
// since they are called LIFO order and the other one failed.
|
// since they are called LIFO order and the other one failed.
|
||||||
Assert.False(callback1Called);
|
Assert.False(callback1Called);
|
||||||
Assert.Equal(2, callback2CallCount);
|
Assert.Equal(2, callback2CallCount);
|
||||||
Assert.Equal(2, testLogger.ApplicationErrorsLogged);
|
Assert.Equal(2, TestApplicationErrorLogger.Messages.Where(message => message.LogLevel == LogLevel.Error).Count());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[MemberData(nameof(ConnectionAdapterData))]
|
[MemberData(nameof(ConnectionAdapterData))]
|
||||||
public async Task ThrowingInOnCompletedIsLogged(ListenOptions listenOptions)
|
public async Task ThrowingInOnCompletedIsLogged(ListenOptions listenOptions)
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext();
|
var testContext= new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
var onCompletedCalled1 = false;
|
var onCompletedCalled1 = false;
|
||||||
var onCompletedCalled2 = false;
|
var onCompletedCalled2 = false;
|
||||||
|
|
||||||
var testLogger = new TestApplicationErrorLogger();
|
|
||||||
testContext.Log = new KestrelTrace(testLogger);
|
|
||||||
|
|
||||||
using (var server = new TestServer(async httpContext =>
|
using (var server = new TestServer(async httpContext =>
|
||||||
{
|
{
|
||||||
var response = httpContext.Response;
|
var response = httpContext.Response;
|
||||||
|
|
@ -2130,7 +2118,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
}
|
}
|
||||||
|
|
||||||
// All OnCompleted callbacks should be called even if they throw.
|
// All OnCompleted callbacks should be called even if they throw.
|
||||||
Assert.Equal(2, testLogger.ApplicationErrorsLogged);
|
Assert.Equal(2, TestApplicationErrorLogger.Messages.Where(message => message.LogLevel == LogLevel.Error).Count());
|
||||||
Assert.True(onCompletedCalled1);
|
Assert.True(onCompletedCalled1);
|
||||||
Assert.True(onCompletedCalled2);
|
Assert.True(onCompletedCalled2);
|
||||||
}
|
}
|
||||||
|
|
@ -2139,13 +2127,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[MemberData(nameof(ConnectionAdapterData))]
|
[MemberData(nameof(ConnectionAdapterData))]
|
||||||
public async Task ThrowingAfterWritingKillsConnection(ListenOptions listenOptions)
|
public async Task ThrowingAfterWritingKillsConnection(ListenOptions listenOptions)
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext();
|
var testContext= new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
bool onStartingCalled = false;
|
bool onStartingCalled = false;
|
||||||
|
|
||||||
var testLogger = new TestApplicationErrorLogger();
|
|
||||||
testContext.Log = new KestrelTrace(testLogger);
|
|
||||||
|
|
||||||
using (var server = new TestServer(async httpContext =>
|
using (var server = new TestServer(async httpContext =>
|
||||||
{
|
{
|
||||||
var response = httpContext.Response;
|
var response = httpContext.Response;
|
||||||
|
|
@ -2177,20 +2162,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.True(onStartingCalled);
|
Assert.True(onStartingCalled);
|
||||||
Assert.Equal(1, testLogger.ApplicationErrorsLogged);
|
Assert.Single(TestApplicationErrorLogger.Messages, message => message.LogLevel == LogLevel.Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[MemberData(nameof(ConnectionAdapterData))]
|
[MemberData(nameof(ConnectionAdapterData))]
|
||||||
public async Task ThrowingAfterPartialWriteKillsConnection(ListenOptions listenOptions)
|
public async Task ThrowingAfterPartialWriteKillsConnection(ListenOptions listenOptions)
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext();
|
var testContext= new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
bool onStartingCalled = false;
|
bool onStartingCalled = false;
|
||||||
|
|
||||||
var testLogger = new TestApplicationErrorLogger();
|
|
||||||
testContext.Log = new KestrelTrace(testLogger);
|
|
||||||
|
|
||||||
using (var server = new TestServer(async httpContext =>
|
using (var server = new TestServer(async httpContext =>
|
||||||
{
|
{
|
||||||
var response = httpContext.Response;
|
var response = httpContext.Response;
|
||||||
|
|
@ -2222,7 +2204,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.True(onStartingCalled);
|
Assert.True(onStartingCalled);
|
||||||
Assert.Equal(1, testLogger.ApplicationErrorsLogged);
|
Assert.Single(TestApplicationErrorLogger.Messages, message => message.LogLevel == LogLevel.Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
|
|
@ -2261,7 +2243,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
}
|
}
|
||||||
|
|
||||||
writeTcs.SetException(new Exception("This shouldn't be reached."));
|
writeTcs.SetException(new Exception("This shouldn't be reached."));
|
||||||
}, new TestServiceContext(), listenOptions))
|
}, new TestServiceContext(LoggerFactory), listenOptions))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
@ -2288,10 +2270,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[MemberData(nameof(ConnectionAdapterData))]
|
[MemberData(nameof(ConnectionAdapterData))]
|
||||||
public async Task NoErrorsLoggedWhenServerEndsConnectionBeforeClient(ListenOptions listenOptions)
|
public async Task NoErrorsLoggedWhenServerEndsConnectionBeforeClient(ListenOptions listenOptions)
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext();
|
var testContext= new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
var testLogger = new TestApplicationErrorLogger();
|
|
||||||
testContext.Log = new KestrelTrace(testLogger);
|
|
||||||
|
|
||||||
using (var server = new TestServer(async httpContext =>
|
using (var server = new TestServer(async httpContext =>
|
||||||
{
|
{
|
||||||
|
|
@ -2316,14 +2295,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.Equal(0, testLogger.TotalErrorsLogged);
|
Assert.Empty(TestApplicationErrorLogger.Messages.Where(message => message.LogLevel == LogLevel.Error));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[MemberData(nameof(ConnectionAdapterData))]
|
[MemberData(nameof(ConnectionAdapterData))]
|
||||||
public async Task NoResponseSentWhenConnectionIsClosedByServerBeforeClientFinishesSendingRequest(ListenOptions listenOptions)
|
public async Task NoResponseSentWhenConnectionIsClosedByServerBeforeClientFinishesSendingRequest(ListenOptions listenOptions)
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext();
|
var testContext= new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
using (var server = new TestServer(httpContext =>
|
using (var server = new TestServer(httpContext =>
|
||||||
{
|
{
|
||||||
|
|
@ -2347,7 +2326,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[MemberData(nameof(ConnectionAdapterData))]
|
[MemberData(nameof(ConnectionAdapterData))]
|
||||||
public async Task ResponseHeadersAreResetOnEachRequest(ListenOptions listenOptions)
|
public async Task ResponseHeadersAreResetOnEachRequest(ListenOptions listenOptions)
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext();
|
var testContext= new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
IHeaderDictionary originalResponseHeaders = null;
|
IHeaderDictionary originalResponseHeaders = null;
|
||||||
var firstRequest = true;
|
var firstRequest = true;
|
||||||
|
|
@ -2400,7 +2379,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
const string response = "hello, world";
|
const string response = "hello, world";
|
||||||
|
|
||||||
var testContext = new TestServiceContext();
|
var testContext= new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
var callOrder = new Stack<int>();
|
var callOrder = new Stack<int>();
|
||||||
var onStartingTcs = new TaskCompletionSource<object>();
|
var onStartingTcs = new TaskCompletionSource<object>();
|
||||||
|
|
@ -2452,7 +2431,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
const string response = "hello, world";
|
const string response = "hello, world";
|
||||||
|
|
||||||
var testContext = new TestServiceContext();
|
var testContext= new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
var callOrder = new Stack<int>();
|
var callOrder = new Stack<int>();
|
||||||
var onCompletedTcs = new TaskCompletionSource<object>();
|
var onCompletedTcs = new TaskCompletionSource<object>();
|
||||||
|
|
@ -2526,7 +2505,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
|
|
||||||
await context.Response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello2"), 0, 6);
|
await context.Response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello2"), 0, 6);
|
||||||
}
|
}
|
||||||
}))
|
}, new TestServiceContext(LoggerFactory)))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
@ -2552,7 +2531,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task SynchronousWritesCanBeDisallowedGlobally()
|
public async Task SynchronousWritesCanBeDisallowedGlobally()
|
||||||
{
|
{
|
||||||
var testContext = new TestServiceContext
|
var testContext = new TestServiceContext(LoggerFactory)
|
||||||
{
|
{
|
||||||
ServerOptions = { AllowSynchronousIO = false }
|
ServerOptions = { AllowSynchronousIO = false }
|
||||||
};
|
};
|
||||||
|
|
@ -2698,9 +2677,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
.Setup(trace => trace.ResponseMininumDataRateNotSatisfied(It.IsAny<string>(), It.IsAny<string>()))
|
.Setup(trace => trace.ResponseMininumDataRateNotSatisfied(It.IsAny<string>(), It.IsAny<string>()))
|
||||||
.Callback(() => messageLogged.Set());
|
.Callback(() => messageLogged.Set());
|
||||||
|
|
||||||
var testContext = new TestServiceContext
|
var testContext = new TestServiceContext(LoggerFactory, mockKestrelTrace.Object)
|
||||||
{
|
{
|
||||||
Log = mockKestrelTrace.Object,
|
|
||||||
SystemClock = new SystemClock(),
|
SystemClock = new SystemClock(),
|
||||||
ServerOptions =
|
ServerOptions =
|
||||||
{
|
{
|
||||||
|
|
@ -2768,7 +2746,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
response.ContentLength = 42;
|
response.ContentLength = 42;
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}))
|
}, new TestServiceContext(LoggerFactory)))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using Microsoft.Extensions.Logging.Testing;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNetCore.Testing
|
||||||
|
{
|
||||||
|
public class TestApplicationErrorLoggerLoggedTest : LoggedTest
|
||||||
|
{
|
||||||
|
public TestApplicationErrorLogger TestApplicationErrorLogger { get; private set; }
|
||||||
|
|
||||||
|
public override void AdditionalSetup()
|
||||||
|
{
|
||||||
|
TestApplicationErrorLogger = new TestApplicationErrorLogger();
|
||||||
|
LoggerFactory.AddProvider(new KestrelTestLoggerProvider(TestApplicationErrorLogger));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -16,7 +16,6 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal;
|
||||||
using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal;
|
using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal;
|
||||||
using Microsoft.AspNetCore.Testing;
|
using Microsoft.AspNetCore.Testing;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
|
|
|
||||||
|
|
@ -9,20 +9,13 @@ using Microsoft.AspNetCore.Server.Kestrel.Core;
|
||||||
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
|
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Server.Kestrel.Tests;
|
using Microsoft.AspNetCore.Server.Kestrel.Tests;
|
||||||
using Microsoft.AspNetCore.Testing;
|
using Microsoft.AspNetCore.Testing;
|
||||||
|
using Microsoft.Extensions.Logging.Testing;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using Xunit.Abstractions;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
public class UpgradeTests
|
public class UpgradeTests : LoggedTest
|
||||||
{
|
{
|
||||||
private readonly ITestOutputHelper _output;
|
|
||||||
|
|
||||||
public UpgradeTests(ITestOutputHelper output)
|
|
||||||
{
|
|
||||||
_output = output;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task ResponseThrowsAfterUpgrade()
|
public async Task ResponseThrowsAfterUpgrade()
|
||||||
{
|
{
|
||||||
|
|
@ -42,7 +35,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
}
|
}
|
||||||
|
|
||||||
upgrade.TrySetResult(true);
|
upgrade.TrySetResult(true);
|
||||||
}))
|
}, new TestServiceContext(LoggerFactory)))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
@ -93,7 +86,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
upgrade.SetException(ex);
|
upgrade.SetException(ex);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}))
|
}, new TestServiceContext(LoggerFactory)))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
@ -136,7 +129,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
await Task.Delay(100);
|
await Task.Delay(100);
|
||||||
}
|
}
|
||||||
}))
|
}, new TestServiceContext(LoggerFactory)))
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
await connection.SendEmptyGetWithUpgrade();
|
await connection.SendEmptyGetWithUpgrade();
|
||||||
|
|
@ -155,7 +148,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task RejectsRequestWithContentLengthAndUpgrade()
|
public async Task RejectsRequestWithContentLengthAndUpgrade()
|
||||||
{
|
{
|
||||||
using (var server = new TestServer(context => Task.CompletedTask))
|
using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory)))
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
await connection.Send("POST / HTTP/1.1",
|
await connection.Send("POST / HTTP/1.1",
|
||||||
|
|
@ -178,7 +171,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task AcceptsRequestWithNoContentLengthAndUpgrade()
|
public async Task AcceptsRequestWithNoContentLengthAndUpgrade()
|
||||||
{
|
{
|
||||||
using (var server = new TestServer(context => Task.CompletedTask))
|
using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory)))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
@ -202,7 +195,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task RejectsRequestWithChunkedEncodingAndUpgrade()
|
public async Task RejectsRequestWithChunkedEncodingAndUpgrade()
|
||||||
{
|
{
|
||||||
using (var server = new TestServer(context => Task.CompletedTask))
|
using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory)))
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
await connection.Send("POST / HTTP/1.1",
|
await connection.Send("POST / HTTP/1.1",
|
||||||
|
|
@ -226,7 +219,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
var upgradeTcs = new TaskCompletionSource<bool>();
|
var upgradeTcs = new TaskCompletionSource<bool>();
|
||||||
using (var server = new TestServer(async context =>
|
using (var server = new TestServer(async context =>
|
||||||
{
|
{
|
||||||
var feature = context.Features.Get<IHttpUpgradeFeature>();
|
var feature = context.Features.Get<IHttpUpgradeFeature>();
|
||||||
Assert.False(feature.IsUpgradableRequest);
|
Assert.False(feature.IsUpgradableRequest);
|
||||||
try
|
try
|
||||||
|
|
@ -241,7 +234,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
upgradeTcs.TrySetResult(false);
|
upgradeTcs.TrySetResult(false);
|
||||||
}
|
}
|
||||||
}))
|
}, new TestServiceContext(LoggerFactory)))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
|
|
@ -259,7 +252,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
const int limit = 10;
|
const int limit = 10;
|
||||||
var upgradeTcs = new TaskCompletionSource<object>();
|
var upgradeTcs = new TaskCompletionSource<object>();
|
||||||
var serviceContext = new TestServiceContext();
|
var serviceContext = new TestServiceContext(LoggerFactory);
|
||||||
serviceContext.ConnectionManager = new HttpConnectionManager(serviceContext.Log, ResourceCounter.Quota(limit));
|
serviceContext.ConnectionManager = new HttpConnectionManager(serviceContext.Log, ResourceCounter.Quota(limit));
|
||||||
|
|
||||||
using (var server = new TestServer(async context =>
|
using (var server = new TestServer(async context =>
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<AssemblyName>Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.FunctionalTests</AssemblyName>
|
<AssemblyName>Libuv.FunctionalTests</AssemblyName>
|
||||||
<RootNamespace>Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.FunctionalTests</RootNamespace>
|
<RootNamespace>Libuv.FunctionalTests</RootNamespace>
|
||||||
<TargetFrameworks>$(StandardTestTfms)</TargetFrameworks>
|
<TargetFrameworks>$(StandardTestTfms)</TargetFrameworks>
|
||||||
<DefineConstants Condition="$([MSBuild]::IsOSPlatform('OSX'))">$(DefineConstants);MACOS</DefineConstants>
|
<DefineConstants Condition="$([MSBuild]::IsOSPlatform('OSX'))">$(DefineConstants);MACOS</DefineConstants>
|
||||||
<ServerGarbageCollection>true</ServerGarbageCollection>
|
<ServerGarbageCollection>true</ServerGarbageCollection>
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,12 @@ using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
||||||
using Microsoft.AspNetCore.Testing;
|
using Microsoft.AspNetCore.Testing;
|
||||||
using Microsoft.AspNetCore.Testing.xunit;
|
using Microsoft.AspNetCore.Testing.xunit;
|
||||||
|
using Microsoft.Extensions.Logging.Testing;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
[OSSkipCondition(OperatingSystems.Windows, SkipReason = "Listening to open TCP socket and/or pipe handles is not supported on Windows.")]
|
[OSSkipCondition(OperatingSystems.Windows, SkipReason = "Listening to open TCP socket and/or pipe handles is not supported on Windows.")]
|
||||||
public class ListenHandleTests
|
public class ListenHandleTests : LoggedTest
|
||||||
{
|
{
|
||||||
[ConditionalFact]
|
[ConditionalFact]
|
||||||
public async Task CanListenToOpenTcpSocketHandle()
|
public async Task CanListenToOpenTcpSocketHandle()
|
||||||
|
|
@ -20,7 +21,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
{
|
{
|
||||||
listenSocket.Bind(new IPEndPoint(IPAddress.Loopback, 0));
|
listenSocket.Bind(new IPEndPoint(IPAddress.Loopback, 0));
|
||||||
|
|
||||||
using (var server = new TestServer(_ => Task.CompletedTask, new TestServiceContext(), new ListenOptions((ulong)listenSocket.Handle)))
|
using (var server = new TestServer(_ => Task.CompletedTask, new TestServiceContext(LoggerFactory), new ListenOptions((ulong)listenSocket.Handle)))
|
||||||
{
|
{
|
||||||
using (var connection = new TestConnection(((IPEndPoint)listenSocket.LocalEndPoint).Port))
|
using (var connection = new TestConnection(((IPEndPoint)listenSocket.LocalEndPoint).Port))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<AssemblyName>Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.FunctionalTests</AssemblyName>
|
<AssemblyName>Sockets.FunctionalTests</AssemblyName>
|
||||||
<RootNamespace>Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.FunctionalTests</RootNamespace>
|
<RootNamespace>Sockets.FunctionalTests</RootNamespace>
|
||||||
<TargetFrameworks>$(StandardTestTfms)</TargetFrameworks>
|
<TargetFrameworks>$(StandardTestTfms)</TargetFrameworks>
|
||||||
<DefineConstants Condition="$([MSBuild]::IsOSPlatform('OSX'))">$(DefineConstants);MACOS</DefineConstants>
|
<DefineConstants Condition="$([MSBuild]::IsOSPlatform('OSX'))">$(DefineConstants);MACOS</DefineConstants>
|
||||||
<DefineConstants>$(DefineConstants);SOCKETS</DefineConstants>
|
<DefineConstants>$(DefineConstants);SOCKETS</DefineConstants>
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal;
|
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal;
|
||||||
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
|
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
|
||||||
|
|
@ -15,6 +16,8 @@ namespace Microsoft.AspNetCore.Testing
|
||||||
// Application errors are logged using 13 as the eventId.
|
// Application errors are logged using 13 as the eventId.
|
||||||
private const int ApplicationErrorEventId = 13;
|
private const int ApplicationErrorEventId = 13;
|
||||||
|
|
||||||
|
public List<Type> IgnoredExceptions { get; } = new List<Type>();
|
||||||
|
|
||||||
public bool ThrowOnCriticalErrors { get; set; } = true;
|
public bool ThrowOnCriticalErrors { get; set; } = true;
|
||||||
|
|
||||||
public ConcurrentQueue<LogMessage> Messages { get; } = new ConcurrentQueue<LogMessage>();
|
public ConcurrentQueue<LogMessage> Messages { get; } = new ConcurrentQueue<LogMessage>();
|
||||||
|
|
@ -49,7 +52,7 @@ namespace Microsoft.AspNetCore.Testing
|
||||||
|
|
||||||
Console.WriteLine(log);
|
Console.WriteLine(log);
|
||||||
|
|
||||||
if (logLevel == LogLevel.Critical && ThrowOnCriticalErrors)
|
if (logLevel == LogLevel.Critical && ThrowOnCriticalErrors && !IgnoredExceptions.Contains(exception.GetType()))
|
||||||
{
|
{
|
||||||
throw new Exception($"Unexpected critical error. {log}", exception);
|
throw new Exception($"Unexpected critical error. {log}", exception);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue