Set certificate in some Kestrel tests to avoid global machine state (#21516) (#21542)

This commit is contained in:
Brennan 2020-05-13 11:11:02 -07:00 committed by GitHub
parent 9e2a480925
commit 8ff1cb906d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 7 deletions

View File

@ -129,12 +129,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
} }
[ConditionalTheory] [ConditionalTheory]
[MemberData(nameof(AddressRegistrationDataIPv6Port5000Default))] [MemberData(nameof(AddressRegistrationDataIPv6Port5000And5001Default))]
[IPv6SupportedCondition] [IPv6SupportedCondition]
[Flaky("https://github.com/aspnet/AspNetCore-Internal/issues/2711", FlakyOn.AzP.All)] [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; return;
} }
@ -183,7 +184,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
private async Task RegisterAddresses_Success(string addressInput, string[] testUrls, int testPort = 0) private async Task RegisterAddresses_Success(string addressInput, string[] testUrls, int testPort = 0)
{ {
var hostBuilder = TransportSelector.GetWebHostBuilder() var hostBuilder = TransportSelector.GetWebHostBuilder()
.UseKestrel() .UseKestrel(serverOptions =>
{
serverOptions.ConfigureHttpsDefaults(httpsOptions =>
{
httpsOptions.ServerCertificate = TestResources.GetTestCertificate();
});
})
.ConfigureServices(AddTestLogging) .ConfigureServices(AddTestLogging)
.UseUrls(addressInput) .UseUrls(addressInput)
.Configure(ConfigureEchoAddress); .Configure(ConfigureEchoAddress);
@ -1039,11 +1046,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
} }
} }
public static TheoryData<string, string[]> AddressRegistrationDataIPv6Port5000Default => public static TheoryData<string, string[]> AddressRegistrationDataIPv6Port5000And5001Default =>
new TheoryData<string, string[]> new TheoryData<string, string[]>
{ {
{ null, 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/" } } { string.Empty, new[] { "http://127.0.0.1:5000/", "http://[::1]:5000/", "https://127.0.0.1:5001/", "https://[::1]:5001/" } }
}; };
public static TheoryData<string, string[]> AddressRegistrationDataIPv6Port80 => public static TheoryData<string, string[]> AddressRegistrationDataIPv6Port80 =>