Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default encryption to true and fixed tests #1697

Merged
merged 3 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package com.microsoft.sqlserver.jdbc;

import java.lang.reflect.Array;
import java.text.MessageFormat;
import java.util.logging.Level;


Expand Down Expand Up @@ -58,7 +60,8 @@ static boolean isDllLoaded() {
}
enabled = true;
} catch (UnsatisfiedLinkError e) {
temp = e;
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_UnableLoadAuthDll"));
temp = new UnsatisfiedLinkError(form.format(new Object[] {SQLServerDriver.AUTH_DLL_NAME}));
// This is not re-thrown on purpose - the constructor will terminate the properly with the appropriate error
// string
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ public String toString() {

enum SQLServerDriverBooleanProperty {
DISABLE_STATEMENT_POOLING("disableStatementPooling", true),
ENCRYPT("encrypt", false),
ENCRYPT("encrypt", true),
INTEGRATED_SECURITY("integratedSecurity", false),
LAST_UPDATE_COUNT("lastUpdateCount", true),
MULTI_SUBNET_FAILOVER("multiSubnetFailover", false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ protected Object[][] getContents() {
{"R_crClientUnrecoverable","The connection is broken and recovery is not possible. The connection is marked by the client driver as unrecoverable. No attempt was made to restore the connection."},
{"R_crClientSSLStateNotRecoverable", "The server did not preserve SSL encryption during a recovery attempt, connection recovery is not possible."},
{"R_crCommandCannotTimeOut", "Request failed to time out and SQLServerConnection does not exist"},
{"R_UnableLoadAuthDll", "Unable to load authentication DLL {0}"},
};
}
// @formatter:on
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ public static void teardown() throws Exception {

@BeforeAll
public static void testSetup() throws Exception {
connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true");
setConnection();

String activityIDTraceOn = Util.ACTIVITY_ID_TRACE_PROPERTY + "=on";
try (InputStream is = new ByteArrayInputStream(activityIDTraceOn.getBytes());) {
LogManager lm = LogManager.getLogManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ 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");

stmtColEncSetting = SQLServerStatementColumnEncryptionSetting.Enabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.List;
import java.util.Map;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
Expand Down Expand Up @@ -189,6 +190,12 @@ public static String[][] enclaveParams() throws Exception {
AbstractTest.enclaveAttestationProtocol[1]}};
}

@BeforeAll
public static void setupTests() throws Exception {
connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true");
setConnection();
}

/**
* Setup environment for test.
*
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/com/microsoft/sqlserver/jdbc/JDBC43Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import javax.sql.ConnectionPoolDataSource;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
Expand All @@ -30,6 +31,12 @@ public class JDBC43Test extends AbstractTest {
ShardingKey superShardingKey = null;
ShardingKey shardingKey = null;

@BeforeAll
public static void setupTests() throws Exception {
connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true");
setConnection();
}

/**
* Tests that we are throwing the unsupported exception for connectionBuilder()
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ void prepareMaxResultBuffer() {
* Signalizes error when creating TEST_TABLE
*/
@BeforeAll
static void createAndPopulateNCharTestTable() throws SQLException {
static void createAndPopulateNCharTestTable() throws Exception {
connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true");
setConnection();

String insertSQL = "INSERT INTO " + AbstractSQLGenerator.escapeIdentifier(TEST_TABLE_NAME) + " VALUES (?)";
int numberOfRows = 800;
int precision = 10;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ 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
LogManager.getLogManager().reset();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public class RegisterKeyStoreProviderTest extends AbstractTest {

@BeforeAll
public static void testSetup() throws Exception {
connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true");
setConnection();

singleKeyStoreProvider.put(dummyProviderName1, new DummyKeyStoreProvider());

multipleKeyStoreProviders.put(dummyProviderName2, new DummyKeyStoreProvider());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import javax.sql.ConnectionEvent;
import javax.sql.PooledConnection;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
Expand All @@ -48,6 +49,12 @@ public class SQLServerConnectionTest extends AbstractTest {

String randomServer = RandomUtil.getIdentifier("Server");

@BeforeAll
public static void setupTests() throws Exception {
connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true");
setConnection();
}

/**
* Test connection properties with SQLServerDataSource
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.logging.Logger;
import java.util.stream.Stream;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
Expand All @@ -32,6 +33,12 @@ public class SQLServerDriverTest extends AbstractTest {
String randomServer = RandomUtil.getIdentifier("Server");
static final Logger logger = Logger.getLogger("SQLServerDriverTest");

@BeforeAll
public static void setupTests() throws Exception {
connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true");
setConnection();
}

/**
* Tests the stream<Driver> drivers() methods in java.sql.DriverManager
*
Expand Down
5 changes: 4 additions & 1 deletion src/test/java/com/microsoft/sqlserver/jdbc/TimeoutTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ public class TimeoutTest extends AbstractTest {
private static final String WAIT_FOR_ONE_MINUTE_SQL = "WAITFOR DELAY '00:01:00'";

@BeforeAll
public static void beforeAll() throws SQLException, InterruptedException {
public static void beforeAll() throws Exception {
connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true");
setConnection();

if (connection != null) {
connection.close();
connection = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.sql.SQLException;
import java.sql.Statement;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
Expand All @@ -31,6 +32,12 @@ public class BulkCopyAllTypesTest extends AbstractTest {
private static DBTable tableSrc = null;
private static DBTable tableDest = null;

@BeforeAll
public static void setupTests() throws Exception {
connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true");
setConnection();
}

/**
* Test TVP with result set
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ public class BulkCopyCSVTest extends AbstractTest {
* Create connection, statement and generate path of resource file
*/
@BeforeAll
public static void setUpConnection() {
public static void setUpConnection() throws Exception {
connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true");
setConnection();

con = new DBConnection(connectionString);
stmt = con.createStatement();
filePath = TestUtils.getCurrentClassPath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Map;
import java.util.Set;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -51,6 +52,12 @@
@Tag(Constants.xAzureSQLDW)
public class BulkCopyISQLServerBulkRecordTest extends AbstractTest {

@BeforeAll
public static void setupTests() throws Exception {
connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true");
setConnection();
}

@Test
public void testISQLServerBulkRecord() throws SQLException {
DBTable dstTable = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.TimeZone;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
Expand Down Expand Up @@ -50,6 +51,12 @@ public class BulkCopyResultSetCursorTest extends AbstractTest {
private static String srcTable = RandomUtil.getIdentifier("BulkCopyResultSetCursorTest_SourceTable");
private static String desTable = RandomUtil.getIdentifier("BulkCopyResultSetCursorTest_DestinationTable");

@BeforeAll
public static void setupTests() throws Exception {
connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true");
setConnection();
}

/**
* Test a previous failure when using server cursor and using the same connection to create Bulk Copy and result
* set.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ 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()) {
String sql1 = "create table " + tableName + " (c1 float, c2 real)";
stmt.execute(sql1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,9 @@ private void beforeEachSetup() throws SQLException {
}

@BeforeAll
public static void setupTest() throws SQLException {
public static void setupTest() throws Exception {
connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true");
setConnection();
filePath = TestUtils.getCurrentClassPath();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.sql.SQLException;

import com.microsoft.sqlserver.jdbc.TestUtils;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.platform.runner.JUnitPlatform;
Expand All @@ -32,7 +33,10 @@ public class BulkCopyTestSetUp extends AbstractTest {
* @throws SQLException
*/
@BeforeAll
public static void setUpSourceTable() throws SQLException {
public static void setUpSourceTable() throws Exception {
connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true");
setConnection();

try (DBConnection con = new DBConnection(connectionString); DBStatement stmt = con.createStatement();
DBPreparedStatement pstmt = new DBPreparedStatement(con);) {
sourceTable = new DBTable(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ public class ISQLServerBulkRecordIssuesTest extends AbstractTest {

String variation;

@BeforeAll
public static void setupTests() throws Exception {
connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true");
setConnection();
}

/**
* Testing that sending a bigger varchar(3) to varchar(2) is thowing the proper error message.
*
Expand Down
6 changes: 5 additions & 1 deletion src/test/java/com/microsoft/sqlserver/jdbc/bvt/BvtTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.microsoft.sqlserver.jdbc.TestUtils;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
Expand Down Expand Up @@ -438,7 +439,10 @@ public static void terminate() throws SQLException {
}

@BeforeAll
public static void init() throws SQLException {
public static void init() throws Exception {
connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true");
setConnection();

try (DBConnection conn = new DBConnection(connectionString); DBStatement stmt = conn.createStatement()) {
// create tables
table1 = new DBTable(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.sql.Statement;
import java.util.UUID;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
Expand All @@ -28,6 +29,12 @@
@Tag(Constants.xAzureSQLDW)
public class CallableMixedTest extends AbstractTest {

@BeforeAll
public static void setupTests() throws Exception {
connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true");
setConnection();
}

@Test
public void datatypestest() throws Exception {
String tableName = RandomUtil.getIdentifier("TFOO3");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ public class CallableStatementTest extends AbstractTest {
* @throws SQLException
*/
@BeforeAll
public static void setupTest() throws SQLException {
public static void setupTest() throws Exception {
connectionString = TestUtils.addOrOverrideProperty(connectionString,"trustServerCertificate", "true");
setConnection();

try (Statement stmt = connection.createStatement()) {
TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableNameGUID), stmt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.sql.ResultSet;
import java.sql.Statement;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
Expand Down Expand Up @@ -48,6 +49,13 @@ public class ClientCertificateAuthenticationTest extends AbstractTest {
static final String PFX_KEY_SUFFIX = ".pfx;";
static final String ENCRYPTED_PFX_KEY_SUFFIX = "-encrypted.pfx;";

@BeforeAll
public static void setupTests() throws Exception {
//Turn off default encrypt true
connectionString = TestUtils.addOrOverrideProperty(connectionString,"encrypt", "false");
setConnection();
}

/**
* Tests client certificate authentication feature with PKCS1 private key.
*
Expand Down
Loading