|
9 | 9 | using System.Linq;
|
10 | 10 | using System.Net;
|
11 | 11 | using System.Net.Sockets;
|
| 12 | +using System.Runtime.InteropServices; |
12 | 13 | using System.Security.Authentication;
|
13 | 14 | using System.Security.Cryptography.X509Certificates;
|
14 | 15 | using System.ServiceProcess;
|
@@ -95,7 +96,6 @@ private static bool IsLocalHost()
|
95 | 96 |
|
96 | 97 | private static bool AreConnStringsSetup() => DataTestUtility.AreConnStringsSetup();
|
97 | 98 | private static bool IsNotAzureServer() => DataTestUtility.IsNotAzureServer();
|
98 |
| - private static bool UseManagedSNIOnWindows() => DataTestUtility.UseManagedSNIOnWindows; |
99 | 99 | private static bool IsAdminOnWindows() => DataTestUtility.IsAdminOnWindows;
|
100 | 100 |
|
101 | 101 | // [ActiveIssue("31754")]
|
@@ -172,24 +172,31 @@ public void OpeningConnectionWitHNICTest()
|
172 | 172 | }
|
173 | 173 | }
|
174 | 174 |
|
175 |
| - [ActiveIssue("31754")] |
176 |
| - [ConditionalFact(nameof(AreConnStringsSetup), nameof(UseManagedSNIOnWindows), nameof(IsNotAzureServer), nameof(IsLocalHost), nameof(IsAdminOnWindows), Skip = "For some reason does not throw on CI")] |
177 |
| - [PlatformSpecific(TestPlatforms.Windows)] |
| 175 | + [ConditionalFact(nameof(AreConnStringsSetup), nameof(IsNotAzureServer), nameof(IsLocalHost))] |
178 | 176 | public void RemoteCertificateNameMismatchErrorTest()
|
179 | 177 | {
|
180 | 178 | SqlConnectionStringBuilder builder = new(DataTestUtility.TCPConnectionString)
|
181 | 179 | {
|
182 |
| - DataSource = GetLocalIpAddress(), |
183 |
| - Encrypt = SqlConnectionEncryptOption.Mandatory, |
184 |
| - HostNameInCertificate = "BadHostName" |
| 180 | + DataSource = GetLocalIpAddress(), Encrypt = SqlConnectionEncryptOption.Mandatory, HostNameInCertificate = "BadHostName" |
185 | 181 | };
|
186 | 182 | using SqlConnection connection = new(builder.ConnectionString);
|
187 | 183 | SqlException exception = Assert.Throws<SqlException>(() => connection.Open());
|
188 |
| - Assert.StartsWith("A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 35 - An internal exception was caught)", exception.Message); |
189 |
| - Assert.Equal(20, exception.Class); |
190 |
| - Assert.IsType<AuthenticationException>(exception.InnerException); |
191 |
| - Assert.StartsWith("Certificate name mismatch. The provided 'DataSource' or 'HostNameInCertificate' does not match the name in the certificate.", exception.InnerException.Message); |
192 | 184 | _testOutputHelper.WriteLine(exception.Message);
|
| 185 | + |
| 186 | + if (DataTestUtility.IsUsingNativeSNI()) |
| 187 | + { |
| 188 | + Assert.StartsWith("A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - The certificate's CN name does not match the passed value.)", exception.Message); |
| 189 | + Assert.Equal(20, exception.Class); |
| 190 | + Assert.IsType<System.ComponentModel.Win32Exception>(exception.InnerException); |
| 191 | + Assert.StartsWith("The certificate's CN name does not match the passed value", exception.InnerException.Message); |
| 192 | + } |
| 193 | + else |
| 194 | + { |
| 195 | + Assert.StartsWith("A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 35 - An internal exception was caught)", exception.Message); |
| 196 | + Assert.Equal(20, exception.Class); |
| 197 | + Assert.IsType<AuthenticationException>(exception.InnerException); |
| 198 | + Assert.StartsWith("Certificate name mismatch. The provided 'DataSource' or 'HostNameInCertificate' does not match the name in the certificate.", exception.InnerException.Message); |
| 199 | + } |
193 | 200 | }
|
194 | 201 |
|
195 | 202 | private static void CreateValidCertificate(string script)
|
|
0 commit comments