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

[QUIC] Removes abstract providers and mock from S.N.Quic #70421

Merged
merged 3 commits into from
Jun 20, 2022
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
18 changes: 6 additions & 12 deletions src/libraries/Common/tests/System/Net/Http/Http3LoopbackServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Diagnostics;
using System.IO;
using System.Net.Quic;
using System.Net.Quic.Implementations;
using System.Net.Security;
using System.Net.Sockets;
using System.Security.Cryptography.X509Certificates;
Expand All @@ -20,7 +19,7 @@ public sealed class Http3LoopbackServer : GenericLoopbackServer

public override Uri Address => new Uri($"https://{_listener.ListenEndPoint}/");

public Http3LoopbackServer(QuicImplementationProvider quicImplementationProvider = null, Http3Options options = null)
public Http3LoopbackServer(Http3Options options = null)
{
options ??= new Http3Options();

Expand All @@ -43,7 +42,9 @@ public Http3LoopbackServer(QuicImplementationProvider quicImplementationProvider
MaxBidirectionalStreams = options.MaxBidirectionalStreams,
};

_listener = new QuicListener(quicImplementationProvider ?? QuicImplementationProviders.Default, listenerOptions);
ValueTask<QuicListener> valueTask = QuicListener.ListenAsync(listenerOptions);
Debug.Assert(valueTask.IsCompleted);
_listener = valueTask.Result;
}

public override void Dispose()
Expand Down Expand Up @@ -82,20 +83,13 @@ public override async Task<HttpRequestData> HandleRequestAsync(HttpStatusCode st

public sealed class Http3LoopbackServerFactory : LoopbackServerFactory
{
private QuicImplementationProvider _quicImplementationProvider;

public Http3LoopbackServerFactory(QuicImplementationProvider quicImplementationProvider)
{
_quicImplementationProvider = quicImplementationProvider;
}

public static Http3LoopbackServerFactory Singleton { get; } = new Http3LoopbackServerFactory(null);
public static Http3LoopbackServerFactory Singleton { get; } = new Http3LoopbackServerFactory();

public override Version Version { get; } = new Version(3, 0);

public override GenericLoopbackServer CreateServer(GenericLoopbackOptions options = null)
{
return new Http3LoopbackServer(_quicImplementationProvider, CreateOptions(options));
return new Http3LoopbackServer(CreateOptions(options));
}

public override async Task CreateServerAsync(Func<GenericLoopbackServer, Uri, Task> funcAsync, int millisecondsTimeout = 60000, GenericLoopbackOptions options = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public abstract partial class HttpClientHandler_ServerCertificates_Test : HttpCl
public HttpClientHandler_ServerCertificates_Test(ITestOutputHelper output) : base(output) { }

// This enables customizing ServerCertificateCustomValidationCallback in WinHttpHandler variants:
protected bool AllowAllHttp2Certificates { get; set; } = true;
protected new HttpClientHandler CreateHttpClientHandler() => CreateHttpClientHandler(UseVersion, allowAllHttp2Certificates: AllowAllHttp2Certificates);
protected bool AllowAllCertificates { get; set; } = true;
protected new HttpClientHandler CreateHttpClientHandler() => CreateHttpClientHandler(UseVersion, allowAllCertificates: AllowAllCertificates);
protected override HttpClient CreateHttpClient() => CreateHttpClient(CreateHttpClientHandler());

[Fact]
Expand Down Expand Up @@ -393,19 +393,19 @@ public void HttpClientUsesSslCertEnvironmentVariables()
File.WriteAllText(sslCertFile, "");
psi.Environment.Add("SSL_CERT_FILE", sslCertFile);

RemoteExecutor.Invoke(async (useVersionString, allowAllHttp2CertificatesString) =>
RemoteExecutor.Invoke(async (useVersionString, allowAllCertificatesString) =>
{
const string Url = "https://www.microsoft.com";

HttpClientHandler handler = CreateHttpClientHandler(
Version.Parse(useVersionString),
allowAllHttp2Certificates: bool.Parse(allowAllHttp2CertificatesString));
allowAllCertificates: bool.Parse(allowAllCertificatesString));

using (HttpClient client = CreateHttpClient(handler, useVersionString))
{
await Assert.ThrowsAsync<HttpRequestException>(() => client.GetAsync(Url));
}
}, UseVersion.ToString(), AllowAllHttp2Certificates.ToString(), new RemoteInvokeOptions { StartInfo = psi }).Dispose();
}, UseVersion.ToString(), AllowAllCertificates.ToString(), new RemoteInvokeOptions { StartInfo = psi }).Dispose();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ public abstract partial class HttpClientHandlerTestBase : FileCleanupTestBase
{
protected static bool IsWinHttpHandler => true;

protected static WinHttpClientHandler CreateHttpClientHandler(Version useVersion = null, bool allowAllHttp2Certificates = true)
protected static WinHttpClientHandler CreateHttpClientHandler(Version useVersion = null, bool allowAllCertificates = true)
{
useVersion ??= HttpVersion.Version11;

WinHttpClientHandler handler = new WinHttpClientHandler(useVersion);

if (useVersion >= HttpVersion20.Value && allowAllHttp2Certificates)
if (useVersion >= HttpVersion20.Value && allowAllCertificates)
{
handler.ServerCertificateCustomValidationCallback = TestHelper.AllowAllCertificates;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,9 @@ public sealed class PlatformHandler_HttpClientHandler_ServerCertificates_Http2_T
{
protected override Version UseVersion => HttpVersion20.Value;

public PlatformHandler_HttpClientHandler_ServerCertificates_Http2_Test(ITestOutputHelper output) : base(output) {
AllowAllHttp2Certificates = false;
public PlatformHandler_HttpClientHandler_ServerCertificates_Http2_Test(ITestOutputHelper output) : base(output)
{
AllowAllCertificates = false;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Diagnostics;
using System.IO;
using System.Net.Quic;
using System.Net.Quic.Implementations;
using System.Net.Security;
using System.Net.Sockets;
using System.Runtime.Versioning;
Expand Down Expand Up @@ -105,19 +104,22 @@ public static async ValueTask<SslStream> EstablishSslConnectionAsync(SslClientAu
[SupportedOSPlatform("windows")]
[SupportedOSPlatform("linux")]
[SupportedOSPlatform("macos")]
public static async ValueTask<QuicConnection> ConnectQuicAsync(HttpRequestMessage request, QuicImplementationProvider quicImplementationProvider, DnsEndPoint endPoint, SslClientAuthenticationOptions clientAuthenticationOptions, CancellationToken cancellationToken)
public static async ValueTask<QuicConnection> ConnectQuicAsync(HttpRequestMessage request, DnsEndPoint endPoint, SslClientAuthenticationOptions clientAuthenticationOptions, CancellationToken cancellationToken)
{
clientAuthenticationOptions = SetUpRemoteCertificateValidationCallback(clientAuthenticationOptions, request);

QuicConnection con = new QuicConnection(quicImplementationProvider, endPoint, clientAuthenticationOptions);
QuicConnection connection = await QuicConnection.ConnectAsync(new QuicClientConnectionOptions()
{
RemoteEndPoint = endPoint,
ClientAuthenticationOptions = clientAuthenticationOptions
}, cancellationToken).ConfigureAwait(false);
try
{
await con.ConnectAsync(cancellationToken).ConfigureAwait(false);
return con;
await connection.ConnectAsync(cancellationToken).ConfigureAwait(false);
return connection;
}
catch (Exception ex)
{
con.Dispose();
connection.Dispose();
throw CreateWrappedException(ex, endPoint.Host, endPoint.Port, cancellationToken);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public HttpConnectionPool(HttpConnectionPoolManager poolManager, HttpConnectionK

if (IsHttp3Supported())
{
_http3Enabled = _poolManager.Settings._maxHttpVersion >= HttpVersion.Version30 && (_poolManager.Settings._quicImplementationProvider ?? QuicImplementationProviders.Default).IsSupported;
_http3Enabled = _poolManager.Settings._maxHttpVersion >= HttpVersion.Version30 && QuicConnection.IsSupported;
}

switch (kind)
Expand Down Expand Up @@ -885,7 +885,7 @@ private async ValueTask<Http3Connection> GetHttp3ConnectionAsync(HttpRequestMess
QuicConnection quicConnection;
try
{
quicConnection = await ConnectHelper.ConnectQuicAsync(request, Settings._quicImplementationProvider ?? QuicImplementationProviders.Default, new DnsEndPoint(authority.IdnHost, authority.Port), _sslOptionsHttp3!, cancellationToken).ConfigureAwait(false);
quicConnection = await ConnectHelper.ConnectQuicAsync(request, new DnsEndPoint(authority.IdnHost, authority.Port), _sslOptionsHttp3!, cancellationToken).ConfigureAwait(false);
}
catch (Exception e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Collections.Generic;
using System.Net.Security;
using System.IO;
using System.Net.Quic.Implementations;
using System.Runtime.Versioning;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -59,9 +58,6 @@ internal sealed class HttpConnectionSettings
internal Func<SocketsHttpConnectionContext, CancellationToken, ValueTask<Stream>>? _connectCallback;
internal Func<SocketsHttpPlaintextStreamFilterContext, CancellationToken, ValueTask<Stream>>? _plaintextStreamFilter;

// !!! NOTE !!! This is temporary and will not ship.
internal QuicImplementationProvider? _quicImplementationProvider;

internal IDictionary<string, object?>? _properties;

// Http2 flow control settings:
Expand Down Expand Up @@ -123,12 +119,6 @@ public HttpConnectionSettings CloneAndNormalize()
_defaultCredentialsUsedForServer = _credentials == CredentialCache.DefaultCredentials,
};

// TODO: Remove if/when QuicImplementationProvider is removed from System.Net.Quic.
if (HttpConnectionPool.IsHttp3Supported())
{
settings._quicImplementationProvider = _quicImplementationProvider;
}

return settings;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ private HttpClient CreateHttpClient(Version version)
[MemberData(nameof(AltSvcHeaderUpgradeVersions))]
public async Task AltSvc_Header_Upgrade_Success(Version fromVersion, bool overrideHost)
{
// [ActiveIssue("https://github.com/dotnet/runtime/issues/54050")]
if (UseQuicImplementationProvider == QuicImplementationProviders.Mock)
{
return;
}

// The test makes a request to a HTTP/1 or HTTP/2 server first, which supplies an Alt-Svc header pointing to the second server.
using GenericLoopbackServer firstServer =
fromVersion.Major switch
Expand All @@ -48,7 +42,7 @@ public async Task AltSvc_Header_Upgrade_Success(Version fromVersion, bool overri

// The second request is expected to come in on this HTTP/3 server.
using Http3LoopbackServer secondServer = CreateHttp3LoopbackServer();

if (!overrideHost)
Assert.Equal(firstServer.Address.IdnHost, secondServer.Address.IdnHost);

Expand Down Expand Up @@ -80,12 +74,6 @@ public async Task AltSvc_Header_Upgrade_Success(Version fromVersion, bool overri
[Fact]
public async Task AltSvc_ConnectionFrame_UpgradeFrom20_Success()
{
// [ActiveIssue("https://github.com/dotnet/runtime/issues/54050")]
if (UseQuicImplementationProvider == QuicImplementationProviders.Mock)
{
return;
}

using Http2LoopbackServer firstServer = Http2LoopbackServer.CreateServer();
using Http3LoopbackServer secondServer = CreateHttp3LoopbackServer();
using HttpClient client = CreateHttpClient(HttpVersion.Version20);
Expand All @@ -111,12 +99,6 @@ public async Task AltSvc_ConnectionFrame_UpgradeFrom20_Success()
[Fact]
public async Task AltSvc_ResponseFrame_UpgradeFrom20_Success()
{
// [ActiveIssue("https://github.com/dotnet/runtime/issues/54050")]
if (UseQuicImplementationProvider == QuicImplementationProviders.Mock)
{
return;
}

using Http2LoopbackServer firstServer = Http2LoopbackServer.CreateServer();
using Http3LoopbackServer secondServer = CreateHttp3LoopbackServer();
using HttpClient client = CreateHttpClient(HttpVersion.Version20);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ private static Task GetAndDropResponse(HttpClient client, Uri url)
[ActiveIssue("https://github.com/dotnet/runtime/issues/69870", TestPlatforms.Android)]
public async Task IncompleteResponseStream_ResponseDropped_CancelsRequestToServer()
{
if (UseQuicImplementationProvider == QuicImplementationProviders.Mock)
{
return;
}

using (HttpClient client = CreateHttpClient())
{
bool stopGCs = false;
Expand Down
Loading