Skip to content

Commit 5ffb1ee

Browse files
committed
ConfigurationReaderTests
1 parent ced9e33 commit 5ffb1ee

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/Servers/Kestrel/Kestrel/test/ConfigurationReaderTests.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Collections.Generic;
66
using System.Linq;
77
using System.Security.Authentication;
8+
using Microsoft.AspNetCore.Http;
89
using Microsoft.AspNetCore.Server.Kestrel.Core;
910
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal;
1011
using Microsoft.AspNetCore.Server.Kestrel.Https;
@@ -273,6 +274,47 @@ public void ReadEndpointWithNoSslProtocolSettings_ReturnsNull()
273274
Assert.Null(endpoint.SslProtocols);
274275
}
275276

277+
[Fact]
278+
public void ReadEndpointWithoutSniConfigured_ReturnsEmptyCollection()
279+
{
280+
var config = new ConfigurationBuilder().AddInMemoryCollection(new[]
281+
{
282+
new KeyValuePair<string, string>("Endpoints:End1:Url", "http://*:5001"),
283+
}).Build();
284+
285+
var reader = new ConfigurationReader(config);
286+
var endpoint = reader.Endpoints.First();
287+
Assert.NotNull(endpoint.SNI);
288+
Assert.False(endpoint.SNI.Any());
289+
}
290+
291+
[Fact]
292+
public void ReadEndpointWithSniConfigured_ReturnsCorrectValue()
293+
{
294+
var config = new ConfigurationBuilder().AddInMemoryCollection(new[]
295+
{
296+
new KeyValuePair<string, string>("Endpoints:End1:Url", "http://*:5001"),
297+
new KeyValuePair<string, string>("Endpoints:End1:SNI:*.example.org:Protocols", "Http1"),
298+
new KeyValuePair<string, string>("Endpoints:End1:SNI:*.example.org:SslProtocols:0", "Tls12"),
299+
new KeyValuePair<string, string>("Endpoints:End1:SNI:*.example.org:Certificate:Path", "/path/cert.pfx"),
300+
new KeyValuePair<string, string>("Endpoints:End1:SNI:*.example.org:Certificate:Password", "certpassword"),
301+
new KeyValuePair<string, string>("Endpoints:End1:SNI:*.example.org:ClientCertificateMode", "AllowCertificate"),
302+
}).Build();
303+
304+
var reader = new ConfigurationReader(config);
305+
var endpoint = reader.Endpoints.First();
306+
var sni = endpoint.SNI["*.EXAMPLE.org"];
307+
308+
Assert.NotNull(sni);
309+
310+
Assert.Equal("*.example.org", sni.Name);
311+
Assert.Equal(HttpProtocols.Http1, sni.Protocols);
312+
Assert.Equal(SslProtocols.Tls12, sni.SslProtocols);
313+
Assert.Equal("/path/cert.pfx", sni.Certificate.Path);
314+
Assert.Equal("certpassword", sni.Certificate.Password);
315+
Assert.Equal(ClientCertificateMode.AllowCertificate, sni.ClientCertificateMode);
316+
}
317+
276318
[Fact]
277319
public void ReadEndpointDefaultsWithSingleSslProtocolSet_ReturnsCorrectValue()
278320
{

0 commit comments

Comments
 (0)