From 282de2956eddce9ef6a0f29eba7b0cf0cba1bbd9 Mon Sep 17 00:00:00 2001 From: lilgreenbird Date: Mon, 15 Apr 2024 13:48:44 -0700 Subject: [PATCH 1/9] update for removing hardcoded passwords in local test server --- .../microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java | 4 ++++ .../com/microsoft/sqlserver/jdbc/EnclavePackageTest.java | 4 +++- .../microsoft/sqlserver/testframework/AbstractTest.java | 7 +------ 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java index 541f2da16..39f789534 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java @@ -186,6 +186,10 @@ static void setAEConnectionString(String serverName, String url, String protocol if (enclaveServer.length > 1) { System.out.println("Testing enclave: " + enclaveProperties); } + + String password = getConfiguredProperty("enclaveServerPassword"); + AETestConnectionString = TestUtils.addOrOverrideProperty(AETestConnectionString, Constants.PASSWORD, + password); } else { AETestConnectionString = connectionString + ";sendTimeAsDateTime=false;columnEncryptionSetting=enabled;"; } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/EnclavePackageTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/EnclavePackageTest.java index d2ed9d088..f10eedfa2 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/EnclavePackageTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/EnclavePackageTest.java @@ -243,7 +243,9 @@ public static void testBasicConnection(String cString, String protocol) throws E if (TestUtils.isAEv2(con4)) { verifyEnclaveEnabled(con4, protocol); } - } + } catch (Exception e) { + System.out.println("exception: " +e.getMessage() + " \n connection string: " + cString); + } } /** diff --git a/src/test/java/com/microsoft/sqlserver/testframework/AbstractTest.java b/src/test/java/com/microsoft/sqlserver/testframework/AbstractTest.java index 1ce9cd195..3881f6385 100644 --- a/src/test/java/com/microsoft/sqlserver/testframework/AbstractTest.java +++ b/src/test/java/com/microsoft/sqlserver/testframework/AbstractTest.java @@ -267,7 +267,6 @@ protected static void setupConnectionString() { // If these properties are defined then NTLM is desired, modify connection string accordingly String domain = getConfiguredProperty("domainNTLM"); String user = getConfiguredProperty("userNTLM"); - String password = getConfiguredProperty("passwordNTLM"); if (null != domain) { connectionStringNTLM = TestUtils.addOrOverrideProperty(connectionStringNTLM, "domain", domain); @@ -277,11 +276,7 @@ protected static void setupConnectionString() { connectionStringNTLM = TestUtils.addOrOverrideProperty(connectionStringNTLM, "user", user); } - if (null != password) { - connectionStringNTLM = TestUtils.addOrOverrideProperty(connectionStringNTLM, "password", password); - } - - if (null != user && null != password) { + if (null != user) { connectionStringNTLM = TestUtils.addOrOverrideProperty(connectionStringNTLM, "authenticationScheme", "NTLM"); connectionStringNTLM = TestUtils.addOrOverrideProperty(connectionStringNTLM, "integratedSecurity", "true"); From f28ef7a961cb2e0ec660a6fa26fd89131cd067ad Mon Sep 17 00:00:00 2001 From: lilgreenbird Date: Mon, 15 Apr 2024 16:42:52 -0700 Subject: [PATCH 2/9] update to linkedServerUser/linkedServerPassword --- .../jdbc/callablestatement/CallableStatementTest.java | 8 ++++---- .../microsoft/sqlserver/testframework/AbstractTest.java | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java index 5a502dab3..6a47bb060 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java @@ -1173,16 +1173,16 @@ public void testFourPartSyntaxCallEscapeSyntax() throws SQLException { } stmt.execute("EXEC sp_addlinkedserver @server='" + linkedServer + "';"); - stmt.execute("EXEC sp_addlinkedsrvlogin @rmtsrvname=N'" + linkedServer + "', @rmtuser=N'" + remoteUser - + "', @rmtpassword=N'" + remotePassword + "'"); + stmt.execute("EXEC sp_addlinkedsrvlogin @rmtsrvname=N'" + linkedServer + "', @rmtuser=N'" + linkedServerUser + + "', @rmtpassword=N'" + linkedServerPassword + "'"); stmt.execute("EXEC sp_serveroption '" + linkedServer + "', 'rpc', true;"); stmt.execute("EXEC sp_serveroption '" + linkedServer + "', 'rpc out', true;"); } SQLServerDataSource ds = new SQLServerDataSource(); ds.setServerName(linkedServer); - ds.setUser(remoteUser); - ds.setPassword(remotePassword); + ds.setUser(linkedServerUser); + ds.setPassword(linkedServerPassword); ds.setEncrypt(false); ds.setTrustServerCertificate(true); diff --git a/src/test/java/com/microsoft/sqlserver/testframework/AbstractTest.java b/src/test/java/com/microsoft/sqlserver/testframework/AbstractTest.java index 3881f6385..00d858c0f 100644 --- a/src/test/java/com/microsoft/sqlserver/testframework/AbstractTest.java +++ b/src/test/java/com/microsoft/sqlserver/testframework/AbstractTest.java @@ -63,8 +63,8 @@ public abstract class AbstractTest { protected static String[] keyIDs = null; protected static String linkedServer = null; - protected static String remoteUser = null; - protected static String remotePassword = null; + protected static String linkedServerUser = null; + protected static String linkedServerPassword = null; protected static String[] enclaveServer = null; protected static String[] enclaveAttestationUrl = null; protected static String[] enclaveAttestationProtocol = null; @@ -201,8 +201,8 @@ public static void setup() throws Exception { clientKeyPassword = getConfiguredProperty("clientKeyPassword", ""); linkedServer = getConfiguredProperty("linkedServer", null); - remoteUser = getConfiguredProperty("remoteUser", null); - remotePassword = getConfiguredProperty("remotePassword", null); + linkedServerUser = getConfiguredProperty("linkedServerUser", null); + linkedServerPassword = getConfiguredProperty("linkedServerPassword", null); kerberosServer = getConfiguredProperty("kerberosServer", null); kerberosServerPort = getConfiguredProperty("kerberosServerPort", null); From 594c627acb5885fd64727e6c5a6afeb2c3c28ab1 Mon Sep 17 00:00:00 2001 From: lilgreenbird Date: Mon, 15 Apr 2024 20:22:24 -0700 Subject: [PATCH 3/9] add debug --- .../jdbc/callablestatement/CallableStatementTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java index 6a47bb060..927b4b998 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java @@ -1158,6 +1158,7 @@ public void testExecDocumentedSystemStoredProceduresIndexedParameters() throws S public void testFourPartSyntaxCallEscapeSyntax() throws SQLException { String table = "serverList"; + System.out.println("testFourPartSyntaxCallEscapeSyntax1: connectionString=" + connectionString); try (Statement stmt = connection.createStatement()) { stmt.execute("IF OBJECT_ID(N'" + table + "') IS NOT NULL DROP TABLE " + table); stmt.execute("CREATE TABLE " + table @@ -1179,12 +1180,15 @@ public void testFourPartSyntaxCallEscapeSyntax() throws SQLException { stmt.execute("EXEC sp_serveroption '" + linkedServer + "', 'rpc out', true;"); } + System.out.println("testFourPartSyntaxCallEscapeSyntax2: connectionString=" + connectionString); SQLServerDataSource ds = new SQLServerDataSource(); ds.setServerName(linkedServer); ds.setUser(linkedServerUser); ds.setPassword(linkedServerPassword); ds.setEncrypt(false); ds.setTrustServerCertificate(true); + System.out.println("testFourPartSyntaxCallEscapeSyntax3: linkedServer=" + linkedServer + " linkedServerUser" + + linkedServerUser + " linkedServerPassword=" + linkedServerPassword); try (Connection linkedServerConnection = ds.getConnection(); Statement stmt = linkedServerConnection.createStatement()) { @@ -1194,6 +1198,8 @@ public void testFourPartSyntaxCallEscapeSyntax() throws SQLException { try (CallableStatement cstmt = connection .prepareCall("{call [" + linkedServer + "].master.dbo.TestAdd(?,?,?)}")) { + System.out.println("testFourPartSyntaxCallEscapeSyntax4: connectionString=" + connectionString); + int sum = 11; int param0 = 1; int param1 = 10; From 222f4e3b0ed3dece477152f85b3aea967b0715b5 Mon Sep 17 00:00:00 2001 From: lilgreenbird Date: Tue, 16 Apr 2024 11:54:36 -0700 Subject: [PATCH 4/9] fixed cstmt test --- .../sqlserver/jdbc/EnclavePackageTest.java | 4 +--- .../callablestatement/CallableStatementTest.java | 13 ++++--------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/EnclavePackageTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/EnclavePackageTest.java index f10eedfa2..d2ed9d088 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/EnclavePackageTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/EnclavePackageTest.java @@ -243,9 +243,7 @@ public static void testBasicConnection(String cString, String protocol) throws E if (TestUtils.isAEv2(con4)) { verifyEnclaveEnabled(con4, protocol); } - } catch (Exception e) { - System.out.println("exception: " +e.getMessage() + " \n connection string: " + cString); - } + } } /** diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java index 927b4b998..656cd20e5 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java @@ -1158,7 +1158,6 @@ public void testExecDocumentedSystemStoredProceduresIndexedParameters() throws S public void testFourPartSyntaxCallEscapeSyntax() throws SQLException { String table = "serverList"; - System.out.println("testFourPartSyntaxCallEscapeSyntax1: connectionString=" + connectionString); try (Statement stmt = connection.createStatement()) { stmt.execute("IF OBJECT_ID(N'" + table + "') IS NOT NULL DROP TABLE " + table); stmt.execute("CREATE TABLE " + table @@ -1174,31 +1173,27 @@ public void testFourPartSyntaxCallEscapeSyntax() throws SQLException { } stmt.execute("EXEC sp_addlinkedserver @server='" + linkedServer + "';"); - stmt.execute("EXEC sp_addlinkedsrvlogin @rmtsrvname=N'" + linkedServer + "', @rmtuser=N'" + linkedServerUser - + "', @rmtpassword=N'" + linkedServerPassword + "'"); + stmt.execute("EXEC sp_addlinkedsrvlogin @rmtsrvname=N'" + linkedServer + "', @useself=false" + + ", @rmtuser=N'" + linkedServerUser + "', @rmtpassword=N'" + linkedServerPassword + "'"); stmt.execute("EXEC sp_serveroption '" + linkedServer + "', 'rpc', true;"); stmt.execute("EXEC sp_serveroption '" + linkedServer + "', 'rpc out', true;"); } - System.out.println("testFourPartSyntaxCallEscapeSyntax2: connectionString=" + connectionString); SQLServerDataSource ds = new SQLServerDataSource(); ds.setServerName(linkedServer); ds.setUser(linkedServerUser); ds.setPassword(linkedServerPassword); ds.setEncrypt(false); ds.setTrustServerCertificate(true); - System.out.println("testFourPartSyntaxCallEscapeSyntax3: linkedServer=" + linkedServer + " linkedServerUser" - + linkedServerUser + " linkedServerPassword=" + linkedServerPassword); try (Connection linkedServerConnection = ds.getConnection(); + // Statement stmt = linkedServerConnection.createStatement()) { Statement stmt = linkedServerConnection.createStatement()) { stmt.execute( "create or alter procedure dbo.TestAdd(@Num1 int, @Num2 int, @Result int output) as begin set @Result = @Num1 + @Num2; end;"); } - try (CallableStatement cstmt = connection - .prepareCall("{call [" + linkedServer + "].master.dbo.TestAdd(?,?,?)}")) { - System.out.println("testFourPartSyntaxCallEscapeSyntax4: connectionString=" + connectionString); + try (CallableStatement cstmt = connection.prepareCall("{call TestAdd(?,?,?)}")) { int sum = 11; int param0 = 1; From cb5c7af15910320feabcb9d23d867355110d9eb7 Mon Sep 17 00:00:00 2001 From: lilgreenbird Date: Tue, 16 Apr 2024 13:25:26 -0700 Subject: [PATCH 5/9] fixed cstmt test --- .../jdbc/callablestatement/CallableStatementTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java index 656cd20e5..463a73d31 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java @@ -1193,8 +1193,8 @@ public void testFourPartSyntaxCallEscapeSyntax() throws SQLException { "create or alter procedure dbo.TestAdd(@Num1 int, @Num2 int, @Result int output) as begin set @Result = @Num1 + @Num2; end;"); } - try (CallableStatement cstmt = connection.prepareCall("{call TestAdd(?,?,?)}")) { - + try (CallableStatement cstmt = connection + .prepareCall("{call [" + linkedServer + "].master.dbo.TestAdd(?,?,?)}")) { int sum = 11; int param0 = 1; int param1 = 10; From 3d17aa1a8e2d6a77735514382eeca425f797490c Mon Sep 17 00:00:00 2001 From: lilgreenbird Date: Tue, 16 Apr 2024 17:01:20 -0700 Subject: [PATCH 6/9] debug --- .../sqlserver/jdbc/AlwaysEncrypted/EnclaveTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/EnclaveTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/EnclaveTest.java index 4b55573af..843512fde 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/EnclaveTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/EnclaveTest.java @@ -53,7 +53,13 @@ public class EnclaveTest extends AESetup { @ParameterizedTest @MethodSource("enclaveParams") public void testBasicConnection(String serverName, String url, String protocol) throws Exception { + System.out.println("serverName= " + serverName); + System.out.println("url= " + url); + System.out.println("protocol= " + protocol); + + System.out.println("before: AETestConnectionString= " +AETestConnectionString); setAEConnectionString(serverName, url, protocol); + System.out.println("after: AETestConnectionString= " +AETestConnectionString); EnclavePackageTest.testBasicConnection(AETestConnectionString, protocol); } From f511ab26ef073f3b86965a1e0ad136327a0504b6 Mon Sep 17 00:00:00 2001 From: lilgreenbird Date: Tue, 16 Apr 2024 18:50:16 -0700 Subject: [PATCH 7/9] update password --- .../com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java index 39f789534..02336f79c 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java @@ -187,7 +187,10 @@ static void setAEConnectionString(String serverName, String url, String protocol System.out.println("Testing enclave: " + enclaveProperties); } + // remove the password in connection string + // this is necessary as updateDataSource will only use 1st occurrence String password = getConfiguredProperty("enclaveServerPassword"); + AETestConnectionString = TestUtils.removeProperty(AETestConnectionString, Constants.PASSWORD); AETestConnectionString = TestUtils.addOrOverrideProperty(AETestConnectionString, Constants.PASSWORD, password); } else { From 1923da9157119fb3d1cbbea441a65f880a3dd593 Mon Sep 17 00:00:00 2001 From: lilgreenbird Date: Tue, 16 Apr 2024 22:41:17 -0700 Subject: [PATCH 8/9] add servername --- .../com/microsoft/sqlserver/testframework/AbstractTest.java | 3 +++ .../java/com/microsoft/sqlserver/testframework/Constants.java | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/test/java/com/microsoft/sqlserver/testframework/AbstractTest.java b/src/test/java/com/microsoft/sqlserver/testframework/AbstractTest.java index 00d858c0f..3590aa7f2 100644 --- a/src/test/java/com/microsoft/sqlserver/testframework/AbstractTest.java +++ b/src/test/java/com/microsoft/sqlserver/testframework/AbstractTest.java @@ -345,6 +345,9 @@ protected static ISQLServerDataSource updateDataSource(String connectionString, case Constants.INTEGRATED_SECURITY: ds.setIntegratedSecurity(Boolean.parseBoolean(value)); break; + case Constants.SERVER_NAME: + ds.setServerName(value); + break; case Constants.USER: case Constants.USER_NAME: ds.setUser(value); diff --git a/src/test/java/com/microsoft/sqlserver/testframework/Constants.java b/src/test/java/com/microsoft/sqlserver/testframework/Constants.java index e4338fc92..8ed409945 100644 --- a/src/test/java/com/microsoft/sqlserver/testframework/Constants.java +++ b/src/test/java/com/microsoft/sqlserver/testframework/Constants.java @@ -139,6 +139,8 @@ private Constants() {} public static final String DOMAIN_NAME = "DOMAINNAME"; public static final String DATABASE = "DATABASE"; public static final String DATABASE_NAME = "DATABASENAME"; + public static final String SERVER_NAME = "SERVERNAME"; + public static final String COLUMN_ENCRYPTION_SETTING = "COLUMNENCRYPTIONSETTING"; public static final String DISABLE_STATEMENT_POOLING = "DISABLESTATEMENTPOOLING"; public static final String STATEMENT_POOLING_CACHE_SIZE = "STATEMENTPOOLINGCACHESIZE"; From bf591f257c6da2323d9476b89b12f67861969c95 Mon Sep 17 00:00:00 2001 From: lilgreenbird Date: Wed, 17 Apr 2024 00:21:46 -0700 Subject: [PATCH 9/9] clean up --- .../sqlserver/jdbc/AlwaysEncrypted/EnclaveTest.java | 6 ------ .../jdbc/callablestatement/CallableStatementTest.java | 4 ---- 2 files changed, 10 deletions(-) diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/EnclaveTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/EnclaveTest.java index 843512fde..4b55573af 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/EnclaveTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/EnclaveTest.java @@ -53,13 +53,7 @@ public class EnclaveTest extends AESetup { @ParameterizedTest @MethodSource("enclaveParams") public void testBasicConnection(String serverName, String url, String protocol) throws Exception { - System.out.println("serverName= " + serverName); - System.out.println("url= " + url); - System.out.println("protocol= " + protocol); - - System.out.println("before: AETestConnectionString= " +AETestConnectionString); setAEConnectionString(serverName, url, protocol); - System.out.println("after: AETestConnectionString= " +AETestConnectionString); EnclavePackageTest.testBasicConnection(AETestConnectionString, protocol); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java index 463a73d31..67dde1fad 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java @@ -22,7 +22,6 @@ import java.util.TimeZone; import java.util.UUID; -import org.junit.Assert; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Tag; @@ -41,8 +40,6 @@ import com.microsoft.sqlserver.testframework.AbstractTest; import com.microsoft.sqlserver.testframework.Constants; -import javax.sql.DataSource; - /** * Test CallableStatement @@ -1187,7 +1184,6 @@ public void testFourPartSyntaxCallEscapeSyntax() throws SQLException { ds.setTrustServerCertificate(true); try (Connection linkedServerConnection = ds.getConnection(); - // Statement stmt = linkedServerConnection.createStatement()) { Statement stmt = linkedServerConnection.createStatement()) { stmt.execute( "create or alter procedure dbo.TestAdd(@Num1 int, @Num2 int, @Result int output) as begin set @Result = @Num1 + @Num2; end;");