1818
1919namespace Microsoft . Data . SqlClient . ManualTesting . Tests
2020{
21+ [ PlatformSpecific ( TestPlatforms . Windows ) ]
2122 public class CertificateTest : IDisposable
2223 {
2324 #region Private Fields
@@ -75,10 +76,11 @@ public CertificateTest()
7576 SlashInstanceName = $ "\\ { InstanceName } ";
7677 }
7778
78- Assert . True ( DataTestUtility . IsAdmin , "CertificateTest class needs to be run in Admin mode." ) ;
79-
80- CreateValidCertificate ( s_fullPathToPowershellScript ) ;
81- _thumbprint = Environment . GetEnvironmentVariable ( ThumbPrintEnvName , EnvironmentVariableTarget . Machine ) ;
79+ if ( IsAdmin ( ) )
80+ {
81+ CreateValidCertificate ( s_fullPathToPowershellScript ) ;
82+ _thumbprint = Environment . GetEnvironmentVariable ( ThumbPrintEnvName , EnvironmentVariableTarget . Machine ) ;
83+ }
8284 }
8385
8486 private static bool IsLocalHost ( )
@@ -91,17 +93,16 @@ private static bool IsLocalHost()
9193 private static bool AreConnStringsSetup ( ) => DataTestUtility . AreConnStringsSetup ( ) ;
9294 private static bool IsNotAzureServer ( ) => DataTestUtility . IsNotAzureServer ( ) ;
9395 private static bool UseManagedSNIOnWindows ( ) => DataTestUtility . UseManagedSNIOnWindows ;
96+ private static bool IsAdmin ( ) => DataTestUtility . IsAdmin ;
9497
95- [ ActiveIssue ( "31754" ) ]
96- [ ConditionalFact ( nameof ( AreConnStringsSetup ) , nameof ( IsNotAzureServer ) , nameof ( IsLocalHost ) ) ]
97- [ PlatformSpecific ( TestPlatforms . Windows ) ]
98- public void OpenningConnectionWithGoodCertificateTest ( )
98+ [ ConditionalFact ( nameof ( AreConnStringsSetup ) , nameof ( IsNotAzureServer ) , nameof ( IsLocalHost ) , nameof ( IsAdmin ) ) ]
99+ public void OpeningConnectionWithGoodCertificateTest ( )
99100 {
100101 SqlConnectionStringBuilder builder = new ( DataTestUtility . TCPConnectionString ) ;
101102
102103 // confirm that ForceEncryption is enabled
103- using SqlConnection notEncryptedConnection = new ( builder . ConnectionString ) ;
104104 builder . Encrypt = SqlConnectionEncryptOption . Optional ;
105+ using SqlConnection notEncryptedConnection = new ( builder . ConnectionString ) ;
105106 notEncryptedConnection . Open ( ) ;
106107 Assert . Equal ( ConnectionState . Open , notEncryptedConnection . State ) ;
107108
@@ -122,9 +123,7 @@ public void OpenningConnectionWithGoodCertificateTest()
122123
123124 // Provided hostname in certificate are:
124125 // localhost, FQDN, Loopback IPv4: 127.0.0.1, IPv6: ::1
125- [ ActiveIssue ( "31754" ) ]
126- [ ConditionalFact ( nameof ( AreConnStringsSetup ) , nameof ( IsNotAzureServer ) , nameof ( IsLocalHost ) ) ]
127- [ PlatformSpecific ( TestPlatforms . Windows ) ]
126+ [ ConditionalFact ( nameof ( AreConnStringsSetup ) , nameof ( IsNotAzureServer ) , nameof ( IsLocalHost ) , nameof ( IsAdmin ) ) ]
128127 public void OpeningConnectionWitHNICTest ( )
129128 {
130129 // Mandatory
@@ -142,8 +141,8 @@ public void OpeningConnectionWitHNICTest()
142141 connection . Open ( ) ;
143142 Assert . Equal ( ConnectionState . Open , connection . State ) ;
144143
145- // Ipv6 however causes name mistmatch error
146- // In net6 Manged SNI does not check for SAN. Therefore Application using Net6 have to use FQDN as HNIC
144+ // Ipv6 however causes name mismatch error
145+ // In net6 Manged SNI does not check for SAN. Therefor Application using Net6 have to use FQDN as HNIC
147146 // According to above no other hostname in certificate than FQDN will work in net6 which is same as SubjectName in case of RemoteCertificateNameMismatch
148147 // Net7.0 the new API added by dotnet runtime will check SANS and then SubjectName
149148
@@ -167,8 +166,7 @@ public void OpeningConnectionWitHNICTest()
167166 }
168167
169168 [ ActiveIssue ( "31754" ) ]
170- [ ConditionalFact ( nameof ( AreConnStringsSetup ) , nameof ( UseManagedSNIOnWindows ) , nameof ( IsNotAzureServer ) , nameof ( IsLocalHost ) ) ]
171- [ PlatformSpecific ( TestPlatforms . Windows ) ]
169+ [ ConditionalFact ( nameof ( AreConnStringsSetup ) , nameof ( UseManagedSNIOnWindows ) , nameof ( IsNotAzureServer ) , nameof ( IsLocalHost ) , nameof ( IsAdmin ) ) ]
172170 public void RemoteCertificateNameMismatchErrorTest ( )
173171 {
174172 SqlConnectionStringBuilder builder = new ( DataTestUtility . TCPConnectionString )
0 commit comments