Skip to content

Commit

Permalink
Fixed CallableStatements test to use defined credentials and some tes…
Browse files Browse the repository at this point in the history
…t config changes (#2393)
  • Loading branch information
lilgreenbird authored Apr 17, 2024
1 parent ae6d4ef commit f452337
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ static void setAEConnectionString(String serverName, String url, String protocol
if (enclaveServer.length > 1) {
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 {
AETestConnectionString = connectionString + ";sendTimeAsDateTime=false;columnEncryptionSetting=enabled;";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -41,8 +40,6 @@
import com.microsoft.sqlserver.testframework.AbstractTest;
import com.microsoft.sqlserver.testframework.Constants;

import javax.sql.DataSource;


/**
* Test CallableStatement
Expand Down Expand Up @@ -1173,16 +1170,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 + "', @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;");
}

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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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");
Expand Down Expand Up @@ -350,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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit f452337

Please sign in to comment.