From: Tomas Weinfurt Date: Mon, 15 Apr 2019 22:15:32 +0000 (-0700) Subject: add test for lower casing header name logic (dotnet/corefx#36708) X-Git-Tag: submit/tizen/20210909.063632~11031^2~1868 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bb20d2572d9cd6291881d7021a124147f797834e;p=platform%2Fupstream%2Fdotnet%2Fruntime.git add test for lower casing header name logic (dotnet/corefx#36708) * add test for 35164 * update SocketsHttpHandler_HttpClientHandler_Cancellation_Test_Http2 * fix uwp tests * change port from 123 to 443 Commit migrated from https://github.com/dotnet/corefx/commit/4e3b46c22cec88a1f0deaa2f594634e5553412e1 --- diff --git a/src/libraries/Common/tests/System/Net/Http/GenericLoopbackServer.cs b/src/libraries/Common/tests/System/Net/Http/GenericLoopbackServer.cs index c9858cf..f644602 100644 --- a/src/libraries/Common/tests/System/Net/Http/GenericLoopbackServer.cs +++ b/src/libraries/Common/tests/System/Net/Http/GenericLoopbackServer.cs @@ -13,14 +13,14 @@ namespace System.Net.Test.Common public abstract class LoopbackServerFactory { - public abstract Task CreateServerAsync(Func funcAsync); + public abstract Task CreateServerAsync(Func funcAsync, int millisecondsTimeout = 30_000); public abstract bool IsHttp11 { get; } public abstract bool IsHttp2 { get; } // Common helper methods - public Task CreateClientAndServerAsync(Func clientFunc, Func serverFunc) + public Task CreateClientAndServerAsync(Func clientFunc, Func serverFunc, int millisecondsTimeout = 30_000) { return CreateServerAsync(async (server, uri) => { @@ -28,7 +28,7 @@ namespace System.Net.Test.Common Task serverTask = serverFunc(server); await new Task[] { clientTask, serverTask }.WhenAllOrAnyFailed(); - }); + }).TimeoutAfter(millisecondsTimeout); } } diff --git a/src/libraries/Common/tests/System/Net/Http/Http2LoopbackServer.cs b/src/libraries/Common/tests/System/Net/Http/Http2LoopbackServer.cs index 54a37d3..6c14210 100644 --- a/src/libraries/Common/tests/System/Net/Http/Http2LoopbackServer.cs +++ b/src/libraries/Common/tests/System/Net/Http/Http2LoopbackServer.cs @@ -673,11 +673,11 @@ namespace System.Net.Test.Common { public static readonly Http2LoopbackServerFactory Singleton = new Http2LoopbackServerFactory(); - public override async Task CreateServerAsync(Func funcAsync) + public override async Task CreateServerAsync(Func funcAsync, int millisecondsTimeout = 30_000) { using (var server = Http2LoopbackServer.CreateServer()) { - await funcAsync(server, server.Address); + await funcAsync(server, server.Address).TimeoutAfter(millisecondsTimeout); } } diff --git a/src/libraries/Common/tests/System/Net/Http/LoopbackServer.cs b/src/libraries/Common/tests/System/Net/Http/LoopbackServer.cs index 409fd11..25cdaf5 100644 --- a/src/libraries/Common/tests/System/Net/Http/LoopbackServer.cs +++ b/src/libraries/Common/tests/System/Net/Http/LoopbackServer.cs @@ -685,7 +685,7 @@ namespace System.Net.Test.Common { public static readonly Http11LoopbackServerFactory Singleton = new Http11LoopbackServerFactory(); - public override Task CreateServerAsync(Func funcAsync) + public override Task CreateServerAsync(Func funcAsync, int millisecondsTimeout = 30_000) { return LoopbackServer.CreateServerAsync((server, uri) => funcAsync(server, uri)); } diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/DefaultCredentialsTest.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/DefaultCredentialsTest.cs index db011f1..3b21906 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/DefaultCredentialsTest.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/DefaultCredentialsTest.cs @@ -36,12 +36,7 @@ namespace System.Net.Http.Functional.Tests private static Uri s_authenticatedServer = DomainJoinedTestsEnabled ? new Uri($"http://{Configuration.Http.DomainJoinedHttpHost}/test/auth/negotiate/showidentity.ashx") : null; - private readonly ITestOutputHelper _output; - - public DefaultCredentialsTest(ITestOutputHelper output) - { - _output = output; - } + public DefaultCredentialsTest(ITestOutputHelper output) : base(output) { } [OuterLoop("Uses external server")] [ConditionalTheory(nameof(ServerAuthenticationTestsEnabled))] diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/DiagnosticsTests.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/DiagnosticsTests.cs index 2b07e41..dc8e57b 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/DiagnosticsTests.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/DiagnosticsTests.cs @@ -14,6 +14,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.DotNet.RemoteExecutor; using Xunit; +using Xunit.Abstractions; namespace System.Net.Http.Functional.Tests { @@ -23,6 +24,8 @@ namespace System.Net.Http.Functional.Tests [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "NetEventSource is only part of .NET Core.")] public abstract class DiagnosticsTest : HttpClientHandlerTestBase { + public DiagnosticsTest(ITestOutputHelper output) : base(output) { } + [Fact] public static void EventSource_ExistsWithCorrectId() { diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClient.SelectedSitesTest.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClient.SelectedSitesTest.cs index d6decc2..8009eb7 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClient.SelectedSitesTest.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClient.SelectedSitesTest.cs @@ -8,11 +8,14 @@ using System.Reflection; using System.Threading.Tasks; using Xunit; +using Xunit.Abstractions; namespace System.Net.Http.Functional.Tests { public abstract class HttpClient_SelectedSites_Test : HttpClientHandlerTestBase { + public HttpClient_SelectedSites_Test(ITestOutputHelper output) : base(output) { } + public static bool IsSelectedSitesTestEnabled() { string envVar = Environment.GetEnvironmentVariable("CORFX_NET_HTTP_SELECTED_SITES"); diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientEKUTest.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientEKUTest.cs index e2a6cc8..81d3002 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientEKUTest.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientEKUTest.cs @@ -10,6 +10,7 @@ using System.Security.Cryptography.X509Certificates; using System.Threading.Tasks; using Xunit; +using Xunit.Abstractions; namespace System.Net.Http.Functional.Tests { @@ -44,6 +45,8 @@ namespace System.Net.Http.Functional.Tests private VerboseTestLogging _log = VerboseTestLogging.GetInstance(); + public HttpClientEKUTest(ITestOutputHelper output) : base(output) { } + [ConditionalFact(nameof(CanTestCertificates))] public async Task HttpClient_NoEKUServerAuth_Ok() { diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.AcceptAllCerts.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.AcceptAllCerts.cs index 3fd307c..25e0016 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.AcceptAllCerts.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.AcceptAllCerts.cs @@ -7,6 +7,7 @@ using System.Net.Test.Common; using System.Security.Authentication; using System.Threading.Tasks; using Xunit; +using Xunit.Abstractions; namespace System.Net.Http.Functional.Tests { @@ -16,6 +17,8 @@ namespace System.Net.Http.Functional.Tests { private static bool ClientSupportsDHECipherSuites => (!PlatformDetection.IsWindows || PlatformDetection.IsWindows10Version1607OrGreater); + public HttpClientHandler_DangerousAcceptAllCertificatesValidator_Test(ITestOutputHelper output) : base(output) { } + [Fact] public void SingletonReturnsTrue() { diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Asynchrony.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Asynchrony.cs index ba18160..2239e49 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Asynchrony.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Asynchrony.cs @@ -10,11 +10,14 @@ using System.Threading; using System.Threading.Tasks; using System.Threading.Tests; using Xunit; +using Xunit.Abstractions; namespace System.Net.Http.Functional.Tests { public abstract class HttpClientHandler_Asynchrony_Test : HttpClientHandlerTestBase { + public HttpClientHandler_Asynchrony_Test(ITestOutputHelper output) : base(output) { } + public static IEnumerable ResponseHeadersRead_SynchronizationContextNotUsedByHandler_MemberData() => from responseHeadersRead in new[] { false, true } from contentMode in Enum.GetValues(typeof(LoopbackServer.ContentMode)).Cast() diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Authentication.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Authentication.cs index a67331b..dd882fb 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Authentication.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Authentication.cs @@ -19,8 +19,6 @@ namespace System.Net.Http.Functional.Tests [SkipOnTargetFramework(TargetFrameworkMonikers.Uap, "Tests would need to be rewritten due to behavior differences with WinRT")] public abstract class HttpClientHandler_Authentication_Test : HttpClientHandlerTestBase { - private readonly ITestOutputHelper _output; - private const string Username = "testusername"; private const string Password = "testpassword"; private const string Domain = "testdomain"; @@ -39,10 +37,7 @@ namespace System.Net.Http.Functional.Tests } }; - public HttpClientHandler_Authentication_Test(ITestOutputHelper output) - { - _output = output; - } + public HttpClientHandler_Authentication_Test(ITestOutputHelper output) : base(output) { } [Theory] [MemberData(nameof(Authentication_TestData))] diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.AutoRedirect.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.AutoRedirect.cs index 8cc5429..9a3fb6f 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.AutoRedirect.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.AutoRedirect.cs @@ -17,7 +17,6 @@ namespace System.Net.Http.Functional.Tests public abstract class HttpClientHandlerTest_AutoRedirect : HttpClientHandlerTestBase { - readonly ITestOutputHelper _output; private const string ExpectedContent = "Test content"; private const string Username = "testuser"; private const string Password = "password"; @@ -61,10 +60,7 @@ namespace System.Net.Http.Functional.Tests new object[] { 308, "HEAD", "HEAD" }, }; - public HttpClientHandlerTest_AutoRedirect(ITestOutputHelper output) - { - _output = output; - } + public HttpClientHandlerTest_AutoRedirect(ITestOutputHelper output) : base(output) { } [OuterLoop("Uses external server")] [Theory, MemberData(nameof(RedirectStatusCodes))] diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Cancellation.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Cancellation.cs index 77d4caf..9c061ad 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Cancellation.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Cancellation.cs @@ -10,11 +10,14 @@ using System.Net.Test.Common; using System.Threading; using System.Threading.Tasks; using Xunit; +using Xunit.Abstractions; namespace System.Net.Http.Functional.Tests { public abstract class HttpClientHandler_Cancellation_Test : HttpClientHandlerTestBase { + public HttpClientHandler_Cancellation_Test(ITestOutputHelper output) : base(output) { } + [Theory] [InlineData(false, CancellationMode.Token)] [InlineData(true, CancellationMode.Token)] diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.ClientCertificates.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.ClientCertificates.cs index 312d8bd..5d888af 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.ClientCertificates.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.ClientCertificates.cs @@ -26,12 +26,8 @@ namespace System.Net.Http.Functional.Tests public bool CanTestClientCertificates => CanTestCertificates && BackendSupportsCustomCertificateHandling; - public HttpClientHandler_ClientCertificates_Test(ITestOutputHelper output) - { - _output = output; - } + public HttpClientHandler_ClientCertificates_Test(ITestOutputHelper output) : base(output) { } - private readonly ITestOutputHelper _output; [Fact] public void ClientCertificateOptions_Default() { diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Cookies.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Cookies.cs index ed7822a..060a5ef 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Cookies.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Cookies.cs @@ -9,6 +9,7 @@ using System.Net.Test.Common; using System.Threading.Tasks; using Microsoft.DotNet.XUnitExtensions; using Xunit; +using Xunit.Abstractions; namespace System.Net.Http.Functional.Tests { @@ -22,6 +23,8 @@ namespace System.Net.Http.Functional.Tests private const string s_simpleContent = "Hello world!"; + public HttpClientHandlerTest_Cookies(ITestOutputHelper output) : base(output) { } + // // Send cookie tests // @@ -670,6 +673,8 @@ namespace System.Net.Http.Functional.Tests public abstract class HttpClientHandlerTest_Cookies_Http11 : HttpClientHandlerTestBase { + public HttpClientHandlerTest_Cookies_Http11(ITestOutputHelper output) : base(output) { } + [Fact] public async Task GetAsync_ReceiveMultipleSetCookieHeaders_CookieAdded() { diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Decompression.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Decompression.cs index 8af2fdb..dd1a284 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Decompression.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Decompression.cs @@ -16,14 +16,9 @@ namespace System.Net.Http.Functional.Tests { public abstract class HttpClientHandler_Decompression_Test : HttpClientHandlerTestBase { - private readonly ITestOutputHelper _output; - public static readonly object[][] CompressedServers = System.Net.Test.Common.Configuration.Http.CompressedServers; - public HttpClientHandler_Decompression_Test(ITestOutputHelper output) - { - _output = output; - } + public HttpClientHandler_Decompression_Test(ITestOutputHelper output) : base(output) { } public static IEnumerable DecompressedResponse_MethodSpecified_DecompressedContentReturned_MemberData() { diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.DefaultProxyCredentials.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.DefaultProxyCredentials.cs index e9326bd..aab7480 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.DefaultProxyCredentials.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.DefaultProxyCredentials.cs @@ -10,6 +10,7 @@ using System.Text; using System.Threading.Tasks; using Microsoft.DotNet.RemoteExecutor; using Xunit; +using Xunit.Abstractions; namespace System.Net.Http.Functional.Tests { @@ -17,6 +18,8 @@ namespace System.Net.Http.Functional.Tests public abstract class HttpClientHandler_DefaultProxyCredentials_Test : HttpClientHandlerTestBase { + public HttpClientHandler_DefaultProxyCredentials_Test(ITestOutputHelper output) : base(output) { } + [Fact] public void Default_Get_Null() { diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Headers.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Headers.cs new file mode 100644 index 0000000..37921cc --- /dev/null +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Headers.cs @@ -0,0 +1,111 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net.Test.Common; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +using Xunit; +using Xunit.Abstractions; + +namespace System.Net.Http.Functional.Tests +{ + using Configuration = System.Net.Test.Common.Configuration; + + public abstract class HttpClientHandlerTest_Headers : HttpClientHandlerTestBase + { + public HttpClientHandlerTest_Headers(ITestOutputHelper output) : base(output) { } + + [Fact] + public async Task SendAsync_UserAgent_CorrectlyWritten() + { + string userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.18 Safari/537.36"; + + await LoopbackServerFactory.CreateClientAndServerAsync(async uri => + { + using (var client = CreateHttpClient()) + { + var message = new HttpRequestMessage(HttpMethod.Get, uri); + message.Headers.TryAddWithoutValidation("User-Agent", userAgent); + (await client.SendAsync(message).ConfigureAwait(false)).Dispose(); + } + }, + async server => + { + HttpRequestData requestData = await server.HandleRequestAsync(HttpStatusCode.OK); + + string agent = requestData.GetSingleHeaderValue("User-Agent"); + Assert.Equal(userAgent, agent); + }); + } + + [Fact] + public async Task SendAsync_SpecialCharacterHeader_Success() + { + string headerValue = "header name with underscore"; + await LoopbackServerFactory.CreateClientAndServerAsync(async uri => + { + using (var client = CreateHttpClient()) + { + var message = new HttpRequestMessage(HttpMethod.Get, uri); + message.Headers.TryAddWithoutValidation("x-Special_name", "header name with underscore"); + (await client.SendAsync(message).ConfigureAwait(false)).Dispose(); + } + }, + async server => + { + HttpRequestData requestData = await server.HandleRequestAsync(HttpStatusCode.OK); + + string header = requestData.GetSingleHeaderValue("x-Special_name"); + Assert.Equal(header, headerValue); + }); + } + + [OuterLoop("Uses external server")] + [Theory] + [InlineData(false)] + [InlineData(true)] + public async Task SendAsync_GetWithValidHostHeader_Success(bool withPort) + { + var m = new HttpRequestMessage(HttpMethod.Get, Configuration.Http.SecureRemoteEchoServer); + m.Headers.Host = withPort ? Configuration.Http.SecureHost + ":443" : Configuration.Http.SecureHost; + + using (HttpClient client = CreateHttpClient()) + using (HttpResponseMessage response = await client.SendAsync(m)) + { + string responseContent = await response.Content.ReadAsStringAsync(); + _output.WriteLine(responseContent); + TestHelper.VerifyResponseBody( + responseContent, + response.Content.Headers.ContentMD5, + false, + null); + } + } + + [OuterLoop("Uses external server")] + [Fact] + public async Task SendAsync_GetWithInvalidHostHeader_ThrowsException() + { + if (PlatformDetection.IsNetCore && (!UseSocketsHttpHandler || LoopbackServerFactory.IsHttp2)) + { + // Only .NET Framework and SocketsHttpHandler with HTTP/1.x use the Host header to influence the SSL auth. + // Host header is not used for HTTP2 + return; + } + + var m = new HttpRequestMessage(HttpMethod.Get, Configuration.Http.SecureRemoteEchoServer); + m.Headers.Host = "hostheaderthatdoesnotmatch"; + + using (HttpClient client = CreateHttpClient()) + { + await Assert.ThrowsAsync(() => client.SendAsync(m)); + } + } + } +} diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Http2.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Http2.cs index a82e73f..daba271 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Http2.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Http2.cs @@ -8,6 +8,7 @@ using System.Threading; using System.Threading.Tasks; using Xunit; +using Xunit.Abstractions; namespace System.Net.Http.Functional.Tests { @@ -18,6 +19,8 @@ namespace System.Net.Http.Functional.Tests public static bool SupportsAlpn => PlatformDetection.SupportsAlpn; + public HttpClientHandlerTest_Http2(ITestOutputHelper output) : base(output) { } + [ConditionalFact(nameof(SupportsAlpn))] public async Task Http2_ClientPreface_Sent() { diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.MaxConnectionsPerServer.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.MaxConnectionsPerServer.cs index df5beb4..c73c3a1 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.MaxConnectionsPerServer.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.MaxConnectionsPerServer.cs @@ -9,6 +9,7 @@ using System.Threading; using System.Threading.Tasks; using Xunit; +using Xunit.Abstractions; namespace System.Net.Http.Functional.Tests { @@ -17,6 +18,8 @@ namespace System.Net.Http.Functional.Tests [SkipOnTargetFramework(TargetFrameworkMonikers.Uap, "UAP connection management behavior is different due to WinRT")] public abstract class HttpClientHandler_MaxConnectionsPerServer_Test : HttpClientHandlerTestBase { + public HttpClientHandler_MaxConnectionsPerServer_Test(ITestOutputHelper output) : base(output) { } + [Fact] [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "MaxConnectionsPerServer either returns two or int.MaxValue depending if ctor of HttpClientHandlerTest executed first. Disabling cause of random xunit execution order.")] public void Default_ExpectedValue() diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.MaxResponseHeadersLength.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.MaxResponseHeadersLength.cs index e4532d2..4ed05d6 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.MaxResponseHeadersLength.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.MaxResponseHeadersLength.cs @@ -8,6 +8,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using Xunit; +using Xunit.Abstractions; namespace System.Net.Http.Functional.Tests { @@ -15,6 +16,8 @@ namespace System.Net.Http.Functional.Tests public abstract class HttpClientHandler_MaxResponseHeadersLength_Test : HttpClientHandlerTestBase { + public HttpClientHandler_MaxResponseHeadersLength_Test(ITestOutputHelper output) : base(output) { } + [SkipOnTargetFramework(TargetFrameworkMonikers.Uap, "Not currently supported on UAP")] [Theory] [InlineData(0)] diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Proxy.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Proxy.cs index a0152d5..329e11f 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Proxy.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Proxy.cs @@ -17,12 +17,7 @@ namespace System.Net.Http.Functional.Tests [SkipOnTargetFramework(TargetFrameworkMonikers.Uap, "UAP HTTP stack doesn't support .Proxy property")] public abstract class HttpClientHandler_Proxy_Test : HttpClientHandlerTestBase { - private readonly ITestOutputHelper _output; - - public HttpClientHandler_Proxy_Test(ITestOutputHelper output) - { - _output = output; - } + public HttpClientHandler_Proxy_Test(ITestOutputHelper output) : base(output) { } [ActiveIssue(32809)] [OuterLoop("Uses external server")] diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.ResponseDrain.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.ResponseDrain.cs index 596493b..3ba0fb5 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.ResponseDrain.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.ResponseDrain.cs @@ -8,11 +8,14 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using Xunit; +using Xunit.Abstractions; namespace System.Net.Http.Functional.Tests { public abstract class HttpClientHandler_ResponseDrain_Test : HttpClientHandlerTestBase { + public HttpClientHandler_ResponseDrain_Test(ITestOutputHelper output) : base(output) { } + protected virtual void SetResponseDrainTimeout(HttpClientHandler handler, TimeSpan time) { } [OuterLoop] diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.ServerCertificates.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.ServerCertificates.cs index 2216045..1a7e7e7 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.ServerCertificates.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.ServerCertificates.cs @@ -12,6 +12,7 @@ using System.Security.Cryptography.X509Certificates; using System.Threading.Tasks; using Microsoft.DotNet.RemoteExecutor; using Xunit; +using Xunit.Abstractions; namespace System.Net.Http.Functional.Tests { @@ -24,6 +25,8 @@ namespace System.Net.Http.Functional.Tests private bool BackendSupportsCustomCertificateHandlingAndClientSupportsDHECipherSuites => (BackendSupportsCustomCertificateHandling && ClientSupportsDHECipherSuites); + public HttpClientHandler_ServerCertificates_Test(ITestOutputHelper output) : base(output) { } + [Fact] [SkipOnTargetFramework(~TargetFrameworkMonikers.Uap)] public void Ctor_ExpectedDefaultPropertyValues_UapPlatform() diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.SslProtocols.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.SslProtocols.cs index 9332ae0..9100253 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.SslProtocols.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.SslProtocols.cs @@ -11,6 +11,7 @@ using System.Security.Authentication; using System.Threading.Tasks; using Microsoft.DotNet.XUnitExtensions; using Xunit; +using Xunit.Abstractions; namespace System.Net.Http.Functional.Tests { @@ -20,6 +21,8 @@ namespace System.Net.Http.Functional.Tests [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "SslProtocols property requires .NET 4.7.2")] public abstract partial class HttpClientHandler_SslProtocols_Test : HttpClientHandlerTestBase { + public HttpClientHandler_SslProtocols_Test(ITestOutputHelper output) : base(output) { } + [Fact] public void DefaultProtocols_MatchesExpected() { diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.TrailingHeaders.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.TrailingHeaders.cs index f7e3678..08b436c 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.TrailingHeaders.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.TrailingHeaders.cs @@ -11,6 +11,7 @@ using System.Threading; using System.Threading.Tasks; using Xunit; +using Xunit.Abstractions; namespace System.Net.Http.Functional.Tests { @@ -23,6 +24,8 @@ namespace System.Net.Http.Functional.Tests private static Frame MakeDataFrame(int streamId, byte[] data, bool endStream = false) => new DataFrame(data, (endStream ? FrameFlags.EndStream : FrameFlags.None), 0, streamId); + public HttpClientHandlerTest_TrailingHeaders_Test (ITestOutputHelper output) : base(output) { } + [Theory] [InlineData(false)] [InlineData(true)] diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.cs index 9ab045a..997e7b7 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.cs @@ -29,7 +29,6 @@ namespace System.Net.Http.Functional.Tests // to separately Dispose (or have a 'using' statement) for the handler. public abstract class HttpClientHandlerTest : HttpClientHandlerTestBase { - readonly ITestOutputHelper _output; private const string ExpectedContent = "Test content"; private const string Username = "testuser"; private const string Password = "password"; @@ -64,12 +63,11 @@ namespace System.Net.Http.Functional.Tests } } - public HttpClientHandlerTest(ITestOutputHelper output) + public HttpClientHandlerTest(ITestOutputHelper output) : base(output) { - _output = output; if (PlatformDetection.IsFullFramework) { - // On .NET Framework, the default limit for connections/server is very low (2). + // On .NET Framework, the default limit for connections/server is very low (2). // On .NET Core, the default limit is higher. Since these tests run in parallel, // the limit needs to be increased to avoid timeouts when running the tests. System.Net.ServicePointManager.DefaultConnectionLimit = int.MaxValue; @@ -249,48 +247,6 @@ namespace System.Net.Http.Functional.Tests } } - [OuterLoop("Uses external server")] - [Theory] - [InlineData(false)] - [InlineData(true)] - public async Task SendAsync_GetWithValidHostHeader_Success(bool withPort) - { - var m = new HttpRequestMessage(HttpMethod.Get, Configuration.Http.SecureRemoteEchoServer); - m.Headers.Host = withPort ? Configuration.Http.SecureHost + ":123" : Configuration.Http.SecureHost; - - using (HttpClient client = CreateHttpClient()) - using (HttpResponseMessage response = await client.SendAsync(m)) - { - string responseContent = await response.Content.ReadAsStringAsync(); - _output.WriteLine(responseContent); - TestHelper.VerifyResponseBody( - responseContent, - response.Content.Headers.ContentMD5, - false, - null); - } - } - - [OuterLoop("Uses external server")] - [Fact] - public async Task SendAsync_GetWithInvalidHostHeader_ThrowsException() - { - if (PlatformDetection.IsNetCore && (!UseSocketsHttpHandler || LoopbackServerFactory.IsHttp2)) - { - // Only .NET Framework and SocketsHttpHandler with HTTP/1.x use the Host header to influence the SSL auth. - // Host header is not used for HTTP2 - return; - } - - var m = new HttpRequestMessage(HttpMethod.Get, Configuration.Http.SecureRemoteEchoServer); - m.Headers.Host = "hostheaderthatdoesnotmatch"; - - using (HttpClient client = CreateHttpClient()) - { - await Assert.ThrowsAsync(() => client.SendAsync(m)); - } - } - [ActiveIssue(22158, TargetFrameworkMonikers.Uap)] [Fact] public async Task GetAsync_IPv6LinkLocalAddressUri_Success() @@ -2660,29 +2616,6 @@ namespace System.Net.Http.Functional.Tests } #endregion - [Fact] - public async Task SendAsync_UserAgent_CorrectlyWritten() - { - string userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.18 Safari/537.36"; - - await LoopbackServerFactory.CreateClientAndServerAsync(async uri => - { - using (var client = CreateHttpClient()) - { - var message = new HttpRequestMessage(HttpMethod.Get, uri); - message.Headers.TryAddWithoutValidation("User-Agent", userAgent); - (await client.SendAsync(message).ConfigureAwait(false)).Dispose(); - } - }, - async server => - { - HttpRequestData requestData = await server.HandleRequestAsync(HttpStatusCode.OK); - - string agent = requestData.GetSingleHeaderValue("User-Agent"); - Assert.Equal(userAgent, agent); - }); - } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // [ActiveIssue(11057)] public async Task GetAsync_InvalidUrl_ExpectedExceptionThrown() { diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTestBase.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTestBase.cs index 27639e8..129a933 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTestBase.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTestBase.cs @@ -7,10 +7,14 @@ using System.IO; using System.Reflection; using System.Net.Test.Common; +using Xunit.Abstractions; + namespace System.Net.Http.Functional.Tests { public abstract class HttpClientHandlerTestBase : FileCleanupTestBase { + public readonly ITestOutputHelper _output; + protected virtual bool UseSocketsHttpHandler => true; protected virtual bool UseHttp2LoopbackServer => false; @@ -19,6 +23,11 @@ namespace System.Net.Http.Functional.Tests protected bool IsNetfxHandler => PlatformDetection.IsWindows && PlatformDetection.IsFullFramework; protected bool IsUapHandler => PlatformDetection.IsWindows && PlatformDetection.IsUap; + public HttpClientHandlerTestBase(ITestOutputHelper output) + { + _output = output; + } + protected HttpClient CreateHttpClient() => new HttpClient(CreateHttpClientHandler()); protected HttpClientHandler CreateHttpClientHandler() => CreateHttpClientHandler(UseSocketsHttpHandler, UseHttp2LoopbackServer); diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientMiniStressTest.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientMiniStressTest.cs index 5d107a8..2394d65 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientMiniStressTest.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientMiniStressTest.cs @@ -9,11 +9,14 @@ using System.Net.Test.Common; using System.Threading; using System.Threading.Tasks; using Xunit; +using Xunit.Abstractions; namespace System.Net.Http.Functional.Tests { public abstract class HttpClientMiniStress : HttpClientHandlerTestBase { + public HttpClientMiniStress(ITestOutputHelper output) : base(output) { } + [ConditionalTheory(typeof(TestEnvironment), nameof(TestEnvironment.IsStressModeEnabled))] [MemberData(nameof(GetStressOptions))] public void SingleClient_ManyGets_Sync(int numRequests, int dop, HttpCompletionOption completionOption) diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpProtocolTests.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpProtocolTests.cs index 543473b..0a0577e 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpProtocolTests.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpProtocolTests.cs @@ -8,6 +8,7 @@ using System.Net.Test.Common; using System.Threading; using System.Threading.Tasks; using Xunit; +using Xunit.Abstractions; namespace System.Net.Http.Functional.Tests { @@ -16,6 +17,8 @@ namespace System.Net.Http.Functional.Tests protected virtual Stream GetStream(Stream s) => s; protected virtual Stream GetStream_ClientDisconnectOk(Stream s) => s; + public HttpProtocolTests(ITestOutputHelper output) : base(output) { } + [SkipOnTargetFramework(TargetFrameworkMonikers.Uap, "Uap does not support 1.0")] [Fact] public async Task GetAsync_RequestVersion10_Success() @@ -642,6 +645,8 @@ namespace System.Net.Http.Functional.Tests public abstract class HttpProtocolTests_Dribble : HttpProtocolTests { + public HttpProtocolTests_Dribble(ITestOutputHelper output) : base(output) { } + protected override Stream GetStream(Stream s) => new DribbleStream(s); protected override Stream GetStream_ClientDisconnectOk(Stream s) => new DribbleStream(s, true); } diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpRequestMessageTest.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpRequestMessageTest.cs index dd3c419..aa02d41 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpRequestMessageTest.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpRequestMessageTest.cs @@ -11,6 +11,7 @@ using System.Threading; using System.Threading.Tasks; using Xunit; +using Xunit.Abstractions; namespace System.Net.Http.Functional.Tests { @@ -18,6 +19,8 @@ namespace System.Net.Http.Functional.Tests { Version _expectedRequestMessageVersion = !PlatformDetection.IsFullFramework ? new Version(2,0) : new Version(1, 1); + public HttpRequestMessageTest(ITestOutputHelper output) : base(output) { } + [Fact] public void Ctor_Default_CorrectDefaults() { diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpRetryProtocolTests.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpRetryProtocolTests.cs index 4134768..5a8a5264 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpRetryProtocolTests.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpRetryProtocolTests.cs @@ -9,6 +9,7 @@ using System.Net.Test.Common; using System.Text; using System.Threading.Tasks; using Xunit; +using Xunit.Abstractions; namespace System.Net.Http.Functional.Tests { @@ -19,6 +20,8 @@ namespace System.Net.Http.Functional.Tests // Retry logic is supported by SocketsHttpHandler, CurlHandler, uap, and netfx. Only WinHttp does not support. private bool IsRetrySupported => !IsWinHttpHandler; + public HttpRetryProtocolTests(ITestOutputHelper output) : base(output) { } + [Fact] [ActiveIssue(26770, TargetFrameworkMonikers.NetFramework)] public async Task GetAsync_RetryOnConnectionClosed_Success() diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/IdnaProtocolTests.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/IdnaProtocolTests.cs index 7c073c6..aa82b32 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/IdnaProtocolTests.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/IdnaProtocolTests.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Net.Test.Common; using System.Threading.Tasks; using Xunit; +using Xunit.Abstractions; namespace System.Net.Http.Functional.Tests { @@ -13,6 +14,8 @@ namespace System.Net.Http.Functional.Tests { protected abstract bool SupportsIdna { get; } + public IdnaProtocolTests(ITestOutputHelper output) : base(output) { } + [SkipOnTargetFramework(TargetFrameworkMonikers.Uap, "UAP does not support custom proxies.")] [Theory] [MemberData(nameof(InternationalHostNames))] diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/PlatformHandlerTest.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/PlatformHandlerTest.cs index 2720322..85f0d2f 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/PlatformHandlerTest.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/PlatformHandlerTest.cs @@ -12,6 +12,8 @@ namespace System.Net.Http.Functional.Tests public class PlatformHandler_HttpClientHandler : HttpClientHandlerTestBase { + public PlatformHandler_HttpClientHandler(ITestOutputHelper output) : base(output) { } + [Theory] [InlineData(false)] [InlineData(true)] @@ -59,31 +61,37 @@ namespace System.Net.Http.Functional.Tests public sealed class PlatformHandler_HttpClientHandler_Asynchrony_Test : HttpClientHandler_Asynchrony_Test { + public PlatformHandler_HttpClientHandler_Asynchrony_Test(ITestOutputHelper output) : base(output) { } protected override bool UseSocketsHttpHandler => false; } public sealed class PlatformHandler_HttpProtocolTests : HttpProtocolTests { + public PlatformHandler_HttpProtocolTests(ITestOutputHelper output) : base(output) { } protected override bool UseSocketsHttpHandler => false; } public sealed class PlatformHandler_HttpProtocolTests_Dribble : HttpProtocolTests_Dribble { + public PlatformHandler_HttpProtocolTests_Dribble(ITestOutputHelper output) : base(output) { } protected override bool UseSocketsHttpHandler => false; } public sealed class PlatformHandler_DiagnosticsTest : DiagnosticsTest { + public PlatformHandler_DiagnosticsTest(ITestOutputHelper output) : base(output) { } protected override bool UseSocketsHttpHandler => false; } public sealed class PlatformHandler_HttpClient_SelectedSites_Test : HttpClient_SelectedSites_Test { + public PlatformHandler_HttpClient_SelectedSites_Test(ITestOutputHelper output) : base(output) { } protected override bool UseSocketsHttpHandler => false; } public sealed class PlatformHandler_HttpClientEKUTest : HttpClientEKUTest { + public PlatformHandler_HttpClientEKUTest(ITestOutputHelper output) : base(output) { } protected override bool UseSocketsHttpHandler => false; } @@ -96,6 +104,7 @@ namespace System.Net.Http.Functional.Tests public sealed class PlatformHandler_HttpClientHandler_DangerousAcceptAllCertificatesValidator_Test : HttpClientHandler_DangerousAcceptAllCertificatesValidator_Test { + public PlatformHandler_HttpClientHandler_DangerousAcceptAllCertificatesValidator_Test(ITestOutputHelper output) : base(output) { } protected override bool UseSocketsHttpHandler => false; } #endif @@ -108,16 +117,19 @@ namespace System.Net.Http.Functional.Tests public sealed class PlatformHandler_HttpClientHandler_DefaultProxyCredentials_Test : HttpClientHandler_DefaultProxyCredentials_Test { + public PlatformHandler_HttpClientHandler_DefaultProxyCredentials_Test(ITestOutputHelper output) : base(output) { } protected override bool UseSocketsHttpHandler => false; } public sealed class PlatformHandler_HttpClientHandler_MaxConnectionsPerServer_Test : HttpClientHandler_MaxConnectionsPerServer_Test { + public PlatformHandler_HttpClientHandler_MaxConnectionsPerServer_Test(ITestOutputHelper output) : base(output) { } protected override bool UseSocketsHttpHandler => false; } public sealed class PlatformHandler_HttpClientHandler_ServerCertificates_Test : HttpClientHandler_ServerCertificates_Test { + public PlatformHandler_HttpClientHandler_ServerCertificates_Test(ITestOutputHelper output) : base(output) { } protected override bool UseSocketsHttpHandler => false; } @@ -135,6 +147,7 @@ namespace System.Net.Http.Functional.Tests public sealed class PlatformHandler_HttpClientHandler_SslProtocols_Test : HttpClientHandler_SslProtocols_Test { + public PlatformHandler_HttpClientHandler_SslProtocols_Test(ITestOutputHelper output) : base(output) { } protected override bool UseSocketsHttpHandler => false; } @@ -152,6 +165,7 @@ namespace System.Net.Http.Functional.Tests public sealed class PlatformHandler_HttpClientMiniStress : HttpClientMiniStress { + public PlatformHandler_HttpClientMiniStress(ITestOutputHelper output) : base(output) { } protected override bool UseSocketsHttpHandler => false; } @@ -175,6 +189,7 @@ namespace System.Net.Http.Functional.Tests public sealed class PlatformHandler_IdnaProtocolTests : IdnaProtocolTests { + public PlatformHandler_IdnaProtocolTests(ITestOutputHelper output) : base(output) { } protected override bool UseSocketsHttpHandler => false; // WinHttp on Win7 does not support IDNA protected override bool SupportsIdna => !PlatformDetection.IsWindows7 && !PlatformDetection.IsFullFramework; @@ -182,26 +197,31 @@ namespace System.Net.Http.Functional.Tests public sealed class PlatformHandler_HttpRetryProtocolTests : HttpRetryProtocolTests { + public PlatformHandler_HttpRetryProtocolTests(ITestOutputHelper output) : base(output) { } protected override bool UseSocketsHttpHandler => false; } public sealed class PlatformHandlerTest_Cookies : HttpClientHandlerTest_Cookies { + public PlatformHandlerTest_Cookies(ITestOutputHelper output) : base(output) { } protected override bool UseSocketsHttpHandler => false; } public sealed class PlatformHandlerTest_Cookies_Http11 : HttpClientHandlerTest_Cookies_Http11 { + public PlatformHandlerTest_Cookies_Http11(ITestOutputHelper output) : base(output) { } protected override bool UseSocketsHttpHandler => false; } public sealed class PlatformHandler_HttpClientHandler_MaxResponseHeadersLength_Test : HttpClientHandler_MaxResponseHeadersLength_Test { + public PlatformHandler_HttpClientHandler_MaxResponseHeadersLength_Test(ITestOutputHelper output) : base(output) { } protected override bool UseSocketsHttpHandler => false; } public sealed class PlatformHandler_HttpClientHandler_Cancellation_Test : HttpClientHandler_Cancellation_Test { + public PlatformHandler_HttpClientHandler_Cancellation_Test(ITestOutputHelper output) : base(output) { } protected override bool UseSocketsHttpHandler => false; } diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/PostScenarioTest.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/PostScenarioTest.cs index 2ff7d2a..f55450d 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/PostScenarioTest.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/PostScenarioTest.cs @@ -25,8 +25,6 @@ namespace System.Net.Http.Functional.Tests private static readonly Uri SecureBasicAuthServerUri = Configuration.Http.BasicAuthUriForCreds(true, UserName, Password); - private readonly ITestOutputHelper _output; - public static readonly object[][] EchoServers = Configuration.Http.EchoServers; public static readonly object[][] VerifyUploadServers = Configuration.Http.VerifyUploadServers; @@ -37,10 +35,7 @@ namespace System.Net.Http.Functional.Tests new object[] { SecureBasicAuthServerUri } }; - public PostScenarioTest(ITestOutputHelper output) - { - _output = output; - } + public PostScenarioTest(ITestOutputHelper output) : base(output) { } [ActiveIssue(30057, TargetFrameworkMonikers.Uap)] [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, ".NET Framework disposes request content after send")] diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/PostScenarioUWPTest.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/PostScenarioUWPTest.cs index 9e76fc2..76a3ce3 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/PostScenarioUWPTest.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/PostScenarioUWPTest.cs @@ -18,12 +18,7 @@ namespace System.Net.Http.Functional.Tests public abstract class PostScenarioUWPTest : HttpClientHandlerTestBase { - private readonly ITestOutputHelper _output; - - public PostScenarioUWPTest(ITestOutputHelper output) - { - _output = output; - } + public PostScenarioUWPTest(ITestOutputHelper output) : base(output) { } [Fact] public void Authentication_UseStreamContent_Throws() diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/ResponseStreamTest.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/ResponseStreamTest.cs index 682e225..57e8a22 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/ResponseStreamTest.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/ResponseStreamTest.cs @@ -17,12 +17,7 @@ namespace System.Net.Http.Functional.Tests public abstract class ResponseStreamTest : HttpClientHandlerTestBase { - private readonly ITestOutputHelper _output; - - public ResponseStreamTest(ITestOutputHelper output) - { - _output = output; - } + public ResponseStreamTest(ITestOutputHelper output) : base(output) { } [OuterLoop("Uses external server")] [Theory] diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/SchSendAuxRecordHttpTest.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/SchSendAuxRecordHttpTest.cs index 0bf5de2..61a1a52 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/SchSendAuxRecordHttpTest.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/SchSendAuxRecordHttpTest.cs @@ -15,12 +15,7 @@ namespace System.Net.Http.Functional.Tests [SkipOnTargetFramework(TargetFrameworkMonikers.Uap, "HttpsTestServer not compatible on UAP")] public abstract class SchSendAuxRecordHttpTest : HttpClientHandlerTestBase { - readonly ITestOutputHelper _output; - - public SchSendAuxRecordHttpTest(ITestOutputHelper output) - { - _output = output; - } + public SchSendAuxRecordHttpTest(ITestOutputHelper output) : base(output) { } [Fact] [PlatformSpecific(TestPlatforms.Windows)] diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.cs index 9a963d3..67417ab 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.cs @@ -25,6 +25,8 @@ namespace System.Net.Http.Functional.Tests { protected override bool UseSocketsHttpHandler => true; + public SocketsHttpHandler_HttpClientHandler_Asynchrony_Test(ITestOutputHelper output) : base(output) { } + [OuterLoop("Relies on finalization")] [Fact] public async Task ExecutionContext_HttpConnectionLifetimeDoesntKeepContextAlive() @@ -91,6 +93,8 @@ namespace System.Net.Http.Functional.Tests { protected override bool UseSocketsHttpHandler => true; + public SocketsHttpHandler_HttpProtocolTests(ITestOutputHelper output) : base(output) { } + [Theory] [InlineData("delete", "DELETE")] [InlineData("options", "OPTIONS")] @@ -102,21 +106,25 @@ namespace System.Net.Http.Functional.Tests public sealed class SocketsHttpHandler_HttpProtocolTests_Dribble : HttpProtocolTests_Dribble { + public SocketsHttpHandler_HttpProtocolTests_Dribble(ITestOutputHelper output) : base(output) { } protected override bool UseSocketsHttpHandler => true; } public sealed class SocketsHttpHandler_DiagnosticsTest : DiagnosticsTest { + public SocketsHttpHandler_DiagnosticsTest(ITestOutputHelper output) : base(output) { } protected override bool UseSocketsHttpHandler => true; } public sealed class SocketsHttpHandler_HttpClient_SelectedSites_Test : HttpClient_SelectedSites_Test { + public SocketsHttpHandler_HttpClient_SelectedSites_Test(ITestOutputHelper output) : base(output) { } protected override bool UseSocketsHttpHandler => true; } public sealed class SocketsHttpHandler_HttpClientEKUTest : HttpClientEKUTest { + public SocketsHttpHandler_HttpClientEKUTest(ITestOutputHelper output) : base(output) { } protected override bool UseSocketsHttpHandler => true; } @@ -128,6 +136,7 @@ namespace System.Net.Http.Functional.Tests public sealed class SocketsHttpHandler_HttpClientHandler_DangerousAcceptAllCertificatesValidator_Test : HttpClientHandler_DangerousAcceptAllCertificatesValidator_Test { + public SocketsHttpHandler_HttpClientHandler_DangerousAcceptAllCertificatesValidator_Test(ITestOutputHelper output) : base(output) { } protected override bool UseSocketsHttpHandler => true; } @@ -139,6 +148,7 @@ namespace System.Net.Http.Functional.Tests public sealed class SocketsHttpHandler_HttpClientHandler_DefaultProxyCredentials_Test : HttpClientHandler_DefaultProxyCredentials_Test { + public SocketsHttpHandler_HttpClientHandler_DefaultProxyCredentials_Test(ITestOutputHelper output) : base(output) { } protected override bool UseSocketsHttpHandler => true; } @@ -146,6 +156,8 @@ namespace System.Net.Http.Functional.Tests { protected override bool UseSocketsHttpHandler => true; + public SocketsHttpHandler_HttpClientHandler_MaxConnectionsPerServer_Test(ITestOutputHelper output) : base(output) { } + [OuterLoop("Incurs a small delay")] [Theory] [InlineData(0)] @@ -192,6 +204,7 @@ namespace System.Net.Http.Functional.Tests public sealed class SocketsHttpHandler_HttpClientHandler_ServerCertificates_Test : HttpClientHandler_ServerCertificates_Test { + public SocketsHttpHandler_HttpClientHandler_ServerCertificates_Test(ITestOutputHelper output) : base(output) { } protected override bool UseSocketsHttpHandler => true; } @@ -206,6 +219,8 @@ namespace System.Net.Http.Functional.Tests s.ResponseDrainTimeout = time; } + public SocketsHttpHandler_HttpClientHandler_ResponseDrain_Test(ITestOutputHelper output) : base(output) { } + [Fact] public void MaxResponseDrainSize_Roundtrips() { @@ -452,6 +467,7 @@ namespace System.Net.Http.Functional.Tests public sealed class SocketsHttpHandler_HttpClientHandler_SslProtocols_Test : HttpClientHandler_SslProtocols_Test { + public SocketsHttpHandler_HttpClientHandler_SslProtocols_Test(ITestOutputHelper output) : base(output) { } protected override bool UseSocketsHttpHandler => true; } @@ -463,6 +479,7 @@ namespace System.Net.Http.Functional.Tests public sealed class SocketsHttpHandler_HttpClientHandler_TrailingHeaders_Test : HttpClientHandlerTest_TrailingHeaders_Test { + public SocketsHttpHandler_HttpClientHandler_TrailingHeaders_Test(ITestOutputHelper output) : base(output) { } // PlatformHandlers don't support trailers. protected override bool UseSocketsHttpHandler => true; } @@ -475,6 +492,7 @@ namespace System.Net.Http.Functional.Tests public sealed class SocketsHttpHandler_HttpClientMiniStress : HttpClientMiniStress { + public SocketsHttpHandler_HttpClientMiniStress(ITestOutputHelper output) : base(output) { } protected override bool UseSocketsHttpHandler => true; } @@ -498,27 +516,32 @@ namespace System.Net.Http.Functional.Tests public sealed class SocketsHttpHandler_IdnaProtocolTests : IdnaProtocolTests { + public SocketsHttpHandler_IdnaProtocolTests(ITestOutputHelper output) : base(output) { } protected override bool UseSocketsHttpHandler => true; protected override bool SupportsIdna => true; } public sealed class SocketsHttpHandler_HttpRetryProtocolTests : HttpRetryProtocolTests { + public SocketsHttpHandler_HttpRetryProtocolTests(ITestOutputHelper output) : base(output) { } protected override bool UseSocketsHttpHandler => true; } public sealed class SocketsHttpHandlerTest_Cookies : HttpClientHandlerTest_Cookies { + public SocketsHttpHandlerTest_Cookies(ITestOutputHelper output) : base(output) { } protected override bool UseSocketsHttpHandler => true; } public sealed class SocketsHttpHandlerTest_Cookies_Http11 : HttpClientHandlerTest_Cookies_Http11 { + public SocketsHttpHandlerTest_Cookies_Http11(ITestOutputHelper output) : base(output) { } protected override bool UseSocketsHttpHandler => true; } public sealed class SocketsHttpHandler_HttpClientHandler_Cancellation_Test : HttpClientHandler_Cancellation_Test { + public SocketsHttpHandler_HttpClientHandler_Cancellation_Test(ITestOutputHelper output) : base(output) { } protected override bool UseSocketsHttpHandler => true; [Fact] @@ -692,6 +715,7 @@ namespace System.Net.Http.Functional.Tests public sealed class SocketsHttpHandler_HttpClientHandler_MaxResponseHeadersLength_Test : HttpClientHandler_MaxResponseHeadersLength_Test { + public SocketsHttpHandler_HttpClientHandler_MaxResponseHeadersLength_Test(ITestOutputHelper output) : base(output) { } protected override bool UseSocketsHttpHandler => true; } @@ -741,6 +765,8 @@ namespace System.Net.Http.Functional.Tests { protected override bool UseSocketsHttpHandler => true; + public SocketsHttpHandler_ConnectionUpgrade_Test(ITestOutputHelper output) : base(output) { } + [Fact] public async Task UpgradeConnection_ReturnsReadableAndWritableStream() { @@ -860,6 +886,8 @@ namespace System.Net.Http.Functional.Tests { protected override bool UseSocketsHttpHandler => true; + public SocketsHttpHandler_Connect_Test(ITestOutputHelper output) : base(output) { } + [Fact] public async Task ConnectMethod_Success() { @@ -948,6 +976,8 @@ namespace System.Net.Http.Functional.Tests { protected override bool UseSocketsHttpHandler => true; + public SocketsHttpHandler_HttpClientHandler_ConnectionPooling_Test(ITestOutputHelper output) : base(output) { } + [Fact] public async Task MultipleIterativeRequests_SameConnectionReused() { @@ -1567,6 +1597,8 @@ namespace System.Net.Http.Functional.Tests public sealed class SocketsHttpHandler_ExternalConfiguration_Test : HttpClientHandlerTestBase { + public SocketsHttpHandler_ExternalConfiguration_Test(ITestOutputHelper output) : base(output) { } + private const string EnvironmentVariableSettingName = "DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER"; private const string AppContextSettingName = "System.Net.Http.UseSocketsHttpHandler"; @@ -1647,12 +1679,14 @@ namespace System.Net.Http.Functional.Tests public sealed class SocketsHttpHandlerTest_Http2 : HttpClientHandlerTest_Http2 { + public SocketsHttpHandlerTest_Http2(ITestOutputHelper output) : base(output) { } protected override bool UseSocketsHttpHandler => true; } [ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.SupportsAlpn))] public sealed class SocketsHttpHandlerTest_Cookies_Http2 : HttpClientHandlerTest_Cookies { + public SocketsHttpHandlerTest_Cookies_Http2(ITestOutputHelper output) : base(output) { } protected override bool UseSocketsHttpHandler => true; protected override bool UseHttp2LoopbackServer => true; } @@ -1661,7 +1695,20 @@ namespace System.Net.Http.Functional.Tests public sealed class SocketsHttpHandlerTest_HttpClientHandlerTest_Http2 : HttpClientHandlerTest { public SocketsHttpHandlerTest_HttpClientHandlerTest_Http2(ITestOutputHelper output) : base(output) { } + protected override bool UseSocketsHttpHandler => true; + protected override bool UseHttp2LoopbackServer => true; + } + + public sealed class SocketsHttpHandlerTest_HttpClientHandlerTest_Headers_Http11 : HttpClientHandlerTest_Headers + { + public SocketsHttpHandlerTest_HttpClientHandlerTest_Headers_Http11(ITestOutputHelper output) : base(output) { } + protected override bool UseSocketsHttpHandler => true; + } + [ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.SupportsAlpn))] + public sealed class SocketsHttpHandlerTest_HttpClientHandlerTest_Headers_Http2 : HttpClientHandlerTest_Headers + { + public SocketsHttpHandlerTest_HttpClientHandlerTest_Headers_Http2(ITestOutputHelper output) : base(output) { } protected override bool UseSocketsHttpHandler => true; protected override bool UseHttp2LoopbackServer => true; } @@ -1669,6 +1716,7 @@ namespace System.Net.Http.Functional.Tests [ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.SupportsAlpn))] public sealed class SocketsHttpHandler_HttpClientHandler_Cancellation_Test_Http2 : HttpClientHandler_Cancellation_Test { + public SocketsHttpHandler_HttpClientHandler_Cancellation_Test_Http2(ITestOutputHelper output) : base(output) { } protected override bool UseSocketsHttpHandler => true; protected override bool UseHttp2LoopbackServer => true; } diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj b/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj index 8f4ce48..6003b5e 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj @@ -114,6 +114,7 @@ +