From 939e7cf3edbd3450a6f7cce8c43a6ba3ff6ea709 Mon Sep 17 00:00:00 2001 From: Pavel Savara Date: Tue, 8 Jun 2021 17:09:05 +0200 Subject: [PATCH 1/4] avoid using crypto in WASM unit tests so that we could cover more scenarios --- .../HttpClientHandlerTest.RemoteServer.cs | 80 ++++++++++++++----- .../tests/System/Net/Http/PostScenarioTest.cs | 23 +++--- .../System/Net/Http/ResponseStreamTest.cs | 2 - .../tests/System/Net/Http/TestHelper.cs | 15 +++- .../Handlers/VerifyUploadHandler.cs | 49 +++++++----- .../HttpClientHandlerTest.Headers.cs | 5 +- 6 files changed, 113 insertions(+), 61 deletions(-) diff --git a/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.RemoteServer.cs b/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.RemoteServer.cs index 70d56f44a6e29..31e206f674bde 100644 --- a/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.RemoteServer.cs +++ b/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.RemoteServer.cs @@ -113,7 +113,6 @@ public async Task SendAsync_MultipleRequestsReusingSameClient_Success(Configurat [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(RemoteServersMemberData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task GetAsync_ResponseContentAfterClientAndHandlerDispose_Success(Configuration.Http.RemoteServer remoteServer) { using (HttpClient client = CreateHttpClientForRemoteServer(remoteServer)) @@ -289,7 +288,6 @@ public static IEnumerable RemoteServersHeaderValuesAndUris() [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(RemoteServersMemberData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task GetAsync_ResponseHeadersRead_ReadFromEachIterativelyDoesntDeadlock(Configuration.Http.RemoteServer remoteServer) { using (HttpClient client = CreateHttpClientForRemoteServer(remoteServer)) @@ -315,7 +313,6 @@ public async Task GetAsync_ResponseHeadersRead_ReadFromEachIterativelyDoesntDead [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(RemoteServersMemberData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task SendAsync_HttpRequestMsgResponseHeadersRead_StatusCodeOK(Configuration.Http.RemoteServer remoteServer) { // Sync API supported only up to HTTP/1.1 @@ -342,14 +339,23 @@ public async Task SendAsync_HttpRequestMsgResponseHeadersRead_StatusCodeOK(Confi [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(RemoteServersMemberData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task PostAsync_CallMethodTwice_StringContent(Configuration.Http.RemoteServer remoteServer) { using (HttpClient client = CreateHttpClientForRemoteServer(remoteServer)) { string data = "Test String"; var content = new StringContent(data, Encoding.UTF8); - content.Headers.ContentMD5 = TestHelper.ComputeMD5Hash(data); + + if(PlatformDetection.IsBrowser) + { + // [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] + content.Headers.Add("Content-MD5-Skip", "browser"); + } + else + { + content.Headers.ContentMD5 = TestHelper.ComputeMD5Hash(data); + } + HttpResponseMessage response; using (response = await client.PostAsync(remoteServer.VerifyUploadUri, content)) { @@ -358,7 +364,16 @@ public async Task PostAsync_CallMethodTwice_StringContent(Configuration.Http.Rem // Repeat call. content = new StringContent(data, Encoding.UTF8); - content.Headers.ContentMD5 = TestHelper.ComputeMD5Hash(data); + if(PlatformDetection.IsBrowser) + { + // [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] + content.Headers.Add("Content-MD5-Skip", "browser"); + } + else + { + content.Headers.ContentMD5 = TestHelper.ComputeMD5Hash(data); + } + using (response = await client.PostAsync(remoteServer.VerifyUploadUri, content)) { Assert.Equal(HttpStatusCode.OK, response.StatusCode); @@ -368,14 +383,21 @@ public async Task PostAsync_CallMethodTwice_StringContent(Configuration.Http.Rem [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(RemoteServersMemberData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task PostAsync_CallMethod_UnicodeStringContent(Configuration.Http.RemoteServer remoteServer) { using (HttpClient client = CreateHttpClientForRemoteServer(remoteServer)) { string data = "\ub4f1\uffc7\u4e82\u67ab4\uc6d4\ud1a0\uc694\uc77c\uffda3\u3155\uc218\uffdb"; var content = new StringContent(data, Encoding.UTF8); - content.Headers.ContentMD5 = TestHelper.ComputeMD5Hash(data); + if(PlatformDetection.IsBrowser) + { + // [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] + content.Headers.Add("Content-MD5-Skip", "browser"); + } + else + { + content.Headers.ContentMD5 = TestHelper.ComputeMD5Hash(data); + } using (HttpResponseMessage response = await client.PostAsync(remoteServer.VerifyUploadUri, content)) { @@ -386,12 +408,19 @@ public async Task PostAsync_CallMethod_UnicodeStringContent(Configuration.Http.R [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(VerifyUploadServersStreamsAndExpectedData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task PostAsync_CallMethod_StreamContent(Configuration.Http.RemoteServer remoteServer, HttpContent content, byte[] expectedData) { using (HttpClient client = CreateHttpClientForRemoteServer(remoteServer)) { - content.Headers.ContentMD5 = TestHelper.ComputeMD5Hash(expectedData); + if(PlatformDetection.IsBrowser) + { + // [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] + content.Headers.Add("Content-MD5-Skip", "browser"); + } + else + { + content.Headers.ContentMD5 = TestHelper.ComputeMD5Hash(expectedData); + } using (HttpResponseMessage response = await client.PostAsync(remoteServer.VerifyUploadUri, content)) { @@ -526,7 +555,6 @@ public static IEnumerable VerifyUploadServersStreamsAndExpectedData [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(RemoteServersMemberData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task PostAsync_CallMethod_NullContent(Configuration.Http.RemoteServer remoteServer) { using (HttpClient client = CreateHttpClientForRemoteServer(remoteServer)) @@ -548,7 +576,6 @@ public async Task PostAsync_CallMethod_NullContent(Configuration.Http.RemoteServ [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(RemoteServersMemberData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task PostAsync_CallMethod_EmptyContent(Configuration.Http.RemoteServer remoteServer) { using (HttpClient client = CreateHttpClientForRemoteServer(remoteServer)) @@ -641,7 +668,6 @@ public async Task PostAsync_Redirect_ResultingGetFormattedCorrectly(Configuratio [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(RemoteServersMemberData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task PostAsync_RedirectWith307_LargePayload(Configuration.Http.RemoteServer remoteServer) { if (remoteServer.HttpVersion == new Version(2, 0)) @@ -657,7 +683,6 @@ public async Task PostAsync_RedirectWith307_LargePayload(Configuration.Http.Remo [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(RemoteServersMemberData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task PostAsync_RedirectWith302_LargePayload(Configuration.Http.RemoteServer remoteServer) { await PostAsync_Redirect_LargePayload_Helper(remoteServer, 302, false); @@ -686,7 +711,15 @@ private async Task PostAsync_Redirect_LargePayload_Helper(Configuration.Http.Rem var content = new StreamContent(fs); // Compute MD5 of request body data. This will be verified by the server when it receives the request. - content.Headers.ContentMD5 = TestHelper.ComputeMD5Hash(contentBytes); + if(PlatformDetection.IsBrowser) + { + // [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] + content.Headers.Add("Content-MD5-Skip", "browser"); + } + else + { + content.Headers.ContentMD5 = TestHelper.ComputeMD5Hash(contentBytes); + } using (HttpClient client = CreateHttpClientForRemoteServer(remoteServer)) using (HttpResponseMessage response = await client.PostAsync(redirectUri, content)) @@ -703,8 +736,12 @@ private async Task PostAsync_Redirect_LargePayload_Helper(Configuration.Http.Rem if (expectRedirectToPost) { - IEnumerable headerValue = response.Headers.GetValues("X-HttpRequest-Method"); - Assert.Equal("POST", headerValue.First()); + // [ActiveIssue("https://github.com/dotnet/runtime/issues/53668", TestPlatforms.Browser)] + if(!PlatformDetection.IsBrowser) + { + IEnumerable headerValue = response.Headers.GetValues("X-HttpRequest-Method"); + Assert.Equal("POST", headerValue.First()); + } } } } @@ -713,7 +750,6 @@ private async Task PostAsync_Redirect_LargePayload_Helper(Configuration.Http.Rem #if !NETFRAMEWORK [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(RemoteServersMemberData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task PostAsync_ReuseRequestContent_Success(Configuration.Http.RemoteServer remoteServer) { const string ContentString = "This is the content string."; @@ -759,12 +795,16 @@ public async Task SendAsync_SendRequestUsingMethodToEchoServerWithNoContent_Meth [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(HttpMethodsThatAllowContent))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/53591", TestPlatforms.Browser)] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task SendAsync_SendRequestUsingMethodToEchoServerWithContent_Success( string method, Uri serverUri) { + if (method == "GET" && PlatformDetection.IsBrowser) + { + // [ActiveIssue("https://github.com/dotnet/runtime/issues/53591", TestPlatforms.Browser)] + return; + } + using (HttpClient client = CreateHttpClient()) { var request = new HttpRequestMessage( diff --git a/src/libraries/Common/tests/System/Net/Http/PostScenarioTest.cs b/src/libraries/Common/tests/System/Net/Http/PostScenarioTest.cs index c6654ec7d36dc..3f18e1d29f1e5 100644 --- a/src/libraries/Common/tests/System/Net/Http/PostScenarioTest.cs +++ b/src/libraries/Common/tests/System/Net/Http/PostScenarioTest.cs @@ -30,7 +30,6 @@ public PostScenarioTest(ITestOutputHelper output) : base(output) { } #if !NETFRAMEWORK [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(RemoteServersMemberData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task PostRewindableStreamContentMultipleTimes_StreamContentFullySent(Configuration.Http.RemoteServer remoteServer) { const string requestBody = "ABC"; @@ -56,7 +55,6 @@ public async Task PostRewindableStreamContentMultipleTimes_StreamContentFullySen [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [MemberData(nameof(RemoteServersMemberData))] [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBrowserDomSupportedOrNotBrowser))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task PostNoContentUsingContentLengthSemantics_Success(Configuration.Http.RemoteServer remoteServer) { await PostHelper(remoteServer, string.Empty, null, @@ -65,7 +63,6 @@ await PostHelper(remoteServer, string.Empty, null, [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(RemoteServersMemberData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task PostEmptyContentUsingContentLengthSemantics_Success(Configuration.Http.RemoteServer remoteServer) { await PostHelper(remoteServer, string.Empty, new StringContent(string.Empty), @@ -74,7 +71,6 @@ public async Task PostEmptyContentUsingContentLengthSemantics_Success(Configurat [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(RemoteServersMemberData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task PostEmptyContentUsingChunkedEncoding_Success(Configuration.Http.RemoteServer remoteServer) { await PostHelper(remoteServer, string.Empty, new StringContent(string.Empty), @@ -83,7 +79,6 @@ public async Task PostEmptyContentUsingChunkedEncoding_Success(Configuration.Htt [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(RemoteServersMemberData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task PostEmptyContentUsingConflictingSemantics_Success(Configuration.Http.RemoteServer remoteServer) { await PostHelper(remoteServer, string.Empty, new StringContent(string.Empty), @@ -92,7 +87,6 @@ public async Task PostEmptyContentUsingConflictingSemantics_Success(Configuratio [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(RemoteServersMemberData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task PostUsingContentLengthSemantics_Success(Configuration.Http.RemoteServer remoteServer) { await PostHelper(remoteServer, ExpectedContent, new StringContent(ExpectedContent), @@ -101,7 +95,6 @@ public async Task PostUsingContentLengthSemantics_Success(Configuration.Http.Rem [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(RemoteServersMemberData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task PostUsingChunkedEncoding_Success(Configuration.Http.RemoteServer remoteServer) { await PostHelper(remoteServer, ExpectedContent, new StringContent(ExpectedContent), @@ -110,7 +103,6 @@ public async Task PostUsingChunkedEncoding_Success(Configuration.Http.RemoteServ [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(RemoteServersMemberData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task PostSyncBlockingContentUsingChunkedEncoding_Success(Configuration.Http.RemoteServer remoteServer) { await PostHelper(remoteServer, ExpectedContent, new SyncBlockingContent(ExpectedContent), @@ -119,7 +111,6 @@ public async Task PostSyncBlockingContentUsingChunkedEncoding_Success(Configurat [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(RemoteServersMemberData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task PostRepeatedFlushContentUsingChunkedEncoding_Success(Configuration.Http.RemoteServer remoteServer) { await PostHelper(remoteServer, ExpectedContent, new RepeatedFlushContent(ExpectedContent), @@ -128,7 +119,6 @@ public async Task PostRepeatedFlushContentUsingChunkedEncoding_Success(Configura [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(RemoteServersMemberData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task PostUsingUsingConflictingSemantics_UsesChunkedSemantics(Configuration.Http.RemoteServer remoteServer) { await PostHelper(remoteServer, ExpectedContent, new StringContent(ExpectedContent), @@ -137,7 +127,6 @@ public async Task PostUsingUsingConflictingSemantics_UsesChunkedSemantics(Config [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(RemoteServersMemberData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task PostUsingNoSpecifiedSemantics_UsesChunkedSemantics(Configuration.Http.RemoteServer remoteServer) { await PostHelper(remoteServer, ExpectedContent, new StringContent(ExpectedContent), @@ -157,7 +146,6 @@ public static IEnumerable RemoteServersAndLargeContentSizes() [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory] [MemberData(nameof(RemoteServersAndLargeContentSizes))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task PostLargeContentUsingContentLengthSemantics_Success(Configuration.Http.RemoteServer remoteServer, int contentLength) { var rand = new Random(42); @@ -226,7 +214,6 @@ public async Task PostNonRewindableContentUsingAuth_PreAuthenticate_Success(Conf [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [MemberData(nameof(RemoteServersMemberData))] [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBrowserDomSupportedOrNotBrowser))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task PostAsync_EmptyContent_ContentTypeHeaderNotSent(Configuration.Http.RemoteServer remoteServer) { using (HttpClient client = CreateHttpClientForRemoteServer(remoteServer)) @@ -262,7 +249,15 @@ private async Task PostHelper( // Compute MD5 of request body data. This will be verified by the server when it // receives the request. - requestContent.Headers.ContentMD5 = TestHelper.ComputeMD5Hash(requestBody); + if(PlatformDetection.IsBrowser) + { + // [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] + requestContent.Headers.Add("Content-MD5-Skip", "browser"); + } + else + { + requestContent.Headers.ContentMD5 = TestHelper.ComputeMD5Hash(requestBody); + } } if (useChunkedEncodingUpload) diff --git a/src/libraries/Common/tests/System/Net/Http/ResponseStreamTest.cs b/src/libraries/Common/tests/System/Net/Http/ResponseStreamTest.cs index 40638272b6373..1a6cc656e9257 100644 --- a/src/libraries/Common/tests/System/Net/Http/ResponseStreamTest.cs +++ b/src/libraries/Common/tests/System/Net/Http/ResponseStreamTest.cs @@ -128,7 +128,6 @@ public async Task GetStreamAsync_ReadToEnd_Success(Configuration.Http.RemoteServ [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(RemoteServersMemberData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task GetAsync_UseResponseHeadersReadAndCallLoadIntoBuffer_Success(Configuration.Http.RemoteServer remoteServer) { using (HttpClient client = CreateHttpClientForRemoteServer(remoteServer)) @@ -148,7 +147,6 @@ public async Task GetAsync_UseResponseHeadersReadAndCallLoadIntoBuffer_Success(C [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(RemoteServersMemberData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task GetAsync_UseResponseHeadersReadAndCopyToMemoryStream_Success(Configuration.Http.RemoteServer remoteServer) { using (HttpClient client = CreateHttpClientForRemoteServer(remoteServer)) diff --git a/src/libraries/Common/tests/System/Net/Http/TestHelper.cs b/src/libraries/Common/tests/System/Net/Http/TestHelper.cs index 352f4e714782a..f855cc18fa539 100644 --- a/src/libraries/Common/tests/System/Net/Http/TestHelper.cs +++ b/src/libraries/Common/tests/System/Net/Http/TestHelper.cs @@ -41,9 +41,13 @@ public static void VerifyResponseBody( bool chunkedUpload, string requestBody) { - // Verify that response body from the server was corrected received by comparing MD5 hash. - byte[] actualMD5Hash = ComputeMD5Hash(responseContent); - Assert.Equal(expectedMD5Hash, actualMD5Hash); + // https://github.com/dotnet/runtime/issues/37669 + if(!PlatformDetection.IsBrowser) + { + // Verify that response body from the server was corrected received by comparing MD5 hash. + byte[] actualMD5Hash = ComputeMD5Hash(responseContent); + Assert.Equal(expectedMD5Hash, actualMD5Hash); + } // Verify upload semantics: 'Content-Length' vs. 'Transfer-Encoding: chunked'. if (requestBody != null) @@ -66,6 +70,11 @@ public static void VerifyResponseBody( public static void VerifyRequestMethod(HttpResponseMessage response, string expectedMethod) { + if(PlatformDetection.IsBrowser) + { + // [ActiveIssue("https://github.com/dotnet/runtime/issues/53668", TestPlatforms.Browser)] + return; + } IEnumerable values = response.Headers.GetValues("X-HttpRequest-Method"); foreach (string value in values) { diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/NetCoreServer/Handlers/VerifyUploadHandler.cs b/src/libraries/Common/tests/System/Net/Prerequisites/NetCoreServer/Handlers/VerifyUploadHandler.cs index 69d3190d35be0..40ef5bffd5b49 100644 --- a/src/libraries/Common/tests/System/Net/Prerequisites/NetCoreServer/Handlers/VerifyUploadHandler.cs +++ b/src/libraries/Common/tests/System/Net/Prerequisites/NetCoreServer/Handlers/VerifyUploadHandler.cs @@ -35,31 +35,40 @@ public static async Task InvokeAsync(HttpContext context) // Check MD5 checksum for non-empty request body. if (requestBodyBytes.Length > 0) { - // Get expected MD5 hash of request body. - string expectedHash = context.Request.Headers["Content-MD5"]; - if (string.IsNullOrEmpty(expectedHash)) - { - context.Response.StatusCode = 400; - context.Response.SetStatusDescription("Missing 'Content-MD5' request header"); - return; - } - - // Compute MD5 hash of received request body. - string actualHash; - using (MD5 md5 = MD5.Create()) - { - byte[] hash = md5.ComputeHash(requestBodyBytes); - actualHash = Convert.ToBase64String(hash); - } - - if (expectedHash == actualHash) + string skip = context.Request.Headers["Content-MD5-Skip"]; + if(!string.IsNullOrEmpty(skip)) { context.Response.StatusCode = 200; } else { - context.Response.StatusCode = 400; - context.Response.SetStatusDescription("Received request body fails MD5 checksum"); + // Get expected MD5 hash of request body. + string expectedHash = context.Request.Headers["Content-MD5"]; + + if (string.IsNullOrEmpty(expectedHash)) + { + context.Response.StatusCode = 400; + context.Response.SetStatusDescription("Missing 'Content-MD5' request header"); + return; + } + + // Compute MD5 hash of received request body. + string actualHash; + using (MD5 md5 = MD5.Create()) + { + byte[] hash = md5.ComputeHash(requestBodyBytes); + actualHash = Convert.ToBase64String(hash); + } + + if (expectedHash == actualHash) + { + context.Response.StatusCode = 200; + } + else + { + context.Response.StatusCode = 400; + context.Response.SetStatusDescription("Received request body fails MD5 checksum"); + } } } else diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Headers.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Headers.cs index 60300e8afff70..b57304068a3c3 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Headers.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Headers.cs @@ -347,7 +347,6 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async uri => [Theory] [InlineData(false)] [InlineData(true)] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task SendAsync_GetWithValidHostHeader_Success(bool withPort) { if (UseVersion == HttpVersion.Version30) @@ -362,7 +361,9 @@ public async Task SendAsync_GetWithValidHostHeader_Success(bool withPort) } var m = new HttpRequestMessage(HttpMethod.Get, Configuration.Http.SecureRemoteEchoServer) { Version = UseVersion }; - m.Headers.Host = withPort ? Configuration.Http.SecureHost + ":" + Configuration.Http.SecurePort : Configuration.Http.SecureHost; + m.Headers.Host = !PlatformDetection.LocalEchoServerIsAvailable && withPort + ? Configuration.Http.SecureHost + ":" + Configuration.Http.SecurePort + : Configuration.Http.SecureHost; using (HttpClient client = CreateHttpClient()) using (HttpResponseMessage response = await client.SendAsync(TestAsync, m)) From 2153517739e6209673ce85c3d2f16fe675c136fe Mon Sep 17 00:00:00 2001 From: Pavel Savara Date: Wed, 9 Jun 2021 18:28:50 +0200 Subject: [PATCH 2/4] fix --- src/libraries/Common/tests/System/Net/Http/TestHelper.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/libraries/Common/tests/System/Net/Http/TestHelper.cs b/src/libraries/Common/tests/System/Net/Http/TestHelper.cs index f855cc18fa539..b4d7b0bdd256f 100644 --- a/src/libraries/Common/tests/System/Net/Http/TestHelper.cs +++ b/src/libraries/Common/tests/System/Net/Http/TestHelper.cs @@ -70,11 +70,6 @@ public static void VerifyResponseBody( public static void VerifyRequestMethod(HttpResponseMessage response, string expectedMethod) { - if(PlatformDetection.IsBrowser) - { - // [ActiveIssue("https://github.com/dotnet/runtime/issues/53668", TestPlatforms.Browser)] - return; - } IEnumerable values = response.Headers.GetValues("X-HttpRequest-Method"); foreach (string value in values) { From 4df3ef5680716f1d7f7e55d1cec9c0e86de0d69d Mon Sep 17 00:00:00 2001 From: Pavel Savara Date: Thu, 10 Jun 2021 09:55:12 +0200 Subject: [PATCH 3/4] feedback --- .../HttpClientHandlerTest.RemoteServer.cs | 12 ++-- .../tests/System/Net/Http/PostScenarioTest.cs | 2 +- .../tests/System/Net/Http/TestHelper.cs | 4 +- .../Handlers/VerifyUploadHandler.cs | 61 ++++++++----------- .../HttpClientHandlerTest.Headers.cs | 4 +- 5 files changed, 37 insertions(+), 46 deletions(-) diff --git a/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.RemoteServer.cs b/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.RemoteServer.cs index 31e206f674bde..1dfdc56837cb2 100644 --- a/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.RemoteServer.cs +++ b/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.RemoteServer.cs @@ -346,7 +346,7 @@ public async Task PostAsync_CallMethodTwice_StringContent(Configuration.Http.Rem string data = "Test String"; var content = new StringContent(data, Encoding.UTF8); - if(PlatformDetection.IsBrowser) + if (PlatformDetection.IsBrowser) { // [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] content.Headers.Add("Content-MD5-Skip", "browser"); @@ -364,7 +364,7 @@ public async Task PostAsync_CallMethodTwice_StringContent(Configuration.Http.Rem // Repeat call. content = new StringContent(data, Encoding.UTF8); - if(PlatformDetection.IsBrowser) + if (PlatformDetection.IsBrowser) { // [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] content.Headers.Add("Content-MD5-Skip", "browser"); @@ -389,7 +389,7 @@ public async Task PostAsync_CallMethod_UnicodeStringContent(Configuration.Http.R { string data = "\ub4f1\uffc7\u4e82\u67ab4\uc6d4\ud1a0\uc694\uc77c\uffda3\u3155\uc218\uffdb"; var content = new StringContent(data, Encoding.UTF8); - if(PlatformDetection.IsBrowser) + if (PlatformDetection.IsBrowser) { // [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] content.Headers.Add("Content-MD5-Skip", "browser"); @@ -412,7 +412,7 @@ public async Task PostAsync_CallMethod_StreamContent(Configuration.Http.RemoteSe { using (HttpClient client = CreateHttpClientForRemoteServer(remoteServer)) { - if(PlatformDetection.IsBrowser) + if (PlatformDetection.IsBrowser) { // [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] content.Headers.Add("Content-MD5-Skip", "browser"); @@ -711,7 +711,7 @@ private async Task PostAsync_Redirect_LargePayload_Helper(Configuration.Http.Rem var content = new StreamContent(fs); // Compute MD5 of request body data. This will be verified by the server when it receives the request. - if(PlatformDetection.IsBrowser) + if (PlatformDetection.IsBrowser) { // [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] content.Headers.Add("Content-MD5-Skip", "browser"); @@ -737,7 +737,7 @@ private async Task PostAsync_Redirect_LargePayload_Helper(Configuration.Http.Rem if (expectRedirectToPost) { // [ActiveIssue("https://github.com/dotnet/runtime/issues/53668", TestPlatforms.Browser)] - if(!PlatformDetection.IsBrowser) + if (!PlatformDetection.IsBrowser) { IEnumerable headerValue = response.Headers.GetValues("X-HttpRequest-Method"); Assert.Equal("POST", headerValue.First()); diff --git a/src/libraries/Common/tests/System/Net/Http/PostScenarioTest.cs b/src/libraries/Common/tests/System/Net/Http/PostScenarioTest.cs index 3f18e1d29f1e5..d1201244c5aac 100644 --- a/src/libraries/Common/tests/System/Net/Http/PostScenarioTest.cs +++ b/src/libraries/Common/tests/System/Net/Http/PostScenarioTest.cs @@ -249,7 +249,7 @@ private async Task PostHelper( // Compute MD5 of request body data. This will be verified by the server when it // receives the request. - if(PlatformDetection.IsBrowser) + if (PlatformDetection.IsBrowser) { // [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] requestContent.Headers.Add("Content-MD5-Skip", "browser"); diff --git a/src/libraries/Common/tests/System/Net/Http/TestHelper.cs b/src/libraries/Common/tests/System/Net/Http/TestHelper.cs index b4d7b0bdd256f..98c19464db941 100644 --- a/src/libraries/Common/tests/System/Net/Http/TestHelper.cs +++ b/src/libraries/Common/tests/System/Net/Http/TestHelper.cs @@ -41,8 +41,8 @@ public static void VerifyResponseBody( bool chunkedUpload, string requestBody) { - // https://github.com/dotnet/runtime/issues/37669 - if(!PlatformDetection.IsBrowser) + // [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] + if (!PlatformDetection.IsBrowser) { // Verify that response body from the server was corrected received by comparing MD5 hash. byte[] actualMD5Hash = ComputeMD5Hash(responseContent); diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/NetCoreServer/Handlers/VerifyUploadHandler.cs b/src/libraries/Common/tests/System/Net/Prerequisites/NetCoreServer/Handlers/VerifyUploadHandler.cs index 40ef5bffd5b49..80a08b9532a31 100644 --- a/src/libraries/Common/tests/System/Net/Prerequisites/NetCoreServer/Handlers/VerifyUploadHandler.cs +++ b/src/libraries/Common/tests/System/Net/Prerequisites/NetCoreServer/Handlers/VerifyUploadHandler.cs @@ -32,49 +32,40 @@ public static async Task InvokeAsync(HttpContext context) // Get request body. byte[] requestBodyBytes = await ReadAllRequestBytesAsync(context); - // Check MD5 checksum for non-empty request body. - if (requestBodyBytes.Length > 0) + // Skip MD5 checksum for empty request body or for requests which opt to skip it. + if (requestBodyBytes.Length == 0 || !string.IsNullOrEmpty(context.Request.Headers["Content-MD5-Skip"])) { - string skip = context.Request.Headers["Content-MD5-Skip"]; - if(!string.IsNullOrEmpty(skip)) - { - context.Response.StatusCode = 200; - } - else - { - // Get expected MD5 hash of request body. - string expectedHash = context.Request.Headers["Content-MD5"]; + context.Response.StatusCode = 200; + return; + } - if (string.IsNullOrEmpty(expectedHash)) - { - context.Response.StatusCode = 400; - context.Response.SetStatusDescription("Missing 'Content-MD5' request header"); - return; - } + // Get expected MD5 hash of request body. + string expectedHash = context.Request.Headers["Content-MD5"]; + if (string.IsNullOrEmpty(expectedHash)) + { + context.Response.StatusCode = 400; + context.Response.SetStatusDescription("Missing 'Content-MD5' request header"); + return; + } - // Compute MD5 hash of received request body. - string actualHash; - using (MD5 md5 = MD5.Create()) - { - byte[] hash = md5.ComputeHash(requestBodyBytes); - actualHash = Convert.ToBase64String(hash); - } + // Compute MD5 hash of received request body. + string actualHash; + using (MD5 md5 = MD5.Create()) + { + byte[] hash = md5.ComputeHash(requestBodyBytes); + actualHash = Convert.ToBase64String(hash); + } - if (expectedHash == actualHash) - { - context.Response.StatusCode = 200; - } - else - { - context.Response.StatusCode = 400; - context.Response.SetStatusDescription("Received request body fails MD5 checksum"); - } - } + if (expectedHash == actualHash) + { + context.Response.StatusCode = 200; } else { - context.Response.StatusCode = 200; + context.Response.StatusCode = 400; + context.Response.SetStatusDescription("Received request body fails MD5 checksum"); } + } private static async Task ReadAllRequestBytesAsync(HttpContext context) diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Headers.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Headers.cs index b57304068a3c3..73a543ac12a21 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Headers.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Headers.cs @@ -361,8 +361,8 @@ public async Task SendAsync_GetWithValidHostHeader_Success(bool withPort) } var m = new HttpRequestMessage(HttpMethod.Get, Configuration.Http.SecureRemoteEchoServer) { Version = UseVersion }; - m.Headers.Host = !PlatformDetection.LocalEchoServerIsAvailable && withPort - ? Configuration.Http.SecureHost + ":" + Configuration.Http.SecurePort + m.Headers.Host = !PlatformDetection.LocalEchoServerIsAvailable && withPort + ? Configuration.Http.SecureHost + ":" + Configuration.Http.SecurePort : Configuration.Http.SecureHost; using (HttpClient client = CreateHttpClient()) From 4a1822dd6572ff58b32009322c90b7230ddd82a1 Mon Sep 17 00:00:00 2001 From: Pavel Savara Date: Thu, 10 Jun 2021 17:46:09 +0200 Subject: [PATCH 4/4] feedback --- .../System/Net/Http/HttpClientHandlerTest.RemoteServer.cs | 8 ++------ .../NetCoreServer/Handlers/VerifyUploadHandler.cs | 3 ++- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.RemoteServer.cs b/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.RemoteServer.cs index 1dfdc56837cb2..732384e64ed24 100644 --- a/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.RemoteServer.cs +++ b/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.RemoteServer.cs @@ -736,12 +736,8 @@ private async Task PostAsync_Redirect_LargePayload_Helper(Configuration.Http.Rem if (expectRedirectToPost) { - // [ActiveIssue("https://github.com/dotnet/runtime/issues/53668", TestPlatforms.Browser)] - if (!PlatformDetection.IsBrowser) - { - IEnumerable headerValue = response.Headers.GetValues("X-HttpRequest-Method"); - Assert.Equal("POST", headerValue.First()); - } + IEnumerable headerValue = response.Headers.GetValues("X-HttpRequest-Method"); + Assert.Equal("POST", headerValue.First()); } } } diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/NetCoreServer/Handlers/VerifyUploadHandler.cs b/src/libraries/Common/tests/System/Net/Prerequisites/NetCoreServer/Handlers/VerifyUploadHandler.cs index 80a08b9532a31..3608f6211a3d6 100644 --- a/src/libraries/Common/tests/System/Net/Prerequisites/NetCoreServer/Handlers/VerifyUploadHandler.cs +++ b/src/libraries/Common/tests/System/Net/Prerequisites/NetCoreServer/Handlers/VerifyUploadHandler.cs @@ -32,7 +32,8 @@ public static async Task InvokeAsync(HttpContext context) // Get request body. byte[] requestBodyBytes = await ReadAllRequestBytesAsync(context); - // Skip MD5 checksum for empty request body or for requests which opt to skip it. + // Skip MD5 checksum for empty request body + // or for requests which opt to skip it due to [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] if (requestBodyBytes.Length == 0 || !string.IsNullOrEmpty(context.Request.Headers["Content-MD5-Skip"])) { context.Response.StatusCode = 200;