Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Commit 9b86b3c

Browse files
committed
Add forced https upgrade test
1 parent 001ef2a commit 9b86b3c

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

test/Kestrel.FunctionalTests/AddressRegistrationTests.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,40 @@ private Task RegisterAddresses_Success(string addressInput, string testUrl, int
191191
private Task RegisterAddresses_StaticPort_Success(string addressInput, string[] testUrls) =>
192192
RunTestWithStaticPort(port => RegisterAddresses_Success($"{addressInput}:{port}", testUrls, port));
193193

194+
[Fact]
195+
public async Task RegisterHttpAddress_UpradedToHttpsByConfigureEndpointDefaults()
196+
{
197+
var hostBuilder = TransportSelector.GetWebHostBuilder()
198+
.UseKestrel(serverOptions =>
199+
{
200+
serverOptions.ConfigureEndpointDefaults(listenOptions =>
201+
{
202+
listenOptions.UseHttps(TestResources.GetTestCertificate());
203+
});
204+
})
205+
.ConfigureLogging(_configureLoggingDelegate)
206+
.UseUrls("http://127.0.0.1:0")
207+
.Configure(app =>
208+
{
209+
var serverAddresses = app.ServerFeatures.Get<IServerAddressesFeature>();
210+
app.Run(context =>
211+
{
212+
Assert.Single(serverAddresses.Addresses);
213+
return context.Response.WriteAsync(serverAddresses.Addresses.First());
214+
});
215+
});
216+
217+
using (var host = hostBuilder.Build())
218+
{
219+
host.Start();
220+
221+
var expectedUrl = $"https://127.0.0.1:{host.GetPort()}";
222+
var response = await HttpClientSlim.GetStringAsync(expectedUrl, validateCertificate: false);
223+
224+
Assert.Equal(expectedUrl, response);
225+
}
226+
}
227+
194228
private async Task RunTestWithStaticPort(Func<int, Task> test)
195229
{
196230
var retryCount = 0;

test/Kestrel.Tests/KestrelConfigurationBuilderTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
using System.Security.Cryptography.X509Certificates;
88
using Microsoft.AspNetCore.Hosting;
99
using Microsoft.AspNetCore.Server.Kestrel.Core;
10-
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal;
1110
using Microsoft.AspNetCore.Server.Kestrel.Https;
12-
using Microsoft.AspNetCore.Server.Kestrel.Internal;
1311
using Microsoft.AspNetCore.Testing;
1412
using Microsoft.Extensions.Configuration;
1513
using Microsoft.Extensions.DependencyInjection;

0 commit comments

Comments
 (0)