44 */
55package com .microsoft .sqlserver .jdbc .clientcertauth ;
66
7+ import static org .junit .Assert .assertFalse ;
78import static org .junit .Assert .assertTrue ;
89
910import java .sql .Connection ;
2627
2728
2829/**
29- * Tests client certificate authentication feature
30- * The feature is only supported against SQL Server Linux CU2 or higher.
30+ * Tests client certificate authentication feature. The feature is only supported against SQL Server Linux CU2 or
31+ * higher.
3132 *
3233 */
3334@ RunWith (JUnitPlatform .class )
@@ -52,8 +53,8 @@ public class ClientCertificateAuthenticationTest extends AbstractTest {
5253
5354 @ BeforeAll
5455 public static void setupTests () throws Exception {
55- //Turn off default encrypt true
56- connectionString = TestUtils .addOrOverrideProperty (connectionString ,"encrypt" , "false" );
56+ // Turn off default encrypt true
57+ connectionString = TestUtils .addOrOverrideProperty (connectionString , "encrypt" , "false" );
5758 setConnection ();
5859 }
5960
@@ -207,32 +208,31 @@ public void testDataSource() throws Exception {
207208 * @throws Exception
208209 */
209210 @ Test
210- public void testEncryptTrusted () throws Exception {
211+ public void testEncryptOn () throws Exception {
211212 String conStr = connectionString + ";clientCertificate=" + clientCertificate + PEM_SUFFIX + "clientKey="
212213 + clientKey + PKCS8_KEY_SUFFIX + "encrypt=true;trustServerCertificate=true;" ;
213- try (Connection conn = DriverManager .getConnection (conStr ); Statement stmt = conn .createStatement ()) {
214- ResultSet rs = stmt
215- .executeQuery ("SELECT encrypt_option FROM sys.dm_exec_connections WHERE session_id = @@SPID" );
214+ try (Connection conn = DriverManager .getConnection (conStr ); Statement stmt = conn .createStatement ();
215+ ResultSet rs = stmt
216+ .executeQuery ("SELECT encrypt_option FROM sys.dm_exec_connections WHERE session_id = @@SPID" )) {
216217 rs .next ();
217218 assertTrue (rs .getBoolean (1 ));
218219 }
219220 }
220221
221222 /**
222- * Tests client certificate authentication feature with encryption turned on, untrusted .
223+ * Tests client certificate authentication feature with encryption turned off .
223224 *
224225 * @throws Exception
225226 */
226227 @ Test
227- public void testEncryptUntrusted () throws Exception {
228+ public void testEncryptOff () throws Exception {
228229 String conStr = connectionString + ";clientCertificate=" + clientCertificate + PEM_SUFFIX + "clientKey="
229- + clientKey + PKCS8_KEY_SUFFIX + "encrypt=true;trustServerCertificate=false;trustStore="
230- + trustStorePath ;
231- try (Connection conn = DriverManager .getConnection (conStr ); Statement stmt = conn .createStatement ()) {
232- ResultSet rs = stmt
233- .executeQuery ("SELECT encrypt_option FROM sys.dm_exec_connections WHERE session_id = @@SPID" );
230+ + clientKey + PKCS8_KEY_SUFFIX + "encrypt=false;trustServerCertificate=true" ;
231+ try (Connection conn = DriverManager .getConnection (conStr ); Statement stmt = conn .createStatement ();
232+ ResultSet rs = stmt
233+ .executeQuery ("SELECT encrypt_option FROM sys.dm_exec_connections WHERE session_id = @@SPID" )) {
234234 rs .next ();
235- assertTrue (rs .getBoolean (1 ));
235+ assertFalse (rs .getBoolean (1 ));
236236 }
237237 }
238238}
0 commit comments