From 8ff1cb906d2bf937484f5cdbab2a951b82459b74 Mon Sep 17 00:00:00 2001 From: Brennan Date: Wed, 13 May 2020 11:11:02 -0700 Subject: [PATCH] Set certificate in some Kestrel tests to avoid global machine state (#21516) (#21542) --- .../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 205bdbbe5f..b337578824 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] [Flaky("https://github.com/aspnet/AspNetCore-Internal/issues/2711", FlakyOn.AzP.All)] - 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); @@ -1039,11 +1046,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 =>