From 88dbfaa2ab2dfbc3a9403c34d21a809db08c9f4f Mon Sep 17 00:00:00 2001 From: Brennan Date: Tue, 5 May 2020 19:18:37 -0700 Subject: [PATCH] Set certificate in some Kestrel tests to avoid global machine state (#21516) --- .../BindTests/AddressRegistrationTests.cs | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/Servers/Kestrel/test/BindTests/AddressRegistrationTests.cs b/src/Servers/Kestrel/test/BindTests/AddressRegistrationTests.cs index 9d6c376e32..f1fcec949b 100644 --- a/src/Servers/Kestrel/test/BindTests/AddressRegistrationTests.cs +++ b/src/Servers/Kestrel/test/BindTests/AddressRegistrationTests.cs @@ -129,12 +129,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } [ConditionalTheory] - [MemberData(nameof(AddressRegistrationDataIPv6Port5000Default))] + [MemberData(nameof(AddressRegistrationDataIPv6Port5000And5001Default))] [IPv6SupportedCondition] [QuarantinedTest("https://github.com/dotnet/aspnetcore-internal/issues/2711")] - public async Task RegisterAddresses_IPv6Port5000Default_Success(string addressInput, string[] testUrls) + public async Task RegisterAddresses_IPv6Port5000And5001Default_Success(string addressInput, string[] testUrls) { - if (!CanBindToEndpoint(IPAddress.Loopback, 5000) || !CanBindToEndpoint(IPAddress.IPv6Loopback, 5000)) + if ((!CanBindToEndpoint(IPAddress.Loopback, 5000) || !CanBindToEndpoint(IPAddress.IPv6Loopback, 5000)) && + (!CanBindToEndpoint(IPAddress.Loopback, 5001) || !CanBindToEndpoint(IPAddress.IPv6Loopback, 5001))) { return; } @@ -183,7 +184,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests private async Task RegisterAddresses_Success(string addressInput, string[] testUrls, int testPort = 0) { var hostBuilder = TransportSelector.GetWebHostBuilder() - .UseKestrel() + .UseKestrel(serverOptions => + { + serverOptions.ConfigureHttpsDefaults(httpsOptions => + { + httpsOptions.ServerCertificate = TestResources.GetTestCertificate(); + }); + }) .ConfigureServices(AddTestLogging) .UseUrls(addressInput) .Configure(ConfigureEchoAddress); @@ -1038,11 +1045,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - public static TheoryData AddressRegistrationDataIPv6Port5000Default => + public static TheoryData AddressRegistrationDataIPv6Port5000And5001Default => new TheoryData { - { null, new[] { "http://127.0.0.1:5000/", "http://[::1]:5000/" } }, - { string.Empty, new[] { "http://127.0.0.1:5000/", "http://[::1]:5000/" } } + { null, new[] { "http://127.0.0.1:5000/", "http://[::1]:5000/", "https://127.0.0.1:5001/", "https://[::1]:5001/" } }, + { string.Empty, new[] { "http://127.0.0.1:5000/", "http://[::1]:5000/", "https://127.0.0.1:5001/", "https://[::1]:5001/" } } }; public static TheoryData AddressRegistrationDataIPv6Port80 =>