Skip to content

Commit

Permalink
Skip Quic IPv6 tests on unsupported platforms (#75341)
Browse files Browse the repository at this point in the history
  • Loading branch information
rzikm committed Sep 9, 2022
1 parent 8101ace commit 752cb7e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public async Task CertificateCallbackThrowPropagates()

var listenerOptions = new QuicListenerOptions()
{
ListenEndPoint = new IPEndPoint(Socket.OSSupportsIPv6 ? IPAddress.IPv6Loopback : IPAddress.Loopback, 0),
ListenEndPoint = new IPEndPoint(IsIPv6Available ? IPAddress.IPv6Loopback : IPAddress.Loopback, 0),
ApplicationProtocols = new List<SslApplicationProtocol>() { ApplicationProtocol },
ConnectionOptionsCallback = (_, _, _) => ValueTask.FromResult(CreateQuicServerOptions())
};
Expand Down Expand Up @@ -289,7 +289,7 @@ public async Task ConnectWithServerCertificateCallback()

var listenerOptions = new QuicListenerOptions()
{
ListenEndPoint = new IPEndPoint(Socket.OSSupportsIPv6 ? IPAddress.IPv6Loopback : IPAddress.Loopback, 0),
ListenEndPoint = new IPEndPoint(IsIPv6Available ? IPAddress.IPv6Loopback : IPAddress.Loopback, 0),
ApplicationProtocols = new List<SslApplicationProtocol>() { ApplicationProtocol },
ConnectionOptionsCallback = (_, _, _) =>
{
Expand Down Expand Up @@ -438,6 +438,10 @@ public async Task ConnectWithCertificateForDifferentName_Throws()
public async Task ConnectWithCertificateForLoopbackIP_IndicatesExpectedError(string ipString, bool expectsError)
{
var ipAddress = IPAddress.Parse(ipString);
if (ipAddress.AddressFamily == AddressFamily.InterNetworkV6 && !IsIPv6Available)
{
throw new SkipTestException("IPv6 is not available on this platform");
}

(X509Certificate2 certificate, X509Certificate2Collection chain) = Configuration.Certificates.GenerateCertificates(expectsError ? "badhost" : "localhost");
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ await Task.Run(async () =>
}).WaitAsync(TimeSpan.FromSeconds(6));
}

[Fact]
[ConditionalFact(nameof(IsIPv6Available))]
public async Task Listener_Backlog_Success_IPv6()
{
await Task.Run(async () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public abstract class QuicTestBase : IDisposable

public static bool IsSupported => QuicListener.IsSupported && QuicConnection.IsSupported;

private static readonly Lazy<bool> _isIPv6Available = new Lazy<bool>(GetIsIPv6Available);
public static bool IsIPv6Available => _isIPv6Available.Value;

public static SslApplicationProtocol ApplicationProtocol { get; } = new SslApplicationProtocol("quictest");

public readonly X509Certificate2 ServerCertificate = System.Net.Test.Common.Configuration.Certificates.GetServerCertificate();
Expand Down Expand Up @@ -367,5 +370,19 @@ internal static async Task<int> WriteForever(QuicStream stream, int size = 1)
ArrayPool<byte>.Shared.Return(buffer);
}
}

internal static bool GetIsIPv6Available()
{
try
{
using Socket s = new Socket(AddressFamily.InterNetworkV6, SocketType.Dgram, ProtocolType.Tcp);
s.Bind(new IPEndPoint(IPAddress.IPv6Loopback, 0));
return true;
}
catch (SocketException)
{
return false;
}
}
}
}

0 comments on commit 752cb7e

Please sign in to comment.