Skip to content

Commit 8ff1cb9

Browse files
Set certificate in some Kestrel tests to avoid global machine state (#21516) (#21542)
1 parent 9e2a480 commit 8ff1cb9

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/Servers/Kestrel/test/BindTests/AddressRegistrationTests.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,13 @@ public async Task RegisterAddresses_IPv6_Success(string addressInput, string[] t
129129
}
130130

131131
[ConditionalTheory]
132-
[MemberData(nameof(AddressRegistrationDataIPv6Port5000Default))]
132+
[MemberData(nameof(AddressRegistrationDataIPv6Port5000And5001Default))]
133133
[IPv6SupportedCondition]
134134
[Flaky("https://github.com/aspnet/AspNetCore-Internal/issues/2711", FlakyOn.AzP.All)]
135-
public async Task RegisterAddresses_IPv6Port5000Default_Success(string addressInput, string[] testUrls)
135+
public async Task RegisterAddresses_IPv6Port5000And5001Default_Success(string addressInput, string[] testUrls)
136136
{
137-
if (!CanBindToEndpoint(IPAddress.Loopback, 5000) || !CanBindToEndpoint(IPAddress.IPv6Loopback, 5000))
137+
if ((!CanBindToEndpoint(IPAddress.Loopback, 5000) || !CanBindToEndpoint(IPAddress.IPv6Loopback, 5000)) &&
138+
(!CanBindToEndpoint(IPAddress.Loopback, 5001) || !CanBindToEndpoint(IPAddress.IPv6Loopback, 5001)))
138139
{
139140
return;
140141
}
@@ -183,7 +184,13 @@ public async Task RegisterAddresses_IPv6LocalhostStaticPort_Success()
183184
private async Task RegisterAddresses_Success(string addressInput, string[] testUrls, int testPort = 0)
184185
{
185186
var hostBuilder = TransportSelector.GetWebHostBuilder()
186-
.UseKestrel()
187+
.UseKestrel(serverOptions =>
188+
{
189+
serverOptions.ConfigureHttpsDefaults(httpsOptions =>
190+
{
191+
httpsOptions.ServerCertificate = TestResources.GetTestCertificate();
192+
});
193+
})
187194
.ConfigureServices(AddTestLogging)
188195
.UseUrls(addressInput)
189196
.Configure(ConfigureEchoAddress);
@@ -1039,11 +1046,11 @@ public static TheoryData<string, string[]> AddressRegistrationDataIPv6
10391046
}
10401047
}
10411048

1042-
public static TheoryData<string, string[]> AddressRegistrationDataIPv6Port5000Default =>
1049+
public static TheoryData<string, string[]> AddressRegistrationDataIPv6Port5000And5001Default =>
10431050
new TheoryData<string, string[]>
10441051
{
1045-
{ null, new[] { "http://127.0.0.1:5000/", "http://[::1]:5000/" } },
1046-
{ string.Empty, new[] { "http://127.0.0.1:5000/", "http://[::1]:5000/" } }
1052+
{ null, new[] { "http://127.0.0.1:5000/", "http://[::1]:5000/", "https://127.0.0.1:5001/", "https://[::1]:5001/" } },
1053+
{ string.Empty, new[] { "http://127.0.0.1:5000/", "http://[::1]:5000/", "https://127.0.0.1:5001/", "https://[::1]:5001/" } }
10471054
};
10481055

10491056
public static TheoryData<string, string[]> AddressRegistrationDataIPv6Port80 =>

0 commit comments

Comments
 (0)