From 887cf6f1665b08cdd61df7f3f8c35153ce397011 Mon Sep 17 00:00:00 2001 From: lilgreenbird Date: Wed, 16 Mar 2022 11:59:53 -0700 Subject: [PATCH] TDSS Support (#1757) --- .../microsoft/sqlserver/jdbc/IOBuffer.java | 29 ++++--- .../sqlserver/jdbc/ISQLServerDataSource.java | 37 +++++--- .../sqlserver/jdbc/SQLServerBulkRecord.java | 1 + .../sqlserver/jdbc/SQLServerConnection.java | 86 +++++++++++++------ .../sqlserver/jdbc/SQLServerDataSource.java | 17 ++-- .../jdbc/SQLServerDatabaseMetaData.java | 3 +- .../sqlserver/jdbc/SQLServerDriver.java | 82 ++++++++++++++---- .../sqlserver/jdbc/ActivityIDTest.java | 1 - .../jdbc/AlwaysEncrypted/AESetup.java | 14 +-- .../RegressionAlwaysEncryptedTest.java | 4 +- .../sqlserver/jdbc/EnclavePackageTest.java | 1 - .../microsoft/sqlserver/jdbc/JDBC43Test.java | 1 - .../sqlserver/jdbc/MaxResultBufferTest.java | 1 - .../sqlserver/jdbc/NTLMConnectionTest.java | 6 +- .../jdbc/RegisterKeyStoreProviderTest.java | 1 - .../jdbc/SQLServerConnectionTest.java | 16 +++- .../microsoft/sqlserver/jdbc/TestUtils.java | 8 +- .../microsoft/sqlserver/jdbc/TimeoutTest.java | 1 - .../jdbc/bulkCopy/BulkCopyAllTypesTest.java | 1 - .../jdbc/bulkCopy/BulkCopyCSVTest.java | 1 - .../BulkCopyISQLServerBulkRecordTest.java | 1 - .../bulkCopy/BulkCopyResultSetCursorTest.java | 1 - .../jdbc/bulkCopy/BulkCopyRowSetTest.java | 1 - ...CopySendTemporalDataTypesAsStringTest.java | 1 - .../jdbc/bulkCopy/BulkCopyTestSetUp.java | 1 - .../ISQLServerBulkRecordIssuesTest.java | 1 - .../microsoft/sqlserver/jdbc/bvt/BvtTest.java | 1 - .../callablestatement/CallableMixedTest.java | 1 - .../CallableStatementTest.java | 1 - .../ClientCertificateAuthenticationTest.java | 25 +++--- .../jdbc/connection/ClientProcessIdTest.java | 1 - .../jdbc/connection/ConnectionTest.java | 1 - .../connection/ConnectionWrapper43Test.java | 1 - .../jdbc/connection/DBMetadataTest.java | 1 - .../jdbc/connection/DriverVersionTest.java | 1 - .../connection/NativeMSSQLDataSourceTest.java | 8 +- .../jdbc/connection/PoolingTest.java | 1 - .../jdbc/connection/ReplicationTest.java | 1 - .../RequestBoundaryMethodsTest.java | 1 - .../jdbc/connection/SSLProtocolTest.java | 1 - .../jdbc/connection/TimeoutTest.java | 1 - .../jdbc/connection/WarningTest.java | 1 - .../jdbc/connection/XADataSourceTest.java | 6 +- .../DatabaseMetaDataForeignKeyTest.java | 1 - .../DatabaseMetaDataTest.java | 1 - .../jdbc/datatypes/BigIntegerTest.java | 1 - .../datatypes/BulkCopyWithSqlVariantTest.java | 1 - .../jdbc/datatypes/DataTypesTest.java | 1 - .../jdbc/datatypes/DateAndTimeTypeTest.java | 1 - .../SQLServerSpatialDatatypeTest.java | 1 - .../datatypes/SQLVariantResultSetTest.java | 1 - .../sqlserver/jdbc/datatypes/SparseTest.java | 1 - .../jdbc/datatypes/TVPWithSqlVariantTest.java | 1 - .../jdbc/exception/ErrorStateTest.java | 1 - .../jdbc/exception/ExceptionTest.java | 1 - .../jdbc/fedauth/ConcurrentLoginTest.java | 1 - .../fedauth/ConnectionSuspensionTest.java | 1 - .../jdbc/fedauth/ErrorMessageTest.java | 1 - .../sqlserver/jdbc/fedauth/FedauthTest.java | 42 ++++----- .../sqlserver/jdbc/fedauth/FedauthWithAE.java | 1 - .../jdbc/fedauth/PooledConnectionTest.java | 1 - .../sqlserver/jdbc/fips/FipsTest.java | 28 +++--- .../sqlserver/jdbc/fmtOnly/APITest.java | 1 - .../sqlserver/jdbc/fmtOnly/DeleteTest.java | 1 - .../sqlserver/jdbc/fmtOnly/InsertTest.java | 1 - .../sqlserver/jdbc/fmtOnly/LexerTest.java | 1 - .../jdbc/fmtOnly/ParameterMetaDataTest.java | 1 - .../sqlserver/jdbc/fmtOnly/SelectTest.java | 1 - .../sqlserver/jdbc/fmtOnly/UpdateTest.java | 1 - .../sqlserver/jdbc/osgi/DataFactoryTest.java | 1 - .../ParameterMetaDataTest.java | 1 - .../ParameterMetaDataWhiteSpaceTest.java | 1 - .../BatchExecutionWithBulkCopyTest.java | 1 - .../BatchExecutionWithNullTest.java | 1 - .../preparedStatement/RegressionTest.java | 1 - .../jdbc/preparedStatement/SetObjectTest.java | 1 - .../jdbc/resiliency/BasicConnectionTest.java | 4 +- .../jdbc/resiliency/PropertyTest.java | 1 - .../jdbc/resiliency/ReflectiveTests.java | 1 - .../ResultSetsWithResiliencyTest.java | 1 - .../resultset/DataClassificationTest.java | 1 - .../jdbc/resultset/ResultSetTest.java | 1 - .../CustomSocketFactoryTest.java | 3 - .../trustmanager/CustomTrustManagerTest.java | 17 ++-- .../sqlserver/jdbc/tvp/TVPAllTypesTest.java | 1 - .../sqlserver/jdbc/tvp/TVPIssuesTest.java | 1 - .../sqlserver/jdbc/tvp/TVPNumericTest.java | 1 - .../jdbc/tvp/TVPResultSetCursorTest.java | 1 - .../sqlserver/jdbc/tvp/TVPSchemaTest.java | 1 - .../sqlserver/jdbc/tvp/TVPTypesTest.java | 1 - .../jdbc/unit/SQLServerErrorTest.java | 1 - .../sqlserver/jdbc/unit/SavepointTest.java | 1 - .../sqlserver/jdbc/unit/UTF8SupportTest.java | 1 - .../jdbc/unit/lobs/LobsStreamingTest.java | 1 - .../sqlserver/jdbc/unit/lobs/LobsTest.java | 1 - .../jdbc/unit/serial/DTOSerialTest.java | 1 - .../statement/BatchExecuteWithErrorsTest.java | 1 - .../unit/statement/BatchExecutionTest.java | 1 - .../jdbc/unit/statement/BatchTriggerTest.java | 1 - .../unit/statement/CallableMixedTest.java | 1 - .../jdbc/unit/statement/LimitEscapeTest.java | 1 - .../jdbc/unit/statement/MergeTest.java | 1 - .../statement/NamedParamMultiPartTest.java | 1 - .../jdbc/unit/statement/PQImpsTest.java | 1 - .../jdbc/unit/statement/PoolableTest.java | 1 - .../unit/statement/PreparedStatementTest.java | 1 - .../jdbc/unit/statement/RegressionTest.java | 1 - .../statement/StatementCancellationTest.java | 1 - .../jdbc/unit/statement/StatementTest.java | 1 - .../jdbc/unit/statement/WrapperTest.java | 1 - .../sqlserver/testframework/AbstractTest.java | 35 +++++++- .../sqlserver/testframework/Constants.java | 5 ++ 112 files changed, 317 insertions(+), 249 deletions(-) diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java b/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java index c0fe5b46f..d242a44b8 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java @@ -761,7 +761,6 @@ final InetSocketAddress open(String host, int port, int timeoutMillis, boolean u channelSocket = tcpSocket = socketFinder.findSocket(host, port, timeoutMillis, useParallel, useTnir, isTnirFirstAttempt, timeoutMillisForFullTimeout); try { - // Set socket options tcpSocket.setTcpNoDelay(true); tcpSocket.setKeepAlive(true); @@ -1828,8 +1827,8 @@ enum SSLHandhsakeState { * Private key file's password * @throws SQLServerException */ - void enableSSL(String host, int port, String clientCertificate, String clientKey, - String clientKeyPassword) throws SQLServerException { + void enableSSL(String host, int port, String clientCertificate, String clientKey, String clientKeyPassword, + boolean isTDSS) throws SQLServerException { // If enabling SSL fails, which it can for a number of reasons, the following items // are used in logging information to the TDS channel logger to help diagnose the problem. Provider tmfProvider = null; // TrustManagerFactory provider @@ -1870,12 +1869,11 @@ void enableSSL(String host, int port, String clientCertificate, String clientKey validateFips(trustStoreType, trustStoreFileName); } - assert TDS.ENCRYPT_OFF == con.getRequestedEncryptionLevel() || // Login only SSL - TDS.ENCRYPT_ON == con.getRequestedEncryptionLevel(); // Full SSL - - assert TDS.ENCRYPT_OFF == con.getNegotiatedEncryptionLevel() || // Login only SSL - TDS.ENCRYPT_ON == con.getNegotiatedEncryptionLevel() || // Full SSL - TDS.ENCRYPT_REQ == con.getNegotiatedEncryptionLevel(); // Full SSL + byte requestedEncryptLevel = con.getRequestedEncryptionLevel(); + assert TDS.ENCRYPT_OFF == requestedEncryptLevel || // Login only SSL + TDS.ENCRYPT_ON == requestedEncryptLevel || // Full SSL + TDS.ENCRYPT_REQ == requestedEncryptLevel || // Full SSL + (isTDSS && TDS.ENCRYPT_NOT_SUP == requestedEncryptLevel); // TDSS // If encryption wasn't negotiated or trust server certificate is specified, // then we'll "validate" the server certificate using a naive TrustManager that trusts @@ -2004,13 +2002,17 @@ else if (con.getTrustManagerClass() != null) { // Got the SSL context. Now create an SSL socket over our own proxy socket // which we can toggle between TDS-encapsulated and raw communications. // Initially, the proxy is set to encapsulate the SSL handshake in TDS packets. - proxySocket = new ProxySocket(this); - if (logger.isLoggable(Level.FINEST)) logger.finest(toString() + " Creating SSL socket"); - // don't close proxy when SSL socket is closed - sslSocket = (SSLSocket) sslContext.getSocketFactory().createSocket(proxySocket, host, port, false); + proxySocket = new ProxySocket(this); + + if (isTDSS) { + sslSocket = (SSLSocket) sslContext.getSocketFactory().createSocket(host, port); + } else { + // don't close proxy when SSL socket is closed + sslSocket = (SSLSocket) sslContext.getSocketFactory().createSocket(proxySocket, host, port, false); + } // At long last, start the SSL handshake ... if (logger.isLoggable(Level.FINER)) @@ -2053,6 +2055,7 @@ else if (con.getTrustManagerClass() != null) { if (logger.isLoggable(Level.FINER)) logger.finer(toString() + " SSL enabled"); + } catch (Exception e) { // Log the original exception and its source at FINER level if (logger.isLoggable(Level.FINER)) diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerDataSource.java b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerDataSource.java index 76db4be5d..0102e6ea8 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerDataSource.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerDataSource.java @@ -101,23 +101,32 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource { boolean getLastUpdateCount(); /** - * Sets a Boolean value that indicates if the encrypt property is enabled. + * Sets the option whether TLS encryption is used. * - * @param encrypt - * true if the Secure Sockets Layer (SSL) encryption is enabled between the client and the SQL Server. - * Otherwise, false. + * @param encryptOption + * TLS encrypt option. Default is "true" */ - void setEncrypt(boolean encrypt); + void setEncrypt(String encryptOption); /** - * Returns a Boolean value that indicates if the encrypt property is enabled. + * Sets the option whether TLS encryption is used. * - * @return true if encrypt is enabled. Otherwise, false. + * @deprecated Use {@link ISQLServerDataSource#setEncrypt(String encryptOption)} instead + * @param encryptOption + * TLS encrypt option. Default is true */ - boolean getEncrypt(); + @Deprecated + void setEncrypt(boolean encryptOption); + + /** + * Returns the TLS encryption option. + * + * @return the TLS encrypt option + */ + String getEncrypt(); /** - * Sets the value to enable/disable Transparent Netowrk IP Resolution (TNIR). Beginning in version 6.0 of the + * Sets the value to enable/disable Transparent Network IP Resolution (TNIR). Beginning in version 6.0 of the * Microsoft JDBC Driver for SQL Server, a new connection property transparentNetworkIPResolution (TNIR) is added * for transparent connection to Always On availability groups or to a server which has multiple IP addresses * associated. When transparentNetworkIPResolution is true, the driver attempts to connect to the first IP address @@ -143,18 +152,20 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource { boolean getTransparentNetworkIPResolution(); /** - * Sets a Boolean value that indicates if the trustServerCertificate property is enabled. + * Sets a boolean value that indicates if the trustServerCertificate property is enabled. * * @param e * true, if the server Secure Sockets Layer (SSL) certificate should be automatically trusted when the - * communication layer is encrypted using SSL. Otherwise, false. + * communication layer is encrypted using SSL. false, if server SLL certificate should not be trusted + * certificate location, if encrypt=strict */ void setTrustServerCertificate(boolean e); /** - * Returns a Boolean value that indicates if the trustServerCertificate property is enabled. + * Returns a boolean value that indicates if the trustServerCertificate property is enabled. * - * @return true if trustServerCertificate is enabled. Otherwise, false. + * @return true if trustServerCertificate is enabled. Otherwise, false. If encrypt=strict, returns server + * certificate location */ boolean getTrustServerCertificate(); diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkRecord.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkRecord.java index 3f27ee12e..bfcf51ef0 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkRecord.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkRecord.java @@ -15,6 +15,7 @@ * Abstract class that implements ISQLServerBulkRecord * */ +@SuppressWarnings("deprecation") abstract class SQLServerBulkRecord implements ISQLServerBulkRecord { /** diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java index 1171a6139..acc07ae91 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java @@ -196,13 +196,13 @@ public class SQLServerConnection implements ISQLServerConnection, java.io.Serial /** Engine Edition 11 = Azure Synapse serverless SQL pool */ private final int ENGINE_EDITION_SQL_AZURE_SYNAPSE_SERVERLESS_SQL_POOL = 11; - /** flag indicated whether server is Azure */ + /** flag indicating whether server is Azure */ private Boolean isAzure = null; - /** flag indicated whether server is Azure DW */ + /** flag indicating whether server is Azure DW */ private Boolean isAzureDW = null; - /** flag indicated whether server is Azure MI */ + /** flag indicating whether server is Azure MI */ private Boolean isAzureMI = null; /** shared timer */ @@ -214,6 +214,9 @@ public class SQLServerConnection implements ISQLServerConnection, java.io.Serial /** connect retry interval */ private int connectRetryInterval = 0; + /** flag indicating whether prelogin TLS handshake is required */ + private boolean isTDSS = false; + /** * Return an existing cached SharedTimer associated with this Connection or create a new one. * @@ -743,9 +746,10 @@ final byte getRequestedEncryptionLevel() { return requestedEncryptionLevel; } - /** trust server certificate */ + /** flag indicating whether to trust server certificate */ private boolean trustServerCertificate; + /** return whether to trust server certificate */ final boolean trustServerCertificate() { return trustServerCertificate; } @@ -754,7 +758,7 @@ final boolean trustServerCertificate() { private byte negotiatedEncryptionLevel = TDS.ENCRYPT_INVALID; final byte getNegotiatedEncryptionLevel() { - assert TDS.ENCRYPT_INVALID != negotiatedEncryptionLevel; + assert (!isTDSS ? TDS.ENCRYPT_INVALID != negotiatedEncryptionLevel : true); return negotiatedEncryptionLevel; } @@ -795,6 +799,9 @@ final String getTrustManagerConstructorArg() { /** column encryption setting */ String columnEncryptionSetting = null; + /** encrypt option */ + String encryptOption = null; + boolean isColumnEncryptionSettingEnabled() { return (columnEncryptionSetting.equalsIgnoreCase(ColumnEncryptionSetting.Enabled.toString())); } @@ -2045,6 +2052,7 @@ Connection connectInternal(Properties propsIn, } transparentNetworkIPResolution = isBooleanPropertyOn(sPropKey, sPropValue); + sPropKey = SQLServerDriverStringProperty.ENCRYPT.toString(); sPropKey = SQLServerDriverStringProperty.PREPARE_METHOD.toString(); sPropValue = activeConnectionProperties.getProperty(sPropKey); if (null == sPropValue) { @@ -2053,20 +2061,13 @@ Connection connectInternal(Properties propsIn, } setPrepareMethod(PrepareMethod.valueOfString(sPropValue).toString()); - sPropKey = SQLServerDriverBooleanProperty.ENCRYPT.toString(); + sPropKey = SQLServerDriverStringProperty.ENCRYPT.toString(); sPropValue = activeConnectionProperties.getProperty(sPropKey); if (null == sPropValue) { - sPropValue = Boolean.toString(SQLServerDriverBooleanProperty.ENCRYPT.getDefaultValue()); + sPropValue = SQLServerDriverStringProperty.ENCRYPT.getDefaultValue(); activeConnectionProperties.setProperty(sPropKey, sPropValue); } - - socketFactoryClass = activeConnectionProperties - .getProperty(SQLServerDriverStringProperty.SOCKET_FACTORY_CLASS.toString()); - socketFactoryConstructorArg = activeConnectionProperties - .getProperty(SQLServerDriverStringProperty.SOCKET_FACTORY_CONSTRUCTOR_ARG.toString()); - - // Set requestedEncryptionLevel according to the value of the encrypt connection property - requestedEncryptionLevel = isBooleanPropertyOn(sPropKey, sPropValue) ? TDS.ENCRYPT_ON : TDS.ENCRYPT_OFF; + encryptOption = EncryptOption.valueOfString(sPropValue).toString(); sPropKey = SQLServerDriverBooleanProperty.TRUST_SERVER_CERTIFICATE.toString(); sPropValue = activeConnectionProperties.getProperty(sPropKey); @@ -2075,8 +2076,33 @@ Connection connectInternal(Properties propsIn, .toString(SQLServerDriverBooleanProperty.TRUST_SERVER_CERTIFICATE.getDefaultValue()); activeConnectionProperties.setProperty(sPropKey, sPropValue); } - trustServerCertificate = isBooleanPropertyOn(sPropKey, sPropValue); + + // Set requestedEncryptionLevel according to the value of the encrypt connection property + if (encryptOption.compareToIgnoreCase(EncryptOption.False.toString()) == 0) { + requestedEncryptionLevel = TDS.ENCRYPT_OFF; + } else if (encryptOption.compareToIgnoreCase(EncryptOption.True.toString()) == 0) { + requestedEncryptionLevel = TDS.ENCRYPT_ON; + } else if (encryptOption.compareToIgnoreCase(EncryptOption.Strict.toString()) == 0) { + // this is necessary so we don't encrypt again + requestedEncryptionLevel = TDS.ENCRYPT_NOT_SUP; + + if (trustServerCertificate) { + if (loggerExternal.isLoggable(Level.FINER)) + loggerExternal.finer(toString() + " ignore trustServerCertificate for strict"); + } + // do not trust server cert for strict + trustServerCertificate = false; + + // prelogin TLS handshake is required + isTDSS = true; + } else { + MessageFormat form = new MessageFormat( + SQLServerException.getErrString("R_InvalidConnectionSetting")); + Object[] msgArgs = {"encrypt", encryptOption}; + throw new SQLServerException(null, form.format(msgArgs), null, 0, false); + } + trustManagerClass = activeConnectionProperties .getProperty(SQLServerDriverStringProperty.TRUST_MANAGER_CLASS.toString()); trustManagerConstructorArg = activeConnectionProperties @@ -2088,6 +2114,11 @@ Connection connectInternal(Properties propsIn, sPropValue = SQLServerDriverStringProperty.SELECT_METHOD.getDefaultValue(); } + socketFactoryClass = activeConnectionProperties + .getProperty(SQLServerDriverStringProperty.SOCKET_FACTORY_CLASS.toString()); + socketFactoryConstructorArg = activeConnectionProperties + .getProperty(SQLServerDriverStringProperty.SOCKET_FACTORY_CONSTRUCTOR_ARG.toString()); + if ("cursor".equalsIgnoreCase(sPropValue) || "direct".equalsIgnoreCase(sPropValue)) { sPropValue = sPropValue.toLowerCase(Locale.ENGLISH); activeConnectionProperties.setProperty(sPropKey, sPropValue); @@ -2721,9 +2752,7 @@ else if (0 == requestedPacketSize) activeConnectionProperties.remove(SQLServerDriverStringProperty.TRUST_STORE_PASSWORD.toString()); } - return this; - } /** @@ -3185,6 +3214,7 @@ private InetSocketAddress connectHelper(ServerPortPlaceHolder serverInfo, int ti // if the timeout is infinite slices are infinite too. tdsChannel = new TDSChannel(this); + InetSocketAddress inetSocketAddress = tdsChannel.open(serverInfo.getParsedServerName(), serverInfo.getPortNumber(), (0 == timeOutFullInSeconds) ? 0 : timeOutSliceInMillis, useParallel, useTnir, isTnirFirstAttempt, timeOutsliceInMillisForFullTimeout); @@ -3202,15 +3232,20 @@ private InetSocketAddress connectHelper(ServerPortPlaceHolder serverInfo, int ti } clientConnectionId = UUID.randomUUID(); } - assert null != clientConnectionId; - Prelogin(serverInfo.getServerName(), serverInfo.getPortNumber()); + if (isTDSS) { + tdsChannel.enableSSL(serverInfo.getParsedServerName(), serverInfo.getPortNumber(), clientCertificate, + clientKey, clientKeyPassword, isTDSS); + clientKeyPassword = ""; + } + + prelogin(serverInfo.getServerName(), serverInfo.getPortNumber()); - // If prelogin negotiated SSL encryption then, enable it on the TDS channel. - if (TDS.ENCRYPT_NOT_SUP != negotiatedEncryptionLevel) { + // If not enabled already and prelogin negotiated SSL encryption then, enable it on the TDS channel. + if (!isTDSS && TDS.ENCRYPT_NOT_SUP != negotiatedEncryptionLevel) { tdsChannel.enableSSL(serverInfo.getParsedServerName(), serverInfo.getPortNumber(), clientCertificate, - clientKey, clientKeyPassword); + clientKey, clientKeyPassword, false); clientKeyPassword = ""; } @@ -3251,7 +3286,7 @@ private void executeReconnect(LogonCommand logonCommand) throws SQLServerExcepti /** * Negotiates prelogin information with the server. */ - void Prelogin(String serverName, int portNumber) throws SQLServerException { + void prelogin(String serverName, int portNumber) throws SQLServerException { // Build a TDS Pre-Login packet to send to the server. if ((!authenticationString.equalsIgnoreCase(SqlAuthentication.NotSpecified.toString())) || (null != accessTokenInByte)) { @@ -3317,7 +3352,8 @@ void Prelogin(String serverName, int portNumber) throws SQLServerException { // Build (Little Endian), 2 bytes (byte) (SQLJdbcVersion.build & 0xff), (byte) ((SQLJdbcVersion.build & 0xff00) >> 8), - // - Encryption - + // Encryption + // turn encryption off for TDSS since it's already enabled (null == clientCertificate) ? requestedEncryptionLevel : (byte) (requestedEncryptionLevel | TDS.ENCRYPT_CLIENT_CERT), diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataSource.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataSource.java index 817236ea9..669a190ed 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataSource.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataSource.java @@ -306,14 +306,21 @@ public boolean getLastUpdateCount() { } @Override - public void setEncrypt(boolean encrypt) { - setBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.ENCRYPT.toString(), encrypt); + public void setEncrypt(String encryptOption) { + setStringProperty(connectionProps, SQLServerDriverStringProperty.ENCRYPT.toString(), encryptOption); } @Override - public boolean getEncrypt() { - return getBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.ENCRYPT.toString(), - SQLServerDriverBooleanProperty.ENCRYPT.getDefaultValue()); + @Deprecated + public void setEncrypt(boolean encryptOption) { + setStringProperty(connectionProps, SQLServerDriverStringProperty.ENCRYPT.toString(), + Boolean.toString(encryptOption)); + } + + @Override + public String getEncrypt() { + return getStringProperty(connectionProps, SQLServerDriverStringProperty.ENCRYPT.toString(), + SQLServerDriverStringProperty.ENCRYPT.getDefaultValue()); } @Override diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDatabaseMetaData.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDatabaseMetaData.java index a16fe339e..5cc2e2fd3 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDatabaseMetaData.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDatabaseMetaData.java @@ -1666,7 +1666,8 @@ public String getURL() throws SQLServerException { if (!name.equals(SQLServerDriverBooleanProperty.INTEGRATED_SECURITY.toString()) && !name.equals(SQLServerDriverStringProperty.USER.toString()) && !name.equals(SQLServerDriverStringProperty.PASSWORD.toString()) - && !name.equals(SQLServerDriverStringProperty.KEY_STORE_SECRET.toString())) { + && !name.equals(SQLServerDriverStringProperty.KEY_STORE_SECRET.toString()) + && !name.equals(SQLServerDriverStringProperty.TRUST_STORE_PASSWORD.toString())) { String val = info[index].value; // skip empty strings if (0 != val.length()) { diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDriver.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDriver.java index 1e11fe20c..ff123be9b 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDriver.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDriver.java @@ -44,8 +44,8 @@ final String getName() { } DriverPropertyInfo build(Properties connProperties) { - String propValue = name - .equals(SQLServerDriverStringProperty.PASSWORD.toString()) ? "" : connProperties.getProperty(name); + String propValue = name.equals(SQLServerDriverStringProperty.PASSWORD.toString()) ? "" : connProperties + .getProperty(name); if (null == propValue) propValue = defaultValue; @@ -121,6 +121,45 @@ static ColumnEncryptionSetting valueOfString(String value) throws SQLServerExcep } +enum EncryptOption { + False, + No, + Optional, + True, + Mandatory, + Strict; + + static EncryptOption valueOfString(String value) throws SQLServerException { + EncryptOption option = null; + + String val = value.toLowerCase(Locale.US); + if (val.equalsIgnoreCase(EncryptOption.False.toString()) || val.equalsIgnoreCase(EncryptOption.No.toString()) + || val.equalsIgnoreCase(EncryptOption.Optional.toString())) { + option = EncryptOption.False; + } else if (val.equalsIgnoreCase(EncryptOption.True.toString()) + || val.equalsIgnoreCase(EncryptOption.Mandatory.toString())) { + option = EncryptOption.True; + } else if (val.equalsIgnoreCase(EncryptOption.Strict.toString())) { + option = EncryptOption.Strict; + } else { + MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_InvalidConnectionSetting")); + Object[] msgArgs = {"EncryptOption", value}; + throw new SQLServerException(form.format(msgArgs), null); + } + return option; + } + + static boolean isValidEncryptOption(String option) { + for (EncryptOption t : EncryptOption.values()) { + if (option.equalsIgnoreCase(t.toString())) { + return true; + } + } + return false; + } +} + + enum AttestationProtocol { HGS("HGS"), AAS("AAS"); @@ -181,7 +220,8 @@ enum SSLProtocol { TLS("TLS"), TLS_V10("TLSv1"), TLS_V11("TLSv1.1"), - TLS_V12("TLSv1.2"),; + TLS_V12("TLSv1.2"), + TLS_V13("TLSv1.3"),; private final String name; @@ -205,6 +245,8 @@ static SSLProtocol valueOfString(String value) throws SQLServerException { protocol = SSLProtocol.TLS_V11; } else if (value.toLowerCase(Locale.ENGLISH).equalsIgnoreCase(SSLProtocol.TLS_V12.toString())) { protocol = SSLProtocol.TLS_V12; + } else if (value.toLowerCase(Locale.ENGLISH).equalsIgnoreCase(SSLProtocol.TLS_V13.toString())) { + protocol = SSLProtocol.TLS_V13; } else { MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidSSLProtocol")); Object[] msgArgs = {value}; @@ -334,8 +376,9 @@ public String toString() { } } + enum PrepareMethod { - PREPEXEC("prepexec"), //sp_prepexec, default prepare method + PREPEXEC("prepexec"), // sp_prepexec, default prepare method PREPARE("prepare"); private final String value; @@ -364,6 +407,7 @@ static PrepareMethod valueOfString(String value) throws SQLServerException { } } + enum SQLServerDriverStringProperty { APPLICATION_INTENT("applicationIntent", ApplicationIntent.READ_WRITE.toString()), APPLICATION_NAME("applicationName", SQLServerDriver.DEFAULT_APP_NAME), @@ -408,7 +452,8 @@ enum SQLServerDriverStringProperty { CLIENT_KEY_PASSWORD("clientKeyPassword", ""), AAD_SECURE_PRINCIPAL_ID("AADSecurePrincipalId", ""), AAD_SECURE_PRINCIPAL_SECRET("AADSecurePrincipalSecret", ""), - MAX_RESULT_BUFFER("maxResultBuffer", "-1"); + MAX_RESULT_BUFFER("maxResultBuffer", "-1"), + ENCRYPT("encrypt", EncryptOption.True.toString()); private final String name; private final String defaultValue; @@ -476,7 +521,6 @@ public String toString() { enum SQLServerDriverBooleanProperty { DISABLE_STATEMENT_POOLING("disableStatementPooling", true), - ENCRYPT("encrypt", true), INTEGRATED_SECURITY("integratedSecurity", false), LAST_UPDATE_COUNT("lastUpdateCount", true), MULTI_SUBNET_FAILOVER("multiSubnetFailover", false), @@ -524,6 +568,7 @@ public final class SQLServerDriver implements java.sql.Driver { static final String DEFAULT_APP_NAME = "Microsoft JDBC Driver for SQL Server"; private static final String[] TRUE_FALSE = {"true", "false"}; + private static final SQLServerDriverPropertyInfo[] DRIVER_PROPERTIES = { // default required available choices // property name value property (if appropriate) @@ -545,11 +590,14 @@ public final class SQLServerDriver implements java.sql.Driver { new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.DISABLE_STATEMENT_POOLING.toString(), Boolean.toString(SQLServerDriverBooleanProperty.DISABLE_STATEMENT_POOLING.getDefaultValue()), false, new String[] {"true"}), + new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.ENCRYPT.toString(), + SQLServerDriverStringProperty.ENCRYPT.getDefaultValue(), false, + new String[] {EncryptOption.False.toString(), EncryptOption.No.toString(), + EncryptOption.Optional.toString(), EncryptOption.True.toString(), + EncryptOption.Mandatory.toString(), EncryptOption.Strict.toString()}), new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.PREPARE_METHOD.toString(), - SQLServerDriverStringProperty.PREPARE_METHOD.getDefaultValue(),false, + SQLServerDriverStringProperty.PREPARE_METHOD.getDefaultValue(), false, new String[] {PrepareMethod.PREPEXEC.toString(), PrepareMethod.PREPARE.toString()}), - new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.ENCRYPT.toString(), - Boolean.toString(SQLServerDriverBooleanProperty.ENCRYPT.getDefaultValue()), false, TRUE_FALSE), new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.FAILOVER_PARTNER.toString(), SQLServerDriverStringProperty.FAILOVER_PARTNER.getDefaultValue(), false, null), new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.HOSTNAME_IN_CERTIFICATE.toString(), @@ -627,8 +675,7 @@ public final class SQLServerDriver implements java.sql.Driver { new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.TRUST_MANAGER_CONSTRUCTOR_ARG.toString(), SQLServerDriverStringProperty.TRUST_MANAGER_CONSTRUCTOR_ARG.getDefaultValue(), false, null), new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.REPLICATION.toString(), - Boolean.toString(SQLServerDriverBooleanProperty.REPLICATION.getDefaultValue()), false, - TRUE_FALSE), + Boolean.toString(SQLServerDriverBooleanProperty.REPLICATION.getDefaultValue()), false, TRUE_FALSE), new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.SEND_TIME_AS_DATETIME.toString(), Boolean.toString(SQLServerDriverBooleanProperty.SEND_TIME_AS_DATETIME.getDefaultValue()), false, TRUE_FALSE), @@ -734,7 +781,8 @@ public final class SQLServerDriver implements java.sql.Driver { {"domainName", SQLServerDriverStringProperty.DOMAIN.toString()}, {"port", SQLServerDriverIntProperty.PORT_NUMBER.toString()}}; static private final AtomicInteger baseID = new AtomicInteger(0); // Unique id generator for each instance (used for - // logging). + // logging + final private int instanceID; // Unique id for this instance. final private String traceID; @@ -936,10 +984,10 @@ static String getPropertyOnlyName(String name, Logger logger) { return null; } - private final static String[] systemPropertiesToLog = new String[] { "java.specification.vendor", + private final static String[] systemPropertiesToLog = new String[] {"java.specification.vendor", "java.specification.version", "java.class.path", "java.class.version", "java.runtime.name", "java.runtime.version", "java.vendor", "java.version", "java.vm.name", "java.vm.vendor", "java.vm.version", - "java.vm.specification.vendor", "java.vm.specification.version", "os.name", "os.version", "os.arch" }; + "java.vm.specification.vendor", "java.vm.specification.version", "os.name", "os.version", "os.arch"}; @Override public java.sql.Connection connect(String Url, Properties suppliedProperties) throws SQLServerException { @@ -947,8 +995,10 @@ public java.sql.Connection connect(String Url, Properties suppliedProperties) th SQLServerConnection result = null; if (loggerExternal.isLoggable(Level.FINE)) { - loggerExternal.log(Level.FINE, "Microsoft JDBC Driver " + SQLJdbcVersion.major + "." + SQLJdbcVersion.minor + - "." + SQLJdbcVersion.patch + "." + SQLJdbcVersion.build + SQLJdbcVersion.releaseExt + " for SQL Server"); + loggerExternal.log(Level.FINE, + "Microsoft JDBC Driver " + SQLJdbcVersion.major + "." + SQLJdbcVersion.minor + "." + + SQLJdbcVersion.patch + "." + SQLJdbcVersion.build + SQLJdbcVersion.releaseExt + + " for SQL Server"); if (loggerExternal.isLoggable(Level.FINER)) { for (String propertyKeyName : systemPropertiesToLog) { String propertyValue = System.getProperty(propertyKeyName); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/ActivityIDTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/ActivityIDTest.java index e099da033..1e139d10f 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/ActivityIDTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/ActivityIDTest.java @@ -163,7 +163,6 @@ public static void teardown() throws Exception { @BeforeAll public static void testSetup() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString, "trustServerCertificate", "true"); try { setConnection(); } catch (SQLServerException e) { 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 dbd270451..820fe5b0e 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java @@ -192,7 +192,6 @@ static void setAEConnectionString(String serverName, String url, String protocol @BeforeAll public static void setupAETest() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString, "trustServerCertificate", "true"); setConnection(); readFromFile(Constants.JAVA_KEY_STORE_FILENAME, "Alias name"); @@ -220,16 +219,19 @@ public static void setupAETest() throws Exception { setAEConnectionString(serverName, url, protocol); - createCMK(AETestConnectionString, cmkJks, Constants.JAVA_KEY_STORE_NAME, javaKeyAliases, Constants.CMK_SIGNATURE); + createCMK(AETestConnectionString, cmkJks, Constants.JAVA_KEY_STORE_NAME, javaKeyAliases, + Constants.CMK_SIGNATURE); createCEK(AETestConnectionString, cmkJks, cekJks, jksProvider); if (null != keyIDs && !keyIDs[0].isEmpty()) { - createCMK(AETestConnectionString, cmkAkv, Constants.AZURE_KEY_VAULT_NAME, keyIDs[0], Constants.CMK_SIGNATURE_AKV); + createCMK(AETestConnectionString, cmkAkv, Constants.AZURE_KEY_VAULT_NAME, keyIDs[0], + Constants.CMK_SIGNATURE_AKV); createCEK(AETestConnectionString, cmkAkv, cekAkv, akvProvider); } if (null != windowsKeyPath) { - createCMK(AETestConnectionString, cmkWin, Constants.WINDOWS_KEY_STORE_NAME, windowsKeyPath, Constants.CMK_SIGNATURE); + createCMK(AETestConnectionString, cmkWin, Constants.WINDOWS_KEY_STORE_NAME, windowsKeyPath, + Constants.CMK_SIGNATURE); createCEK(AETestConnectionString, cmkWin, cekWin, null); } } @@ -1945,7 +1947,7 @@ protected static void dropCMK(String cmkName, Statement stmt) throws SQLExceptio protected static void dropObject(String connString, String objectType, String objectName) { try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(connString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - switch(objectType) { + switch (objectType) { case "TABLE": TestUtils.dropTableIfExists(objectName, stmt); break; @@ -1958,7 +1960,7 @@ protected static void dropObject(String connString, String objectType, String ob default: break; } - } catch(Exception ex) { + } catch (Exception ex) { fail(ex.getMessage()); } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/RegressionAlwaysEncryptedTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/RegressionAlwaysEncryptedTest.java index c30dc0e50..87584eb79 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/RegressionAlwaysEncryptedTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/RegressionAlwaysEncryptedTest.java @@ -44,7 +44,7 @@ public class RegressionAlwaysEncryptedTest extends AESetup { public void alwaysEncrypted1(String serverName, String url, String protocol) throws Exception { setAEConnectionString(serverName, url, protocol); try (Connection connection = PrepUtil.getConnection( - AETestConnectionString + ";trustservercertificate=true;columnEncryptionSetting=enabled;", AEInfo); + AETestConnectionString + ";columnEncryptionSetting=enabled;", AEInfo); Statement stmt = connection.createStatement()) { dropTables(stmt); @@ -74,7 +74,7 @@ public void alwaysEncrypted1(String serverName, String url, String protocol) thr public void alwaysEncrypted2(String serverName, String url, String protocol) throws Exception { setAEConnectionString(serverName, url, protocol); try (Connection connection = PrepUtil.getConnection( - AETestConnectionString + ";trustservercertificate=true;columnEncryptionSetting=enabled;", AEInfo); + AETestConnectionString + ";columnEncryptionSetting=enabled;", AEInfo); Statement stmt = connection.createStatement()) { dropTables(stmt); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/EnclavePackageTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/EnclavePackageTest.java index ffcb80b7f..c9ee28dc6 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/EnclavePackageTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/EnclavePackageTest.java @@ -192,7 +192,6 @@ public static String[][] enclaveParams() throws Exception { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/JDBC43Test.java b/src/test/java/com/microsoft/sqlserver/jdbc/JDBC43Test.java index 487c1647d..b6947d820 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/JDBC43Test.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/JDBC43Test.java @@ -33,7 +33,6 @@ public class JDBC43Test extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/MaxResultBufferTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/MaxResultBufferTest.java index 1694ecce1..7e5b2d5f8 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/MaxResultBufferTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/MaxResultBufferTest.java @@ -69,7 +69,6 @@ static void createAndPopulateNCharTestTable() throws Exception { // reset logging to avoid severe logs triggered from tests LogManager.getLogManager().reset(); - connectionString = TestUtils.addOrOverrideProperty(connectionString, "trustServerCertificate", "true"); setConnection(); String insertSQL = "INSERT INTO " + AbstractSQLGenerator.escapeIdentifier(TEST_TABLE_NAME) + " VALUES (?)"; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/NTLMConnectionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/NTLMConnectionTest.java index b569ad79a..18d4fc667 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/NTLMConnectionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/NTLMConnectionTest.java @@ -51,7 +51,6 @@ public class NTLMConnectionTest extends AbstractTest { */ @BeforeAll public static void setUp() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); // reset logging to avoid servere logs due to negative testing @@ -121,10 +120,11 @@ public void testNTLMInvalidProperties() { */ @Test public void testNTLMEncryptedConnection() throws SQLException { - try (Connection con = PrepUtil - .getConnection(connectionStringNTLM + ";encrypt=true;trustServerCertificate=true")) { + try (Connection con = PrepUtil.getConnection( + connectionStringNTLM + ";encrypt=" + encrypt + ";trustServerCertificate=" + trustServerCertificate)) { verifyNTLM(con); } + } /** diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/RegisterKeyStoreProviderTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/RegisterKeyStoreProviderTest.java index 1b22b03f8..199f22a2b 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/RegisterKeyStoreProviderTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/RegisterKeyStoreProviderTest.java @@ -39,7 +39,6 @@ public class RegisterKeyStoreProviderTest extends AbstractTest { @BeforeAll public static void testSetup() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); singleKeyStoreProvider.put(dummyProviderName1, new DummyKeyStoreProvider()); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/SQLServerConnectionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/SQLServerConnectionTest.java index e91984c02..0f206df8b 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/SQLServerConnectionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/SQLServerConnectionTest.java @@ -51,7 +51,6 @@ public class SQLServerConnectionTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } @@ -63,6 +62,7 @@ public void testDataSource() { SQLServerDataSource ds = new SQLServerDataSource(); String stringPropValue = "stringPropValue"; boolean booleanPropValue = true; + String booleanStringValue = "true"; int intPropValue = 1; ds.setInstanceName(stringPropValue); @@ -159,8 +159,12 @@ public void testDataSource() { ds.setTrustStorePassword(stringPropValue); assertEquals(stringPropValue, ds.getTrustStorePassword(), TestResource.getResource("R_valuesAreDifferent")); + ds.setEncrypt(booleanStringValue); + assertEquals(booleanStringValue, ds.getEncrypt(), TestResource.getResource("R_valuesAreDifferent")); + ds.setEncrypt(booleanPropValue); - assertEquals(booleanPropValue, ds.getEncrypt(), TestResource.getResource("R_valuesAreDifferent")); + assertEquals(Boolean.toString(booleanPropValue), ds.getEncrypt(), + TestResource.getResource("R_valuesAreDifferent")); ds.setPrepareMethod(stringPropValue); assertEquals(stringPropValue, ds.getPrepareMethod(), TestResource.getResource("R_valuesAreDifferent")); @@ -281,8 +285,12 @@ public void testEncryptedConnection() throws SQLException { SQLServerDataSource ds = new SQLServerDataSource(); ds.setApplicationName("User"); ds.setURL(connectionString); - ds.setEncrypt(true); - ds.setTrustServerCertificate(true); + if (encrypt == null) { + ds.setEncrypt(Constants.TRUE); + } + if (trustServerCertificate == null) { + ds.setTrustServerCertificate(true); + } ds.setPacketSize(8192); try (Connection con = ds.getConnection()) {} } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/TestUtils.java b/src/test/java/com/microsoft/sqlserver/jdbc/TestUtils.java index 0787f6fe5..83e02b527 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/TestUtils.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/TestUtils.java @@ -75,18 +75,20 @@ public final class TestUtils { static final int ENGINE_EDITION_FOR_SQL_AZURE_MI = 8; private TestUtils() {} - + /** * Checks if the connection session recovery object has negotiated reflection. + * * @param con * @return */ public static boolean isConnectionRecoveryNegotiated(Connection con) { return ((SQLServerConnection) con).getSessionRecovery().isConnectionRecoveryNegotiated(); } - + /** * Checks if connection is dead. + * * @param con * @return * @throws SQLServerException @@ -868,7 +870,7 @@ public static String addOrOverrideProperty(String connectionString, String prope * @return The updated connection string */ public static String removeProperty(String connectionString, String property) { - int start = connectionString.indexOf(property); + int start = connectionString.toLowerCase().indexOf(property.toLowerCase()); int end = connectionString.indexOf(";", start); String propertyStr = connectionString.substring(start, -1 != end ? end + 1 : connectionString.length()); return connectionString.replace(propertyStr, ""); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/TimeoutTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/TimeoutTest.java index d1bbf8639..d232859fb 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/TimeoutTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/TimeoutTest.java @@ -38,7 +38,6 @@ public class TimeoutTest extends AbstractTest { @BeforeAll public static void beforeAll() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); if (connection != null) { diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyAllTypesTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyAllTypesTest.java index ceedbef01..11d88d616 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyAllTypesTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyAllTypesTest.java @@ -34,7 +34,6 @@ public class BulkCopyAllTypesTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyCSVTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyCSVTest.java index 2b927c67c..48e28b712 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyCSVTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyCSVTest.java @@ -77,7 +77,6 @@ public class BulkCopyCSVTest extends AbstractTest { */ @BeforeAll public static void setUpConnection() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); con = new DBConnection(connectionString); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyISQLServerBulkRecordTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyISQLServerBulkRecordTest.java index 25c95b4c0..cc0115107 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyISQLServerBulkRecordTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyISQLServerBulkRecordTest.java @@ -54,7 +54,6 @@ public class BulkCopyISQLServerBulkRecordTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyResultSetCursorTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyResultSetCursorTest.java index be0e209a9..b38d11cbe 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyResultSetCursorTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyResultSetCursorTest.java @@ -53,7 +53,6 @@ public class BulkCopyResultSetCursorTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyRowSetTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyRowSetTest.java index be24f8f1e..c3e55cb8f 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyRowSetTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyRowSetTest.java @@ -104,7 +104,6 @@ public void testBulkCopyJapaneseCollation() throws SQLException { @BeforeAll public static void testSetup() throws TestAbortedException, Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); try (Statement stmt = connection.createStatement()) { diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopySendTemporalDataTypesAsStringTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopySendTemporalDataTypesAsStringTest.java index 5f096207b..d8a837ed2 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopySendTemporalDataTypesAsStringTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopySendTemporalDataTypesAsStringTest.java @@ -256,7 +256,6 @@ private void beforeEachSetup() throws SQLException { @BeforeAll public static void setupTest() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); filePath = TestUtils.getCurrentClassPath(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyTestSetUp.java b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyTestSetUp.java index b6141447f..9f82a1eed 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyTestSetUp.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyTestSetUp.java @@ -34,7 +34,6 @@ public class BulkCopyTestSetUp extends AbstractTest { */ @BeforeAll public static void setUpSourceTable() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); try (DBConnection con = new DBConnection(connectionString); DBStatement stmt = con.createStatement(); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/ISQLServerBulkRecordIssuesTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/ISQLServerBulkRecordIssuesTest.java index eea352227..22dab1005 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/ISQLServerBulkRecordIssuesTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/ISQLServerBulkRecordIssuesTest.java @@ -52,7 +52,6 @@ public class ISQLServerBulkRecordIssuesTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/bvt/BvtTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/bvt/BvtTest.java index 2e6816bfb..afa907cb4 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bvt/BvtTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bvt/BvtTest.java @@ -440,7 +440,6 @@ public static void terminate() throws SQLException { @BeforeAll public static void init() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); try (DBConnection conn = new DBConnection(connectionString); DBStatement stmt = conn.createStatement()) { diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableMixedTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableMixedTest.java index d8cbe226e..e6aaa14f6 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableMixedTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableMixedTest.java @@ -31,7 +31,6 @@ public class CallableMixedTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } 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 ea02ae37c..6f4610a25 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java @@ -58,7 +58,6 @@ public class CallableStatementTest extends AbstractTest { */ @BeforeAll public static void setupTest() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); try (Statement stmt = connection.createStatement()) { diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/clientcertauth/ClientCertificateAuthenticationTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/clientcertauth/ClientCertificateAuthenticationTest.java index af34de30d..e8fb57bb6 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/clientcertauth/ClientCertificateAuthenticationTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/clientcertauth/ClientCertificateAuthenticationTest.java @@ -26,8 +26,8 @@ /** - * Tests client certificate authentication feature - * The feature is only supported against SQL Server Linux CU2 or higher. + * Tests client certificate authentication feature. The feature is only supported against SQL Server Linux CU2 or + * higher. * */ @RunWith(JUnitPlatform.class) @@ -52,8 +52,8 @@ public class ClientCertificateAuthenticationTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - //Turn off default encrypt true - connectionString = TestUtils.addOrOverrideProperty(connectionString,"encrypt", "false"); + // Turn off default encrypt true + connectionString = TestUtils.addOrOverrideProperty(connectionString, "encrypt", "false"); setConnection(); } @@ -209,10 +209,10 @@ public void testDataSource() throws Exception { @Test public void testEncryptTrusted() throws Exception { String conStr = connectionString + ";clientCertificate=" + clientCertificate + PEM_SUFFIX + "clientKey=" - + clientKey + PKCS8_KEY_SUFFIX + "encrypt=true;trustServerCertificate=true;"; - try (Connection conn = DriverManager.getConnection(conStr); Statement stmt = conn.createStatement()) { - ResultSet rs = stmt - .executeQuery("SELECT encrypt_option FROM sys.dm_exec_connections WHERE session_id = @@SPID"); + + clientKey + PKCS8_KEY_SUFFIX; + try (Connection conn = DriverManager.getConnection(conStr); Statement stmt = conn.createStatement(); + ResultSet rs = stmt + .executeQuery("SELECT encrypt_option FROM sys.dm_exec_connections WHERE session_id = @@SPID")) { rs.next(); assertTrue(rs.getBoolean(1)); } @@ -226,11 +226,10 @@ public void testEncryptTrusted() throws Exception { @Test public void testEncryptUntrusted() throws Exception { String conStr = connectionString + ";clientCertificate=" + clientCertificate + PEM_SUFFIX + "clientKey=" - + clientKey + PKCS8_KEY_SUFFIX + "encrypt=true;trustServerCertificate=false;trustStore=" - + trustStorePath; - try (Connection conn = DriverManager.getConnection(conStr); Statement stmt = conn.createStatement()) { - ResultSet rs = stmt - .executeQuery("SELECT encrypt_option FROM sys.dm_exec_connections WHERE session_id = @@SPID"); + + clientKey + PKCS8_KEY_SUFFIX; + try (Connection conn = DriverManager.getConnection(conStr); Statement stmt = conn.createStatement(); + ResultSet rs = stmt + .executeQuery("SELECT encrypt_option FROM sys.dm_exec_connections WHERE session_id = @@SPID")) { rs.next(); assertTrue(rs.getBoolean(1)); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/ClientProcessIdTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/ClientProcessIdTest.java index cced33bc1..8d6724584 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/ClientProcessIdTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/ClientProcessIdTest.java @@ -33,7 +33,6 @@ public class ClientProcessIdTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/ConnectionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/ConnectionTest.java index 41d3d4fd1..40110c6a2 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/ConnectionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/ConnectionTest.java @@ -24,7 +24,6 @@ public class ConnectionTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/ConnectionWrapper43Test.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/ConnectionWrapper43Test.java index 8923c75b5..3970c7bba 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/ConnectionWrapper43Test.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/ConnectionWrapper43Test.java @@ -55,7 +55,6 @@ public void SQLServerConnection43Test() throws SQLException { @BeforeAll public static void setupConnection() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); connection = getConnection(); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/DBMetadataTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/DBMetadataTest.java index 27a38a085..dc18afcac 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/DBMetadataTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/DBMetadataTest.java @@ -32,7 +32,6 @@ public class DBMetadataTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/DriverVersionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/DriverVersionTest.java index c319ad1d7..e2349f861 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/DriverVersionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/DriverVersionTest.java @@ -37,7 +37,6 @@ public class DriverVersionTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/NativeMSSQLDataSourceTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/NativeMSSQLDataSourceTest.java index 4059faf12..e8c508f40 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/NativeMSSQLDataSourceTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/NativeMSSQLDataSourceTest.java @@ -33,7 +33,6 @@ public class NativeMSSQLDataSourceTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } @@ -75,7 +74,9 @@ public void testDSTSPassword() throws ClassNotFoundException, IOException, SQLEx System.setProperty("java.net.preferIPv6Addresses", Boolean.TRUE.toString()); ds.setURL(connectionString); ds.setTrustStorePassword("wrong_password"); - try (Connection conn = ds.getConnection()) {} + try (Connection conn = ds.getConnection()) {} catch (SQLException e) { + assert (e.getMessage().contains(TestResource.getResource("R_keystorePassword"))); + } ds = testSerial(ds); try (Connection conn = ds.getConnection()) {} catch (SQLException e) { assertEquals(TestResource.getResource("R_trustStorePasswordNotSet"), e.getMessage()); @@ -117,8 +118,7 @@ public void testInterfaceWrapping() throws ClassNotFoundException, SQLException @Test public void testDSReference() { SQLServerDataSource ds = new SQLServerDataSource(); - assertTrue(ds.getReference().getClassName() - .equals("com.microsoft.sqlserver.jdbc.SQLServerDataSource")); + assertTrue(ds.getReference().getClassName().equals("com.microsoft.sqlserver.jdbc.SQLServerDataSource")); } private SQLServerDataSource testSerial(SQLServerDataSource ds) throws IOException, ClassNotFoundException { diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/PoolingTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/PoolingTest.java index c0518047f..a23d6151f 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/PoolingTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/PoolingTest.java @@ -49,7 +49,6 @@ public class PoolingTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/ReplicationTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/ReplicationTest.java index a8ffdfef3..afbf560aa 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/ReplicationTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/ReplicationTest.java @@ -34,7 +34,6 @@ public class ReplicationTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/RequestBoundaryMethodsTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/RequestBoundaryMethodsTest.java index dab2329ca..ee768ccf4 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/RequestBoundaryMethodsTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/RequestBoundaryMethodsTest.java @@ -49,7 +49,6 @@ public class RequestBoundaryMethodsTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/SSLProtocolTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/SSLProtocolTest.java index bc03c2e2a..3c66ffac4 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/SSLProtocolTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/SSLProtocolTest.java @@ -33,7 +33,6 @@ public class SSLProtocolTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/TimeoutTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/TimeoutTest.java index ba084cb8f..7838039ea 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/TimeoutTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/TimeoutTest.java @@ -43,7 +43,6 @@ public class TimeoutTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/WarningTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/WarningTest.java index e96d63da3..b2b62af2d 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/WarningTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/WarningTest.java @@ -30,7 +30,6 @@ public class WarningTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/XADataSourceTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/XADataSourceTest.java index 7b867f23a..803aa2ee9 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/XADataSourceTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/XADataSourceTest.java @@ -5,6 +5,8 @@ package com.microsoft.sqlserver.jdbc.connection; +import java.sql.Connection; + import javax.sql.XAConnection; import com.microsoft.sqlserver.jdbc.TestUtils; @@ -14,6 +16,7 @@ import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; +import com.microsoft.sqlserver.jdbc.SQLServerDataSource; import com.microsoft.sqlserver.jdbc.SQLServerXADataSource; import com.microsoft.sqlserver.testframework.AbstractTest; import com.microsoft.sqlserver.testframework.Constants; @@ -22,11 +25,10 @@ @RunWith(JUnitPlatform.class) @Tag(Constants.reqExternalSetup) public class XADataSourceTest extends AbstractTest { - private static String connectionUrlSSL = connectionString + ";encrypt=true;trustServerCertificate=false;"; + private static String connectionUrlSSL = connectionString; @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataForeignKeyTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataForeignKeyTest.java index 3ef964fe3..d394a8917 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataForeignKeyTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataForeignKeyTest.java @@ -54,7 +54,6 @@ public class DatabaseMetaDataForeignKeyTest extends AbstractTest { @BeforeAll public static void setupVariation() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); cleanup(); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataTest.java index 569da9d11..8041a35be 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataTest.java @@ -797,7 +797,6 @@ public void testGetImportedKeysDW() throws SQLException { @BeforeAll public static void setupTable() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); try (Statement stmt = connection.createStatement()) { diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/BigIntegerTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/BigIntegerTest.java index 0622be0ef..d46d93883 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/BigIntegerTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/BigIntegerTest.java @@ -40,7 +40,6 @@ enum TestType { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/BulkCopyWithSqlVariantTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/BulkCopyWithSqlVariantTest.java index 2490d92ac..dde706a3e 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/BulkCopyWithSqlVariantTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/BulkCopyWithSqlVariantTest.java @@ -42,7 +42,6 @@ public class BulkCopyWithSqlVariantTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/DataTypesTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/DataTypesTest.java index a2cd3557d..4ddff40de 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/DataTypesTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/DataTypesTest.java @@ -98,7 +98,6 @@ enum SQLType { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/DateAndTimeTypeTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/DateAndTimeTypeTest.java index 533a04c2d..b83a47d5c 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/DateAndTimeTypeTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/DateAndTimeTypeTest.java @@ -196,7 +196,6 @@ private void createTVPs(String tvpName, String tvpType) throws SQLException { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLServerSpatialDatatypeTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLServerSpatialDatatypeTest.java index 87e79e4a9..b4c7078a9 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLServerSpatialDatatypeTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLServerSpatialDatatypeTest.java @@ -2202,7 +2202,6 @@ private void validateGeometryGeography(String geoWKT, byte[] geomCLR, byte[] geo */ @BeforeAll public static void setupHere() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); geomTableName = RandomUtil.getIdentifier("geometryTestTable"); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLVariantResultSetTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLVariantResultSetTest.java index 214f67e21..e404ded61 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLVariantResultSetTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLVariantResultSetTest.java @@ -1111,7 +1111,6 @@ private void createAndPopulateTable(String columnType, Object value) throws SQLE */ @BeforeAll public static void setupHere() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); tableName = RandomUtil.getIdentifier("sqlVariantTestSrcTable"); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SparseTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SparseTest.java index 2a5272421..a2ee54337 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SparseTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SparseTest.java @@ -26,7 +26,6 @@ public class SparseTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/TVPWithSqlVariantTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/TVPWithSqlVariantTest.java index dc2c4f2c2..1dd652326 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/TVPWithSqlVariantTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/TVPWithSqlVariantTest.java @@ -469,7 +469,6 @@ private static String[] createNumericValues() { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/exception/ErrorStateTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/exception/ErrorStateTest.java index 9e2de1dd9..58ce056c5 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/exception/ErrorStateTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/exception/ErrorStateTest.java @@ -18,7 +18,6 @@ public class ErrorStateTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/exception/ExceptionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/exception/ExceptionTest.java index 11dff51cc..2d61efbd0 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/exception/ExceptionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/exception/ExceptionTest.java @@ -39,7 +39,6 @@ public class ExceptionTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ConcurrentLoginTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ConcurrentLoginTest.java index 6b8509978..72dae99f9 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ConcurrentLoginTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ConcurrentLoginTest.java @@ -36,7 +36,6 @@ public void uncaughtException(Thread t, Throwable e) { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ConnectionSuspensionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ConnectionSuspensionTest.java index c23d6f813..9e42e19b8 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ConnectionSuspensionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ConnectionSuspensionTest.java @@ -38,7 +38,6 @@ public class ConnectionSuspensionTest extends FedauthCommon { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ErrorMessageTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ErrorMessageTest.java index 0630c05c5..933e7559c 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ErrorMessageTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ErrorMessageTest.java @@ -33,7 +33,6 @@ public class ErrorMessageTest extends FedauthCommon { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthTest.java index 6a6d16ef9..1324ff8a5 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthTest.java @@ -42,7 +42,7 @@ public class FedauthTest extends FedauthCommon { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); + connectionString = TestUtils.addOrOverrideProperty(connectionString, "trustServerCertificate", "true"); setConnection(); } @@ -168,56 +168,56 @@ public void testGroupAuthenticationDS() throws SQLException { @Test public void testNotValidNotSpecified() throws SQLException { - testNotValid(SqlAuthentication.NotSpecified.toString(), false, false); - testNotValid(SqlAuthentication.NotSpecified.toString(), false, true); - testNotValid(SqlAuthentication.NotSpecified.toString(), true, true); + testNotValid(SqlAuthentication.NotSpecified.toString(), Constants.FALSE, false); + testNotValid(SqlAuthentication.NotSpecified.toString(), Constants.FALSE, true); + testNotValid(SqlAuthentication.NotSpecified.toString(), Constants.TRUE, true); } @Test public void testNotValidSqlPassword() throws SQLException { - testNotValid(SqlAuthentication.SqlPassword.toString(), false, true); - testNotValid(SqlAuthentication.SqlPassword.toString(), true, true); + testNotValid(SqlAuthentication.SqlPassword.toString(), Constants.FALSE, true); + testNotValid(SqlAuthentication.SqlPassword.toString(), Constants.TRUE, true); } @Test public void testNotValidActiveDirectoryIntegrated() throws SQLException { org.junit.Assume.assumeTrue(enableADIntegrated); - testNotValid(SqlAuthentication.ActiveDirectoryIntegrated.toString(), false, true); - testNotValid(SqlAuthentication.ActiveDirectoryIntegrated.toString(), true, true); + testNotValid(SqlAuthentication.ActiveDirectoryIntegrated.toString(), Constants.FALSE, true); + testNotValid(SqlAuthentication.ActiveDirectoryIntegrated.toString(), Constants.TRUE, true); } @Test public void testNotValidActiveDirectoryPassword() throws SQLException { - testNotValid(SqlAuthentication.ActiveDirectoryPassword.toString(), false, true); - testNotValid(SqlAuthentication.ActiveDirectoryPassword.toString(), true, true); + testNotValid(SqlAuthentication.ActiveDirectoryPassword.toString(), Constants.FALSE, true); + testNotValid(SqlAuthentication.ActiveDirectoryPassword.toString(), Constants.TRUE, true); } @Test public void testValidNotSpecified() throws SQLException { - testValid(SqlAuthentication.NotSpecified.toString(), false, false); - testValid(SqlAuthentication.NotSpecified.toString(), false, true); - testValid(SqlAuthentication.NotSpecified.toString(), true, true); + testValid(SqlAuthentication.NotSpecified.toString(), Constants.FALSE, false); + testValid(SqlAuthentication.NotSpecified.toString(), Constants.FALSE, true); + testValid(SqlAuthentication.NotSpecified.toString(), Constants.TRUE, true); } @Test public void testValidSqlPassword() throws SQLException { - testValid(SqlAuthentication.SqlPassword.toString(), false, true); - testValid(SqlAuthentication.SqlPassword.toString(), true, true); + testValid(SqlAuthentication.SqlPassword.toString(), Constants.FALSE, true); + testValid(SqlAuthentication.SqlPassword.toString(), Constants.TRUE, true); } @Test public void testValidActiveDirectoryIntegrated() throws SQLException { org.junit.Assume.assumeTrue(enableADIntegrated); - testValid(SqlAuthentication.ActiveDirectoryIntegrated.toString(), false, true); - testValid(SqlAuthentication.ActiveDirectoryIntegrated.toString(), true, true); + testValid(SqlAuthentication.ActiveDirectoryIntegrated.toString(), Constants.FALSE, true); + testValid(SqlAuthentication.ActiveDirectoryIntegrated.toString(), Constants.TRUE, true); } @Test public void testValidActiveDirectoryPassword() throws SQLException { - testValid(SqlAuthentication.ActiveDirectoryPassword.toString(), false, true); - testValid(SqlAuthentication.ActiveDirectoryPassword.toString(), true, true); + testValid(SqlAuthentication.ActiveDirectoryPassword.toString(), Constants.FALSE, true); + testValid(SqlAuthentication.ActiveDirectoryPassword.toString(), Constants.TRUE, true); } @Test @@ -360,7 +360,7 @@ private static void validateException(String url, String resourceKey) { } } - private void testValid(String authentication, boolean encrypt, boolean trustServerCertificate) throws SQLException { + private void testValid(String authentication, String encrypt, boolean trustServerCertificate) throws SQLException { try { SQLServerDataSource ds = new SQLServerDataSource(); if (!authentication.equalsIgnoreCase(SqlAuthentication.ActiveDirectoryIntegrated.toString())) { @@ -391,7 +391,7 @@ private void testValid(String authentication, boolean encrypt, boolean trustServ } } - private void testNotValid(String authentication, boolean encrypt, + private void testNotValid(String authentication, String encrypt, boolean trustServerCertificate) throws SQLException { try { SQLServerDataSource ds = new SQLServerDataSource(); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthWithAE.java b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthWithAE.java index a34d4ee32..bfd09d3b9 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthWithAE.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthWithAE.java @@ -52,7 +52,6 @@ public class FedauthWithAE extends FedauthCommon { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString, "trustServerCertificate", "true"); setConnection(); ds.setServerName(azureServer); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/PooledConnectionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/PooledConnectionTest.java index 884b6c276..244fc059d 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/PooledConnectionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/PooledConnectionTest.java @@ -46,7 +46,6 @@ public class PooledConnectionTest extends FedauthCommon { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/fips/FipsTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/fips/FipsTest.java index a486e3c27..5a032c59c 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fips/FipsTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fips/FipsTest.java @@ -33,15 +33,14 @@ public class FipsTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - //Turn off default encrypt true - connectionString = TestUtils.addOrOverrideProperty(connectionString,"encrypt", "false"); setConnection(); } /** * Test after setting TrustServerCertificate as true. * - * @throws Exception when an error occurs + * @throws Exception + * when an error occurs */ @Test public void fipsTrustServerCertificateTest() throws Exception { @@ -58,7 +57,8 @@ public void fipsTrustServerCertificateTest() throws Exception { /** * Test after passing encrypt as false. * - * @throws Exception when an error occurs + * @throws Exception + * when an error occurs */ @Test public void fipsEncryptTest() throws Exception { @@ -75,7 +75,8 @@ public void fipsEncryptTest() throws Exception { /** * Test after removing fips, encrypt & trustStore it should work appropriately. * - * @throws Exception when an error occurs + * @throws Exception + * when an error occurs */ @Test public void fipsPropertyTest() throws Exception { @@ -95,14 +96,15 @@ public void fipsPropertyTest() throws Exception { /** * Tests after removing all FIPS related properties. * - * @throws Exception when an error occurs + * @throws Exception + * when an error occurs */ @Test public void fipsDataSourcePropertyTest() throws Exception { SQLServerDataSource ds = new SQLServerDataSource(); setDataSourceProperties(ds); ds.setFIPS(false); - ds.setEncrypt(false); + ds.setEncrypt(Constants.FALSE); ds.setTrustStoreType(Constants.JKS); try (Connection con = ds.getConnection()) { Assertions.assertTrue(!StringUtils.isEmpty(con.getSchema())); @@ -118,7 +120,7 @@ public void fipsDataSourcePropertyTest() throws Exception { public void fipsDatSourceEncrypt() { SQLServerDataSource ds = new SQLServerDataSource(); setDataSourceProperties(ds); - ds.setEncrypt(false); + ds.setEncrypt(Constants.FALSE); try (Connection con = ds.getConnection()) { Assertions.fail(TestResource.getResource("R_expectedExceptionNotThrown")); @@ -131,7 +133,8 @@ public void fipsDatSourceEncrypt() { /** * Test after setting TrustServerCertificate as true. * - * @throws Exception when an error occurs + * @throws Exception + * when an error occurs */ @Test public void fipsDataSourceTrustServerCertificateTest() throws Exception { @@ -157,7 +160,7 @@ private void setDataSourceProperties(SQLServerDataSource ds) { // Set all properties for FIPS ds.setFIPS(true); - ds.setEncrypt(true); + ds.setEncrypt(Constants.TRUE); ds.setTrustServerCertificate(false); ds.setIntegratedSecurity(false); ds.setTrustStoreType(Constants.PKCS12); @@ -174,11 +177,12 @@ private Properties buildConnectionProperties() { connectionProps.setProperty(Constants.ENCRYPT, Boolean.TRUE.toString()); connectionProps.setProperty(Constants.INTEGRATED_SECURITY, Boolean.FALSE.toString()); - // In case of false we need to pass keystore etc. which is not passing by default. connectionProps.setProperty(Constants.TRUST_SERVER_CERTIFICATE, Boolean.FALSE.toString()); - // For New Code connectionProps.setProperty(Constants.TRUST_STORE_TYPE, Constants.PKCS12); + connectionProps.setProperty(Constants.TRUST_STORE, trustStore); + connectionProps.setProperty(Constants.TRUST_STORE_SECRET_PROPERTY, trustStorePassword); + connectionProps.setProperty(Constants.FIPS, Boolean.TRUE.toString()); return connectionProps; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/fmtOnly/APITest.java b/src/test/java/com/microsoft/sqlserver/jdbc/fmtOnly/APITest.java index 050c59a50..29f5db8de 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fmtOnly/APITest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fmtOnly/APITest.java @@ -28,7 +28,6 @@ public class APITest extends AbstractTest { @BeforeAll private static void setupTest() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); try (Statement s = connection.createStatement()) { diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/fmtOnly/DeleteTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/fmtOnly/DeleteTest.java index f59e01dde..b95f01055 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fmtOnly/DeleteTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fmtOnly/DeleteTest.java @@ -15,7 +15,6 @@ public class DeleteTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/fmtOnly/InsertTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/fmtOnly/InsertTest.java index b104729df..721c5ebe0 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fmtOnly/InsertTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fmtOnly/InsertTest.java @@ -15,7 +15,6 @@ public class InsertTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/fmtOnly/LexerTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/fmtOnly/LexerTest.java index 8653d1f9b..7e1ceaaa0 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fmtOnly/LexerTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fmtOnly/LexerTest.java @@ -15,7 +15,6 @@ public class LexerTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/fmtOnly/ParameterMetaDataTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/fmtOnly/ParameterMetaDataTest.java index 0d1b49a45..f9aaf72b1 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fmtOnly/ParameterMetaDataTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fmtOnly/ParameterMetaDataTest.java @@ -31,7 +31,6 @@ public class ParameterMetaDataTest extends AbstractTest { @BeforeEach public void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); try (Connection c = getConnection(); Statement s = c.createStatement()) { diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/fmtOnly/SelectTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/fmtOnly/SelectTest.java index 1e195de2f..42d57ab87 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fmtOnly/SelectTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fmtOnly/SelectTest.java @@ -15,7 +15,6 @@ public class SelectTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/fmtOnly/UpdateTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/fmtOnly/UpdateTest.java index ed7dc975f..c3cc932e7 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fmtOnly/UpdateTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fmtOnly/UpdateTest.java @@ -15,7 +15,6 @@ public class UpdateTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/osgi/DataFactoryTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/osgi/DataFactoryTest.java index 047e180c7..bfa8c3fe6 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/osgi/DataFactoryTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/osgi/DataFactoryTest.java @@ -40,7 +40,6 @@ public class DataFactoryTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/parametermetadata/ParameterMetaDataTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/parametermetadata/ParameterMetaDataTest.java index 9cd25a6f5..61b9936af 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/parametermetadata/ParameterMetaDataTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/parametermetadata/ParameterMetaDataTest.java @@ -32,7 +32,6 @@ public class ParameterMetaDataTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/parametermetadata/ParameterMetaDataWhiteSpaceTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/parametermetadata/ParameterMetaDataWhiteSpaceTest.java index 1edc67cce..31ab3d35f 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/parametermetadata/ParameterMetaDataWhiteSpaceTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/parametermetadata/ParameterMetaDataWhiteSpaceTest.java @@ -33,7 +33,6 @@ public class ParameterMetaDataWhiteSpaceTest extends AbstractTest { @BeforeAll public static void BeforeTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); createCharTable(); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/BatchExecutionWithBulkCopyTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/BatchExecutionWithBulkCopyTest.java index 766ddb8aa..efd9180f6 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/BatchExecutionWithBulkCopyTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/BatchExecutionWithBulkCopyTest.java @@ -697,7 +697,6 @@ public void testNonSupportedColumns() throws Exception { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/BatchExecutionWithNullTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/BatchExecutionWithNullTest.java index 05b7e54dc..672708de3 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/BatchExecutionWithNullTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/BatchExecutionWithNullTest.java @@ -184,7 +184,6 @@ private void executeBatch(PreparedStatement pstmt, int count, int run) throws SQ @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/RegressionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/RegressionTest.java index ef4ab2f58..cc987984f 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/RegressionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/RegressionTest.java @@ -51,7 +51,6 @@ public class RegressionTest extends AbstractTest { */ @BeforeAll public static void setupTest() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); try (Statement stmt = connection.createStatement()) { diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/SetObjectTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/SetObjectTest.java index 05f95bbc7..212829ef5 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/SetObjectTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/SetObjectTest.java @@ -40,7 +40,6 @@ public class SetObjectTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/resiliency/BasicConnectionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/resiliency/BasicConnectionTest.java index 3d326c78f..9f1a41bd3 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/resiliency/BasicConnectionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/resiliency/BasicConnectionTest.java @@ -35,8 +35,6 @@ public class BasicConnectionTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - // Turn off default encrypt true - connectionString = TestUtils.addOrOverrideProperty(connectionString, "encrypt", "false"); setConnection(); } @@ -59,7 +57,7 @@ public void testBasicConnectionAAD() throws SQLException { @Test public void testBasicEncryptedConnection() throws SQLException { - basicReconnect(connectionString + ";encrypt=true;trustServerCertificate=true;"); + basicReconnect(connectionString); } @Test diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/resiliency/PropertyTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/resiliency/PropertyTest.java index f0ea6b7de..7dc843ecd 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/resiliency/PropertyTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/resiliency/PropertyTest.java @@ -29,7 +29,6 @@ public class PropertyTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/resiliency/ReflectiveTests.java b/src/test/java/com/microsoft/sqlserver/jdbc/resiliency/ReflectiveTests.java index 88a72e735..e25579d0e 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/resiliency/ReflectiveTests.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/resiliency/ReflectiveTests.java @@ -35,7 +35,6 @@ public class ReflectiveTests extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/resiliency/ResultSetsWithResiliencyTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/resiliency/ResultSetsWithResiliencyTest.java index fb8aa6e32..a326234b0 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/resiliency/ResultSetsWithResiliencyTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/resiliency/ResultSetsWithResiliencyTest.java @@ -35,7 +35,6 @@ public class ResultSetsWithResiliencyTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); try (Connection c = DriverManager.getConnection(connectionString); Statement s = c.createStatement();) { diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/resultset/DataClassificationTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/resultset/DataClassificationTest.java index ad6c70632..620772a5b 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/resultset/DataClassificationTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/resultset/DataClassificationTest.java @@ -44,7 +44,6 @@ public class DataClassificationTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/resultset/ResultSetTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/resultset/ResultSetTest.java index d94078eb7..c176fb2cd 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/resultset/ResultSetTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/resultset/ResultSetTest.java @@ -52,7 +52,6 @@ public class ResultSetTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/socketfactory/CustomSocketFactoryTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/socketfactory/CustomSocketFactoryTest.java index 98861436f..543d8e91d 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/socketfactory/CustomSocketFactoryTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/socketfactory/CustomSocketFactoryTest.java @@ -14,8 +14,6 @@ import java.util.List; import javax.net.SocketFactory; - -import com.microsoft.sqlserver.jdbc.TestUtils; import org.junit.Assert; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; @@ -33,7 +31,6 @@ public class CustomSocketFactoryTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/ssl/trustmanager/CustomTrustManagerTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/ssl/trustmanager/CustomTrustManagerTest.java index f3c70eb78..54c817842 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/ssl/trustmanager/CustomTrustManagerTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/ssl/trustmanager/CustomTrustManagerTest.java @@ -5,8 +5,8 @@ package com.microsoft.sqlserver.jdbc.ssl.trustmanager; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.sql.Connection; import java.sql.SQLException; @@ -16,7 +16,9 @@ import org.junit.runner.RunWith; import com.microsoft.sqlserver.jdbc.TestResource; +import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractTest; +import com.microsoft.sqlserver.testframework.Constants; import com.microsoft.sqlserver.testframework.PrepUtil; @@ -30,8 +32,7 @@ public class CustomTrustManagerTest extends AbstractTest { */ @Test public void testWithPermissiveX509TrustManager() throws Exception { - String url = connectionString + ";trustManagerClass=" + PermissiveTrustManager.class.getName() - + ";encrypt=true;"; + String url = connectionString + ";trustManagerClass=" + PermissiveTrustManager.class.getName(); try (Connection con = PrepUtil.getConnection(url)) { assertTrue(con != null); } @@ -45,7 +46,7 @@ public void testWithPermissiveX509TrustManager() throws Exception { @Test public void testWithTrustManagerConstructorArg() throws Exception { String url = connectionString + ";trustManagerClass=" + TrustManagerWithConstructorArg.class.getName() - + ";trustManagerConstructorArg=dummyString;" + ";encrypt=true;"; + + ";trustManagerConstructorArg=dummyString;"; try (Connection con = PrepUtil.getConnection(url)) { assertTrue(con != null); } @@ -58,12 +59,14 @@ public void testWithTrustManagerConstructorArg() throws Exception { */ @Test public void testWithInvalidTrustManager() throws Exception { - String url = connectionString + ";trustManagerClass=" + InvalidTrustManager.class.getName() + ";encrypt=true;"; + String url = TestUtils.removeProperty(connectionString, Constants.TRUST_SERVER_CERTIFICATE); + url = url + "encrypt=true;trustManagerClass=" + InvalidTrustManager.class.getName(); try (Connection con = PrepUtil.getConnection(url)) { fail(TestResource.getResource("R_expectedFailPassed")); } catch (SQLException e) { assertTrue(e.getMessage().contains( - "The class specified by the trustManagerClass property must be assignable to javax.net.ssl.TrustManager.")); + "The class specified by the trustManagerClass property must be assignable to javax.net.ssl.TrustManager."), + e.getMessage()); } } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPAllTypesTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPAllTypesTest.java index 9fef3a91e..fdb4c7ded 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPAllTypesTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPAllTypesTest.java @@ -45,7 +45,6 @@ public class TVPAllTypesTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPIssuesTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPIssuesTest.java index e97b69a3c..e110ccda0 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPIssuesTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPIssuesTest.java @@ -133,7 +133,6 @@ private void testTime6DestTable(Statement stmt) throws SQLException, IOException @BeforeAll public static void beforeAll() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); try (Connection connection = getConnection(); Statement stmt = connection.createStatement()) { diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPNumericTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPNumericTest.java index 231e9adfb..0c3101605 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPNumericTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPNumericTest.java @@ -95,7 +95,6 @@ public void testTVPNameWithDataTable() throws SQLException { @BeforeAll public static void testSetup() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); tvpName = RandomUtil.getIdentifier("numericTVP"); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPResultSetCursorTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPResultSetCursorTest.java index 1e5c4e274..69060eb7b 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPResultSetCursorTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPResultSetCursorTest.java @@ -57,7 +57,6 @@ public class TVPResultSetCursorTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPSchemaTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPSchemaTest.java index 63c39b04d..075c9f2cb 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPSchemaTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPSchemaTest.java @@ -132,7 +132,6 @@ public void testTVPSchemaCallableInsertCommand() throws SQLException, IOExceptio @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPTypesTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPTypesTest.java index 37eb1ea22..e56ec220f 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPTypesTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPTypesTest.java @@ -668,7 +668,6 @@ public String toString() { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/SQLServerErrorTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/SQLServerErrorTest.java index 834e6da49..b4ca10c04 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/SQLServerErrorTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/SQLServerErrorTest.java @@ -36,7 +36,6 @@ public class SQLServerErrorTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/SavepointTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/SavepointTest.java index 8b3f62af9..63a9c9567 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/SavepointTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/SavepointTest.java @@ -36,7 +36,6 @@ public class SavepointTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/UTF8SupportTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/UTF8SupportTest.java index 0b509b7f2..263366b04 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/UTF8SupportTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/UTF8SupportTest.java @@ -107,7 +107,6 @@ public void testVarchar() throws SQLException { @BeforeAll public static void setUp() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); assert (TestUtils.serverSupportsUTF8(connection)); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/LobsStreamingTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/LobsStreamingTest.java index 466b80f2d..c8b48a5bc 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/LobsStreamingTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/LobsStreamingTest.java @@ -39,7 +39,6 @@ public class LobsStreamingTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/LobsTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/LobsTest.java index a2856c2eb..82becbcd0 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/LobsTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/LobsTest.java @@ -79,7 +79,6 @@ public class LobsTest extends AbstractTest { @BeforeAll public static void init() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); tableName = RandomUtil.getIdentifier("LOBS"); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/serial/DTOSerialTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/serial/DTOSerialTest.java index 09cdfe7d1..9b462d403 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/serial/DTOSerialTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/serial/DTOSerialTest.java @@ -38,7 +38,6 @@ public class DTOSerialTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecuteWithErrorsTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecuteWithErrorsTest.java index a5371ad5f..5744b9773 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecuteWithErrorsTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecuteWithErrorsTest.java @@ -53,7 +53,6 @@ public class BatchExecuteWithErrorsTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecutionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecutionTest.java index 775cf58a3..b74d99cb5 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecutionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecutionTest.java @@ -242,7 +242,6 @@ private void modifyConnectionForBulkCopyAPI(SQLServerConnection con) throws Exce @BeforeAll public static void testSetup() throws TestAbortedException, Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); ctstable1 = RandomUtil.getIdentifier("ctstable1"); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchTriggerTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchTriggerTest.java index 67c1266df..777dbac14 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchTriggerTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchTriggerTest.java @@ -107,7 +107,6 @@ private static void createTable(Statement stmt) throws SQLException { */ @BeforeAll public static void testSetup() throws TestAbortedException, Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); tableName = RandomUtil.getIdentifier("triggerTable"); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/CallableMixedTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/CallableMixedTest.java index defbce668..ab8d4ce22 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/CallableMixedTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/CallableMixedTest.java @@ -37,7 +37,6 @@ public class CallableMixedTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/LimitEscapeTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/LimitEscapeTest.java index dc84a3b04..e54b6760f 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/LimitEscapeTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/LimitEscapeTest.java @@ -893,7 +893,6 @@ public void verifyOffsetException() throws Exception { */ @BeforeAll public static void beforeAll() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); try { diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/MergeTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/MergeTest.java index c042fb3e1..67ce9c36e 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/MergeTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/MergeTest.java @@ -38,7 +38,6 @@ public class MergeTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/NamedParamMultiPartTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/NamedParamMultiPartTest.java index 3c55f88b5..aa4b85886 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/NamedParamMultiPartTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/NamedParamMultiPartTest.java @@ -44,7 +44,6 @@ public class NamedParamMultiPartTest extends AbstractTest { */ @BeforeAll public static void beforeAll() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); procedureName = RandomUtil.getIdentifier("mystoredproc"); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PQImpsTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PQImpsTest.java index 99947ccaf..22080f486 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PQImpsTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PQImpsTest.java @@ -67,7 +67,6 @@ public class PQImpsTest extends AbstractTest { */ @BeforeAll public static void BeforeTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); connection = getConnection(); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PoolableTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PoolableTest.java index b5725363b..86b34b71f 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PoolableTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PoolableTest.java @@ -37,7 +37,6 @@ public class PoolableTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PreparedStatementTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PreparedStatementTest.java index 061f14682..5fc74e478 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PreparedStatementTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PreparedStatementTest.java @@ -51,7 +51,6 @@ public class PreparedStatementTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/RegressionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/RegressionTest.java index 350e61442..9785f0eda 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/RegressionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/RegressionTest.java @@ -39,7 +39,6 @@ public class RegressionTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementCancellationTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementCancellationTest.java index ec3764c73..9db593b24 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementCancellationTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementCancellationTest.java @@ -31,7 +31,6 @@ public class StatementCancellationTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementTest.java index a9cdf27b8..ba7375970 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementTest.java @@ -66,7 +66,6 @@ public class StatementTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/WrapperTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/WrapperTest.java index 3343bc5e8..1fdf54aca 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/WrapperTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/WrapperTest.java @@ -32,7 +32,6 @@ public class WrapperTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true"); setConnection(); } diff --git a/src/test/java/com/microsoft/sqlserver/testframework/AbstractTest.java b/src/test/java/com/microsoft/sqlserver/testframework/AbstractTest.java index 7a563b938..678451f12 100644 --- a/src/test/java/com/microsoft/sqlserver/testframework/AbstractTest.java +++ b/src/test/java/com/microsoft/sqlserver/testframework/AbstractTest.java @@ -69,7 +69,11 @@ public abstract class AbstractTest { protected static String clientKey = null; protected static String clientKeyPassword = ""; - protected static String trustStorePath = ""; + protected static String trustStore = ""; + protected static String trustStorePassword = ""; + + protected static String encrypt = ""; + protected static String trustServerCertificate = ""; protected static String windowsKeyPath = null; protected static String javaKeyPath = null; @@ -134,6 +138,13 @@ public static void setup() throws Exception { applicationKey = getConfiguredProperty("applicationKey"); tenantID = getConfiguredProperty("tenantID"); + encrypt = getConfiguredProperty("encrypt", "false"); + connectionString = TestUtils.addOrOverrideProperty(connectionString, "encrypt", encrypt); + + trustServerCertificate = getConfiguredProperty("trustServerCertificate", "true"); + connectionString = TestUtils.addOrOverrideProperty(connectionString, "trustServerCertificate", + trustServerCertificate); + javaKeyPath = TestUtils.getCurrentClassPath() + Constants.JKS_NAME; keyIDs = getConfiguredProperty("keyID", "").split(Constants.SEMI_COLON); @@ -163,7 +174,16 @@ public static void setup() throws Exception { clientKeyPassword = getConfiguredProperty("clientKeyPassword", ""); - trustStorePath = getConfiguredProperty("trustStore", ""); + trustStore = getConfiguredProperty("trustStore", ""); + if (!(trustStore.isBlank() || trustStore.isEmpty())) { + connectionString = TestUtils.addOrOverrideProperty(connectionString, "trustStore", trustStore); + } + + trustStorePassword = getConfiguredProperty("trustStorePassword", ""); + if (!(trustStorePassword.isBlank() || trustStorePassword.isEmpty())) { + connectionString = TestUtils.addOrOverrideProperty(connectionString, "trustStorePassword", + trustStorePassword); + } Map map = new HashMap(); if (null == jksProvider) { @@ -318,11 +338,20 @@ protected static ISQLServerDataSource updateDataSource(String connectionString, ds.setCancelQueryTimeout(Integer.parseInt(value)); break; case Constants.ENCRYPT: - ds.setEncrypt(Boolean.parseBoolean(value)); + ds.setEncrypt(value); break; case Constants.TRUST_SERVER_CERTIFICATE: ds.setTrustServerCertificate(Boolean.parseBoolean(value)); break; + case Constants.TRUST_STORE: + ds.setTrustStore(value); + break; + case Constants.TRUST_STORE_SECRET_PROPERTY: + ds.setTrustStorePassword(value); + break; + case Constants.TRUST_STORE_TYPE: + ds.setTrustStoreType(value); + break; case Constants.HOST_NAME_IN_CERTIFICATE: ds.setHostNameInCertificate(value); break; diff --git a/src/test/java/com/microsoft/sqlserver/testframework/Constants.java b/src/test/java/com/microsoft/sqlserver/testframework/Constants.java index 00ba22eda..f6507619b 100644 --- a/src/test/java/com/microsoft/sqlserver/testframework/Constants.java +++ b/src/test/java/com/microsoft/sqlserver/testframework/Constants.java @@ -118,6 +118,11 @@ private Constants() {} public static final String CEK_STRING = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; public static final String CEK_ENCRYPTED_VALUE = "0x016E000001630075007200720065006E00740075007300650072002F006D0079002F006100320032003600650031003800310034003300350063003300370065003800660035003500330035003500660066006100340037003400340062003600330035003600610031006200650035003500A83E74C244AD62ED7D83FDEAED3923B4D843BBB8FDE1ECFEE11DB5275144BC936FD3485D157B4921A6CF12EEEAD52F6BAB5822383C7101508523C51858A1487FD10173CD945159418B70DD9FF432D28B453146FA72F90CFA90810B0E905C95FD99D1CA4009BA3D56C783853751EA74482C53C49667C62DD588452473FFECA835B5233B1BDACD4C461560635204DF8EE674C0A3AD63E4C63D787B6602B0902306DC145354C05B7DD74EDED34D5DE4F05379851E36612C9D3BA3B8551BC558FCF7F705711D22AD4C7CD99931662B73DD647B1B3C1FB109A5850919EFB75774F64ECBEBD7808A0D69FBE124906CDD39B7552B03712FDF9B46399766E79B6BFCBBC75267496B257E40BA05CDB4E294C7353A2FCEA7C0983BF5E1599B71B2C975A682D29CDC9CEEEFE8E11676004C6F1217FB7726451A708A7C1F6CADEB00D2D81110771DEB9050B244B20DC787C58FBD07F2B4AE7467422249A4134D63E09BE26ED165EB1393F313B1877399C803B61E1860F5D8223054DD1F07835492C3AEFA48FDF71F123D7DE430DD1EA69D82B91B85176BF46306FC3D68CC43497A9D625584213BEF754FB0E8D64201FEA74DAE37E3D3BF6D58D1A7CA9502173C192E038DD7CEB5A16A7982044538021AE7B96A94B9941AF87AE879032F783108729EB366114DFCF7A68B440F26D752BEAE6433E90F857C13EAB1CCE1EC42D9897893488E4182"; + // Encrypt Options + public static final String FALSE = "FALSE"; + public static final String TRUE = "TRUE"; + public static final String STRICT = "STRICT"; + // Start: Connection Properties parsed in AbstractTest class for creating DataSource. public static final String INTEGRATED_SECURITY = "INTEGRATEDSECURITY"; public static final String USER = "USER";