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

[WASI] HTTP client testing #105838

Closed
wants to merge 13 commits into from
Closed
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
2 changes: 2 additions & 0 deletions eng/testing/tests.wasi.targets
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
<_XHarnessArgs Condition="'$(WasmXHarnessTestsTimeout)' != ''" >$(_XHarnessArgs) &quot;--timeout=$(WasmXHarnessTestsTimeout)&quot;</_XHarnessArgs>
<_XHarnessArgs >$(_XHarnessArgs) --engine-arg=--wasi --engine-arg=http</_XHarnessArgs>
<_XHarnessArgs >$(_XHarnessArgs) --engine-arg=--wasi --engine-arg=inherit-network</_XHarnessArgs>
<_XHarnessArgs >$(_XHarnessArgs) --engine-arg=--wasi --engine-arg=tcp</_XHarnessArgs>
<_XHarnessArgs >$(_XHarnessArgs) --engine-arg=--wasi --engine-arg=udp</_XHarnessArgs>
<_XHarnessArgs >$(_XHarnessArgs) --engine-arg=--wasi --engine-arg=allow-ip-name-lookup</_XHarnessArgs>
<_XHarnessArgs >$(_XHarnessArgs) --engine-arg=--env --engine-arg=DOTNET_WASI_PRINT_EXIT_CODE=1</_XHarnessArgs>
<_XHarnessArgs Condition="'$(WasmXHarnessArgsCli)' != ''" >$(_XHarnessArgs) $(WasmXHarnessArgsCli)</_XHarnessArgs>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Runtime.InteropServices;

internal static partial class Interop
{
internal static partial class Sys
{
[Flags]
internal enum SocketEvents : int
{
None = 0x00,
Read = 0x01,
Write = 0x02,
ReadClose = 0x04,
Close = 0x08,
Error = 0x10
}

[LibraryImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetWasiSocketDescriptor")]
internal static unsafe partial Error GetWasiSocketDescriptor(IntPtr socket, IntPtr* entry);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ private static unsafe bool IsSupported(AddressFamily af)
{
// Check for AF_UNIX on iOS/tvOS. The OS claims to support this, but returns EPERM on bind.
// We should explicitly set the return here to false, to avoid giving a false impression.
if (af == AddressFamily.Unix && (OperatingSystem.IsTvOS() || (OperatingSystem.IsIOS() && !OperatingSystem.IsMacCatalyst())))
if (af == AddressFamily.Unix && (OperatingSystem.IsTvOS() || OperatingSystem.IsWasi() || (OperatingSystem.IsIOS() && !OperatingSystem.IsMacCatalyst())))
{
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ static class TaskToAsyncResult
public static IAsyncResult Begin(Task task, AsyncCallback? callback, object? state)
{
#if NET
if (OperatingSystem.IsWasi()) throw new PlatformNotSupportedException(); // TODO remove with https://github.com/dotnet/runtime/pull/107185

ArgumentNullException.ThrowIfNull(task);
#else
if (task is null)
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ await ValidateClientCancellationAsync(async () =>
[InlineData(CancellationMode.CancelPendingRequests, true)]
[InlineData(CancellationMode.DisposeHttpClient, true)]
[SkipOnPlatform(TestPlatforms.Browser, "Browser doesn't have blocking synchronous Stream.ReadByte and so it waits for whole body")]
[SkipOnPlatform(TestPlatforms.Wasi, "Wasi doesn't have blocking synchronous Stream.ReadByte and so it waits for whole body")]
public async Task GetAsync_CancelPendingRequests_DoesntCancelReadAsyncOnResponseStream(CancellationMode mode, bool copyToAsync)
{
if (IsWinHttpHandler && UseVersion >= HttpVersion20.Value)
Expand Down Expand Up @@ -347,6 +348,7 @@ await LoopbackServerFactory.CreateServerAsync(async (server, url) =>

[Fact]
[SkipOnPlatform(TestPlatforms.Browser, "MaxConnectionsPerServer is not supported on Browser")]
[SkipOnPlatform(TestPlatforms.Wasi, "MaxConnectionsPerServer is not supported on Wasi")]
public async Task MaxConnectionsPerServer_WaitingConnectionsAreCancelable()
{
if (LoopbackServerFactory.Version >= HttpVersion20.Value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ await LoopbackServerFactory.CreateClientAndServerAsync(
[Theory]
[MemberData(nameof(CookieNamesValuesAndUseCookies))]
[SkipOnPlatform(TestPlatforms.Browser, "CookieContainer is not supported on Browser")]
[SkipOnPlatform(TestPlatforms.Wasi, "CookieContainer is not supported on Wasi")]
public async Task GetAsync_SetCookieContainer_CookieSent(string cookieName, string cookieValue, bool useCookies)
{
await LoopbackServerFactory.CreateClientAndServerAsync(
Expand Down Expand Up @@ -94,6 +95,7 @@ await LoopbackServerFactory.CreateClientAndServerAsync(

[Fact]
[SkipOnPlatform(TestPlatforms.Browser, "CookieContainer is not supported on Browser")]
[SkipOnPlatform(TestPlatforms.Wasi, "CookieContainer is not supported on Wasi")]
public async Task GetAsync_SetCookieContainerMultipleCookies_CookiesSent()
{
var cookies = new Cookie[]
Expand Down Expand Up @@ -230,6 +232,7 @@ private string GetCookieValue(HttpRequestData request)

[Fact]
[SkipOnPlatform(TestPlatforms.Browser, "CookieContainer is not supported on Browser")]
[SkipOnPlatform(TestPlatforms.Wasi, "CookieContainer is not supported on Wasi")]
public async Task GetAsync_SetCookieContainerAndCookieHeader_BothCookiesSent()
{
await LoopbackServerFactory.CreateServerAsync(async (server, url) =>
Expand Down Expand Up @@ -258,6 +261,7 @@ await LoopbackServerFactory.CreateServerAsync(async (server, url) =>

[Fact]
[SkipOnPlatform(TestPlatforms.Browser, "CookieContainer is not supported on Browser")]
[SkipOnPlatform(TestPlatforms.Wasi, "CookieContainer is not supported on Wasi")]
public async Task GetAsync_SetCookieContainerAndMultipleCookieHeaders_BothCookiesSent()
{
await LoopbackServerFactory.CreateServerAsync(async (server, url) =>
Expand Down Expand Up @@ -298,6 +302,7 @@ await LoopbackServerFactory.CreateServerAsync(async (server, url) =>

[Fact]
[SkipOnPlatform(TestPlatforms.Browser, "CookieContainer is not supported on Browser")]
[SkipOnPlatform(TestPlatforms.Wasi, "CookieContainer is not supported on Wasi")]
public async Task GetAsyncWithRedirect_SetCookieContainer_CorrectCookiesSent()
{
if (UseVersion == HttpVersion30)
Expand Down Expand Up @@ -345,6 +350,7 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async url =>
[Theory]
[MemberData(nameof(CookieNamesValuesAndUseCookies))]
[SkipOnPlatform(TestPlatforms.Browser, "CookieContainer is not supported on Browser")]
[SkipOnPlatform(TestPlatforms.Wasi, "CookieContainer is not supported on Wasi")]
public async Task GetAsync_ReceiveSetCookieHeader_CookieAdded(string cookieName, string cookieValue, bool useCookies)
{
await LoopbackServerFactory.CreateServerAsync(async (server, url) =>
Expand Down Expand Up @@ -377,6 +383,7 @@ await LoopbackServerFactory.CreateServerAsync(async (server, url) =>

[Fact]
[SkipOnPlatform(TestPlatforms.Browser, "CookieContainer is not supported on Browser")]
[SkipOnPlatform(TestPlatforms.Wasi, "CookieContainer is not supported on Wasi")]
public async Task GetAsync_ReceiveMultipleSetCookieHeaders_CookieAdded()
{
await LoopbackServerFactory.CreateServerAsync(async (server, url) =>
Expand Down Expand Up @@ -417,6 +424,7 @@ await LoopbackServerFactory.CreateServerAsync(async (server, url) =>
// ConditionalFact: CookieContainer does not follow RFC6265 on .NET Framework, therefore the (WinHttpHandler) test is expected to fail
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotNetFramework))]
[SkipOnPlatform(TestPlatforms.Browser, "CookieContainer is not supported on Browser")]
[SkipOnPlatform(TestPlatforms.Wasi, "CookieContainer is not supported on Wasi")]
public async Task GetAsync_NoPathDefined_CookieAddedWithDefaultPath()
{
await LoopbackServerFactory.CreateServerAsync(async (server, serverUrl) =>
Expand Down Expand Up @@ -447,6 +455,7 @@ await LoopbackServerFactory.CreateServerAsync(async (server, serverUrl) =>
// ConditionalFact: CookieContainer does not follow RFC6265 on .NET Framework, therefore the (WinHttpHandler) test is expected to fail
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotNetFramework))]
[SkipOnPlatform(TestPlatforms.Browser, "CookieContainer is not supported on Browser")]
[SkipOnPlatform(TestPlatforms.Wasi, "CookieContainer is not supported on Wasi")]
public async Task GetAsync_CookiePathDoesNotMatchRequestPath_CookieAccepted()
{
await LoopbackServerFactory.CreateServerAsync(async (server, serverUrl) =>
Expand Down Expand Up @@ -479,6 +488,7 @@ await LoopbackServerFactory.CreateServerAsync(async (server, serverUrl) =>
// ConditionalFact: CookieContainer does not follow RFC6265 on .NET Framework, therefore the (WinHttpHandler) test is expected to fail
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotNetFramework))]
[SkipOnPlatform(TestPlatforms.Browser, "CookieContainer is not supported on Browser")]
[SkipOnPlatform(TestPlatforms.Wasi, "CookieContainer is not supported on Wasi")]
public async Task GetAsync_Redirect_CookiesArePreserved()
{
if (UseVersion == HttpVersion30)
Expand Down Expand Up @@ -528,6 +538,7 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async serverUrl =>

[Fact]
[SkipOnPlatform(TestPlatforms.Browser, "CookieContainer is not supported on Browser")]
[SkipOnPlatform(TestPlatforms.Wasi, "CookieContainer is not supported on Wasi")]
public async Task GetAsync_ReceiveSetCookieHeader_CookieUpdated()
{
const string newCookieValue = "789";
Expand Down Expand Up @@ -556,6 +567,7 @@ await LoopbackServerFactory.CreateServerAsync(async (server, url) =>

[Fact]
[SkipOnPlatform(TestPlatforms.Browser, "CookieContainer is not supported on Browser")]
[SkipOnPlatform(TestPlatforms.Wasi, "CookieContainer is not supported on Wasi")]
public async Task GetAsync_ReceiveSetCookieHeader_CookieRemoved()
{
await LoopbackServerFactory.CreateServerAsync(async (server, url) =>
Expand All @@ -580,6 +592,7 @@ await LoopbackServerFactory.CreateServerAsync(async (server, url) =>

[Fact]
[SkipOnPlatform(TestPlatforms.Browser, "CookieContainer is not supported on Browser")]
[SkipOnPlatform(TestPlatforms.Wasi, "CookieContainer is not supported on Wasi")]
public async Task GetAsync_ReceiveInvalidSetCookieHeader_ValidCookiesAdded()
{
await LoopbackServerFactory.CreateServerAsync(async (server, url) =>
Expand Down Expand Up @@ -615,6 +628,7 @@ await LoopbackServerFactory.CreateServerAsync(async (server, url) =>

[Fact]
[SkipOnPlatform(TestPlatforms.Browser, "CookieContainer is not supported on Browser")]
[SkipOnPlatform(TestPlatforms.Wasi, "CookieContainer is not supported on Wasi")]
public async Task GetAsyncWithRedirect_ReceiveSetCookie_CookieSent()
{
if (UseVersion == HttpVersion30)
Expand Down Expand Up @@ -675,6 +689,7 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async url =>

[Fact]
[SkipOnPlatform(TestPlatforms.Browser, "CookieContainer is not supported on Browser")]
[SkipOnPlatform(TestPlatforms.Wasi, "CookieContainer is not supported on Wasi")]
public async Task GetAsyncWithBasicAuth_ReceiveSetCookie_CookieSent()
{
if (UseVersion == HttpVersion30)
Expand Down Expand Up @@ -801,6 +816,7 @@ public HttpClientHandlerTest_Cookies_Http11(ITestOutputHelper output) : base(out

[Fact]
[SkipOnPlatform(TestPlatforms.Browser, "CookieContainer is not supported on Browser")]
[SkipOnPlatform(TestPlatforms.Wasi, "CookieContainer is not supported on Wasi")]
public async Task GetAsync_ReceiveMultipleSetCookieHeaders_CookieAdded()
{
await LoopbackServer.CreateServerAsync(async (server, url) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public static IEnumerable<object[]> DecompressedResponse_MethodSpecified_Decompr
[Theory]
[MemberData(nameof(DecompressedResponse_MethodSpecified_DecompressedContentReturned_MemberData))]
[SkipOnPlatform(TestPlatforms.Browser, "AutomaticDecompression not supported on Browser")]
[SkipOnPlatform(TestPlatforms.Wasi, "AutomaticDecompression not supported on Wasi")]
public async Task DecompressedResponse_MethodSpecified_DecompressedContentReturned(string compressionName, bool all, bool useCopyTo, int contentLength)
{
if (IsWinHttpHandler &&
Expand Down Expand Up @@ -140,6 +141,7 @@ public static IEnumerable<object[]> DecompressedResponse_MethodNotSpecified_Orig
[Theory]
[MemberData(nameof(DecompressedResponse_MethodNotSpecified_OriginalContentReturned_MemberData))]
[SkipOnPlatform(TestPlatforms.Browser, "AutomaticDecompression not supported on Browser")]
[SkipOnPlatform(TestPlatforms.Wasi, "AutomaticDecompression not supported on Wasi")]
public async Task DecompressedResponse_MethodNotSpecified_OriginalContentReturned(
string encodingName, Func<Stream, Stream> compress, DecompressionMethods methods, bool useCopyTo)
{
Expand Down Expand Up @@ -179,6 +181,7 @@ await server.AcceptConnectionAsync(async connection =>
[InlineData("br", DecompressionMethods.Brotli)]
#endif
[SkipOnPlatform(TestPlatforms.Browser, "AutomaticDecompression not supported on Browser")]
[SkipOnPlatform(TestPlatforms.Wasi, "AutomaticDecompression not supported on Wasi")]
public async Task DecompressedResponse_EmptyBody_Success(string encodingName, DecompressionMethods methods)
{
await LoopbackServer.CreateClientAndServerAsync(async uri =>
Expand Down Expand Up @@ -270,6 +273,7 @@ await LoopbackServer.CreateServerAsync(async (server, url) =>
[InlineData(DecompressionMethods.GZip | DecompressionMethods.Deflate, "gzip; q=1.0, deflate; q=1.0", "")]
[InlineData(DecompressionMethods.GZip | DecompressionMethods.Deflate, "gzip; q=1.0", "deflate")]
[SkipOnPlatform(TestPlatforms.Browser, "AutomaticDecompression not supported on Browser")]
[SkipOnPlatform(TestPlatforms.Wasi, "AutomaticDecompression not supported on Wasi")]
public async Task GetAsync_SetAutomaticDecompression_AcceptEncodingHeaderSentWithQualityWeightingsNoDuplicates(
DecompressionMethods methods,
string manualAcceptEncodingHeaderValues,
Expand Down
Loading
Loading