|
5 | 5 | using System.Collections.Generic;
|
6 | 6 | using System.Linq;
|
7 | 7 | using System.Security.Authentication;
|
| 8 | +using Microsoft.AspNetCore.Http; |
8 | 9 | using Microsoft.AspNetCore.Server.Kestrel.Core;
|
9 | 10 | using Microsoft.AspNetCore.Server.Kestrel.Core.Internal;
|
10 | 11 | using Microsoft.AspNetCore.Server.Kestrel.Https;
|
@@ -273,6 +274,47 @@ public void ReadEndpointWithNoSslProtocolSettings_ReturnsNull()
|
273 | 274 | Assert.Null(endpoint.SslProtocols);
|
274 | 275 | }
|
275 | 276 |
|
| 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 | + |
276 | 318 | [Fact]
|
277 | 319 | public void ReadEndpointDefaultsWithSingleSslProtocolSet_ReturnsCorrectValue()
|
278 | 320 | {
|
|
0 commit comments