Skip to content

Commit df665e5

Browse files
committed
Fix RemoteCertificateNameMismatchErrorTest
1 parent 54f8a1d commit df665e5

File tree

1 file changed

+18
-11
lines changed
  • src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ConnectionTestWithSSLCert

1 file changed

+18
-11
lines changed

src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ConnectionTestWithSSLCert/CertificateTest.cs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Linq;
1010
using System.Net;
1111
using System.Net.Sockets;
12+
using System.Runtime.InteropServices;
1213
using System.Security.Authentication;
1314
using System.Security.Cryptography.X509Certificates;
1415
using System.ServiceProcess;
@@ -95,7 +96,6 @@ private static bool IsLocalHost()
9596

9697
private static bool AreConnStringsSetup() => DataTestUtility.AreConnStringsSetup();
9798
private static bool IsNotAzureServer() => DataTestUtility.IsNotAzureServer();
98-
private static bool UseManagedSNIOnWindows() => DataTestUtility.UseManagedSNIOnWindows;
9999
private static bool IsAdminOnWindows() => DataTestUtility.IsAdminOnWindows;
100100

101101
// [ActiveIssue("31754")]
@@ -172,24 +172,31 @@ public void OpeningConnectionWitHNICTest()
172172
}
173173
}
174174

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))]
178176
public void RemoteCertificateNameMismatchErrorTest()
179177
{
180178
SqlConnectionStringBuilder builder = new(DataTestUtility.TCPConnectionString)
181179
{
182-
DataSource = GetLocalIpAddress(),
183-
Encrypt = SqlConnectionEncryptOption.Mandatory,
184-
HostNameInCertificate = "BadHostName"
180+
DataSource = GetLocalIpAddress(), Encrypt = SqlConnectionEncryptOption.Mandatory, HostNameInCertificate = "BadHostName"
185181
};
186182
using SqlConnection connection = new(builder.ConnectionString);
187183
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);
192184
_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+
}
193200
}
194201

195202
private static void CreateValidCertificate(string script)

0 commit comments

Comments
 (0)