6
6
using System . IO ;
7
7
using System . Linq ;
8
8
using System . Security . Cryptography . X509Certificates ;
9
+ using System . Threading . Tasks ;
9
10
using Microsoft . AspNetCore . Hosting ;
10
11
using Microsoft . AspNetCore . Server . Kestrel . Core ;
11
12
using Microsoft . AspNetCore . Server . Kestrel . Https ;
14
15
using Microsoft . Extensions . DependencyInjection ;
15
16
using Microsoft . Extensions . FileProviders ;
16
17
using Microsoft . Extensions . Hosting ;
18
+ using Microsoft . Extensions . Logging ;
19
+ using Microsoft . Extensions . Logging . Testing ;
17
20
using Xunit ;
18
21
19
22
namespace Microsoft . AspNetCore . Server . Kestrel . Tests
@@ -22,15 +25,41 @@ public class KestrelConfigurationBuilderTests
22
25
{
23
26
private KestrelServerOptions CreateServerOptions ( )
24
27
{
28
+ var testSink = new TestSink ( ) ;
25
29
var serverOptions = new KestrelServerOptions ( ) ;
26
30
var env = new MockHostingEnvironment { ApplicationName = "TestApplication" } ;
27
31
serverOptions . ApplicationServices = new ServiceCollection ( )
28
- . AddLogging ( )
32
+ . AddLogging ( l => l . AddProvider ( new TestLoggerProvider ( testSink ) ) )
29
33
. AddSingleton < IHostEnvironment > ( env )
34
+ . AddSingleton ( testSink )
30
35
. BuildServiceProvider ( ) ;
31
36
return serverOptions ;
32
37
}
33
38
39
+ [ Fact ]
40
+ [ SkipOnHelix ( "(none)" , Queues = "Ubuntu.1604.Amd64.Open;Windows.10.Amd64.Open" ) ]
41
+ [ OSSkipCondition ( OperatingSystems . Linux , SkipReason = "This check only applies to Mac OS as it is the one that checks the key for validity." ) ]
42
+ [ OSSkipCondition ( OperatingSystems . Windows , SkipReason = "This check only applies to Mac OS as it is the one that checks the key for validity." ) ]
43
+ public void DevCertWithInvalidPrivateKeyProducesCustomWarning ( )
44
+ {
45
+ var serverOptions = CreateServerOptions ( ) ;
46
+ var sink = serverOptions . ApplicationServices . GetRequiredService < TestSink > ( ) ;
47
+ var messages = new List < WriteContext > ( ) ;
48
+ sink . MessageLogged += wc => messages . Add ( wc ) ;
49
+ serverOptions . Configure ( )
50
+ . LocalhostEndpoint ( 5001 , endpointOptions => { } ) ;
51
+
52
+ Assert . Empty ( serverOptions . ListenOptions ) ;
53
+
54
+ serverOptions . ConfigurationLoader . Load ( ) ;
55
+
56
+ Assert . Single ( serverOptions . ListenOptions ) ;
57
+ Assert . Equal ( 5001 , serverOptions . ListenOptions [ 0 ] . IPEndPoint . Port ) ;
58
+
59
+ Assert . Equal ( 5 , messages [ ^ 1 ] . EventId ) ;
60
+ Assert . Equal ( LogLevel . Warning , messages [ ^ 1 ] . LogLevel ) ;
61
+ }
62
+
34
63
[ Fact ]
35
64
public void ConfigureNamedEndpoint_OnlyRunForMatchingConfig ( )
36
65
{
0 commit comments