Skip to content

Commit

Permalink
avoid using crypto in WASM unit tests so that we could cover more sce…
Browse files Browse the repository at this point in the history
…narios
  • Loading branch information
pavelsavara committed Jun 9, 2021
1 parent fb61be4 commit 939e7cf
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 61 deletions.
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)
{
// [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 @@ -703,8 +736,12 @@ private async Task PostAsync_Redirect_LargePayload_Helper(Configuration.Http.Rem

if (expectRedirectToPost)
{
IEnumerable<string> 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<string> headerValue = response.Headers.GetValues("X-HttpRequest-Method");
Assert.Equal("POST", headerValue.First());
}
}
}
}
Expand All @@ -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.";
Expand Down Expand Up @@ -759,12 +795,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

0 comments on commit 939e7cf

Please sign in to comment.