|
7 | 7 | using System.Net; |
8 | 8 | using System.Net.Security; |
9 | 9 | using System.Reflection; |
| 10 | +using System.Runtime.InteropServices; |
10 | 11 | using System.Security.Authentication; |
11 | 12 | using System.Security.Cryptography.X509Certificates; |
12 | 13 | using System.Text; |
13 | 14 | using System.Threading.Tasks; |
| 15 | +using NSubstitute.Exceptions; |
14 | 16 | using StackExchange.Redis.Tests.Helpers; |
15 | 17 | using Xunit; |
16 | 18 | using Xunit.Abstractions; |
@@ -182,34 +184,35 @@ public async Task ConnectToSSLServer(bool useSsl, bool specifyHost) |
182 | 184 | [InlineData(SslProtocols.Ssl3 | SslProtocols.Tls12 | SslProtocols.Tls13, true)] |
183 | 185 | [InlineData(SslProtocols.Ssl2, false, TlsCipherSuite.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, TlsCipherSuite.TLS_AES_256_GCM_SHA384)] |
184 | 186 | #pragma warning restore CS0618 // Type or member is obsolete |
| 187 | + [System.Diagnostics.CodeAnalysis.SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "Yes, we know.")] |
185 | 188 | public async Task ConnectSslClientAuthenticationOptions(SslProtocols protocols, bool expectSuccess, params TlsCipherSuite[] tlsCipherSuites) |
186 | 189 | { |
187 | 190 | Fixture.SkipIfNoServer(); |
188 | 191 |
|
189 | | - var config = new ConfigurationOptions() |
| 192 | + try |
190 | 193 | { |
191 | | - EndPoints = { TestConfig.Current.SslServerAndPort }, |
192 | | - AllowAdmin = true, |
193 | | - ConnectRetry = 1, |
194 | | - SyncTimeout = Debugger.IsAttached ? int.MaxValue : 5000, |
195 | | - Ssl = true, |
196 | | - SslClientAuthenticationOptions = host => new SslClientAuthenticationOptions() |
| 194 | + var config = new ConfigurationOptions() |
197 | 195 | { |
198 | | - TargetHost = host, |
199 | | - CertificateRevocationCheckMode = X509RevocationMode.NoCheck, |
200 | | - EnabledSslProtocols = protocols, |
201 | | - CipherSuitesPolicy = tlsCipherSuites?.Length > 0 ? new CipherSuitesPolicy(tlsCipherSuites) : null, |
202 | | - RemoteCertificateValidationCallback = (sender, cert, chain, errors) => |
| 196 | + EndPoints = { TestConfig.Current.SslServerAndPort }, |
| 197 | + AllowAdmin = true, |
| 198 | + ConnectRetry = 1, |
| 199 | + SyncTimeout = Debugger.IsAttached ? int.MaxValue : 5000, |
| 200 | + Ssl = true, |
| 201 | + SslClientAuthenticationOptions = host => new SslClientAuthenticationOptions() |
203 | 202 | { |
204 | | - Log(" Errors: " + errors); |
205 | | - Log(" Cert issued to: " + cert?.Subject); |
206 | | - return true; |
| 203 | + TargetHost = host, |
| 204 | + CertificateRevocationCheckMode = X509RevocationMode.NoCheck, |
| 205 | + EnabledSslProtocols = protocols, |
| 206 | + CipherSuitesPolicy = tlsCipherSuites?.Length > 0 ? new CipherSuitesPolicy(tlsCipherSuites) : null, |
| 207 | + RemoteCertificateValidationCallback = (sender, cert, chain, errors) => |
| 208 | + { |
| 209 | + Log(" Errors: " + errors); |
| 210 | + Log(" Cert issued to: " + cert?.Subject); |
| 211 | + return true; |
| 212 | + }, |
207 | 213 | }, |
208 | | - }, |
209 | | - }; |
| 214 | + }; |
210 | 215 |
|
211 | | - try |
212 | | - { |
213 | 216 | if (expectSuccess) |
214 | 217 | { |
215 | 218 | using var conn = await ConnectionMultiplexer.ConnectAsync(config, Writer); |
@@ -376,12 +379,12 @@ public void SSLHostInferredFromEndpoints() |
376 | 379 | }, |
377 | 380 | Ssl = true, |
378 | 381 | }; |
379 | | - Assert.True(options.SslHost == "mycache.rediscache.windows.net"); |
| 382 | + Assert.Equal("mycache.rediscache.windows.net", options.SslHost); |
380 | 383 | options = new ConfigurationOptions() |
381 | 384 | { |
382 | 385 | EndPoints = { { "121.23.23.45", 15000 } }, |
383 | 386 | }; |
384 | | - Assert.True(options.SslHost == null); |
| 387 | + Assert.Null(options.SslHost); |
385 | 388 | } |
386 | 389 |
|
387 | 390 | private void Check(string name, object? x, object? y) |
@@ -528,7 +531,7 @@ public void SSLParseViaConfig_Issue883_ConfigString() |
528 | 531 | [Fact] |
529 | 532 | public void ConfigObject_Issue1407_ToStringIncludesSslProtocols() |
530 | 533 | { |
531 | | - const SslProtocols sslProtocols = SslProtocols.Tls12 | SslProtocols.Tls; |
| 534 | + const SslProtocols sslProtocols = SslProtocols.Tls12 | SslProtocols.Tls13; |
532 | 535 | var sourceOptions = new ConfigurationOptions |
533 | 536 | { |
534 | 537 | AbortOnConnectFail = false, |
|
0 commit comments