Skip to content

Commit 86a486d

Browse files
authored
Fix up SYSLIB0039, SYSLIB0040 warnings
1 parent e812f17 commit 86a486d

File tree

7 files changed

+180
-138
lines changed

7 files changed

+180
-138
lines changed

src/Middleware/WebSockets/test/ConformanceTests/Autobahn/AutobahnTester.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ public async Task DeployTestAndAddToSpec(ServerType server, bool ssl, string env
151151
// Win7 HttpClient on NetCoreApp2.2 defaults to TLS 1.0 and won't connect to Kestrel. https://github.com/dotnet/corefx/issues/28733
152152
// Mac HttpClient on NetCoreApp2.0 doesn't alow you to set some combinations.
153153
// https://github.com/dotnet/corefx/blob/586cffcdfdf23ad6c193a4bf37fce88a1bf69508/src/System.Net.Http/src/System/Net/Http/CurlHandler/CurlHandler.SslProvider.OSX.cs#L104-L106
154+
#pragma warning disable SYSLIB0039 // TLS 1.0 and 1.1 are obsolete
154155
handler.SslProtocols = SslProtocols.Tls12 | SslProtocols.Tls11 | SslProtocols.Tls;
156+
#pragma warning restore SYSLIB0039
155157
handler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;
156158
var client = result.CreateHttpClient(handler);
157159

src/Servers/Kestrel/Core/test/SniOptionsSelectorTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,9 @@ public void PrefersSslProtocolsDefinedInSniConfig()
532532
"www.example.org",
533533
new SniConfig
534534
{
535+
#pragma warning disable SYSLIB0039 // TLS 1.0 and 1.1 are obsolete
535536
SslProtocols = SslProtocols.Tls13 | SslProtocols.Tls11,
537+
#pragma warning restore SYSLIB0039
536538
Certificate = new CertificateConfig()
537539
}
538540
}
@@ -550,7 +552,9 @@ public void PrefersSslProtocolsDefinedInSniConfig()
550552
logger: Mock.Of<ILogger<HttpsConnectionMiddleware>>());
551553

552554
var (options, _) = sniOptionsSelector.GetOptions(new MockConnectionContext(), "www.example.org");
555+
#pragma warning disable SYSLIB0039 // TLS 1.0 and 1.1 are obsolete
553556
Assert.Equal(SslProtocols.Tls13 | SslProtocols.Tls11, options.EnabledSslProtocols);
557+
#pragma warning restore SYSLIB0039
554558
}
555559

556560
[Fact]
@@ -690,9 +694,13 @@ public void CloneSslOptionsClonesAllProperties()
690694
// Defaults to false
691695
ClientCertificateRequired = true,
692696
// Defaults to SslProtocols.None
697+
#pragma warning disable SYSLIB0039 // TLS 1.0 and 1.1 are obsolete
693698
EnabledSslProtocols = SslProtocols.Tls13 | SslProtocols.Tls11,
699+
#pragma warning restore SYSLIB0039
700+
#pragma warning disable SYSLIB0040 // EncryptionPolicy.NoEncryption is obsolete
694701
// Defaults to EncryptionPolicy.RequireEncryption
695702
EncryptionPolicy = EncryptionPolicy.NoEncryption,
703+
#pragma warning restore SYSLIB0040
696704
// Defaults to null
697705
RemoteCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true,
698706
// Defaults to null

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

Lines changed: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public void ReadCertificatesWhenEmptyCertificatesSection_ReturnsEmptyCollection(
3131
{
3232
var config = new ConfigurationBuilder().AddInMemoryCollection(new[]
3333
{
34-
new KeyValuePair<string, string>("Certificates", ""),
35-
}).Build();
34+
new KeyValuePair<string, string>("Certificates", ""),
35+
}).Build();
3636
var reader = new ConfigurationReader(config);
3737
var certificates = reader.Certificates;
3838
Assert.NotNull(certificates);
@@ -44,13 +44,13 @@ public void ReadCertificatesSection_ReturnsCollection()
4444
{
4545
var config = new ConfigurationBuilder().AddInMemoryCollection(new[]
4646
{
47-
new KeyValuePair<string, string>("Certificates:FileCert:Path", "/path/cert.pfx"),
48-
new KeyValuePair<string, string>("Certificates:FileCert:Password", "certpassword"),
49-
new KeyValuePair<string, string>("Certificates:StoreCert:Subject", "certsubject"),
50-
new KeyValuePair<string, string>("Certificates:StoreCert:Store", "certstore"),
51-
new KeyValuePair<string, string>("Certificates:StoreCert:Location", "cetlocation"),
52-
new KeyValuePair<string, string>("Certificates:StoreCert:AllowInvalid", "true"),
53-
}).Build();
47+
new KeyValuePair<string, string>("Certificates:FileCert:Path", "/path/cert.pfx"),
48+
new KeyValuePair<string, string>("Certificates:FileCert:Password", "certpassword"),
49+
new KeyValuePair<string, string>("Certificates:StoreCert:Subject", "certsubject"),
50+
new KeyValuePair<string, string>("Certificates:StoreCert:Store", "certstore"),
51+
new KeyValuePair<string, string>("Certificates:StoreCert:Location", "cetlocation"),
52+
new KeyValuePair<string, string>("Certificates:StoreCert:AllowInvalid", "true"),
53+
}).Build();
5454
var reader = new ConfigurationReader(config);
5555
var certificates = reader.Certificates;
5656
Assert.NotNull(certificates);
@@ -76,9 +76,9 @@ public void ReadCertificatesSection_IsCaseInsensitive()
7676
{
7777
var config = new ConfigurationBuilder().AddInMemoryCollection(new[]
7878
{
79-
new KeyValuePair<string, string>("Certificates:filecert:Path", "/path/cert.pfx"),
80-
new KeyValuePair<string, string>("CERTIFICATES:FILECERT:PASSWORD", "certpassword"),
81-
}).Build();
79+
new KeyValuePair<string, string>("Certificates:filecert:Path", "/path/cert.pfx"),
80+
new KeyValuePair<string, string>("CERTIFICATES:FILECERT:PASSWORD", "certpassword"),
81+
}).Build();
8282
var reader = new ConfigurationReader(config);
8383
var certificates = reader.Certificates;
8484
Assert.NotNull(certificates);
@@ -223,51 +223,57 @@ public void ReadEndpointWithSingleSslProtocolSet_ReturnsCorrectValue()
223223
{
224224
var config = new ConfigurationBuilder().AddInMemoryCollection(new[]
225225
{
226-
new KeyValuePair<string, string>("Endpoints:End1:Url", "http://*:5001"),
227-
new KeyValuePair<string, string>("Endpoints:End1:SslProtocols:0", "Tls11"),
228-
}).Build();
226+
new KeyValuePair<string, string>("Endpoints:End1:Url", "http://*:5001"),
227+
new KeyValuePair<string, string>("Endpoints:End1:SslProtocols:0", "Tls11"),
228+
}).Build();
229229
var reader = new ConfigurationReader(config);
230230

231231
var endpoint = reader.Endpoints.First();
232+
#pragma warning disable SYSLIB0039 // TLS 1.0 and 1.1 are obsolete
232233
Assert.Equal(SslProtocols.Tls11, endpoint.SslProtocols);
234+
#pragma warning restore SYSLIB0039
233235
}
234236

235237
[Fact]
236238
public void ReadEndpointWithMultipleSslProtocolsSet_ReturnsCorrectValue()
237239
{
238240
var config = new ConfigurationBuilder().AddInMemoryCollection(new[]
239241
{
240-
new KeyValuePair<string, string>("Endpoints:End1:Url", "http://*:5001"),
241-
new KeyValuePair<string, string>("Endpoints:End1:SslProtocols:0", "Tls11"),
242-
new KeyValuePair<string, string>("Endpoints:End1:SslProtocols:1", "Tls12"),
243-
}).Build();
242+
new KeyValuePair<string, string>("Endpoints:End1:Url", "http://*:5001"),
243+
new KeyValuePair<string, string>("Endpoints:End1:SslProtocols:0", "Tls11"),
244+
new KeyValuePair<string, string>("Endpoints:End1:SslProtocols:1", "Tls12"),
245+
}).Build();
244246
var reader = new ConfigurationReader(config);
245247

246248
var endpoint = reader.Endpoints.First();
249+
#pragma warning disable SYSLIB0039 // TLS 1.0 and 1.1 are obsolete
247250
Assert.Equal(SslProtocols.Tls11 | SslProtocols.Tls12, endpoint.SslProtocols);
251+
#pragma warning restore SYSLIB0039
248252
}
249253

250254
[Fact]
251255
public void ReadEndpointWithSslProtocolSet_ReadsCaseInsensitive()
252256
{
253257
var config = new ConfigurationBuilder().AddInMemoryCollection(new[]
254258
{
255-
new KeyValuePair<string, string>("Endpoints:End1:Url", "http://*:5001"),
256-
new KeyValuePair<string, string>("Endpoints:End1:SslProtocols:0", "TLS11"),
257-
}).Build();
259+
new KeyValuePair<string, string>("Endpoints:End1:Url", "http://*:5001"),
260+
new KeyValuePair<string, string>("Endpoints:End1:SslProtocols:0", "TLS11"),
261+
}).Build();
258262
var reader = new ConfigurationReader(config);
259263

260264
var endpoint = reader.Endpoints.First();
265+
#pragma warning disable SYSLIB0039 // TLS 1.0 and 1.1 are obsolete
261266
Assert.Equal(SslProtocols.Tls11, endpoint.SslProtocols);
267+
#pragma warning restore SYSLIB0039
262268
}
263269

264270
[Fact]
265271
public void ReadEndpointWithNoSslProtocolSettings_ReturnsNull()
266272
{
267273
var config = new ConfigurationBuilder().AddInMemoryCollection(new[]
268274
{
269-
new KeyValuePair<string, string>("Endpoints:End1:Url", "http://*:5001"),
270-
}).Build();
275+
new KeyValuePair<string, string>("Endpoints:End1:Url", "http://*:5001"),
276+
}).Build();
271277
var reader = new ConfigurationReader(config);
272278

273279
var endpoint = reader.Endpoints.First();
@@ -279,8 +285,8 @@ public void ReadEndpointWithEmptySniSection_ReturnsEmptyCollection()
279285
{
280286
var config = new ConfigurationBuilder().AddInMemoryCollection(new[]
281287
{
282-
new KeyValuePair<string, string>("Endpoints:End1:Url", "http://*:5001"),
283-
}).Build();
288+
new KeyValuePair<string, string>("Endpoints:End1:Url", "http://*:5001"),
289+
}).Build();
284290

285291
var reader = new ConfigurationReader(config);
286292

@@ -294,9 +300,9 @@ public void ReadEndpointWithEmptySniKey_Throws()
294300
{
295301
var config = new ConfigurationBuilder().AddInMemoryCollection(new[]
296302
{
297-
new KeyValuePair<string, string>("Endpoints:End1:Url", "http://*:5001"),
298-
new KeyValuePair<string, string>("Endpoints:End1:Sni::Protocols", "Http1"),
299-
}).Build();
303+
new KeyValuePair<string, string>("Endpoints:End1:Url", "http://*:5001"),
304+
new KeyValuePair<string, string>("Endpoints:End1:Sni::Protocols", "Http1"),
305+
}).Build();
300306

301307
var reader = new ConfigurationReader(config);
302308
var end1Ex = Assert.Throws<InvalidOperationException>(() => reader.Endpoints);
@@ -309,13 +315,13 @@ public void ReadEndpointWithSniConfigured_ReturnsCorrectValue()
309315
{
310316
var config = new ConfigurationBuilder().AddInMemoryCollection(new[]
311317
{
312-
new KeyValuePair<string, string>("Endpoints:End1:Url", "http://*:5001"),
313-
new KeyValuePair<string, string>("Endpoints:End1:Sni:*.example.org:Protocols", "Http1"),
314-
new KeyValuePair<string, string>("Endpoints:End1:Sni:*.example.org:SslProtocols:0", "Tls12"),
315-
new KeyValuePair<string, string>("Endpoints:End1:Sni:*.example.org:Certificate:Path", "/path/cert.pfx"),
316-
new KeyValuePair<string, string>("Endpoints:End1:Sni:*.example.org:Certificate:Password", "certpassword"),
317-
new KeyValuePair<string, string>("Endpoints:End1:SNI:*.example.org:ClientCertificateMode", "AllowCertificate"),
318-
}).Build();
318+
new KeyValuePair<string, string>("Endpoints:End1:Url", "http://*:5001"),
319+
new KeyValuePair<string, string>("Endpoints:End1:Sni:*.example.org:Protocols", "Http1"),
320+
new KeyValuePair<string, string>("Endpoints:End1:Sni:*.example.org:SslProtocols:0", "Tls12"),
321+
new KeyValuePair<string, string>("Endpoints:End1:Sni:*.example.org:Certificate:Path", "/path/cert.pfx"),
322+
new KeyValuePair<string, string>("Endpoints:End1:Sni:*.example.org:Certificate:Password", "certpassword"),
323+
new KeyValuePair<string, string>("Endpoints:End1:SNI:*.example.org:ClientCertificateMode", "AllowCertificate"),
324+
}).Build();
319325

320326
var reader = new ConfigurationReader(config);
321327

@@ -338,12 +344,14 @@ public void ReadEndpointDefaultsWithSingleSslProtocolSet_ReturnsCorrectValue()
338344
{
339345
var config = new ConfigurationBuilder().AddInMemoryCollection(new[]
340346
{
341-
new KeyValuePair<string, string>("EndpointDefaults:SslProtocols:0", "Tls11"),
342-
}).Build();
347+
new KeyValuePair<string, string>("EndpointDefaults:SslProtocols:0", "Tls11"),
348+
}).Build();
343349
var reader = new ConfigurationReader(config);
344350

345351
var endpoint = reader.EndpointDefaults;
352+
#pragma warning disable SYSLIB0039 // TLS 1.0 and 1.1 are obsolete
346353
Assert.Equal(SslProtocols.Tls11, endpoint.SslProtocols);
354+
#pragma warning restore SYSLIB0039
347355
}
348356

349357
[Fact]

0 commit comments

Comments
 (0)