Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wasm][testing] Avoid using crypto in WASM HTTP unit tests #53925

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -289,7 +288,6 @@ public static IEnumerable<(Configuration.Http.RemoteServer remoteServer, Uri uri

[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))
Expand All @@ -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
Expand All @@ -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))
{
Expand All @@ -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)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should you have this extracted to a method to reduce copy&paste? :-)

{
// [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);
Expand All @@ -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))
{
Expand All @@ -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))
{
Expand Down Expand Up @@ -526,7 +555,6 @@ public static IEnumerable<object[]> 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))
Expand All @@ -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))
Expand Down Expand Up @@ -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))
Expand All @@ -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);
Expand Down Expand Up @@ -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))
Expand All @@ -713,7 +746,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.";
Expand Down Expand Up @@ -759,12 +791,16 @@ public async Task PostAsync_ReuseRequestContent_Success(Configuration.Http.Remot

[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(
Expand Down
Loading