Skip to content

Commit

Permalink
[browser][http] test and compatibility improvements (#89504)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelsavara committed Jul 27, 2023
1 parent 89030ce commit a0a8ce6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ await LoopbackServerFactory.CreateServerAsync(async (server, url) =>
[InlineData("nocolon")]
[InlineData("no colon")]
[InlineData("Content-Length ")]
[ActiveIssue("https://github.com/dotnet/runtime/issues/54160", TestPlatforms.Browser)]
[SkipOnPlatform(TestPlatforms.Browser, "Browser is relaxed about validating HTTP headers")]
public async Task GetAsync_InvalidHeaderNameValue_ThrowsHttpRequestException(string invalidHeader)
{
if (UseVersion == HttpVersion30)
Expand All @@ -373,7 +373,7 @@ await LoopbackServer.CreateClientAndServerAsync(async uri =>
[InlineData(true, false)]
[InlineData(false, true)]
[InlineData(true, true)]
[ActiveIssue("https://github.com/dotnet/runtime/issues/54160", TestPlatforms.Browser)]
[ActiveIssue("https://github.com/dotnet/runtime/issues/86317", typeof(PlatformDetection), nameof(PlatformDetection.IsNodeJS))]
public async Task GetAsync_IncompleteData_ThrowsHttpRequestException(bool failDuringHeaders, bool getString)
{
if (IsWinHttpHandler)
Expand All @@ -386,6 +386,11 @@ public async Task GetAsync_IncompleteData_ThrowsHttpRequestException(bool failDu
return;
}

if (PlatformDetection.IsBrowser && failDuringHeaders)
{
return; // chrome browser doesn't validate this
}

await LoopbackServer.CreateClientAndServerAsync(async uri =>
{
using (HttpClient client = CreateHttpClient())
Expand Down Expand Up @@ -763,7 +768,7 @@ await LoopbackServer.CreateClientAndServerAsync(async uri =>
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/54160", TestPlatforms.Browser)]
[SkipOnPlatform(TestPlatforms.Browser, "TypeError: Failed to fetch on a Browser")]
public async Task GetAsync_NonTraditionalChunkSizes_Accepted()
{
if (LoopbackServerFactory.Version >= HttpVersion20.Value)
Expand Down Expand Up @@ -816,7 +821,7 @@ await TestHelper.WhenAllCompletedOrAnyFailed(
[InlineData("xyz")] // non-hex
[InlineData("7gibberish")] // valid size then gibberish
[InlineData("7\v\f")] // unacceptable whitespace
[ActiveIssue("https://github.com/dotnet/runtime/issues/54160", TestPlatforms.Browser)]
[ActiveIssue("https://github.com/dotnet/runtime/issues/86317", typeof(PlatformDetection), nameof(PlatformDetection.IsNodeJS))]
public async Task GetAsync_InvalidChunkSize_ThrowsHttpRequestException(string chunkSize)
{
if (UseVersion != HttpVersion.Version11)
Expand Down Expand Up @@ -849,7 +854,7 @@ await LoopbackServer.CreateServerAsync(async (server, url) =>
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/54160", TestPlatforms.Browser)]
[ActiveIssue("https://github.com/dotnet/runtime/issues/86317", typeof(PlatformDetection), nameof(PlatformDetection.IsNodeJS))]
public async Task GetAsync_InvalidChunkTerminator_ThrowsHttpRequestException()
{
if (UseVersion != HttpVersion.Version11)
Expand Down Expand Up @@ -878,7 +883,7 @@ await LoopbackServer.CreateClientAndServerAsync(async url =>
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/54160", TestPlatforms.Browser)]
[ActiveIssue("https://github.com/dotnet/runtime/issues/86317", typeof(PlatformDetection), nameof(PlatformDetection.IsNodeJS))]
public async Task GetAsync_InfiniteChunkSize_ThrowsHttpRequestException()
{
if (UseVersion != HttpVersion.Version11)
Expand Down Expand Up @@ -1468,7 +1473,7 @@ await LoopbackServerFactory.CreateServerAsync(async (server3, url3) =>
[Theory]
[InlineData(99)]
[InlineData(1000)]
[ActiveIssue("https://github.com/dotnet/runtime/issues/54160", TestPlatforms.Browser)]
[SkipOnPlatform(TestPlatforms.Browser, "Browser is relaxed about validating HTTP headers")]
public async Task GetAsync_StatusCodeOutOfRange_ExpectedException(int statusCode)
{
if (UseVersion == HttpVersion30)
Expand Down Expand Up @@ -1743,7 +1748,7 @@ await server.AcceptConnectionAsync(async connection =>
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/54160", TestPlatforms.Browser)]
[SkipOnPlatform(TestPlatforms.Browser, "ExpectContinue not supported on Browser")]
public async Task SendAsync_Expect100Continue_RequestBodyFails_ThrowsContentException()
{
if (IsWinHttpHandler)
Expand Down Expand Up @@ -1885,7 +1890,6 @@ await connection.ReadRequestHeaderAndSendCustomResponseAsync(
[Theory]
[InlineData(false)]
[InlineData(true)]
[ActiveIssue("https://github.com/dotnet/runtime/issues/54160", TestPlatforms.Browser)]
public async Task PostAsync_ThrowFromContentCopy_RequestFails(bool syncFailure)
{
if (UseVersion == HttpVersion30)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,17 @@ public async Task BrowserHttpHandler_Streaming()
[InlineData(TransferType.ContentLength, TransferError.ContentLengthTooLarge)]
[InlineData(TransferType.Chunked, TransferError.MissingChunkTerminator)]
[InlineData(TransferType.Chunked, TransferError.ChunkSizeTooLarge)]
[ActiveIssue("https://github.com/dotnet/runtime/issues/54160", TestPlatforms.Browser)]
public async Task ReadAsStreamAsync_InvalidServerResponse_ThrowsIOException(
TransferType transferType,
TransferError transferError)
{
await StartTransferTypeAndErrorServer(transferType, transferError, async uri =>
{
if (IsWinHttpHandler)
if (PlatformDetection.IsBrowser) // TypeError: Failed to fetch
{
await Assert.ThrowsAsync<HttpRequestException>(() => ReadAsStreamHelper(uri));
}
else if (IsWinHttpHandler)
{
await Assert.ThrowsAsync<IOException>(() => ReadAsStreamHelper(uri));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ private static async Task<WasmFetchResponse> CallFetch(HttpRequestMessage reques
JSObject fetchResponse = await BrowserHttpInterop.CancelationHelper(promise, cancellationToken, abortController, null).ConfigureAwait(true);
return new WasmFetchResponse(fetchResponse, abortRegistration.Value);
}
catch (JSException jse)
{
throw new HttpRequestException(jse.Message, jse);
}
catch (Exception)
{
// this would also trigger abort
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async uri =>
[Theory]
[InlineData("\u05D1\u05F1")]
[InlineData("jp\u30A5")]
[ActiveIssue("https://github.com/dotnet/runtime/issues/54160", TestPlatforms.Browser)]
[SkipOnPlatform(TestPlatforms.Browser, "Browser is relaxed about validating HTTP headers")]
public async Task SendAsync_InvalidCharactersInHeader_Throw(string value)
{
await LoopbackServerFactory.CreateClientAndServerAsync(async uri =>
Expand Down Expand Up @@ -412,7 +412,7 @@ public async Task SendAsync_GetWithInvalidHostHeader_ThrowsException()
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/54160", TestPlatforms.Browser)]
[SkipOnPlatform(TestPlatforms.Browser, "Browser is relaxed about validating HTTP headers")]
public async Task SendAsync_WithZeroLengthHeaderName_Throws()
{
await LoopbackServerFactory.CreateClientAndServerAsync(
Expand Down

0 comments on commit a0a8ce6

Please sign in to comment.