From c97b863c95385bdcd1afc897ef39cbebaf495578 Mon Sep 17 00:00:00 2001 From: lilgreenbird Date: Wed, 5 Feb 2020 11:03:48 -0800 Subject: [PATCH 1/8] Fix AEv2 tests exclude for reqExternalSetup and cleanup (#1247) --- .../jdbc/AlwaysEncrypted/AESetup.java | 179 ++-- .../CallableStatementTest.java | 431 ++++----- .../jdbc/AlwaysEncrypted/EnclaveTest.java | 6 +- .../JDBCEncryptionDecryptionTest.java | 885 ++++++++++++++---- .../AlwaysEncrypted/PrecisionScaleTest.java | 27 +- .../RegressionAlwaysEncryptedTest.java | 31 +- .../sqlserver/testframework/AbstractTest.java | 4 +- 7 files changed, 1028 insertions(+), 535 deletions(-) diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java index 2b988d029e..b21e45e9cf 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java @@ -75,13 +75,18 @@ public class AESetup extends AbstractTest { protected static boolean isAEv2 = false; - public static final String tableName = RandomUtil.getIdentifier("AETest_"); - public static final String CHAR_TABLE_AE = RandomUtil.getIdentifier("JDBCEncryptedChar"); - public static final String BINARY_TABLE_AE = RandomUtil.getIdentifier("JDBCEncryptedBinary"); - public static final String DATE_TABLE_AE = RandomUtil.getIdentifier("JDBCEncryptedDate"); - public static final String NUMERIC_TABLE_AE = RandomUtil.getIdentifier("JDBCEncryptedNumeric"); - public static final String SCALE_DATE_TABLE_AE = RandomUtil.getIdentifier("JDBCEncryptedScaleDate"); - private static final boolean isSqlLinux = false; + public static final String tableName = TestUtils + .escapeSingleQuotes(AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("AETest_"))); + public static final String CHAR_TABLE_AE = TestUtils + .escapeSingleQuotes(AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("JDBCEncryptedChar"))); + public static final String BINARY_TABLE_AE = TestUtils + .escapeSingleQuotes(AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("JDBCEncryptedBinary"))); + public static final String DATE_TABLE_AE = TestUtils + .escapeSingleQuotes(AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("JDBCEncryptedDate"))); + public static final String NUMERIC_TABLE_AE = TestUtils.escapeSingleQuotes( + AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("JDBCEncryptedNumeric"))); + public static final String SCALE_DATE_TABLE_AE = TestUtils.escapeSingleQuotes( + AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("JDBCEncryptedScaleDate"))); enum ColumnType { PLAIN, @@ -147,6 +152,9 @@ enum ColumnType { "PlainMoney money", "PlainDecimal2 decimal(28,4)", "PlainNumeric2 numeric(28,4)", "PlainFloat float(30)", "PlainDecimal decimal(30)", "PlainNumeric numeric(30)"}; + // junit test parameters: serverName, enclaveAttestationUrl, enclaveAttestationProtocol + static String[][] param = new String[AbstractTest.enclaveServer.length][3]; + /** * This provides the arguments (serverName, enclaveAttestationUrl, enclaveAttestationProtocol) for the parameterized * tests using MethodSource parameters @@ -154,17 +162,7 @@ enum ColumnType { * @return parameters for the tests * @throws Exception */ - public static String[][] enclaveParams() throws Exception { - setup(); - - String[][] param = new String[AbstractTest.enclaveServer.length][3]; - - for (int i = 0; i < enclaveServer.length; i++) { - param[i][0] = enclaveServer[i]; - param[i][1] = null != enclaveAttestationUrl ? enclaveAttestationUrl[i] : null; - param[i][2] = null != enclaveAttestationProtocol ? enclaveAttestationProtocol[i] : null; - } - + static String[][] enclaveParams() throws Exception { return param; } @@ -175,9 +173,9 @@ public static String[][] enclaveParams() throws Exception { * @param url * @param protocol */ - void setAEConnectionString(String serverName, String url, String protocol) { + static void setAEConnectionString(String serverName, String url, String protocol) { // AEv2 is not supported on Linux servers - if (!isSqlLinux() && null != serverName) { + if (!isSqlLinux() && null != serverName && null != url && null != protocol) { enclaveProperties = "serverName=" + serverName + ";" + Constants.ENCLAVE_ATTESTATIONURL + "=" + url + ";" + Constants.ENCLAVE_ATTESTATIONPROTOCOL + "=" + protocol; AETestConnectionString = connectionString + ";sendTimeAsDateTime=false" + ";columnEncryptionSetting=enabled" @@ -194,14 +192,14 @@ void setAEConnectionString(String serverName, String url, String protocol) { } /** - * Check if AEv2 + * Setup AE connection string and check setup * * @param serverName * @param url * @param protocol * @throws SQLException */ - void checkAEv2(String serverName, String url, String protocol) throws SQLException { + void checkAESetup(String serverName, String url, String protocol) throws Exception { setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo)) { @@ -214,26 +212,8 @@ void checkAEv2(String serverName, String url, String protocol) throws SQLExcepti } } - void checkAESetup(String serverName, String url, String protocol) throws Exception { - checkAEv2(serverName, url, protocol); - - createCMK(cmkJks, Constants.JAVA_KEY_STORE_NAME, javaKeyAliases, Constants.CMK_SIGNATURE); - createCEK(cmkJks, cekJks, jksProvider); - - createCMK(cmkAkv, Constants.AZURE_KEY_VAULT_NAME, keyIDs[0], Constants.CMK_SIGNATURE_AKV); - createCEK(cmkAkv, cekAkv, akvProvider); - - createCMK(cmkWin, Constants.WINDOWS_KEY_STORE_NAME, windowsKeyPath, Constants.CMK_SIGNATURE); - createCEK(cmkWin, cekWin, null); - } - @BeforeAll - public static void getProperties() throws Exception { - if (null == applicationClientID || null == applicationKey || null == keyIDs - || (isWindows && null == windowsKeyPath)) { - fail("enclaveProperties: " + enclaveProperties + "\n" + TestResource.getResource("R_reqExternalSetup")); - } - + public static void setupAETest() throws Exception { readFromFile(Constants.JAVA_KEY_STORE_FILENAME, "Alias name"); stmtColEncSetting = SQLServerStatementColumnEncryptionSetting.Enabled; @@ -246,6 +226,32 @@ public static void getProperties() throws Exception { // reset logging to avoid severe logs due to negative testing LogManager.getLogManager().reset(); + + // setup test params and encryption keys on each server + for (int i = 0; i < enclaveServer.length; i++) { + String serverName = enclaveServer[i]; + String url = null != enclaveAttestationUrl ? enclaveAttestationUrl[i] : null; + String protocol = null != enclaveAttestationProtocol ? enclaveAttestationProtocol[i] : null; + + param[i][0] = serverName; + param[i][1] = url; + param[i][2] = protocol; + + setAEConnectionString(serverName, url, protocol); + + createCMK(cmkJks, Constants.JAVA_KEY_STORE_NAME, javaKeyAliases, Constants.CMK_SIGNATURE); + createCEK(cmkJks, cekJks, jksProvider); + + if (null != keyIDs && !keyIDs[0].isEmpty()) { + createCMK(cmkAkv, Constants.AZURE_KEY_VAULT_NAME, keyIDs[0], Constants.CMK_SIGNATURE_AKV); + createCEK(cmkAkv, cekAkv, akvProvider); + } + + if (null != windowsKeyPath) { + createCMK(cmkWin, Constants.WINDOWS_KEY_STORE_NAME, windowsKeyPath, Constants.CMK_SIGNATURE); + createCEK(cmkWin, cekWin, null); + } + } } /** @@ -336,8 +342,8 @@ protected static void createTable(String tableName, String cekName, String table sql += ColumnType.RANDOMIZED.name() + table[i][0] + " " + table[i][1] + String.format(encryptSql, ColumnType.RANDOMIZED.name(), cekName) + ") NULL,"; } - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); - sql = String.format(createSql, AbstractSQLGenerator.escapeIdentifier(tableName), sql); + TestUtils.dropTableIfExists(tableName, stmt); + sql = String.format(createSql, tableName, sql); stmt.execute(sql); stmt.execute("DBCC FREEPROCCACHE"); } catch (SQLException e) { @@ -371,7 +377,7 @@ protected static void createPrecisionTable(String tableName, String table[][], S + ") NULL,"; } } - sql = String.format(createSql, AbstractSQLGenerator.escapeIdentifier(tableName), sql); + sql = String.format(createSql, tableName, sql); stmt.execute(sql); stmt.execute("DBCC FREEPROCCACHE"); } catch (SQLException e) { @@ -399,7 +405,7 @@ protected static void createScaleTable(String tableName, String table[][], Strin + String.format(encryptSql, ColumnType.DETERMINISTIC.name(), cekName) + ") NULL,"; } - sql = String.format(createSql, AbstractSQLGenerator.escapeIdentifier(tableName), sql); + sql = String.format(createSql, tableName, sql); stmt.execute(sql); stmt.execute("DBCC FREEPROCCACHE"); } catch (SQLException e) { @@ -574,10 +580,10 @@ private static void createCEK(String cmkName, String cekName, * @throws SQLException */ protected static void dropTables(Statement stmt) throws SQLException { - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(NUMERIC_TABLE_AE), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(CHAR_TABLE_AE), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(BINARY_TABLE_AE), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(DATE_TABLE_AE), stmt); + TestUtils.dropTableIfExists(NUMERIC_TABLE_AE, stmt); + TestUtils.dropTableIfExists(CHAR_TABLE_AE, stmt); + TestUtils.dropTableIfExists(BINARY_TABLE_AE, stmt); + TestUtils.dropTableIfExists(DATE_TABLE_AE, stmt); } /** @@ -587,8 +593,8 @@ protected static void dropTables(Statement stmt) throws SQLException { * @throws SQLException */ protected static void populateBinaryNormalCase(LinkedList byteValues) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(BINARY_TABLE_AE) + " values( " + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + String sql = "insert into " + BINARY_TABLE_AE + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + + "?,?,?" + ")"; try (SQLServerConnection con = (SQLServerConnection) PrepUtil .getConnection(AETestConnectionString + ";sendTimeAsDateTime=false", AEInfo); @@ -651,8 +657,8 @@ protected static void populateBinaryNormalCase(LinkedList byteValues) th * @throws SQLException */ protected static void populateBinarySetObject(LinkedList byteValues) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(BINARY_TABLE_AE) + " values( " + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + String sql = "insert into " + BINARY_TABLE_AE + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + + "?,?,?" + ")"; try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, stmtColEncSetting)) { @@ -713,8 +719,8 @@ protected static void populateBinarySetObject(LinkedList byteValues) thr * @throws SQLException */ protected static void populateBinarySetObjectWithJDBCType(LinkedList byteValues) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(BINARY_TABLE_AE) + " values( " + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + String sql = "insert into " + BINARY_TABLE_AE + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + + "?,?,?" + ")"; try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, @@ -775,8 +781,8 @@ protected static void populateBinarySetObjectWithJDBCType(LinkedList byt * @throws SQLException */ protected static void populateBinaryNullCase() throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(BINARY_TABLE_AE) + " values( " + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + String sql = "insert into " + BINARY_TABLE_AE + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + + "?,?,?" + ")"; try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, @@ -813,8 +819,8 @@ protected static void populateBinaryNullCase() throws SQLException { * @throws SQLException */ protected static void populateCharNormalCase(String[] charValues) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(CHAR_TABLE_AE) + " values( " + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + String sql = "insert into " + CHAR_TABLE_AE + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, @@ -880,8 +886,8 @@ protected static void populateCharNormalCase(String[] charValues) throws SQLExce * @throws SQLException */ protected static void populateCharSetObject(String[] charValues) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(CHAR_TABLE_AE) + " values( " + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + String sql = "insert into " + CHAR_TABLE_AE + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, @@ -943,8 +949,8 @@ protected static void populateCharSetObject(String[] charValues) throws SQLExcep * @throws SQLException */ protected static void populateCharSetObjectWithJDBCTypes(String[] charValues) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(CHAR_TABLE_AE) + " values( " + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + String sql = "insert into " + CHAR_TABLE_AE + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, @@ -1005,8 +1011,8 @@ protected static void populateCharSetObjectWithJDBCTypes(String[] charValues) th * @throws SQLException */ protected static void populateCharNullCase() throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(CHAR_TABLE_AE) + " values( " + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + String sql = "insert into " + CHAR_TABLE_AE + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, @@ -1059,8 +1065,8 @@ protected static void populateCharNullCase() throws SQLException { * @throws SQLException */ protected static void populateDateNormalCase(LinkedList dateValues) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(DATE_TABLE_AE) + " values( " + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + String sql = "insert into " + DATE_TABLE_AE + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + + "?,?,?" + ")"; try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, @@ -1106,8 +1112,7 @@ protected static void populateDateNormalCase(LinkedList dateValues) thro * @throws SQLException */ protected static void populateDateScaleNormalCase(LinkedList dateValues) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(SCALE_DATE_TABLE_AE) + " values( " - + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + String sql = "insert into " + SCALE_DATE_TABLE_AE + " values( " + "?,?,?," + "?,?,?," + "?,?,?" + ")"; try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, @@ -1141,8 +1146,8 @@ protected static void populateDateScaleNormalCase(LinkedList dateValues) */ protected static void populateDateSetObject(LinkedList dateValues, String setter) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(DATE_TABLE_AE) + " values( " + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + String sql = "insert into " + DATE_TABLE_AE + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + + "?,?,?" + ")"; try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, @@ -1208,8 +1213,8 @@ else if (setter.equalsIgnoreCase("setwithJDBCType")) * @throws SQLException */ protected void populateDateSetObjectNull() throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(DATE_TABLE_AE) + " values( " + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + String sql = "insert into " + DATE_TABLE_AE + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + + "?,?,?" + ")"; try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, @@ -1255,8 +1260,8 @@ protected void populateDateSetObjectNull() throws SQLException { * @throws SQLException */ protected static void populateDateNullCase() throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(DATE_TABLE_AE) + " values( " + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + String sql = "insert into " + DATE_TABLE_AE + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + + "?,?,?" + ")"; try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, @@ -1303,9 +1308,9 @@ protected static void populateDateNullCase() throws SQLException { * @throws SQLException */ protected static void populateNumeric(String[] values) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(NUMERIC_TABLE_AE) + " values( " + "?,?,?," + String sql = "insert into " + NUMERIC_TABLE_AE + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + + "?,?,?," + "?,?,?," + "?,?,?" + ")"; try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, @@ -1412,9 +1417,9 @@ protected static void populateNumeric(String[] values) throws SQLException { * @throws SQLException */ protected static void populateNumericSetObject(String[] values) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(NUMERIC_TABLE_AE) + " values( " + "?,?,?," + String sql = "insert into " + NUMERIC_TABLE_AE + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + + "?,?,?," + "?,?,?," + "?,?,?" + ")"; try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, @@ -1521,9 +1526,9 @@ protected static void populateNumericSetObject(String[] values) throws SQLExcept * @throws SQLException */ protected static void populateNumericSetObjectWithJDBCTypes(String[] values) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(NUMERIC_TABLE_AE) + " values( " + "?,?,?," + String sql = "insert into " + NUMERIC_TABLE_AE + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + + "?,?,?," + "?,?,?," + "?,?,?" + ")"; try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, @@ -1629,9 +1634,9 @@ protected static void populateNumericSetObjectWithJDBCTypes(String[] values) thr * @throws SQLException */ protected static void populateNumericSetObjectNull() throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(NUMERIC_TABLE_AE) + " values( " + "?,?,?," + String sql = "insert into " + NUMERIC_TABLE_AE + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + + "?,?,?," + "?,?,?," + "?,?,?" + ")"; try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, @@ -1728,9 +1733,9 @@ protected static void populateNumericSetObjectNull() throws SQLException { * @throws SQLException */ protected static void populateNumericNullCase(String[] values) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(NUMERIC_TABLE_AE) + " values( " + "?,?,?," + String sql = "insert into " + NUMERIC_TABLE_AE + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + + "?,?,?," + "?,?,?," + "?,?,?" + ")"; @@ -1828,9 +1833,9 @@ protected static void populateNumericNullCase(String[] values) throws SQLExcepti * @throws SQLException */ protected static void populateNumericNormalCase(String[] numericValues) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(NUMERIC_TABLE_AE) + " values( " + "?,?,?," + String sql = "insert into " + NUMERIC_TABLE_AE + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + + "?,?,?," + "?,?,?," + "?,?,?" + ")"; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java index 3d092bc347..eaa9f48970 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java @@ -20,6 +20,7 @@ import java.util.LinkedList; import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Tag; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; @@ -51,32 +52,55 @@ @Tag(Constants.xAzureSQLDB) public class CallableStatementTest extends AESetup { - private static String multiStatementsProcedure = RandomUtil.getIdentifier("multiStatementsProcedure"); - private static String inputProcedure = RandomUtil.getIdentifier("inputProcedure"); - private static String inputProcedure2 = RandomUtil.getIdentifier("inputProcedure2"); - private static String outputProcedure = RandomUtil.getIdentifier("outputProcedure"); - private static String outputProcedure2 = RandomUtil.getIdentifier("outputProcedure2"); - private static String outputProcedure3 = RandomUtil.getIdentifier("outputProcedure3"); - private static String outputProcedure4 = RandomUtil.getIdentifier("outputProcedure4"); - private static String outputProcedureChar = RandomUtil.getIdentifier("outputProcedureChar"); - private static String outputProcedureNumeric = RandomUtil.getIdentifier("outputProcedureNumeric"); - private static String outputProcedureBinary = RandomUtil.getIdentifier("outputProcedureBinary"); - private static String outputProcedureDate = RandomUtil.getIdentifier("outputProcedureDate"); - private static String outputProcedureDateScale = RandomUtil.getIdentifier("outputProcedureDateScale"); - private static String outputProcedureBatch = RandomUtil.getIdentifier("outputProcedureBatch"); - private static String inoutProcedure = RandomUtil.getIdentifier("inoutProcedure"); - private static String mixedProcedure = RandomUtil.getIdentifier("mixedProcedure"); - private static String mixedProcedure2 = RandomUtil.getIdentifier("mixedProcedure2"); - private static String mixedProcedure3 = RandomUtil.getIdentifier("mixedProcedure3"); - private static String mixedProcedureNumericPrcisionScale = RandomUtil - .getIdentifier("mixedProcedureNumericPrcisionScale"); - - private static String table1 = RandomUtil.getIdentifier("StoredProcedure_table1"); - private static String table2 = RandomUtil.getIdentifier("StoredProcedure_table2"); - private static String table3 = RandomUtil.getIdentifier("StoredProcedure_table3"); - private static String table4 = RandomUtil.getIdentifier("StoredProcedure_table4"); - private static String table5 = RandomUtil.getIdentifier("StoredProcedure_table5"); - private static String table6 = RandomUtil.getIdentifier("StoredProcedure_table6"); + private static String multiStatementsProcedure = AbstractSQLGenerator + .escapeIdentifier(RandomUtil.getIdentifier("multiStatementsProcedure")); + private static String inputProcedure = AbstractSQLGenerator + .escapeIdentifier(RandomUtil.getIdentifier("inputProcedure")); + private static String inputProcedure2 = AbstractSQLGenerator + .escapeIdentifier(RandomUtil.getIdentifier("inputProcedure2")); + private static String outputProcedure = AbstractSQLGenerator + .escapeIdentifier(RandomUtil.getIdentifier("outputProcedure")); + private static String outputProcedure2 = AbstractSQLGenerator + .escapeIdentifier(RandomUtil.getIdentifier("outputProcedure2")); + private static String outputProcedure3 = AbstractSQLGenerator + .escapeIdentifier(RandomUtil.getIdentifier("outputProcedure3")); + private static String outputProcedure4 = AbstractSQLGenerator + .escapeIdentifier(RandomUtil.getIdentifier("outputProcedure4")); + private static String outputProcedureChar = AbstractSQLGenerator + .escapeIdentifier(RandomUtil.getIdentifier("outputProcedureChar")); + private static String outputProcedureNumeric = AbstractSQLGenerator + .escapeIdentifier(RandomUtil.getIdentifier("outputProcedureNumeric")); + private static String outputProcedureBinary = AbstractSQLGenerator + .escapeIdentifier(RandomUtil.getIdentifier("outputProcedureBinary")); + private static String outputProcedureDate = AbstractSQLGenerator + .escapeIdentifier(RandomUtil.getIdentifier("outputProcedureDate")); + private static String outputProcedureDateScale = AbstractSQLGenerator + .escapeIdentifier(RandomUtil.getIdentifier("outputProcedureDateScale")); + private static String outputProcedureBatch = AbstractSQLGenerator + .escapeIdentifier(RandomUtil.getIdentifier("outputProcedureBatch")); + private static String inoutProcedure = AbstractSQLGenerator + .escapeIdentifier(RandomUtil.getIdentifier("inoutProcedure")); + private static String mixedProcedure = AbstractSQLGenerator + .escapeIdentifier(RandomUtil.getIdentifier("mixedProcedure")); + private static String mixedProcedure2 = AbstractSQLGenerator + .escapeIdentifier(RandomUtil.getIdentifier("mixedProcedure2")); + private static String mixedProcedure3 = AbstractSQLGenerator + .escapeIdentifier(RandomUtil.getIdentifier("mixedProcedure3")); + private static String mixedProcedureNumericPrecisionScale = AbstractSQLGenerator + .escapeIdentifier(RandomUtil.getIdentifier("mixedProcedureNumericPrecisionScale")); + + private static String table1 = TestUtils.escapeSingleQuotes( + AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("StoredProcedure_table1"))); + private static String table2 = TestUtils.escapeSingleQuotes( + AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("StoredProcedure_table2"))); + private static String table3 = TestUtils.escapeSingleQuotes( + AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("StoredProcedure_table3"))); + private static String table4 = TestUtils.escapeSingleQuotes( + AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("StoredProcedure_table4"))); + private static String table5 = TestUtils.escapeSingleQuotes( + AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("StoredProcedure_table5"))); + private static String table6 = TestUtils.escapeSingleQuotes( + AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("StoredProcedure_table6"))); private static String[] numericValues; private static LinkedList byteValues; @@ -101,15 +125,20 @@ public class CallableStatementTest extends AESetup { * * @throws SQLException */ - public void initCallableStatementTest() throws Exception { + @BeforeAll + public static void initValues() throws Exception { dropAll(); numericValues = createNumericValues(nullable); byteValues = createBinaryValues(nullable); dateValues = createTemporalTypesCallableStatement(nullable); charValues = createCharValues(nullable); + } + + void initCallableStatementTest() throws Exception { + dropAll(); - createTables(cekJks); + createSPTables(cekJks); populateTable3(); populateTable4(); @@ -150,9 +179,7 @@ public void testInputProcedureNumeric(String serverName, String url, String prot initCallableStatementTest(); createInputProcedure(); - testInputProcedure( - "{call " + AbstractSQLGenerator.escapeIdentifier(inputProcedure) + "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}", - numericValues); + testInputProcedure("{call " + inputProcedure + "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}", numericValues); } @ParameterizedTest @@ -162,7 +189,7 @@ public void testInputProcedureChar(String serverName, String url, String protoco initCallableStatementTest(); createInputProcedure2(); - testInputProcedure2("{call " + AbstractSQLGenerator.escapeIdentifier(inputProcedure2) + "(?,?,?,?,?,?,?,?)}"); + testInputProcedure2("{call " + inputProcedure2 + "(?,?,?,?,?,?,?,?)}"); } @ParameterizedTest @@ -172,14 +199,10 @@ public void testEncryptedOutputNumericParams(String serverName, String url, Stri initCallableStatementTest(); createOutputProcedure(); - testOutputProcedureRandomOrder( - "{call " + AbstractSQLGenerator.escapeIdentifier(outputProcedure) + "(?,?,?,?,?,?,?)}", numericValues); - testOutputProcedureInorder( - "{call " + AbstractSQLGenerator.escapeIdentifier(outputProcedure) + "(?,?,?,?,?,?,?)}", numericValues); - testOutputProcedureReverseOrder( - "{call " + AbstractSQLGenerator.escapeIdentifier(outputProcedure) + "(?,?,?,?,?,?,?)}", numericValues); - testOutputProcedureRandomOrder( - "exec " + AbstractSQLGenerator.escapeIdentifier(outputProcedure) + " ?,?,?,?,?,?,?", numericValues); + testOutputProcedureRandomOrder("{call " + outputProcedure + "(?,?,?,?,?,?,?)}", numericValues); + testOutputProcedureInorder("{call " + outputProcedure + "(?,?,?,?,?,?,?)}", numericValues); + testOutputProcedureReverseOrder("{call " + outputProcedure + "(?,?,?,?,?,?,?)}", numericValues); + testOutputProcedureRandomOrder("exec " + outputProcedure + " ?,?,?,?,?,?,?", numericValues); } @ParameterizedTest @@ -190,15 +213,9 @@ public void testUnencryptedAndEncryptedNumericOutputParams(String serverName, St initCallableStatementTest(); createOutputProcedure2(); - testOutputProcedure2RandomOrder( - "{call " + AbstractSQLGenerator.escapeIdentifier(outputProcedure2) + "(?,?,?,?,?,?,?,?,?,?)}", - numericValues); - testOutputProcedure2Inorder( - "{call " + AbstractSQLGenerator.escapeIdentifier(outputProcedure2) + "(?,?,?,?,?,?,?,?,?,?)}", - numericValues); - testOutputProcedure2ReverseOrder( - "{call " + AbstractSQLGenerator.escapeIdentifier(outputProcedure2) + "(?,?,?,?,?,?,?,?,?,?)}", - numericValues); + testOutputProcedure2RandomOrder("{call " + outputProcedure2 + "(?,?,?,?,?,?,?,?,?,?)}", numericValues); + testOutputProcedure2Inorder("{call " + outputProcedure2 + "(?,?,?,?,?,?,?,?,?,?)}", numericValues); + testOutputProcedure2ReverseOrder("{call " + outputProcedure2 + "(?,?,?,?,?,?,?,?,?,?)}", numericValues); } @ParameterizedTest @@ -209,9 +226,9 @@ public void testEncryptedOutputParamsFromDifferentTables(String serverName, Stri initCallableStatementTest(); createOutputProcedure3(); - testOutputProcedure3RandomOrder("{call " + AbstractSQLGenerator.escapeIdentifier(outputProcedure3) + "(?,?)}"); - testOutputProcedure3Inorder("{call " + AbstractSQLGenerator.escapeIdentifier(outputProcedure3) + "(?,?)}"); - testOutputProcedure3ReverseOrder("{call " + AbstractSQLGenerator.escapeIdentifier(outputProcedure3) + "(?,?)}"); + testOutputProcedure3RandomOrder("{call " + outputProcedure3 + "(?,?)}"); + testOutputProcedure3Inorder("{call " + outputProcedure3 + "(?,?)}"); + testOutputProcedure3ReverseOrder("{call " + outputProcedure3 + "(?,?)}"); } @ParameterizedTest @@ -221,8 +238,8 @@ public void testInOutProcedure(String serverName, String url, String protocol) t initCallableStatementTest(); createInOutProcedure(); - testInOutProcedure("{call " + AbstractSQLGenerator.escapeIdentifier(inoutProcedure) + "(?)}"); - testInOutProcedure("exec " + AbstractSQLGenerator.escapeIdentifier(inoutProcedure) + " ?"); + testInOutProcedure("{call " + inoutProcedure + "(?)}"); + testInOutProcedure("exec " + inoutProcedure + " ?"); } @ParameterizedTest @@ -232,7 +249,7 @@ public void testMixedProcedure(String serverName, String url, String protocol) t initCallableStatementTest(); createMixedProcedure(); - testMixedProcedure("{ ? = call " + AbstractSQLGenerator.escapeIdentifier(mixedProcedure) + "(?,?,?)}"); + testMixedProcedure("{ ? = call " + mixedProcedure + "(?,?,?)}"); } @ParameterizedTest @@ -244,9 +261,8 @@ public void testUnencryptedAndEncryptedIOParams(String serverName, String url, S // unencrypted input and output parameter // encrypted input and output parameter createMixedProcedure2(); - testMixedProcedure2RandomOrder( - "{call " + AbstractSQLGenerator.escapeIdentifier(mixedProcedure2) + "(?,?,?,?)}"); - testMixedProcedure2Inorder("{call " + AbstractSQLGenerator.escapeIdentifier(mixedProcedure2) + "(?,?,?,?)}"); + testMixedProcedure2RandomOrder("{call " + mixedProcedure2 + "(?,?,?,?)}"); + testMixedProcedure2Inorder("{call " + mixedProcedure2 + "(?,?,?,?)}"); } @ParameterizedTest @@ -256,11 +272,9 @@ public void testUnencryptedIOParams(String serverName, String url, String protoc initCallableStatementTest(); createMixedProcedure3(); - testMixedProcedure3RandomOrder( - "{call " + AbstractSQLGenerator.escapeIdentifier(mixedProcedure3) + "(?,?,?,?)}"); - testMixedProcedure3Inorder("{call " + AbstractSQLGenerator.escapeIdentifier(mixedProcedure3) + "(?,?,?,?)}"); - testMixedProcedure3ReverseOrder( - "{call " + AbstractSQLGenerator.escapeIdentifier(mixedProcedure3) + "(?,?,?,?)}"); + testMixedProcedure3RandomOrder("{call " + mixedProcedure3 + "(?,?,?,?)}"); + testMixedProcedure3Inorder("{call " + mixedProcedure3 + "(?,?,?,?)}"); + testMixedProcedure3ReverseOrder("{call " + mixedProcedure3 + "(?,?,?,?)}"); } @ParameterizedTest @@ -269,11 +283,10 @@ public void testVariousIOParams(String serverName, String url, String protocol) checkAESetup(serverName, url, protocol); initCallableStatementTest(); - createMixedProcedureNumericPrcisionScale(); - testMixedProcedureNumericPrcisionScaleInorder( - "{call " + AbstractSQLGenerator.escapeIdentifier(mixedProcedureNumericPrcisionScale) + "(?,?,?,?)}"); - testMixedProcedureNumericPrcisionScaleParameterName( - "{call " + AbstractSQLGenerator.escapeIdentifier(mixedProcedureNumericPrcisionScale) + "(?,?,?,?)}"); + createmixedProcedureNumericPrecisionScale(); + testmixedProcedureNumericPrecisionScaleInorder("{call " + mixedProcedureNumericPrecisionScale + "(?,?,?,?)}"); + testmixedProcedureNumericPrecisionScaleParameterName( + "{call " + mixedProcedureNumericPrecisionScale + "(?,?,?,?)}"); } @ParameterizedTest @@ -283,10 +296,8 @@ public void testOutputProcedureChar(String serverName, String url, String protoc initCallableStatementTest(); createOutputProcedureChar(); - testOutputProcedureCharInorder( - "{call " + AbstractSQLGenerator.escapeIdentifier(outputProcedureChar) + "(?,?,?,?,?,?,?,?,?)}"); - testOutputProcedureCharInorderObject( - "{call " + AbstractSQLGenerator.escapeIdentifier(outputProcedureChar) + "(?,?,?,?,?,?,?,?,?)}"); + testOutputProcedureCharInorder("{call " + outputProcedureChar + "(?,?,?,?,?,?,?,?,?)}"); + testOutputProcedureCharInorderObject("{call " + outputProcedureChar + "(?,?,?,?,?,?,?,?,?)}"); } @ParameterizedTest @@ -296,10 +307,9 @@ public void testOutputProcedureNumeric(String serverName, String url, String pro initCallableStatementTest(); createOutputProcedureNumeric(); - testOutputProcedureNumericInorder("{call " + AbstractSQLGenerator.escapeIdentifier(outputProcedureNumeric) - + "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}"); - testcoerctionsOutputProcedureNumericInorder("{call " - + AbstractSQLGenerator.escapeIdentifier(outputProcedureNumeric) + "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}"); + testOutputProcedureNumericInorder("{call " + outputProcedureNumeric + "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}"); + testcoerctionsOutputProcedureNumericInorder( + "{call " + outputProcedureNumeric + "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}"); } @ParameterizedTest @@ -309,12 +319,9 @@ public void testOutputProcedureBinary(String serverName, String url, String prot initCallableStatementTest(); createOutputProcedureBinary(); - testOutputProcedureBinaryInorder( - "{call " + AbstractSQLGenerator.escapeIdentifier(outputProcedureBinary) + "(?,?,?,?,?)}"); - testOutputProcedureBinaryInorderObject( - "{call " + AbstractSQLGenerator.escapeIdentifier(outputProcedureBinary) + "(?,?,?,?,?)}"); - testOutputProcedureBinaryInorderString( - "{call " + AbstractSQLGenerator.escapeIdentifier(outputProcedureBinary) + "(?,?,?,?,?)}"); + testOutputProcedureBinaryInorder("{call " + outputProcedureBinary + "(?,?,?,?,?)}"); + testOutputProcedureBinaryInorderObject("{call " + outputProcedureBinary + "(?,?,?,?,?)}"); + testOutputProcedureBinaryInorderString("{call " + outputProcedureBinary + "(?,?,?,?,?)}"); } @ParameterizedTest @@ -324,10 +331,8 @@ public void testOutputProcedureDate(String serverName, String url, String protoc initCallableStatementTest(); createOutputProcedureDate(); - testOutputProcedureDateInorder("{call " + AbstractSQLGenerator.escapeIdentifier(outputProcedureDate) - + "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}"); - testOutputProcedureDateInorderObject("{call " + AbstractSQLGenerator.escapeIdentifier(outputProcedureDate) - + "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}"); + testOutputProcedureDateInorder("{call " + outputProcedureDate + "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}"); + testOutputProcedureDateInorderObject("{call " + outputProcedureDate + "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}"); } @ParameterizedTest @@ -337,10 +342,8 @@ public void testMixedProcedureDateScale(String serverName, String url, String pr initCallableStatementTest(); createMixedProcedureDateScale(); - testMixedProcedureDateScaleInorder( - "{call " + AbstractSQLGenerator.escapeIdentifier(outputProcedureDateScale) + "(?,?,?,?,?,?)}"); - testMixedProcedureDateScaleWithParameterName( - "{call " + AbstractSQLGenerator.escapeIdentifier(outputProcedureDateScale) + "(?,?,?,?,?,?)}"); + testMixedProcedureDateScaleInorder("{call " + outputProcedureDateScale + "(?,?,?,?,?,?)}"); + testMixedProcedureDateScaleWithParameterName("{call " + outputProcedureDateScale + "(?,?,?,?,?,?)}"); } @ParameterizedTest @@ -350,8 +353,7 @@ public void testOutputProcedureBatch(String serverName, String url, String proto initCallableStatementTest(); createOutputProcedureBatch(); - testOutputProcedureBatchInorder( - "{call " + AbstractSQLGenerator.escapeIdentifier(outputProcedureBatch) + "(?,?,?,?)}"); + testOutputProcedureBatchInorder("{call " + outputProcedureBatch + "(?,?,?,?)}"); } @ParameterizedTest @@ -365,51 +367,50 @@ public void testOutputProcedure4(String serverName, String url, String protocol) private static void dropProcedures() throws SQLException { try (Statement stmt = connection.createStatement()) { - TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(multiStatementsProcedure), stmt); - TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(inputProcedure), stmt); - TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(inputProcedure2), stmt); - TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(outputProcedure), stmt); - TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(outputProcedure2), stmt); - TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(outputProcedure3), stmt); - TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(outputProcedure4), stmt); - TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(outputProcedureChar), stmt); - TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(outputProcedureNumeric), stmt); - TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(outputProcedureBinary), stmt); - TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(outputProcedureDate), stmt); - TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(outputProcedureDateScale), stmt); - TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(outputProcedureBatch), stmt); - TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(inoutProcedure), stmt); - TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(mixedProcedure), stmt); - TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(mixedProcedure2), stmt); - TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(mixedProcedure3), stmt); - TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(mixedProcedureNumericPrcisionScale), - stmt); + TestUtils.dropProcedureIfExists(multiStatementsProcedure, stmt); + TestUtils.dropProcedureIfExists(inputProcedure, stmt); + TestUtils.dropProcedureIfExists(inputProcedure2, stmt); + TestUtils.dropProcedureIfExists(outputProcedure, stmt); + TestUtils.dropProcedureIfExists(outputProcedure2, stmt); + TestUtils.dropProcedureIfExists(outputProcedure3, stmt); + TestUtils.dropProcedureIfExists(outputProcedure4, stmt); + TestUtils.dropProcedureIfExists(outputProcedureChar, stmt); + TestUtils.dropProcedureIfExists(outputProcedureNumeric, stmt); + TestUtils.dropProcedureIfExists(outputProcedureBinary, stmt); + TestUtils.dropProcedureIfExists(outputProcedureDate, stmt); + TestUtils.dropProcedureIfExists(outputProcedureDateScale, stmt); + TestUtils.dropProcedureIfExists(outputProcedureBatch, stmt); + TestUtils.dropProcedureIfExists(inoutProcedure, stmt); + TestUtils.dropProcedureIfExists(mixedProcedure, stmt); + TestUtils.dropProcedureIfExists(mixedProcedure2, stmt); + TestUtils.dropProcedureIfExists(mixedProcedure3, stmt); + TestUtils.dropProcedureIfExists(mixedProcedureNumericPrecisionScale, stmt); } } private static void dropTables() throws SQLException { try (Statement stmt = connection.createStatement()) { - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table1), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table2), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table3), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table4), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(CHAR_TABLE_AE), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(NUMERIC_TABLE_AE), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(BINARY_TABLE_AE), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(DATE_TABLE_AE), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table5), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table6), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(SCALE_DATE_TABLE_AE), stmt); + TestUtils.dropTableIfExists(table1, stmt); + TestUtils.dropTableIfExists(table2, stmt); + TestUtils.dropTableIfExists(table3, stmt); + TestUtils.dropTableIfExists(table4, stmt); + TestUtils.dropTableIfExists(CHAR_TABLE_AE, stmt); + TestUtils.dropTableIfExists(NUMERIC_TABLE_AE, stmt); + TestUtils.dropTableIfExists(BINARY_TABLE_AE, stmt); + TestUtils.dropTableIfExists(DATE_TABLE_AE, stmt); + TestUtils.dropTableIfExists(table5, stmt); + TestUtils.dropTableIfExists(table6, stmt); + TestUtils.dropTableIfExists(SCALE_DATE_TABLE_AE, stmt); } } - private static void createTables(String cekName) throws SQLException { + private static void createSPTables(String cekName) throws SQLException { createTable(table1, cekJks, SP_table1); createTable(table2, cekJks, SP_table2); createTable(table3, cekJks, SP_table3); createTable(table4, cekJks, SP_table4); - String sql = "create table " + AbstractSQLGenerator.escapeIdentifier(table5) + " (" + String sql = "create table " + table5 + " (" + "c1 int ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + cekJks + ") NULL," + "c2 smallint ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " @@ -424,7 +425,7 @@ private static void createTables(String cekName) throws SQLException { fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage()); } - sql = "create table " + AbstractSQLGenerator.escapeIdentifier(table6) + " (" + sql = "create table " + table6 + " (" + "c1 int ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + cekName + ") NULL," + "c2 smallint ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " @@ -434,8 +435,8 @@ private static void createTables(String cekName) throws SQLException { try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); Statement stmt = con.createStatement()) { - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table5), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table6), stmt); + TestUtils.dropTableIfExists(table5, stmt); + TestUtils.dropTableIfExists(table6, stmt); stmt.execute(sql); } catch (SQLException e) { fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage()); @@ -443,7 +444,7 @@ private static void createTables(String cekName) throws SQLException { } private static void populateTable4() throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(table4) + " values( " + "?,?,?" + ")"; + String sql = "insert into " + table4 + " values( " + "?,?,?" + ")"; try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); PreparedStatement pstmt = TestUtils.getPreparedStmt(con, sql, stmtColEncSetting)) { @@ -458,9 +459,9 @@ private static void populateTable4() throws SQLException { } private static void populateTable3() throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(table3) + " values( " + "?,?,?," + "?,?,?," + String sql = "insert into " + table3 + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + + "?,?,?," + "?,?,?," + "?,?,?" + ")"; try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, @@ -567,28 +568,24 @@ private static void populateTable3() throws SQLException { private void createMultiInsertionSelection() throws SQLException { String sql = " IF EXISTS (select * from sysobjects where id = object_id(N'" + TestUtils.escapeSingleQuotes(multiStatementsProcedure) - + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " - + AbstractSQLGenerator.escapeIdentifier(multiStatementsProcedure); + + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + multiStatementsProcedure; try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); - sql = "CREATE PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(multiStatementsProcedure) + sql = "CREATE PROCEDURE " + multiStatementsProcedure + " (@p0 char(20) = null, @p1 char(20) = null, @p2 char(20) = null, " + "@p3 varchar(50) = null, @p4 varchar(50) = null, @p5 varchar(50) = null)" + " AS" - + " INSERT INTO " + AbstractSQLGenerator.escapeIdentifier(table1) - + " values (@p0,@p1,@p2,@p3,@p4,@p5)" + " INSERT INTO " - + AbstractSQLGenerator.escapeIdentifier(table2) + " values (@p0,@p1,@p2,@p3,@p4,@p5)" - + " SELECT * FROM " + AbstractSQLGenerator.escapeIdentifier(table1) + " SELECT * FROM " - + AbstractSQLGenerator.escapeIdentifier(table2); + + " INSERT INTO " + table1 + " values (@p0,@p1,@p2,@p3,@p4,@p5)" + " INSERT INTO " + table2 + + " values (@p0,@p1,@p2,@p3,@p4,@p5)" + " SELECT * FROM " + table1 + " SELECT * FROM " + table2; stmt.execute(sql); } } private void MultiInsertionSelection() throws SQLException { - String sql = "{call " + AbstractSQLGenerator.escapeIdentifier(multiStatementsProcedure) + " (?,?,?,?,?,?)}"; + String sql = "{call " + multiStatementsProcedure + " (?,?,?,?,?,?)}"; try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -641,19 +638,17 @@ private void testGetString(ResultSet rs, int numberOfColumns) throws SQLExceptio private void createInputProcedure() throws SQLException { String sql = " IF EXISTS (select * from sysobjects where id = object_id(N'" + TestUtils.escapeSingleQuotes(inputProcedure) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" - + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(inputProcedure); + + " DROP PROCEDURE " + inputProcedure; try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); - sql = "CREATE PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(inputProcedure) - + " @p0 int, @p1 decimal(18, 0), " + sql = "CREATE PROCEDURE " + inputProcedure + " @p0 int, @p1 decimal(18, 0), " + "@p2 float, @p3 real, @p4 numeric(18, 0), @p5 smallmoney, @p6 money," + "@p7 bit, @p8 smallint, @p9 bigint, @p10 float(30), @p11 decimal(10,5), @p12 numeric(8,2), " + "@p13 decimal(28,4), @p14 numeric(28,4) " + " AS" + " SELECT top 1 RandomizedInt FROM " - + AbstractSQLGenerator.escapeIdentifier(NUMERIC_TABLE_AE) - + " where DeterministicInt=@p0 and DeterministicDecimalDefault=@p1 and " + + NUMERIC_TABLE_AE + " where DeterministicInt=@p0 and DeterministicDecimalDefault=@p1 and " + " DeterministicFloatDefault=@p2 and DeterministicReal=@p3 and DeterministicNumericDefault=@p4 and" + " DeterministicSmallMoney=@p5 and DeterministicMoney=@p6 and DeterministicBit=@p7 and" + " DeterministicSmallint=@p8 and DeterministicBigint=@p9 and DeterministicFloat=@p10 and" @@ -706,19 +701,18 @@ private void testInputProcedure(String sql, String[] values) throws SQLException private void createInputProcedure2() throws SQLException { String sql = " IF EXISTS (select * from sysobjects where id = object_id(N'" + TestUtils.escapeSingleQuotes(inputProcedure2) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" - + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(inputProcedure2); + + " DROP PROCEDURE " + inputProcedure2; try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); - sql = "CREATE PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(inputProcedure2) + sql = "CREATE PROCEDURE " + inputProcedure2 + " @p0 varchar(50), @p1 uniqueidentifier, @p2 varchar(max), @p3 nchar(30), @p4 nvarchar(60), @p5 nvarchar(max), " + " @p6 varchar(8000), @p7 nvarchar(4000)" + " AS" + " SELECT top 1 RandomizedVarchar, DeterministicUniqueidentifier, DeterministicVarcharMax, RandomizedNchar, " + " DeterministicNvarchar, DeterministicNvarcharMax, DeterministicVarchar8000, RandomizedNvarchar4000 FROM " - + AbstractSQLGenerator.escapeIdentifier(CHAR_TABLE_AE) - + " where DeterministicVarchar = @p0 and DeterministicUniqueidentifier =@p1"; + + CHAR_TABLE_AE + " where DeterministicVarchar = @p0 and DeterministicUniqueidentifier =@p1"; stmt.execute(sql); } @@ -759,16 +753,15 @@ private void testInputProcedure2(String sql) throws SQLException { private void createOutputProcedure3() throws SQLException { String sql = " IF EXISTS (select * from sysobjects where id = object_id(N'" + TestUtils.escapeSingleQuotes(outputProcedure3) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" - + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(outputProcedure3); + + " DROP PROCEDURE " + outputProcedure3; try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); - sql = "CREATE PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(outputProcedure3) - + " @p0 int OUTPUT, @p1 int OUTPUT " + " AS" + " SELECT top 1 @p0=DeterministicInt FROM " - + AbstractSQLGenerator.escapeIdentifier(table3) + " SELECT top 1 @p1=RandomizedInt FROM " - + AbstractSQLGenerator.escapeIdentifier(table4); + sql = "CREATE PROCEDURE " + outputProcedure3 + " @p0 int OUTPUT, @p1 int OUTPUT " + " AS" + + " SELECT top 1 @p0=DeterministicInt FROM " + table3 + " SELECT top 1 @p1=RandomizedInt FROM " + + table4; stmt.execute(sql); } @@ -850,18 +843,18 @@ private void testOutputProcedure3ReverseOrder(String sql) throws SQLException { private void createOutputProcedure2() throws SQLException { String sql = " IF EXISTS (select * from sysobjects where id = object_id(N'" + TestUtils.escapeSingleQuotes(outputProcedure2) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" - + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(outputProcedure2); + + " DROP PROCEDURE " + outputProcedure2; try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); - sql = "CREATE PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(outputProcedure2) + sql = "CREATE PROCEDURE " + outputProcedure2 + " @p0 int OUTPUT, @p1 int OUTPUT, @p2 smallint OUTPUT, @p3 smallint OUTPUT, @p4 tinyint OUTPUT, @p5 tinyint OUTPUT, @p6 smallmoney OUTPUT," + " @p7 smallmoney OUTPUT, @p8 money OUTPUT, @p9 money OUTPUT " + " AS" + " SELECT top 1 @p0=PlainInt, @p1=DeterministicInt, @p2=PlainSmallint," + " @p3=RandomizedSmallint, @p4=PlainTinyint, @p5=DeterministicTinyint, @p6=DeterministicSmallMoney, @p7=PlainSmallMoney," - + " @p8=PlainMoney, @p9=DeterministicMoney FROM " + AbstractSQLGenerator.escapeIdentifier(table3); + + " @p8=PlainMoney, @p9=DeterministicMoney FROM " + table3; stmt.execute(sql); } @@ -1030,18 +1023,17 @@ private void testOutputProcedure2ReverseOrder(String sql, String[] values) throw private void createOutputProcedure() throws SQLException { String sql = " IF EXISTS (select * from sysobjects where id = object_id(N'" + TestUtils.escapeSingleQuotes(outputProcedure) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" - + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(outputProcedure); + + " DROP PROCEDURE " + outputProcedure; try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); - sql = "CREATE PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(outputProcedure) - + " @p0 int OUTPUT, @p1 float OUTPUT, @p2 smallint OUTPUT, " + sql = "CREATE PROCEDURE " + outputProcedure + " @p0 int OUTPUT, @p1 float OUTPUT, @p2 smallint OUTPUT, " + "@p3 bigint OUTPUT, @p4 tinyint OUTPUT, @p5 smallmoney OUTPUT, @p6 money OUTPUT " + " AS" + " SELECT top 1 @p0=RandomizedInt, @p1=DeterministicFloatDefault, @p2=RandomizedSmallint," + " @p3=RandomizedBigint, @p4=DeterministicTinyint, @p5=DeterministicSmallMoney, @p6=DeterministicMoney FROM " - + AbstractSQLGenerator.escapeIdentifier(table3); + + table3; stmt.execute(sql); } @@ -1182,15 +1174,14 @@ private void testOutputProcedureReverseOrder(String sql, String[] values) throws private void createInOutProcedure() throws SQLException { String sql = " IF EXISTS (select * from sysobjects where id = object_id(N'" + TestUtils.escapeSingleQuotes(inoutProcedure) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" - + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(inoutProcedure); + + " DROP PROCEDURE " + inoutProcedure; try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); - sql = "CREATE PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(inoutProcedure) + " @p0 int OUTPUT" - + " AS" + " SELECT top 1 @p0=DeterministicInt FROM " + AbstractSQLGenerator.escapeIdentifier(table3) - + " where DeterministicInt=@p0"; + sql = "CREATE PROCEDURE " + inoutProcedure + " @p0 int OUTPUT" + " AS" + + " SELECT top 1 @p0=DeterministicInt FROM " + table3 + " where DeterministicInt=@p0"; stmt.execute(sql); } @@ -1217,16 +1208,14 @@ private void testInOutProcedure(String sql) throws SQLException { private void createMixedProcedure() throws SQLException { String sql = " IF EXISTS (select * from sysobjects where id = object_id(N'" + TestUtils.escapeSingleQuotes(mixedProcedure) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" - + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(mixedProcedure); + + " DROP PROCEDURE " + mixedProcedure; try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); - sql = "CREATE PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(mixedProcedure) - + " @p0 int OUTPUT, @p1 float OUTPUT, @p3 decimal " + " AS" - + " SELECT top 1 @p0=DeterministicInt2, @p1=RandomizedFloatDefault FROM " - + AbstractSQLGenerator.escapeIdentifier(table3) + sql = "CREATE PROCEDURE " + mixedProcedure + " @p0 int OUTPUT, @p1 float OUTPUT, @p3 decimal " + " AS" + + " SELECT top 1 @p0=DeterministicInt2, @p1=RandomizedFloatDefault FROM " + table3 + " where DeterministicInt=@p0 and DeterministicDecimalDefault=@p3" + " return 123"; stmt.execute(sql); @@ -1265,16 +1254,14 @@ private void testMixedProcedure(String sql) throws SQLException { private void createMixedProcedure2() throws SQLException { String sql = " IF EXISTS (select * from sysobjects where id = object_id(N'" + TestUtils.escapeSingleQuotes(mixedProcedure2) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" - + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(mixedProcedure2); + + " DROP PROCEDURE " + mixedProcedure2; try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); - sql = "CREATE PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(mixedProcedure2) - + " @p0 int OUTPUT, @p1 float OUTPUT, @p3 int, @p4 float " + " AS" - + " SELECT top 1 @p0=DeterministicInt, @p1=PlainFloatDefault FROM " - + AbstractSQLGenerator.escapeIdentifier(table3) + sql = "CREATE PROCEDURE " + mixedProcedure2 + " @p0 int OUTPUT, @p1 float OUTPUT, @p3 int, @p4 float " + + " AS" + " SELECT top 1 @p0=DeterministicInt, @p1=PlainFloatDefault FROM " + table3 + " where PlainInt=@p3 and DeterministicFloatDefault=@p4"; stmt.execute(sql); @@ -1341,16 +1328,16 @@ private void testMixedProcedure2Inorder(String sql) throws SQLException { private void createMixedProcedure3() throws SQLException { String sql = " IF EXISTS (select * from sysobjects where id = object_id(N'" + TestUtils.escapeSingleQuotes(mixedProcedure3) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" - + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(mixedProcedure3); + + " DROP PROCEDURE " + mixedProcedure3; try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); - sql = "CREATE PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(mixedProcedure3) + sql = "CREATE PROCEDURE " + mixedProcedure3 + " @p0 bigint OUTPUT, @p1 float OUTPUT, @p2 int OUTPUT, @p3 smallint" + " AS" - + " SELECT top 1 @p0=PlainBigint, @p1=PlainFloatDefault FROM " - + AbstractSQLGenerator.escapeIdentifier(table3) + " where PlainInt=@p2 and PlainSmallint=@p3"; + + " SELECT top 1 @p0=PlainBigint, @p1=PlainFloatDefault FROM " + table3 + + " where PlainInt=@p2 and PlainSmallint=@p3"; stmt.execute(sql); } @@ -1434,28 +1421,27 @@ private void testMixedProcedure3ReverseOrder(String sql) throws SQLException { } } - private void createMixedProcedureNumericPrcisionScale() throws SQLException { + private void createmixedProcedureNumericPrecisionScale() throws SQLException { String sql = " IF EXISTS (select * from sysobjects where id = object_id(N'" - + TestUtils.escapeSingleQuotes(mixedProcedureNumericPrcisionScale) + + TestUtils.escapeSingleQuotes(mixedProcedureNumericPrecisionScale) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " - + AbstractSQLGenerator.escapeIdentifier(mixedProcedureNumericPrcisionScale); + + mixedProcedureNumericPrecisionScale; try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); - sql = "CREATE PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(mixedProcedureNumericPrcisionScale) + sql = "CREATE PROCEDURE " + mixedProcedureNumericPrecisionScale + " @p1 decimal(18,0) OUTPUT, @p2 decimal(10,5) OUTPUT, @p3 numeric(18, 0) OUTPUT, @p4 numeric(8,2) OUTPUT " + " AS" + " SELECT top 1 @p1=RandomizedDecimalDefault, @p2=DeterministicDecimal," - + " @p3=RandomizedNumericDefault, @p4=DeterministicNumeric FROM " - + AbstractSQLGenerator.escapeIdentifier(table3) + + " @p3=RandomizedNumericDefault, @p4=DeterministicNumeric FROM " + table3 + " where DeterministicDecimal=@p2 and DeterministicNumeric=@p4" + " return 123"; stmt.execute(sql); } } - private void testMixedProcedureNumericPrcisionScaleInorder(String sql) throws SQLException { + private void testmixedProcedureNumericPrecisionScaleInorder(String sql) throws SQLException { try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils @@ -1486,7 +1472,7 @@ private void testMixedProcedureNumericPrcisionScaleInorder(String sql) throws SQ } } - private void testMixedProcedureNumericPrcisionScaleParameterName(String sql) throws SQLException { + private void testmixedProcedureNumericPrecisionScaleParameterName(String sql) throws SQLException { try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils @@ -1520,19 +1506,19 @@ private void testMixedProcedureNumericPrcisionScaleParameterName(String sql) thr private void createOutputProcedureChar() throws SQLException { String sql = " IF EXISTS (select * from sysobjects where id = object_id(N'" + TestUtils.escapeSingleQuotes(outputProcedureChar) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" - + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(outputProcedureChar); + + " DROP PROCEDURE " + outputProcedureChar; try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); - sql = "CREATE PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(outputProcedureChar) + sql = "CREATE PROCEDURE " + outputProcedureChar + " @p0 char(20) OUTPUT,@p1 varchar(50) OUTPUT,@p2 nchar(30) OUTPUT," + "@p3 nvarchar(60) OUTPUT, @p4 uniqueidentifier OUTPUT, @p5 varchar(max) OUTPUT, @p6 nvarchar(max) OUTPUT, @p7 varchar(8000) OUTPUT, @p8 nvarchar(4000) OUTPUT" + " AS" + " SELECT top 1 @p0=DeterministicChar,@p1=RandomizedVarChar,@p2=RandomizedNChar," + " @p3=DeterministicNVarChar, @p4=DeterministicUniqueidentifier, @p5=DeterministicVarcharMax," + " @p6=DeterministicNvarcharMax, @p7=DeterministicVarchar8000, @p8=RandomizedNvarchar4000 FROM " - + AbstractSQLGenerator.escapeIdentifier(CHAR_TABLE_AE); + + CHAR_TABLE_AE; stmt.execute(sql); } @@ -1644,14 +1630,13 @@ private void testOutputProcedureCharInorderObject(String sql) throws SQLExceptio private void createOutputProcedureNumeric() throws SQLException { String sql = " IF EXISTS (select * from sysobjects where id = object_id(N'" + TestUtils.escapeSingleQuotes(outputProcedureNumeric) - + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " - + AbstractSQLGenerator.escapeIdentifier(outputProcedureNumeric); + + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + outputProcedureNumeric; try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); - sql = "CREATE PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(outputProcedureNumeric) + sql = "CREATE PROCEDURE " + outputProcedureNumeric + " @p0 bit OUTPUT, @p1 tinyint OUTPUT, @p2 smallint OUTPUT, @p3 int OUTPUT," + " @p4 bigint OUTPUT, @p5 float OUTPUT, @p6 float(30) output, @p7 real output, @p8 decimal(18, 0) output, @p9 decimal(10,5) output," + " @p10 numeric(18, 0) output, @p11 numeric(8,2) output, @p12 smallmoney output, @p13 money output, @p14 decimal(28,4) output, @p15 numeric(28,4) output" @@ -1659,8 +1644,7 @@ private void createOutputProcedureNumeric() throws SQLException { + " @p3=RandomizedInt, @p4=DeterministicBigint, @p5=RandomizedFloatDefault, @p6=DeterministicFloat," + " @p7=RandomizedReal, @p8=DeterministicDecimalDefault, @p9=RandomizedDecimal," + " @p10=DeterministicNumericDefault, @p11=RandomizedNumeric, @p12=RandomizedSmallMoney, @p13=DeterministicMoney," - + " @p14=DeterministicDecimal2, @p15=DeterministicNumeric2 FROM " - + AbstractSQLGenerator.escapeIdentifier(NUMERIC_TABLE_AE); + + " @p14=DeterministicDecimal2, @p15=DeterministicNumeric2 FROM " + NUMERIC_TABLE_AE; stmt.execute(sql); } @@ -2041,18 +2025,17 @@ private Object getxxx(int ordinal, Class coercion, private void createOutputProcedureBinary() throws SQLException { String sql = " IF EXISTS (select * from sysobjects where id = object_id(N'" + TestUtils.escapeSingleQuotes(outputProcedureBinary) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" - + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(outputProcedureBinary); + + " DROP PROCEDURE " + outputProcedureBinary; try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); - sql = "CREATE PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(outputProcedureBinary) + sql = "CREATE PROCEDURE " + outputProcedureBinary + " @p0 binary(20) OUTPUT,@p1 varbinary(50) OUTPUT,@p2 varbinary(max) OUTPUT," + " @p3 binary(512) OUTPUT,@p4 varbinary(8000) OUTPUT " + " AS" + " SELECT top 1 @p0=RandomizedBinary,@p1=DeterministicVarbinary,@p2=DeterministicVarbinaryMax," - + " @p3=DeterministicBinary512,@p4=DeterministicBinary8000 FROM " - + AbstractSQLGenerator.escapeIdentifier(BINARY_TABLE_AE); + + " @p3=DeterministicBinary512,@p4=DeterministicBinary8000 FROM " + BINARY_TABLE_AE; stmt.execute(sql); } @@ -2188,8 +2171,7 @@ private void testOutputProcedureBinaryInorderString(String sql) throws SQLExcept } protected static void createDateTableCallableStatement(String cekName) throws SQLException { - String sql = "create table " + AbstractSQLGenerator.escapeIdentifier(DATE_TABLE_AE) + " (" - + "PlainDate date null," + String sql = "create table " + DATE_TABLE_AE + " (" + "PlainDate date null," + "RandomizedDate date ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + cekName + ") NULL," + "DeterministicDate date ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " @@ -2247,7 +2229,7 @@ protected static void createDateTableCallableStatement(String cekName) throws SQ try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(DATE_TABLE_AE), stmt); + TestUtils.dropTableIfExists(DATE_TABLE_AE, stmt); stmt.execute(sql); stmt.execute("DBCC FREEPROCCACHE"); } catch (SQLException e) { @@ -2282,8 +2264,8 @@ private static LinkedList createTemporalTypesCallableStatement(boolean n } private static void populateDateNormalCase() throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(DATE_TABLE_AE) + " values( " + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + String sql = "insert into " + DATE_TABLE_AE + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement sqlPstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, @@ -2340,13 +2322,13 @@ private static void populateDateNormalCase() throws SQLException { private void createOutputProcedureDate() throws SQLException { String sql = " IF EXISTS (select * from sysobjects where id = object_id(N'" + TestUtils.escapeSingleQuotes(outputProcedureDate) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" - + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(outputProcedureDate); + + " DROP PROCEDURE " + outputProcedureDate; try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); - sql = "CREATE PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(outputProcedureDate) + sql = "CREATE PROCEDURE " + outputProcedureDate + " @p0 date OUTPUT, @p01 date OUTPUT, @p1 datetime2 OUTPUT, @p11 datetime2 OUTPUT," + " @p2 datetimeoffset OUTPUT, @p21 datetimeoffset OUTPUT, @p3 time OUTPUT, @p31 time OUTPUT, @p4 datetime OUTPUT, @p41 datetime OUTPUT," + " @p5 smalldatetime OUTPUT, @p51 smalldatetime OUTPUT, @p6 datetime2(2) OUTPUT, @p61 datetime2(2) OUTPUT, @p7 time(2) OUTPUT, @p71 time(2) OUTPUT, " @@ -2356,8 +2338,7 @@ private void createOutputProcedureDate() throws SQLException { + " @p3=PlainTimeDefault,@p31=DeterministicTimeDefault," + " @p4=PlainDateTime,@p41=DeterministicDateTime, @p5=PlainSmallDateTime,@p51=RandomizedSmallDateTime, " + " @p6=PlainDatetime2,@p61=RandomizedDatetime2, @p7=PlainTime,@p71=Deterministictime, " - + " @p8=PlainDatetimeoffset, @p81=RandomizedDatetimeoffset" + " FROM " - + AbstractSQLGenerator.escapeIdentifier(DATE_TABLE_AE); + + " @p8=PlainDatetimeoffset, @p81=RandomizedDatetimeoffset" + " FROM " + DATE_TABLE_AE; stmt.execute(sql); } @@ -2468,7 +2449,7 @@ private void testOutputProcedureDateInorderObject(String sql) throws SQLExceptio private void createOutputProcedureBatch() throws SQLException { String sql = " IF EXISTS (select * from sysobjects where id = object_id(N'" + TestUtils.escapeSingleQuotes(outputProcedureBatch) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" - + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(outputProcedureBatch); + + " DROP PROCEDURE " + outputProcedureBatch; try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -2476,13 +2457,12 @@ private void createOutputProcedureBatch() throws SQLException { // If a procedure contains more than one SQL statement, it is considered // to be a batch of SQL statements. - sql = "CREATE PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(outputProcedureBatch) + sql = "CREATE PROCEDURE " + outputProcedureBatch + " @p0 int OUTPUT, @p1 float OUTPUT, @p2 smallint OUTPUT, @p3 smallmoney OUTPUT " + " AS" - + " select top 1 @p0=RandomizedInt FROM " + AbstractSQLGenerator.escapeIdentifier(table3) - + " select top 1 @p1=DeterministicFloatDefault FROM " - + AbstractSQLGenerator.escapeIdentifier(table3) + " select top 1 @p2=RandomizedSmallint FROM " - + AbstractSQLGenerator.escapeIdentifier(table3) + " select top 1 @p3=DeterministicSmallMoney FROM " - + AbstractSQLGenerator.escapeIdentifier(table3); + + " select top 1 @p0=RandomizedInt FROM " + table3 + + " select top 1 @p1=DeterministicFloatDefault FROM " + table3 + + " select top 1 @p2=RandomizedSmallint FROM " + table3 + + " select top 1 @p3=DeterministicSmallMoney FROM " + table3; stmt.execute(sql); } @@ -2519,20 +2499,18 @@ private void testOutputProcedureBatchInorder(String sql) throws SQLException { private void createOutputProcedure4() throws SQLException { String sql = " IF EXISTS (select * from sysobjects where id = object_id(N'" + TestUtils.escapeSingleQuotes(outputProcedure4) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" - + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(outputProcedure4); + + " DROP PROCEDURE " + outputProcedure4; try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); - sql = "create procedure " + AbstractSQLGenerator.escapeIdentifier(outputProcedure4) + sql = "create procedure " + outputProcedure4 + " @in1 int, @in2 smallint, @in3 bigint, @in4 int, @in5 smallint, @in6 bigint, @out1 int output, @out2 smallint output, @out3 bigint output, @out4 int output, @out5 smallint output, @out6 bigint output" - + " as " + " insert into " + AbstractSQLGenerator.escapeIdentifier(table5) - + " values (@in1, @in2, @in3)" + " insert into " + AbstractSQLGenerator.escapeIdentifier(table6) - + " values (@in4, @in5, @in6)" + " select * from " + AbstractSQLGenerator.escapeIdentifier(table5) - + " select * from " + AbstractSQLGenerator.escapeIdentifier(table6) - + " select @out1 = c1, @out2=c2, @out3=c3 from " + AbstractSQLGenerator.escapeIdentifier(table5) - + " select @out4 = c1, @out5=c2, @out6=c3 from " + AbstractSQLGenerator.escapeIdentifier(table6); + + " as " + " insert into " + table5 + " values (@in1, @in2, @in3)" + " insert into " + table6 + + " values (@in4, @in5, @in6)" + " select * from " + table5 + " select * from " + table6 + + " select @out1 = c1, @out2=c2, @out3=c3 from " + table5 + + " select @out4 = c1, @out5=c2, @out6=c3 from " + table6; stmt.execute(sql); } @@ -2541,20 +2519,17 @@ private void createOutputProcedure4() throws SQLException { private void createMixedProcedureDateScale() throws SQLException { String sql = " IF EXISTS (select * from sysobjects where id = object_id(N'" + TestUtils.escapeSingleQuotes(outputProcedureDateScale) - + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " - + AbstractSQLGenerator.escapeIdentifier(outputProcedureDateScale); + + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + outputProcedureDateScale; try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); - sql = "CREATE PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(outputProcedureDateScale) - + " @p1 datetime2(2) OUTPUT, @p2 datetime2(2) OUTPUT," + sql = "CREATE PROCEDURE " + outputProcedureDateScale + " @p1 datetime2(2) OUTPUT, @p2 datetime2(2) OUTPUT," + " @p3 time(2) OUTPUT, @p4 time(2) OUTPUT, @p5 datetimeoffset(2) OUTPUT, @p6 datetimeoffset(2) OUTPUT " + " AS" + " SELECT top 1 @p1=DeterministicDatetime2,@p2=RandomizedDatetime2,@p3=DeterministicTime,@p4=RandomizedTime," - + " @p5=DeterministicDatetimeoffset,@p6=RandomizedDatetimeoffset " + " FROM " - + AbstractSQLGenerator.escapeIdentifier(SCALE_DATE_TABLE_AE) + + " @p5=DeterministicDatetimeoffset,@p6=RandomizedDatetimeoffset " + " FROM " + SCALE_DATE_TABLE_AE + " where DeterministicDatetime2 = @p1 and DeterministicTime = @p3 and DeterministicDatetimeoffset=@p5"; stmt.execute(sql); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/EnclaveTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/EnclaveTest.java index bb7005a6ef..65f5aab061 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/EnclaveTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/EnclaveTest.java @@ -25,7 +25,6 @@ import com.microsoft.sqlserver.jdbc.SQLServerStatement; import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.jdbc.TestUtils; -import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.Constants; import com.microsoft.sqlserver.testframework.PrepUtil; @@ -850,11 +849,10 @@ public void testAEFMTOnly(String serverName, String url, String protocol) throws checkAESetup(serverName, url, protocol); try (SQLServerConnection c = PrepUtil.getConnection(AETestConnectionString + ";useFmtOnly=true", AEInfo); Statement s = c.createStatement()) { - dropTables(s); createTable(NUMERIC_TABLE_AE, cekJks, numericTable); - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(NUMERIC_TABLE_AE) + " values( " + String sql = "insert into " + NUMERIC_TABLE_AE + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + + "?,?,?," + "?,?,?," + "?,?,?" + ")"; try (PreparedStatement p = c.prepareStatement(sql)) { ParameterMetaData pmd = p.getParameterMetaData(); assertTrue(pmd.getParameterCount() == 48); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java index 4c74d38358..9c8b8b4b65 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java @@ -41,7 +41,6 @@ import com.microsoft.sqlserver.jdbc.SQLServerStatement; import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.jdbc.TestUtils; -import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.Constants; import com.microsoft.sqlserver.testframework.PrepUtil; @@ -382,6 +381,7 @@ public void testCharSpecificSetter(String serverName, String url, String protoco */ @ParameterizedTest @MethodSource("enclaveParams") + @Tag(Constants.reqExternalSetup) public void testCharSpecificSetterWindows(String serverName, String url, String protocol) throws Exception { checkAESetup(serverName, url, protocol); @@ -395,6 +395,25 @@ public void testCharSpecificSetterWindows(String serverName, String url, String } } + /** + * Junit test case for char set object for string values using AKV + * + * @throws SQLException + */ + @ParameterizedTest + @MethodSource("enclaveParams") + @Tag(Constants.reqExternalSetup) + public void testCharSetObjectAkv(String serverName, String url, String protocol) throws Exception { + checkAESetup(serverName, url, protocol); + + try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + String[] values = createCharValues(nullable); + + testChars(stmt, cekAkv, charTable, values, TestCase.SETOBJECT, false); + } + } + /** * Junit test case for char set object for string values * @@ -410,7 +429,6 @@ public void testCharSetObject(String serverName, String url, String protocol) th String[] values = createCharValues(nullable); testChars(stmt, cekJks, charTable, values, TestCase.SETOBJECT, false); - testChars(stmt, cekAkv, charTable, values, TestCase.SETOBJECT, false); } } @@ -421,513 +439,971 @@ public void testCharSetObject(String serverName, String url, String protocol) th */ @ParameterizedTest @MethodSource("enclaveParams") - public void testCharSetObjectWithJDBCTypes(String serverName, String url, String protocol) throws Exception { + @Tag(Constants.reqExternalSetup) + public void testCharSetObjectWithJDBCTypesAkv(String serverName, String url, String protocol) throws Exception { checkAESetup(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { String[] values = createCharValues(nullable); - testChars(stmt, cekJks, charTable, values, TestCase.SETOBJECT_WITH_JDBCTYPES, false); testChars(stmt, cekAkv, charTable, values, TestCase.SETOBJECT_WITH_JDBCTYPES, false); } } /** - * Junit test case for char set string for null values + * Junit test case for char set object for jdbc string values * * @throws SQLException */ @ParameterizedTest @MethodSource("enclaveParams") - public void testCharSpecificSetterNull(String serverName, String url, String protocol) throws Exception { + public void testCharSetObjectWithJDBCTypes(String serverName, String url, String protocol) throws Exception { checkAESetup(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - String[] values = {null, null, null, null, null, null, null, null, null}; + String[] values = createCharValues(nullable); - testChars(stmt, cekJks, charTable, values, TestCase.NORMAL, false); - testChars(stmt, cekAkv, charTable, values, TestCase.NORMAL, false); + testChars(stmt, cekJks, charTable, values, TestCase.SETOBJECT_WITH_JDBCTYPES, false); } } /** - * Junit test case for char set object for null values + * Junit test case for char set string for null values * * @throws SQLException */ @ParameterizedTest @MethodSource("enclaveParams") - public void testCharSetObjectNull(String serverName, String url, String protocol) throws Exception { + @Tag(Constants.reqExternalSetup) + public void testCharSpecificSetterNullAkv(String serverName, String url, String protocol) throws Exception { checkAESetup(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { String[] values = {null, null, null, null, null, null, null, null, null}; - testChars(stmt, cekJks, charTable, values, TestCase.SETOBJECT, false); - testChars(stmt, cekAkv, charTable, values, TestCase.SETOBJECT, false); + testChars(stmt, cekAkv, charTable, values, TestCase.NORMAL, false); } } /** - * Junit test case for char set null for null values + * Junit test case for char set string for null values * * @throws SQLException */ @ParameterizedTest @MethodSource("enclaveParams") - public void testCharSetNull(String serverName, String url, String protocol) throws Exception { + public void testCharSpecificSetterNull(String serverName, String url, String protocol) throws Exception { checkAESetup(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { String[] values = {null, null, null, null, null, null, null, null, null}; - testChars(stmt, cekJks, charTable, values, TestCase.NULL, false); - testChars(stmt, cekAkv, charTable, values, TestCase.NULL, false); + testChars(stmt, cekJks, charTable, values, TestCase.NORMAL, false); } } /** - * Junit test case for binary set binary for binary values + * Junit test case for char set object for null values * * @throws SQLException */ @ParameterizedTest @MethodSource("enclaveParams") - public void testBinarySpecificSetter(String serverName, String url, String protocol) throws Exception { + @Tag(Constants.reqExternalSetup) + public void testCharSetObjectNullAkv(String serverName, String url, String protocol) throws Exception { checkAESetup(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - LinkedList values = createBinaryValues(false); + String[] values = {null, null, null, null, null, null, null, null, null}; - testBinaries(stmt, cekJks, binaryTable, values, TestCase.NORMAL, false); - testBinaries(stmt, cekAkv, binaryTable, values, TestCase.NORMAL, false); + testChars(stmt, cekAkv, charTable, values, TestCase.SETOBJECT, false); } } /** - * Junit test case for binary set binary for binary values using windows certificate store + * Junit test case for char set object for null values * * @throws SQLException */ @ParameterizedTest @MethodSource("enclaveParams") - public void testBinarySpecificSetterWindows(String serverName, String url, String protocol) throws Exception { - org.junit.Assume.assumeTrue(isWindows); - + public void testCharSetObjectNull(String serverName, String url, String protocol) throws Exception { checkAESetup(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - LinkedList values = createBinaryValues(false); + String[] values = {null, null, null, null, null, null, null, null, null}; - testBinaries(stmt, cekWin, binaryTable, values, TestCase.NORMAL, false); + testChars(stmt, cekJks, charTable, values, TestCase.SETOBJECT, false); } } /** - * Junit test case for binary set object for binary values + * Junit test case for char set null for null values * * @throws SQLException */ @ParameterizedTest @MethodSource("enclaveParams") - public void testBinarySetobject(String serverName, String url, String protocol) throws Exception { + @Tag(Constants.reqExternalSetup) + public void testCharSetNullAkv(String serverName, String url, String protocol) throws Exception { checkAESetup(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - LinkedList values = createBinaryValues(false); + String[] values = {null, null, null, null, null, null, null, null, null}; - testBinaries(stmt, cekJks, binaryTable, values, TestCase.SETOBJECT, false); - testBinaries(stmt, cekAkv, binaryTable, values, TestCase.SETOBJECT, false); + testChars(stmt, cekAkv, charTable, values, TestCase.NULL, false); } } /** - * Junit test case for binary set null for binary values + * Junit test case for char set null for null values * * @throws SQLException */ @ParameterizedTest @MethodSource("enclaveParams") - public void testBinarySetNull(String serverName, String url, String protocol) throws Exception { + public void testCharSetNull(String serverName, String url, String protocol) throws Exception { checkAESetup(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - LinkedList values = createBinaryValues(true); + String[] values = {null, null, null, null, null, null, null, null, null}; - testBinaries(stmt, cekJks, binaryTable, values, TestCase.NULL, false); - testBinaries(stmt, cekAkv, binaryTable, values, TestCase.NULL, false); + testChars(stmt, cekJks, charTable, values, TestCase.NULL, false); } } /** - * Junit test case for binary set binary for null values + * Junit test case for binary set binary for binary values * * @throws SQLException */ @ParameterizedTest @MethodSource("enclaveParams") - public void testBinarySpecificSetterNull(String serverName, String url, String protocol) throws Exception { + @Tag(Constants.reqExternalSetup) + public void testBinarySpecificSetterAkv(String serverName, String url, String protocol) throws Exception { checkAESetup(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - LinkedList values = createBinaryValues(true); + LinkedList values = createBinaryValues(false); - testBinaries(stmt, cekJks, binaryTable, values, TestCase.NORMAL, false); testBinaries(stmt, cekAkv, binaryTable, values, TestCase.NORMAL, false); } } /** - * Junit test case for binary set object for null values + * Junit test case for binary set binary for binary values * * @throws SQLException */ @ParameterizedTest @MethodSource("enclaveParams") - public void testBinarysetObjectNull(String serverName, String url, String protocol) throws Exception { + public void testBinarySpecificSetter(String serverName, String url, String protocol) throws Exception { checkAESetup(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - LinkedList values = createBinaryValues(true); + LinkedList values = createBinaryValues(false); - testBinaries(stmt, cekJks, binaryTable, values, TestCase.SETOBJECT_NULL, false); - testBinaries(stmt, cekAkv, binaryTable, values, TestCase.SETOBJECT_NULL, false); + testBinaries(stmt, cekJks, binaryTable, values, TestCase.NORMAL, false); } } /** - * Junit test case for binary set object for jdbc type binary values + * Junit test case for binary set binary for binary values using windows certificate store * * @throws SQLException */ @ParameterizedTest @MethodSource("enclaveParams") - public void testBinarySetObjectWithJDBCTypes(String serverName, String url, String protocol) throws Exception { + @Tag(Constants.reqExternalSetup) + public void testBinarySpecificSetterWindows(String serverName, String url, String protocol) throws Exception { + org.junit.Assume.assumeTrue(isWindows); + checkAESetup(serverName, url, protocol); + try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { LinkedList values = createBinaryValues(false); - testBinaries(stmt, cekJks, binaryTable, values, TestCase.SETOBJECT_WITH_JDBCTYPES, false); - testBinaries(stmt, cekAkv, binaryTable, values, TestCase.SETOBJECT_WITH_JDBCTYPES, false); + testBinaries(stmt, cekWin, binaryTable, values, TestCase.NORMAL, false); } } /** - * Junit test case for date set date for date values + * Junit test case for binary set object for binary values * * @throws SQLException */ @ParameterizedTest @MethodSource("enclaveParams") - public void testDateSpecificSetter(String serverName, String url, String protocol) throws Exception { + @Tag(Constants.reqExternalSetup) + public void testBinarySetobjectAkv(String serverName, String url, String protocol) throws Exception { checkAESetup(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - LinkedList values = createTemporalTypes(nullable); + LinkedList values = createBinaryValues(false); - testDates(stmt, cekJks, dateTable, values, TestCase.NORMAL, false); - testDates(stmt, cekAkv, dateTable, values, TestCase.NORMAL, false); + testBinaries(stmt, cekAkv, binaryTable, values, TestCase.SETOBJECT, false); } } /** - * Junit test case for date set date for date values using windows certificate store + * Junit test case for binary set object for binary values * * @throws SQLException */ @ParameterizedTest @MethodSource("enclaveParams") - public void testDateSpecificSetterWindows(String serverName, String url, String protocol) throws Exception { - org.junit.Assume.assumeTrue(isWindows); - + public void testBinarySetobject(String serverName, String url, String protocol) throws Exception { checkAESetup(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - LinkedList values = createTemporalTypes(nullable); + LinkedList values = createBinaryValues(false); - testDates(stmt, cekWin, dateTable, values, TestCase.NORMAL, false); + testBinaries(stmt, cekJks, binaryTable, values, TestCase.SETOBJECT, false); } } /** - * Junit test case for date set object for date values + * Junit test case for binary set null for binary values * * @throws SQLException */ @ParameterizedTest @MethodSource("enclaveParams") - public void testDateSetObject(String serverName, String url, String protocol) throws Exception { + @Tag(Constants.reqExternalSetup) + public void testBinarySetNullAkv(String serverName, String url, String protocol) throws Exception { checkAESetup(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - LinkedList values = createTemporalTypes(nullable); + LinkedList values = createBinaryValues(true); - testDates(stmt, cekJks, dateTable, values, TestCase.SETOBJECT, false); - testDates(stmt, cekAkv, dateTable, values, TestCase.SETOBJECT, false); + testBinaries(stmt, cekAkv, binaryTable, values, TestCase.NULL, false); } } /** - * Junit test case for date set object for java date values + * Junit test case for binary set null for binary values * * @throws SQLException */ @ParameterizedTest @MethodSource("enclaveParams") - public void testDateSetObjectWithJavaType(String serverName, String url, String protocol) throws Exception { + public void testBinarySetNull(String serverName, String url, String protocol) throws Exception { checkAESetup(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - LinkedList values = createTemporalTypes(nullable); + LinkedList values = createBinaryValues(true); - testDates(stmt, cekJks, dateTable, values, TestCase.SETOBJECT_WITH_JAVATYPES, false); - testDates(stmt, cekAkv, dateTable, values, TestCase.SETOBJECT_WITH_JAVATYPES, false); + testBinaries(stmt, cekJks, binaryTable, values, TestCase.NULL, false); } } /** - * Junit test case for date set object for jdbc date values + * Junit test case for binary set binary for null values * * @throws SQLException */ @ParameterizedTest @MethodSource("enclaveParams") - public void testDateSetObjectWithJDBCType(String serverName, String url, String protocol) throws Exception { + @Tag(Constants.reqExternalSetup) + public void testBinarySpecificSetterNullAkv(String serverName, String url, String protocol) throws Exception { checkAESetup(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - LinkedList values = createTemporalTypes(nullable); + LinkedList values = createBinaryValues(true); - testDates(stmt, cekJks, dateTable, values, TestCase.SETOBJECT_WITH_JDBCTYPES, false); - testDates(stmt, cekAkv, dateTable, values, TestCase.SETOBJECT_WITH_JDBCTYPES, false); + testBinaries(stmt, cekAkv, binaryTable, values, TestCase.NORMAL, false); } } /** - * Junit test case for date set date for min/max date values + * Junit test case for binary set binary for null values * * @throws SQLException */ @ParameterizedTest @MethodSource("enclaveParams") - public void testDateSpecificSetterMinMaxValue(String serverName, String url, String protocol) throws Exception { + public void testBinarySpecificSetterNull(String serverName, String url, String protocol) throws Exception { checkAESetup(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - RandomData.returnMinMax = true; - LinkedList values = createTemporalTypes(nullable); + LinkedList values = createBinaryValues(true); - testDates(stmt, cekJks, dateTable, values, TestCase.NORMAL, false); - testDates(stmt, cekAkv, dateTable, values, TestCase.NORMAL, false); + testBinaries(stmt, cekJks, binaryTable, values, TestCase.NORMAL, false); } } /** - * Junit test case for date set date for null values + * Junit test case for binary set object for null values * * @throws SQLException */ @ParameterizedTest @MethodSource("enclaveParams") - public void testDateSetNull(String serverName, String url, String protocol) throws Exception { + @Tag(Constants.reqExternalSetup) + public void testBinarysetObjectNullAkv(String serverName, String url, String protocol) throws Exception { checkAESetup(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - RandomData.returnNull = true; - nullable = true; - LinkedList values = createTemporalTypes(nullable); + LinkedList values = createBinaryValues(true); - testDates(stmt, cekJks, dateTable, values, TestCase.NULL, false); - testDates(stmt, cekAkv, dateTable, values, TestCase.NULL, false); + testBinaries(stmt, cekAkv, binaryTable, values, TestCase.SETOBJECT_NULL, false); } - - nullable = false; - RandomData.returnNull = false; } /** - * Junit test case for date set object for null values + * Junit test case for binary set object for null values * * @throws SQLException */ @ParameterizedTest @MethodSource("enclaveParams") - public void testDateSetObjectNull(String serverName, String url, String protocol) throws Exception { + public void testBinarysetObjectNull(String serverName, String url, String protocol) throws Exception { checkAESetup(serverName, url, protocol); - RandomData.returnNull = true; - nullable = true; - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - LinkedList values = createTemporalTypes(nullable); + LinkedList values = createBinaryValues(true); - testDates(stmt, cekJks, dateTable, values, TestCase.SETOBJECT_NULL, false); - testDates(stmt, cekAkv, dateTable, values, TestCase.SETOBJECT_NULL, false); + testBinaries(stmt, cekJks, binaryTable, values, TestCase.SETOBJECT_NULL, false); } - - nullable = false; - RandomData.returnNull = false; } /** - * Junit test case for numeric set numeric for numeric values + * Junit test case for binary set object for jdbc type binary values * * @throws SQLException */ @ParameterizedTest @MethodSource("enclaveParams") - public void testNumericSpecificSetter(String serverName, String url, String protocol) throws Exception { + @Tag(Constants.reqExternalSetup) + public void testBinarySetObjectWithJDBCTypesAkv(String serverName, String url, String protocol) throws Exception { checkAESetup(serverName, url, protocol); - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + LinkedList values = createBinaryValues(false); - String[] values1 = createNumericValues(nullable); - String[] values2 = new String[values1.length]; - System.arraycopy(values1, 0, values2, 0, values1.length); - - testNumerics(stmt, cekJks, numericTable, values1, values2, TestCase.NORMAL, false); - testNumerics(stmt, cekAkv, numericTable, values1, values2, TestCase.NORMAL, false); + testBinaries(stmt, cekAkv, binaryTable, values, TestCase.SETOBJECT_WITH_JDBCTYPES, false); } } /** - * Junit test case for numeric set numeric for numeric values using windows certificate store + * Junit test case for binary set object for jdbc type binary values * * @throws SQLException */ @ParameterizedTest @MethodSource("enclaveParams") - public void testNumericSpecificSetterWindows(String serverName, String url, String protocol) throws Exception { - org.junit.Assume.assumeTrue(isWindows); - + public void testBinarySetObjectWithJDBCTypes(String serverName, String url, String protocol) throws Exception { checkAESetup(serverName, url, protocol); - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + LinkedList values = createBinaryValues(false); - String[] values1 = createNumericValues(nullable); - String[] values2 = new String[values1.length]; - System.arraycopy(values1, 0, values2, 0, values1.length); - - testNumerics(stmt, cekWin, numericTable, values1, values2, TestCase.NORMAL, false); + testBinaries(stmt, cekJks, binaryTable, values, TestCase.SETOBJECT_WITH_JDBCTYPES, false); } } /** - * Junit test case for numeric set object for numeric values + * Junit test case for date set date for date values * * @throws SQLException */ @ParameterizedTest @MethodSource("enclaveParams") - public void testNumericSetObject(String serverName, String url, String protocol) throws Exception { + @Tag(Constants.reqExternalSetup) + public void testDateSpecificSetterAkv(String serverName, String url, String protocol) throws Exception { checkAESetup(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - String[] values1 = createNumericValues(nullable); - String[] values2 = new String[values1.length]; - System.arraycopy(values1, 0, values2, 0, values1.length); + LinkedList values = createTemporalTypes(nullable); - testNumerics(stmt, cekJks, numericTable, values1, values2, TestCase.SETOBJECT, false); - testNumerics(stmt, cekAkv, numericTable, values1, values2, TestCase.SETOBJECT, false); + testDates(stmt, cekAkv, dateTable, values, TestCase.NORMAL, false); } } /** - * Junit test case for numeric set object for jdbc type numeric values + * Junit test case for date set date for date values * * @throws SQLException */ @ParameterizedTest @MethodSource("enclaveParams") - public void testNumericSetObjectWithJDBCTypes(String serverName, String url, String protocol) throws Exception { + public void testDateSpecificSetter(String serverName, String url, String protocol) throws Exception { checkAESetup(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - String[] values1 = createNumericValues(nullable); - String[] values2 = new String[values1.length]; - System.arraycopy(values1, 0, values2, 0, values1.length); + LinkedList values = createTemporalTypes(nullable); - testNumerics(stmt, cekJks, numericTable, values1, values2, TestCase.SETOBJECT_WITH_JDBCTYPES, false); - testNumerics(stmt, cekAkv, numericTable, values1, values2, TestCase.SETOBJECT_WITH_JDBCTYPES, false); + testDates(stmt, cekJks, dateTable, values, TestCase.NORMAL, false); } } /** - * Junit test case for numeric set numeric for max numeric values + * Junit test case for date set date for date values using windows certificate store * * @throws SQLException */ @ParameterizedTest @MethodSource("enclaveParams") - public void testNumericSpecificSetterMaxValue(String serverName, String url, String protocol) throws Exception { + @Tag(Constants.reqExternalSetup) + public void testDateSpecificSetterWindows(String serverName, String url, String protocol) throws Exception { + org.junit.Assume.assumeTrue(isWindows); + checkAESetup(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + LinkedList values = createTemporalTypes(nullable); - String[] values1 = {Boolean.TRUE.toString(), "255", "32767", "2147483647", "9223372036854775807", - "1.79E308", "1.123", "3.4E38", "999999999999999999", "12345.12345", "999999999999999999", - "567812.78", "214748.3647", "922337203685477.5807", "999999999999999999999999.9999", - "999999999999999999999999.9999"}; - String[] values2 = {Boolean.TRUE.toString(), "255", "32767", "2147483647", "9223372036854775807", - "1.79E308", "1.123", "3.4E38", "999999999999999999", "12345.12345", "999999999999999999", - "567812.78", "214748.3647", "922337203685477.5807", "999999999999999999999999.9999", - "999999999999999999999999.9999"}; - - testNumerics(stmt, cekJks, numericTable, values1, values2, TestCase.NORMAL, false); - testNumerics(stmt, cekAkv, numericTable, values1, values2, TestCase.NORMAL, false); + testDates(stmt, cekWin, dateTable, values, TestCase.NORMAL, false); } } /** - * Junit test case for numeric set numeric for min numeric values + * Junit test case for date set object for date values * * @throws SQLException */ @ParameterizedTest @MethodSource("enclaveParams") - public void testNumericSpecificSetterMinValue(String serverName, String url, String protocol) throws Exception { + @Tag(Constants.reqExternalSetup) + public void testDateSetObjectAkv(String serverName, String url, String protocol) throws Exception { checkAESetup(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - String[] values1 = {Boolean.FALSE.toString(), "0", "-32768", "-2147483648", "-9223372036854775808", - "-1.79E308", "1.123", "-3.4E38", "999999999999999999", "12345.12345", "999999999999999999", - "567812.78", "-214748.3648", "-922337203685477.5808", "999999999999999999999999.9999", - "999999999999999999999999.9999"}; - String[] values2 = {Boolean.FALSE.toString(), "0", "-32768", "-2147483648", "-9223372036854775808", + LinkedList values = createTemporalTypes(nullable); + + testDates(stmt, cekAkv, dateTable, values, TestCase.SETOBJECT, false); + } + } + + /** + * Junit test case for date set object for date values + * + * @throws SQLException + */ + @ParameterizedTest + @MethodSource("enclaveParams") + public void testDateSetObject(String serverName, String url, String protocol) throws Exception { + checkAESetup(serverName, url, protocol); + + try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + LinkedList values = createTemporalTypes(nullable); + + testDates(stmt, cekJks, dateTable, values, TestCase.SETOBJECT, false); + } + } + + /** + * Junit test case for date set object for java date values + * + * @throws SQLException + */ + @ParameterizedTest + @MethodSource("enclaveParams") + @Tag(Constants.reqExternalSetup) + public void testDateSetObjectWithJavaTypeAkv(String serverName, String url, String protocol) throws Exception { + checkAESetup(serverName, url, protocol); + + try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + LinkedList values = createTemporalTypes(nullable); + + testDates(stmt, cekAkv, dateTable, values, TestCase.SETOBJECT_WITH_JAVATYPES, false); + } + } + + /** + * Junit test case for date set object for java date values + * + * @throws SQLException + */ + @ParameterizedTest + @MethodSource("enclaveParams") + public void testDateSetObjectWithJavaType(String serverName, String url, String protocol) throws Exception { + checkAESetup(serverName, url, protocol); + + try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + LinkedList values = createTemporalTypes(nullable); + + testDates(stmt, cekJks, dateTable, values, TestCase.SETOBJECT_WITH_JAVATYPES, false); + } + } + + /** + * Junit test case for date set object for jdbc date values + * + * @throws SQLException + */ + @ParameterizedTest + @MethodSource("enclaveParams") + @Tag(Constants.reqExternalSetup) + public void testDateSetObjectWithJDBCTypeAkv(String serverName, String url, String protocol) throws Exception { + checkAESetup(serverName, url, protocol); + + try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + LinkedList values = createTemporalTypes(nullable); + + testDates(stmt, cekAkv, dateTable, values, TestCase.SETOBJECT_WITH_JDBCTYPES, false); + } + } + + /** + * Junit test case for date set object for jdbc date values + * + * @throws SQLException + */ + @ParameterizedTest + @MethodSource("enclaveParams") + public void testDateSetObjectWithJDBCType(String serverName, String url, String protocol) throws Exception { + checkAESetup(serverName, url, protocol); + + try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + LinkedList values = createTemporalTypes(nullable); + + testDates(stmt, cekJks, dateTable, values, TestCase.SETOBJECT_WITH_JDBCTYPES, false); + } + } + + /** + * Junit test case for date set date for min/max date values + * + * @throws SQLException + */ + @ParameterizedTest + @MethodSource("enclaveParams") + @Tag(Constants.reqExternalSetup) + public void testDateSpecificSetterMinMaxValueAkv(String serverName, String url, String protocol) throws Exception { + checkAESetup(serverName, url, protocol); + + try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + RandomData.returnMinMax = true; + LinkedList values = createTemporalTypes(nullable); + + testDates(stmt, cekAkv, dateTable, values, TestCase.NORMAL, false); + } + } + + /** + * Junit test case for date set date for min/max date values + * + * @throws SQLException + */ + @ParameterizedTest + @MethodSource("enclaveParams") + public void testDateSpecificSetterMinMaxValue(String serverName, String url, String protocol) throws Exception { + checkAESetup(serverName, url, protocol); + + try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + RandomData.returnMinMax = true; + LinkedList values = createTemporalTypes(nullable); + + testDates(stmt, cekJks, dateTable, values, TestCase.NORMAL, false); + } + } + + /** + * Junit test case for date set date for null values + * + * @throws SQLException + */ + @ParameterizedTest + @MethodSource("enclaveParams") + @Tag(Constants.reqExternalSetup) + public void testDateSetNullAkv(String serverName, String url, String protocol) throws Exception { + checkAESetup(serverName, url, protocol); + + try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + RandomData.returnNull = true; + nullable = true; + LinkedList values = createTemporalTypes(nullable); + + testDates(stmt, cekAkv, dateTable, values, TestCase.NULL, false); + } + + nullable = false; + RandomData.returnNull = false; + } + + /** + * Junit test case for date set date for null values + * + * @throws SQLException + */ + @ParameterizedTest + @MethodSource("enclaveParams") + public void testDateSetNull(String serverName, String url, String protocol) throws Exception { + checkAESetup(serverName, url, protocol); + + try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + RandomData.returnNull = true; + nullable = true; + LinkedList values = createTemporalTypes(nullable); + + testDates(stmt, cekJks, dateTable, values, TestCase.NULL, false); + } + + nullable = false; + RandomData.returnNull = false; + } + + /** + * Junit test case for date set object for null values + * + * @throws SQLException + */ + @ParameterizedTest + @MethodSource("enclaveParams") + @Tag(Constants.reqExternalSetup) + public void testDateSetObjectNullAkv(String serverName, String url, String protocol) throws Exception { + checkAESetup(serverName, url, protocol); + + RandomData.returnNull = true; + nullable = true; + + try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + LinkedList values = createTemporalTypes(nullable); + + testDates(stmt, cekAkv, dateTable, values, TestCase.SETOBJECT_NULL, false); + } + + nullable = false; + RandomData.returnNull = false; + } + + /** + * Junit test case for date set object for null values + * + * @throws SQLException + */ + @ParameterizedTest + @MethodSource("enclaveParams") + public void testDateSetObjectNull(String serverName, String url, String protocol) throws Exception { + checkAESetup(serverName, url, protocol); + + RandomData.returnNull = true; + nullable = true; + + try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + LinkedList values = createTemporalTypes(nullable); + + testDates(stmt, cekJks, dateTable, values, TestCase.SETOBJECT_NULL, false); + } + + nullable = false; + RandomData.returnNull = false; + } + + /** + * Junit test case for numeric set numeric for numeric values + * + * @throws SQLException + */ + @ParameterizedTest + @MethodSource("enclaveParams") + @Tag(Constants.reqExternalSetup) + public void testNumericSpecificSetterAkv(String serverName, String url, String protocol) throws Exception { + checkAESetup(serverName, url, protocol); + + try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + + String[] values1 = createNumericValues(nullable); + String[] values2 = new String[values1.length]; + System.arraycopy(values1, 0, values2, 0, values1.length); + + testNumerics(stmt, cekAkv, numericTable, values1, values2, TestCase.NORMAL, false); + } + } + + /** + * Junit test case for numeric set numeric for numeric values + * + * @throws SQLException + */ + @ParameterizedTest + @MethodSource("enclaveParams") + public void testNumericSpecificSetter(String serverName, String url, String protocol) throws Exception { + checkAESetup(serverName, url, protocol); + + try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + + String[] values1 = createNumericValues(nullable); + String[] values2 = new String[values1.length]; + System.arraycopy(values1, 0, values2, 0, values1.length); + + testNumerics(stmt, cekJks, numericTable, values1, values2, TestCase.NORMAL, false); + } + } + + /** + * Junit test case for numeric set numeric for numeric values using windows certificate store + * + * @throws SQLException + */ + @ParameterizedTest + @MethodSource("enclaveParams") + @Tag(Constants.reqExternalSetup) + public void testNumericSpecificSetterWindows(String serverName, String url, String protocol) throws Exception { + org.junit.Assume.assumeTrue(isWindows); + + checkAESetup(serverName, url, protocol); + + try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + + String[] values1 = createNumericValues(nullable); + String[] values2 = new String[values1.length]; + System.arraycopy(values1, 0, values2, 0, values1.length); + + testNumerics(stmt, cekWin, numericTable, values1, values2, TestCase.NORMAL, false); + } + } + + /** + * Junit test case for numeric set object for numeric values + * + * @throws SQLException + */ + @ParameterizedTest + @MethodSource("enclaveParams") + @Tag(Constants.reqExternalSetup) + public void testNumericSetObjectAkv(String serverName, String url, String protocol) throws Exception { + checkAESetup(serverName, url, protocol); + + try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + String[] values1 = createNumericValues(nullable); + String[] values2 = new String[values1.length]; + System.arraycopy(values1, 0, values2, 0, values1.length); + + testNumerics(stmt, cekAkv, numericTable, values1, values2, TestCase.SETOBJECT, false); + } + } + + /** + * Junit test case for numeric set object for numeric values + * + * @throws SQLException + */ + @ParameterizedTest + @MethodSource("enclaveParams") + public void testNumericSetObject(String serverName, String url, String protocol) throws Exception { + checkAESetup(serverName, url, protocol); + + try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + String[] values1 = createNumericValues(nullable); + String[] values2 = new String[values1.length]; + System.arraycopy(values1, 0, values2, 0, values1.length); + + testNumerics(stmt, cekJks, numericTable, values1, values2, TestCase.SETOBJECT, false); + } + } + + /** + * Junit test case for numeric set object for jdbc type numeric values + * + * @throws SQLException + */ + @ParameterizedTest + @MethodSource("enclaveParams") + @Tag(Constants.reqExternalSetup) + public void testNumericSetObjectWithJDBCTypesAkv(String serverName, String url, String protocol) throws Exception { + checkAESetup(serverName, url, protocol); + + try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + String[] values1 = createNumericValues(nullable); + String[] values2 = new String[values1.length]; + System.arraycopy(values1, 0, values2, 0, values1.length); + + testNumerics(stmt, cekAkv, numericTable, values1, values2, TestCase.SETOBJECT_WITH_JDBCTYPES, false); + } + } + + /** + * Junit test case for numeric set object for jdbc type numeric values + * + * @throws SQLException + */ + @ParameterizedTest + @MethodSource("enclaveParams") + public void testNumericSetObjectWithJDBCTypes(String serverName, String url, String protocol) throws Exception { + checkAESetup(serverName, url, protocol); + + try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + String[] values1 = createNumericValues(nullable); + String[] values2 = new String[values1.length]; + System.arraycopy(values1, 0, values2, 0, values1.length); + + testNumerics(stmt, cekJks, numericTable, values1, values2, TestCase.SETOBJECT_WITH_JDBCTYPES, false); + } + } + + /** + * Junit test case for numeric set numeric for max numeric values + * + * @throws SQLException + */ + @ParameterizedTest + @MethodSource("enclaveParams") + @Tag(Constants.reqExternalSetup) + public void testNumericSpecificSetterMaxValueAkv(String serverName, String url, String protocol) throws Exception { + checkAESetup(serverName, url, protocol); + + try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + + String[] values1 = {Boolean.TRUE.toString(), "255", "32767", "2147483647", "9223372036854775807", + "1.79E308", "1.123", "3.4E38", "999999999999999999", "12345.12345", "999999999999999999", + "567812.78", "214748.3647", "922337203685477.5807", "999999999999999999999999.9999", + "999999999999999999999999.9999"}; + String[] values2 = {Boolean.TRUE.toString(), "255", "32767", "2147483647", "9223372036854775807", + "1.79E308", "1.123", "3.4E38", "999999999999999999", "12345.12345", "999999999999999999", + "567812.78", "214748.3647", "922337203685477.5807", "999999999999999999999999.9999", + "999999999999999999999999.9999"}; + + testNumerics(stmt, cekAkv, numericTable, values1, values2, TestCase.NORMAL, false); + } + } + + /** + * Junit test case for numeric set numeric for max numeric values + * + * @throws SQLException + */ + @ParameterizedTest + @MethodSource("enclaveParams") + public void testNumericSpecificSetterMaxValue(String serverName, String url, String protocol) throws Exception { + checkAESetup(serverName, url, protocol); + + try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + + String[] values1 = {Boolean.TRUE.toString(), "255", "32767", "2147483647", "9223372036854775807", + "1.79E308", "1.123", "3.4E38", "999999999999999999", "12345.12345", "999999999999999999", + "567812.78", "214748.3647", "922337203685477.5807", "999999999999999999999999.9999", + "999999999999999999999999.9999"}; + String[] values2 = {Boolean.TRUE.toString(), "255", "32767", "2147483647", "9223372036854775807", + "1.79E308", "1.123", "3.4E38", "999999999999999999", "12345.12345", "999999999999999999", + "567812.78", "214748.3647", "922337203685477.5807", "999999999999999999999999.9999", + "999999999999999999999999.9999"}; + + testNumerics(stmt, cekJks, numericTable, values1, values2, TestCase.NORMAL, false); + } + } + + /** + * Junit test case for numeric set numeric for min numeric values + * + * @throws SQLException + */ + @ParameterizedTest + @MethodSource("enclaveParams") + @Tag(Constants.reqExternalSetup) + public void testNumericSpecificSetterMinValueAkv(String serverName, String url, String protocol) throws Exception { + checkAESetup(serverName, url, protocol); + + try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + String[] values1 = {Boolean.FALSE.toString(), "0", "-32768", "-2147483648", "-9223372036854775808", + "-1.79E308", "1.123", "-3.4E38", "999999999999999999", "12345.12345", "999999999999999999", + "567812.78", "-214748.3648", "-922337203685477.5808", "999999999999999999999999.9999", + "999999999999999999999999.9999"}; + String[] values2 = {Boolean.FALSE.toString(), "0", "-32768", "-2147483648", "-9223372036854775808", "-1.79E308", "1.123", "-3.4E38", "999999999999999999", "12345.12345", "999999999999999999", "567812.78", "-214748.3648", "-922337203685477.5808", "999999999999999999999999.9999", "999999999999999999999999.9999"}; - testNumerics(stmt, cekJks, numericTable, values1, values2, TestCase.NORMAL, false); testNumerics(stmt, cekAkv, numericTable, values1, values2, TestCase.NORMAL, false); } } + /** + * Junit test case for numeric set numeric for min numeric values + * + * @throws SQLException + */ + @ParameterizedTest + @MethodSource("enclaveParams") + public void testNumericSpecificSetterMinValue(String serverName, String url, String protocol) throws Exception { + checkAESetup(serverName, url, protocol); + + try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + String[] values1 = {Boolean.FALSE.toString(), "0", "-32768", "-2147483648", "-9223372036854775808", + "-1.79E308", "1.123", "-3.4E38", "999999999999999999", "12345.12345", "999999999999999999", + "567812.78", "-214748.3648", "-922337203685477.5808", "999999999999999999999999.9999", + "999999999999999999999999.9999"}; + String[] values2 = {Boolean.FALSE.toString(), "0", "-32768", "-2147483648", "-9223372036854775808", + "-1.79E308", "1.123", "-3.4E38", "999999999999999999", "12345.12345", "999999999999999999", + "567812.78", "-214748.3648", "-922337203685477.5808", "999999999999999999999999.9999", + "999999999999999999999999.9999"}; + + testNumerics(stmt, cekJks, numericTable, values1, values2, TestCase.NORMAL, false); + } + } + + /** + * Junit test case for numeric set numeric for null values + * + * @throws SQLException + */ + @ParameterizedTest + @MethodSource("enclaveParams") + @Tag(Constants.reqExternalSetup) + public void testNumericSpecificSetterNullAkv(String serverName, String url, String protocol) throws Exception { + checkAESetup(serverName, url, protocol); + + try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + nullable = true; + RandomData.returnNull = true; + String[] values1 = createNumericValues(nullable); + String[] values2 = new String[values1.length]; + System.arraycopy(values1, 0, values2, 0, values1.length); + + testNumerics(stmt, cekAkv, numericTable, values1, values2, TestCase.NULL, false); + } + + nullable = false; + RandomData.returnNull = false; + } + /** * Junit test case for numeric set numeric for null values * @@ -947,6 +1423,31 @@ public void testNumericSpecificSetterNull(String serverName, String url, String System.arraycopy(values1, 0, values2, 0, values1.length); testNumerics(stmt, cekJks, numericTable, values1, values2, TestCase.NULL, false); + } + + nullable = false; + RandomData.returnNull = false; + } + + /** + * Junit test case for numeric set object for null values + * + * @throws SQLException + */ + @ParameterizedTest + @MethodSource("enclaveParams") + @Tag(Constants.reqExternalSetup) + public void testNumericSpecificSetterSetObjectNullAkv(String serverName, String url, + String protocol) throws Exception { + checkAESetup(serverName, url, protocol); + try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + nullable = true; + RandomData.returnNull = true; + String[] values1 = createNumericValues(nullable); + String[] values2 = new String[values1.length]; + System.arraycopy(values1, 0, values2, 0, values1.length); + testNumerics(stmt, cekAkv, numericTable, values1, values2, TestCase.NULL, false); } @@ -973,13 +1474,36 @@ public void testNumericSpecificSetterSetObjectNull(String serverName, String url System.arraycopy(values1, 0, values2, 0, values1.length); testNumerics(stmt, cekJks, numericTable, values1, values2, TestCase.NULL, false); - testNumerics(stmt, cekAkv, numericTable, values1, values2, TestCase.NULL, false); } nullable = false; RandomData.returnNull = false; } + /** + * Junit test case for numeric set numeric for null normalization values + * + * @throws SQLException + */ + @ParameterizedTest + @MethodSource("enclaveParams") + @Tag(Constants.reqExternalSetup) + public void testNumericNormalizationAkv(String serverName, String url, String protocol) throws Exception { + checkAESetup(serverName, url, protocol); + + try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + String[] values1 = {Boolean.TRUE.toString(), "1", "127", "100", "100", "1.123", "1.123", "1.123", + "123456789123456789", "12345.12345", "987654321123456789", "567812.78", "7812.7812", "7812.7812", + "999999999999999999999999.9999", "999999999999999999999999.9999"}; + String[] values2 = {Boolean.TRUE.toString(), "1", "127", "100", "100", "1.123", "1.123", "1.123", + "123456789123456789", "12345.12345", "987654321123456789", "567812.78", "7812.7812", "7812.7812", + "999999999999999999999999.9999", "999999999999999999999999.9999"}; + + testNumerics(stmt, cekAkv, numericTable, values1, values2, TestCase.NORMAL, false); + } + } + /** * Junit test case for numeric set numeric for null normalization values * @@ -1000,10 +1524,17 @@ public void testNumericNormalization(String serverName, String url, String proto "999999999999999999999999.9999", "999999999999999999999999.9999"}; testNumerics(stmt, cekJks, numericTable, values1, values2, TestCase.NORMAL, false); - testNumerics(stmt, cekAkv, numericTable, values1, values2, TestCase.NORMAL, false); } } + /** + * Junit test case for testing FMTOnly + * + * @param serverName + * @param url + * @param protocol + * @throws Exception + */ @ParameterizedTest @MethodSource("enclaveParams") public void testAEFMTOnly(String serverName, String url, String protocol) throws Exception { @@ -1011,11 +1542,10 @@ public void testAEFMTOnly(String serverName, String url, String protocol) throws try (SQLServerConnection c = PrepUtil.getConnection(AETestConnectionString + ";useFmtOnly=true", AEInfo); Statement s = c.createStatement()) { - dropTables(s); createTable(NUMERIC_TABLE_AE, cekJks, numericTable); - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(NUMERIC_TABLE_AE) + " values( " + String sql = "insert into " + NUMERIC_TABLE_AE + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + + "?,?,?," + "?,?,?," + "?,?,?" + ")"; try (PreparedStatement p = c.prepareStatement(sql)) { ParameterMetaData pmd = p.getParameterMetaData(); assertTrue(pmd.getParameterCount() == 48); @@ -1024,7 +1554,7 @@ public void testAEFMTOnly(String serverName, String url, String protocol) throws } void testChar(SQLServerStatement stmt, String[] values) throws SQLException { - String sql = "select * from " + AbstractSQLGenerator.escapeIdentifier(CHAR_TABLE_AE); + String sql = "select * from " + CHAR_TABLE_AE; try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, @@ -1041,7 +1571,7 @@ void testChar(SQLServerStatement stmt, String[] values) throws SQLException { } void testBinary(SQLServerStatement stmt, LinkedList values) throws SQLException { - String sql = "select * from " + AbstractSQLGenerator.escapeIdentifier(BINARY_TABLE_AE.toString()); + String sql = "select * from " + BINARY_TABLE_AE; try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, @@ -1058,7 +1588,7 @@ void testBinary(SQLServerStatement stmt, LinkedList values) throws SQLEx } void testDate(SQLServerStatement stmt, LinkedList values1) throws SQLException { - String sql = "select * from " + AbstractSQLGenerator.escapeIdentifier(DATE_TABLE_AE); + String sql = "select * from " + DATE_TABLE_AE; try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, @@ -1439,7 +1969,7 @@ void testGetDate(ResultSet rs, int numberOfColumns, LinkedList values) t } void testNumeric(Statement stmt, String[] numericValues, boolean isNull) throws SQLException { - String sql = "select * from " + AbstractSQLGenerator.escapeIdentifier(NUMERIC_TABLE_AE); + String sql = "select * from " + NUMERIC_TABLE_AE; try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, @@ -1627,8 +2157,8 @@ private void testAlterColumnEncryption(SQLServerStatement stmt, String tableName try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo)) { for (int i = 0; i < table.length; i++) { // alter deterministic to randomized - String sql = "ALTER TABLE " + AbstractSQLGenerator.escapeIdentifier(tableName) + " ALTER COLUMN " - + ColumnType.DETERMINISTIC.name() + table[i][0] + " " + table[i][1] + String sql = "ALTER TABLE " + tableName + " ALTER COLUMN " + ColumnType.DETERMINISTIC.name() + + table[i][0] + " " + table[i][1] + String.format(encryptSql, ColumnType.RANDOMIZED.name(), cekName) + ")"; try (SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, stmtColEncSetting)) { @@ -1654,8 +2184,7 @@ private void testRichQuery(SQLServerStatement stmt, String tableName, String tab String[] values) throws SQLException { try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo)) { for (int i = 0; i < table.length; i++) { - String sql = "SELECT * FROM " + AbstractSQLGenerator.escapeIdentifier(tableName) + " WHERE " - + ColumnType.PLAIN.name() + table[i][0] + "= ?"; + String sql = "SELECT * FROM " + tableName + " WHERE " + ColumnType.PLAIN.name() + table[i][0] + "= ?"; try (SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, stmtColEncSetting)) { switch (table[i][2]) { @@ -1780,8 +2309,7 @@ private void testRichQueryDate(SQLServerStatement stmt, String tableName, String LinkedList values) throws SQLException { try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo)) { for (int i = 0; i < table.length; i++) { - String sql = "SELECT * FROM " + AbstractSQLGenerator.escapeIdentifier(tableName) + " WHERE " - + ColumnType.PLAIN.name() + table[i][0] + "= ?"; + String sql = "SELECT * FROM " + tableName + " WHERE " + ColumnType.PLAIN.name() + table[i][0] + "= ?"; try (SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, stmtColEncSetting)) { switch (table[i][2]) { @@ -1840,8 +2368,7 @@ private void testRichQuery(SQLServerStatement stmt, String tableName, String tab LinkedList values) throws SQLException { try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo)) { for (int i = 0; i < table.length; i++) { - String sql = "SELECT * FROM " + AbstractSQLGenerator.escapeIdentifier(tableName) + " WHERE " - + ColumnType.PLAIN.name() + table[i][0] + "= ?"; + String sql = "SELECT * FROM " + tableName + " WHERE " + ColumnType.PLAIN.name() + table[i][0] + "= ?"; try (SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, stmtColEncSetting)) { switch (table[i][2]) { @@ -1907,7 +2434,7 @@ void Compare(String expectedValue, String value1, String value2, String value3) void testChars(SQLServerStatement stmt, String cekName, String[][] table, String[] values, TestCase testCase, boolean isTestEnclave) throws SQLException { - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(CHAR_TABLE_AE), stmt); + TestUtils.dropTableIfExists(CHAR_TABLE_AE, stmt); createTable(CHAR_TABLE_AE, cekName, table); switch (testCase) { @@ -1947,7 +2474,7 @@ void testChars(SQLServerStatement stmt, String cekName, String[][] table, String void testBinaries(SQLServerStatement stmt, String cekName, String[][] table, LinkedList values, TestCase testCase, boolean isTestEnclave) throws SQLException { - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(BINARY_TABLE_AE), stmt); + TestUtils.dropTableIfExists(BINARY_TABLE_AE, stmt); createTable(BINARY_TABLE_AE, cekName, table); switch (testCase) { @@ -1986,7 +2513,7 @@ void testBinaries(SQLServerStatement stmt, String cekName, String[][] table, Lin void testDates(SQLServerStatement stmt, String cekName, String[][] table, LinkedList values, TestCase testCase, boolean isTestEnclave) throws SQLException { - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(DATE_TABLE_AE), stmt); + TestUtils.dropTableIfExists(DATE_TABLE_AE, stmt); createTable(DATE_TABLE_AE, cekName, table); switch (testCase) { @@ -2029,7 +2556,7 @@ void testDates(SQLServerStatement stmt, String cekName, String[][] table, Linked void testNumerics(SQLServerStatement stmt, String cekName, String[][] table, String[] values1, String[] values2, TestCase testCase, boolean isTestEnclave) throws SQLException { - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(NUMERIC_TABLE_AE), stmt); + TestUtils.dropTableIfExists(NUMERIC_TABLE_AE, stmt); createTable(NUMERIC_TABLE_AE, cekName, table); boolean isNull = false; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java index e154365f08..6df71a88f8 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java @@ -29,7 +29,6 @@ import com.microsoft.sqlserver.jdbc.SQLServerStatement; import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.jdbc.TestUtils; -import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.Constants; import com.microsoft.sqlserver.testframework.PrepUtil; @@ -214,8 +213,8 @@ public void testDateScale5Null(String serverName, String url, String protocol) t private void testNumeric(String[] numeric) throws SQLException { try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); - SQLServerStatement stmt = (SQLServerStatement) con.createStatement(); ResultSet rs = stmt - .executeQuery("select * from " + AbstractSQLGenerator.escapeIdentifier(NUMERIC_TABLE_AE))) { + SQLServerStatement stmt = (SQLServerStatement) con.createStatement(); + ResultSet rs = stmt.executeQuery("select * from " + NUMERIC_TABLE_AE)) { int numberOfColumns = rs.getMetaData().getColumnCount(); ArrayList skipMax = new ArrayList<>(); @@ -230,8 +229,8 @@ private void testNumeric(String[] numeric) throws SQLException { private void testDate(String[] dateNormalCase, String[] dateSetObject) throws Exception { try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); - SQLServerStatement stmt = (SQLServerStatement) con.createStatement(); ResultSet rs = stmt - .executeQuery("select * from " + AbstractSQLGenerator.escapeIdentifier(DATE_TABLE_AE))) { + SQLServerStatement stmt = (SQLServerStatement) con.createStatement(); + ResultSet rs = stmt.executeQuery("select * from " + DATE_TABLE_AE)) { int numberOfColumns = rs.getMetaData().getColumnCount(); ArrayList skipMax = new ArrayList<>(); @@ -397,8 +396,8 @@ private void testGetDate(ResultSet rs, int numberOfColumns, String[] dates) thro } private void populateDate(int scale) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(DATE_TABLE_AE) + " values( " + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + String sql = "insert into " + DATE_TABLE_AE + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + + "?,?,?" + ")"; try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, @@ -477,8 +476,8 @@ private void populateDate(int scale) throws SQLException { } private void populateDateNormalCaseNull(int scale) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(DATE_TABLE_AE) + " values( " + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + String sql = "insert into " + DATE_TABLE_AE + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + + "?,?,?" + ")"; try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, @@ -520,8 +519,7 @@ private void populateDateNormalCaseNull(int scale) throws SQLException { } private void populateNumeric(String[] numeric, int precision, int scale) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(NUMERIC_TABLE_AE) + " values( " + "?,?,?," - + "?,?,?," + "?,?,?" + ")"; + String sql = "insert into " + NUMERIC_TABLE_AE + " values( " + "?,?,?," + "?,?,?," + "?,?,?" + ")"; try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, stmtColEncSetting)) { @@ -578,8 +576,7 @@ private void populateNumeric(String[] numeric, int precision, int scale) throws } private void populateNumericSetObjectNull(int precision, int scale) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(NUMERIC_TABLE_AE) + " values( " + "?,?,?," - + "?,?,?," + "?,?,?" + ")"; + String sql = "insert into " + NUMERIC_TABLE_AE + " values( " + "?,?,?," + "?,?,?," + "?,?,?" + ")"; try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, @@ -606,8 +603,8 @@ private void populateNumericSetObjectNull(int precision, int scale) throws SQLEx } private void populateDateSetObjectNull(int scale) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(DATE_TABLE_AE) + " values( " + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + String sql = "insert into " + DATE_TABLE_AE + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + + "?,?,?" + ")"; try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, 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 6dd9da2f38..8b45b1735b 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/RegressionAlwaysEncryptedTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/RegressionAlwaysEncryptedTest.java @@ -20,7 +20,6 @@ import org.junit.runners.Parameterized; import com.microsoft.sqlserver.jdbc.TestUtils; -import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.Constants; import com.microsoft.sqlserver.testframework.PrepUtil; @@ -99,8 +98,7 @@ public void alwaysEncrypted2(String serverName, String url, String protocol) thr } private void populateDateTable(Connection connection) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(DATE_TABLE_AE) + " values( " + "?,?,?" - + ")"; + String sql = "insert into " + DATE_TABLE_AE + " values( " + "?,?,?" + ")"; try (PreparedStatement sqlPstmt = connection.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, connection.getHoldability())) { sqlPstmt.setObject(1, Constants.DATE); @@ -111,8 +109,7 @@ private void populateDateTable(Connection connection) throws SQLException { } private void populateCharTable(Connection connection) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(CHAR_TABLE_AE) + " values( " + "?,?,?,?,?,?" - + ")"; + String sql = "insert into " + CHAR_TABLE_AE + " values( " + "?,?,?,?,?,?" + ")"; try (PreparedStatement sqlPstmt = connection.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, connection.getHoldability())) { sqlPstmt.setObject(1, "hi"); @@ -126,8 +123,7 @@ private void populateCharTable(Connection connection) throws SQLException { } private void populateNumericTable(Connection connection) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(NUMERIC_TABLE_AE) - + " values(?,?,?,?,?,?,?,?,?)"; + String sql = "insert into " + NUMERIC_TABLE_AE + " values(?,?,?,?,?,?,?,?,?)"; try (PreparedStatement sqlPstmt = connection.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, connection.getHoldability())) { sqlPstmt.setObject(1, true); @@ -145,8 +141,7 @@ private void populateNumericTable(Connection connection) throws SQLException { } private void populateNumericTableSpecificSetter(Connection connection) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(NUMERIC_TABLE_AE) + " values( " - + "?,?,?,?,?,?,?,?,?" + ")"; + String sql = "insert into " + NUMERIC_TABLE_AE + " values( " + "?,?,?,?,?,?,?,?,?" + ")"; try (PreparedStatement sqlPstmt = connection.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, connection.getHoldability())) { sqlPstmt.setBoolean(1, true); @@ -164,8 +159,7 @@ private void populateNumericTableSpecificSetter(Connection connection) throws SQ } private void populateNumericTableWithNull(Connection connection) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(NUMERIC_TABLE_AE) + " values( " + "?,?,?" - + ",?,?,?" + ",?,?,?" + ")"; + String sql = "insert into " + NUMERIC_TABLE_AE + " values( " + "?,?,?" + ",?,?,?" + ",?,?,?" + ")"; try (PreparedStatement sqlPstmt = connection.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, connection.getHoldability())) { sqlPstmt.setObject(1, null, java.sql.Types.BIT); @@ -183,8 +177,7 @@ private void populateNumericTableWithNull(Connection connection) throws SQLExcep private void verifyDateTable(Connection connection) throws SQLException { try (Statement stmt = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); - ResultSet rs = stmt - .executeQuery("select * from " + AbstractSQLGenerator.escapeIdentifier(DATE_TABLE_AE))) { + ResultSet rs = stmt.executeQuery("select * from " + DATE_TABLE_AE)) { while (rs.next()) { // VSTS BUG 5268 // assertEquals(date.getTime(), ((Date) rs.getObject(1)).getTime()); @@ -194,8 +187,7 @@ private void verifyDateTable(Connection connection) throws SQLException { private void verifyCharTable(Connection connection) throws SQLException { try (Statement stmt = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); - ResultSet rs = stmt - .executeQuery("select * from " + AbstractSQLGenerator.escapeIdentifier(CHAR_TABLE_AE))) { + ResultSet rs = stmt.executeQuery("select * from " + CHAR_TABLE_AE)) { while (rs.next()) { assertEquals("hi ", rs.getObject(1)); assertEquals("sample ", rs.getObject(2)); @@ -209,8 +201,7 @@ private void verifyCharTable(Connection connection) throws SQLException { private void verifyNumericTable(Connection connection, boolean isNull) throws SQLException { try (Statement stmt = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); - ResultSet rs = stmt - .executeQuery("select * from " + AbstractSQLGenerator.escapeIdentifier(NUMERIC_TABLE_AE))) { + ResultSet rs = stmt.executeQuery("select * from " + NUMERIC_TABLE_AE)) { while (rs.next()) { if (isNull) { assertEquals(null, rs.getObject(1)); @@ -238,8 +229,8 @@ private void verifyNumericTable(Connection connection, boolean isNull) throws SQ } public static void dropTables(Statement stmt) throws SQLException { - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(DATE_TABLE_AE), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(CHAR_TABLE_AE), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(NUMERIC_TABLE_AE), stmt); + TestUtils.dropTableIfExists(DATE_TABLE_AE, stmt); + TestUtils.dropTableIfExists(CHAR_TABLE_AE, stmt); + TestUtils.dropTableIfExists(NUMERIC_TABLE_AE, stmt); } } diff --git a/src/test/java/com/microsoft/sqlserver/testframework/AbstractTest.java b/src/test/java/com/microsoft/sqlserver/testframework/AbstractTest.java index 3fcf1d1b3e..246785546c 100644 --- a/src/test/java/com/microsoft/sqlserver/testframework/AbstractTest.java +++ b/src/test/java/com/microsoft/sqlserver/testframework/AbstractTest.java @@ -123,8 +123,8 @@ public static void setup() throws Exception { prop = getConfiguredProperty("enclaveServer", null); if (null == prop) { // default to server in connection string - String serverName = connectionString.substring(Constants.JDBC_PREFIX.length()) - .split(Constants.SEMI_COLON)[0]; + String serverName = (connectionString.substring(Constants.JDBC_PREFIX.length()) + .split(Constants.SEMI_COLON)[0]).split(":")[0]; enclaveServer = new String[1]; enclaveServer[0] = new String(serverName); } else { From 54b5a194e5d46552419c86e0d1f8c800f42d3de8 Mon Sep 17 00:00:00 2001 From: Peter Bae Date: Fri, 7 Feb 2020 16:19:05 -0800 Subject: [PATCH 2/8] Fix | Add null check for getObject() with LocalTime and LocalDate (#1250) --- .../sqlserver/jdbc/SQLServerResultSet.java | 14 +++++++---- .../jdbc/datatypes/DataTypesTest.java | 24 +++++++++++++++++++ 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResultSet.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResultSet.java index 5ea0469d80..58e4930d6c 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResultSet.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResultSet.java @@ -2394,12 +2394,16 @@ public T getObject(int columnIndex, Class type) throws SQLException { } else if (type == java.time.LocalDateTime.class || type == java.time.LocalDate.class || type == java.time.LocalTime.class) { java.time.LocalDateTime ldt = getLocalDateTime(columnIndex); - if (type == java.time.LocalDateTime.class) { - returnValue = ldt; - } else if (type == java.time.LocalDate.class) { - returnValue = ldt.toLocalDate(); + if (null == ldt) { + returnValue = null; } else { - returnValue = ldt.toLocalTime(); + if (type == java.time.LocalDateTime.class) { + returnValue = ldt; + } else if (type == java.time.LocalDate.class) { + returnValue = ldt.toLocalDate(); + } else { + returnValue = ldt.toLocalTime(); + } } } else if (type == java.time.OffsetDateTime.class) { microsoft.sql.DateTimeOffset dateTimeOffset = getDateTimeOffset(columnIndex); 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 5282debe96..634b7376bc 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/DataTypesTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/DataTypesTest.java @@ -19,7 +19,9 @@ import java.text.DateFormatSymbols; import java.time.Duration; import java.time.Instant; +import java.time.LocalDate; import java.time.LocalDateTime; +import java.time.LocalTime; import java.time.ZoneId; import java.time.temporal.ChronoUnit; import java.time.zone.ZoneOffsetTransition; @@ -1821,6 +1823,28 @@ public void testGetLocalDateTimePriorGregorian() throws Exception { } } } + + @Test + public void testNullValuesWithGetObject() throws Exception { + String ldtTable = AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("ldtTable")); + try (Connection conn = getConnection(); Statement st = conn.createStatement();) { + TestUtils.dropTableIfExists(ldtTable, st); + st.execute("CREATE TABLE " + ldtTable + " (c1 datetime2)"); + st.execute("INSERT INTO " + ldtTable + " VALUES (NULL)"); + + try (ResultSet rs = st.executeQuery("SELECT c1 FROM " + ldtTable);) { + rs.next(); + LocalDateTime ldtActual = rs.getObject(1, LocalDateTime.class); + assertEquals(ldtActual, null); + LocalTime ltActual = rs.getObject(1, LocalTime.class); + assertEquals(ltActual, null); + LocalDate ldActual = rs.getObject(1, LocalDate.class); + assertEquals(ldActual, null); + } finally { + TestUtils.dropTableIfExists(ldtTable, st); + } + } + } /** * Test example from https://github.com/microsoft/mssql-jdbc/issues/1143 From 672b7d67caae75250c53f82a760e8d3880e62a37 Mon Sep 17 00:00:00 2001 From: lilgreenbird Date: Mon, 10 Feb 2020 11:04:22 -0800 Subject: [PATCH 3/8] added all AKV tests to use reqExternalSetup tag so they will be skipped by default (#1254) * skip AKV test properly * removed enclave properties string to failed errors as enclave tests could be skipped --- .../jdbc/AlwaysEncrypted/AESetup.java | 11 +- .../CallableStatementTest.java | 76 ++++---- .../jdbc/AlwaysEncrypted/EnclaveTest.java | 3 +- .../JDBCEncryptionDecryptionTest.java | 172 ++++++++---------- .../AlwaysEncrypted/PrecisionScaleTest.java | 3 +- 5 files changed, 117 insertions(+), 148 deletions(-) diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java index b21e45e9cf..10437c5f9e 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java @@ -207,8 +207,7 @@ void checkAESetup(String serverName, String url, String protocol) throws Excepti } catch (SQLException e) { isAEv2 = false; } catch (Exception e) { - fail("enclaveProperties: " + enclaveProperties + "\n" + TestResource.getResource("R_unexpectedErrorMessage") - + e.getMessage()); + fail(TestResource.getResource("R_unexpectedErrorMessage") + e.getMessage()); } } @@ -318,7 +317,7 @@ private static void readFromFile(String inputFile, String lookupValue) throws IO } } } catch (IOException e) { - fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage()); + fail(e.getMessage()); } } @@ -347,7 +346,7 @@ protected static void createTable(String tableName, String cekName, String table stmt.execute(sql); stmt.execute("DBCC FREEPROCCACHE"); } catch (SQLException e) { - fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage()); + fail(e.getMessage()); } } @@ -381,7 +380,7 @@ protected static void createPrecisionTable(String tableName, String table[][], S stmt.execute(sql); stmt.execute("DBCC FREEPROCCACHE"); } catch (SQLException e) { - fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage()); + fail(e.getMessage()); } } @@ -409,7 +408,7 @@ protected static void createScaleTable(String tableName, String table[][], Strin stmt.execute(sql); stmt.execute("DBCC FREEPROCCACHE"); } catch (SQLException e) { - fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage()); + fail(e.getMessage()); } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java index eaa9f48970..e1eaa251e5 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java @@ -422,7 +422,7 @@ private static void createSPTables(String cekName) throws SQLException { Statement stmt = con.createStatement()) { stmt.execute(sql); } catch (SQLException e) { - fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage()); + fail(e.getMessage()); } sql = "create table " + table6 + " (" @@ -439,7 +439,7 @@ private static void createSPTables(String cekName) throws SQLException { TestUtils.dropTableIfExists(table6, stmt); stmt.execute(sql); } catch (SQLException e) { - fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage()); + fail(e.getMessage()); } } @@ -617,7 +617,7 @@ private void MultiInsertionSelection() throws SQLException { results = callableStatement.getMoreResults(); } } catch (SQLException e) { - fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage()); + fail(e.getMessage()); } } @@ -694,7 +694,7 @@ private void testInputProcedure(String sql, String[] values) throws SQLException assertEquals(rs.getString(1), values[3], "" + TestResource.getResource("R_inputParamFailed")); } } catch (Exception e) { - fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage()); + fail(e.getMessage()); } } @@ -746,7 +746,7 @@ private void testInputProcedure2(String sql) throws SQLException { assertEquals(rs.getString(8).trim(), charValues[8], TestResource.getResource("R_inputParamFailed")); } } catch (Exception e) { - fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage()); + fail(e.getMessage()); } } @@ -793,7 +793,7 @@ private void testOutputProcedure3RandomOrder(String sql) throws SQLException { int intValue5 = callableStatement.getInt(1); assertEquals("" + intValue5, numericValues[3], TestResource.getResource("R_outputParamFailed")); } catch (Exception e) { - fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage()); + fail(e.getMessage()); } } @@ -815,7 +815,7 @@ private void testOutputProcedure3Inorder(String sql) throws SQLException { assertEquals("" + intValue2, numericValues[3], TestResource.getResource("R_outputParamFailed")); } catch (Exception e) { - fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage()); + fail(e.getMessage()); } } @@ -836,7 +836,7 @@ private void testOutputProcedure3ReverseOrder(String sql) throws SQLException { int intValue = callableStatement.getInt(1); assertEquals("" + intValue, numericValues[3], TestResource.getResource("R_outputParamFailed")); } catch (Exception e) { - fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage()); + fail(e.getMessage()); } } @@ -909,7 +909,7 @@ private void testOutputProcedure2RandomOrder(String sql, String[] values) throws int encryptedInt = callableStatement.getInt(2); assertEquals("" + encryptedInt, values[3], TestResource.getResource("R_outputParamFailed")); } catch (Exception e) { - fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage()); + fail(e.getMessage()); } } @@ -962,7 +962,7 @@ private void testOutputProcedure2Inorder(String sql, String[] values) throws SQL assertEquals("" + encryptedMoney, values[13], TestResource.getResource("R_outputParamFailed")); } catch (Exception e) { - fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage()); + fail(e.getMessage()); } } @@ -1016,7 +1016,7 @@ private void testOutputProcedure2ReverseOrder(String sql, String[] values) throw assertEquals("" + intValue, values[3], TestResource.getResource("R_outputParamFailed")); } catch (Exception e) { - fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage()); + fail(e.getMessage()); } } @@ -1084,7 +1084,7 @@ private void testOutputProcedureRandomOrder(String sql, String[] values) throws BigDecimal money1 = callableStatement.getMoney(7); assertEquals("" + money1, "" + values[13], TestResource.getResource("R_outputParamFailed")); } catch (Exception e) { - fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage()); + fail(e.getMessage()); } } @@ -1126,7 +1126,7 @@ private void testOutputProcedureInorder(String sql, String[] values) throws SQLE assertEquals("" + money1, values[13], TestResource.getResource("R_outputParamFailed")); } catch (Exception e) { - fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage()); + fail(e.getMessage()); } } @@ -1167,7 +1167,7 @@ private void testOutputProcedureReverseOrder(String sql, String[] values) throws assertEquals("" + intValue2, values[3], TestResource.getResource("R_outputParamFailed")); } catch (Exception e) { - fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage()); + fail(e.getMessage()); } } @@ -1201,7 +1201,7 @@ private void testInOutProcedure(String sql) throws SQLException { assertEquals("" + intValue, numericValues[3], "Test for Inout parameter fails.\n"); } catch (Exception e) { - fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage()); + fail(e.getMessage()); } } @@ -1247,7 +1247,7 @@ private void testMixedProcedure(String sql) throws SQLException { int returnedValue = callableStatement.getInt(1); assertEquals("" + returnedValue, "" + 123, "Test for Inout parameter fails.\n"); } catch (Exception e) { - fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage()); + fail(e.getMessage()); } } @@ -1299,7 +1299,7 @@ private void testMixedProcedure2RandomOrder(String sql) throws SQLException { assertEquals("" + floatValue3, numericValues[5], TestResource.getResource("R_outputParamFailed")); } catch (Exception e) { - fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage()); + fail(e.getMessage()); } } @@ -1321,7 +1321,7 @@ private void testMixedProcedure2Inorder(String sql) throws SQLException { double floatValue = callableStatement.getDouble(2); assertEquals("" + floatValue, numericValues[5], TestResource.getResource("R_outputParamFailed")); } catch (Exception e) { - fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage()); + fail(e.getMessage()); } } @@ -1373,7 +1373,7 @@ private void testMixedProcedure3RandomOrder(String sql) throws SQLException { assertEquals("" + bigintValue3, numericValues[4], TestResource.getResource("R_outputParamFailed")); } catch (Exception e) { - fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage()); + fail(e.getMessage()); } } @@ -1395,7 +1395,7 @@ private void testMixedProcedure3Inorder(String sql) throws SQLException { double floatValue = callableStatement.getDouble(2); assertEquals("" + floatValue, numericValues[5], TestResource.getResource("R_outputParamFailed")); } catch (Exception e) { - fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage()); + fail(e.getMessage()); } } @@ -1417,7 +1417,7 @@ private void testMixedProcedure3ReverseOrder(String sql) throws SQLException { long bigintValue = callableStatement.getLong(1); assertEquals("" + bigintValue, numericValues[4], TestResource.getResource("R_outputParamFailed")); } catch (Exception e) { - fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage()); + fail(e.getMessage()); } } @@ -1468,7 +1468,7 @@ private void testmixedProcedureNumericPrecisionScaleInorder(String sql) throws S assertEquals(value4, new BigDecimal(numericValues[11]), "Test for input output parameter fails.\n"); } catch (Exception e) { - fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage()); + fail(e.getMessage()); } } @@ -1499,7 +1499,7 @@ private void testmixedProcedureNumericPrecisionScaleParameterName(String sql) th assertEquals(value4, new BigDecimal(numericValues[11]), "Test for input output parameter fails.\n"); } catch (Exception e) { - fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage()); + fail(e.getMessage()); } } @@ -1570,7 +1570,7 @@ private void testOutputProcedureCharInorder(String sql) throws SQLException { assertEquals(nvarcharValue4000, charValues[8], TestResource.getResource("R_outputParamFailed")); } catch (Exception e) { - fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage()); + fail(e.getMessage()); } } @@ -1623,7 +1623,7 @@ private void testOutputProcedureCharInorderObject(String sql) throws SQLExceptio assertEquals(nvarcharValue4000, charValues[8], TestResource.getResource("R_outputParamFailed")); } catch (Exception e) { - fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage()); + fail(e.getMessage()); } } @@ -1735,7 +1735,7 @@ private void testOutputProcedureNumericInorder(String sql) throws SQLException { TestResource.getResource("R_outputParamFailed")); } catch (Exception e) { - fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage()); + fail(e.getMessage()); } } @@ -1955,7 +1955,7 @@ else if (value.toString().equals("0") || value.equals(false) || value.toString() } } catch (Exception e) { - fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage()); + fail(e.getMessage()); } } @@ -2016,7 +2016,7 @@ private Object getxxx(int ordinal, Class coercion, return callableStatement.getDateTimeOffset(ordinal); } else { // Otherwise - fail("enclaveProperties: " + enclaveProperties + "\n" + "Unhandled type: " + coercion); + fail("Unhandled type: " + coercion); } return null; @@ -2085,7 +2085,7 @@ private void testOutputProcedureBinaryInorder(String sql) throws SQLException { assertEquals(received5[i], expected[i], TestResource.getResource("R_outputParamFailed")); } } catch (Exception e) { - fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage()); + fail(e.getMessage()); } } @@ -2120,13 +2120,13 @@ private void testOutputProcedureBinaryInorderObject(String sql) throws SQLExcept } } } catch (Exception e) { - fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage()); + fail(e.getMessage()); } finally { index++; } } } catch (Exception e) { - fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage()); + fail(e.getMessage()); } } @@ -2162,7 +2162,7 @@ private void testOutputProcedureBinaryInorderString(String sql) throws SQLExcept assertEquals(stringValue1.startsWith(expectedStr), true, "\nDecryption failed with getString(): " + stringValue1 + ".\nExpected Value: " + expectedStr); } catch (Exception e) { - fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage()); + fail(e.getMessage()); } finally { index++; } @@ -2233,7 +2233,7 @@ protected static void createDateTableCallableStatement(String cekName) throws SQ stmt.execute(sql); stmt.execute("DBCC FREEPROCCACHE"); } catch (SQLException e) { - fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage()); + fail(e.getMessage()); } } @@ -2391,7 +2391,7 @@ private void testOutputProcedureDateInorder(String sql) throws SQLException { TestResource.getResource("R_outputParamFailed")); } catch (Exception e) { - fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage()); + fail(e.getMessage()); } } @@ -2442,7 +2442,7 @@ private void testOutputProcedureDateInorderObject(String sql) throws SQLExceptio TestResource.getResource("R_outputParamFailed")); } catch (Exception e) { - fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage()); + fail(e.getMessage()); } } @@ -2492,7 +2492,7 @@ private void testOutputProcedureBatchInorder(String sql) throws SQLException { BigDecimal smallmoneyValue = callableStatement.getSmallMoney(4); assertEquals("" + smallmoneyValue, numericValues[12], TestResource.getResource("R_outputParamFailed")); } catch (Exception e) { - fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage()); + fail(e.getMessage()); } } @@ -2563,7 +2563,7 @@ private void testMixedProcedureDateScaleInorder(String sql) throws SQLException TestResource.getResource("R_outputParamFailed")); } catch (Exception e) { - fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage()); + fail(e.getMessage()); } } @@ -2594,7 +2594,7 @@ private void testMixedProcedureDateScaleWithParameterName(String sql) throws SQL TestResource.getResource("R_outputParamFailed")); } catch (Exception e) { - fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage()); + fail(e.getMessage()); } } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/EnclaveTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/EnclaveTest.java index 65f5aab061..259125c112 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/EnclaveTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/EnclaveTest.java @@ -208,8 +208,7 @@ public void testAEv2Disabled(String serverName, String url, String protocol) thr SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { String[] values = createCharValues(nullable); testChars(stmt, cekJks, charTable, values, TestCase.NORMAL, true); - fail("enclaveProperties: " + enclaveProperties + "\n" - + TestResource.getResource("R_expectedExceptionNotThrown")); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (Throwable e) { // testChars called fail() assertTrue(e.getMessage().contains(TestResource.getResource("R_AlterAEv2Error"))); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java index 9c8b8b4b65..c96e40731a 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java @@ -82,8 +82,7 @@ public void testJksName(String serverName, String url, String protocol) throws E jksp.setName(keystoreName); assertTrue(jksp.getName().equals(keystoreName)); } catch (SQLServerException e) { - fail("enclaveProperties: " + enclaveProperties + "\n " + TestResource.getResource("R_unexpectedException") - + e.getMessage()); + fail(TestResource.getResource("R_unexpectedException") + e.getMessage()); } } @@ -102,8 +101,7 @@ public void testAkvName(String serverName, String url, String protocol) throws E akv.setName(keystoreName); assertTrue(akv.getName().equals(keystoreName)); } catch (SQLServerException e) { - fail("enclaveProperties: " + enclaveProperties + "\n " + TestResource.getResource("R_unexpectedException") - + e.getMessage()); + fail(TestResource.getResource("R_unexpectedException") + e.getMessage()); } } @@ -119,8 +117,7 @@ public void testBadJks(String serverName, String url, String protocol) throws Ex try { SQLServerColumnEncryptionJavaKeyStoreProvider jksp = new SQLServerColumnEncryptionJavaKeyStoreProvider(null, null); - fail("enclaveProperties: " + enclaveProperties + "\n " - + TestResource.getResource("R_expectedExceptionNotThrown")); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (SQLServerException e) { assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_InvalidConnectionSetting"))); } @@ -138,8 +135,7 @@ public void testBadAkv(String serverName, String url, String protocol) throws Ex try { SQLServerColumnEncryptionAzureKeyVaultProvider akv = new SQLServerColumnEncryptionAzureKeyVaultProvider( null); - fail("enclaveProperties: " + enclaveProperties + "\n " - + TestResource.getResource("R_expectedExceptionNotThrown")); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (SQLServerException e) { assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_NullValue"))); } @@ -158,15 +154,13 @@ public void testJksBadEncryptColumnEncryptionKey(String serverName, String url, try { jksp = new SQLServerColumnEncryptionJavaKeyStoreProvider(javaKeyPath, secret); } catch (SQLServerException e) { - fail("enclaveProperties: " + enclaveProperties + "\n " + TestResource.getResource("R_unexpectedException") - + e.getMessage()); + fail(TestResource.getResource("R_unexpectedException") + e.getMessage()); } // null masterKeyPath try { jksp.encryptColumnEncryptionKey(null, null, null); - fail("enclaveProperties: " + enclaveProperties + "\n " - + TestResource.getResource("R_expectedExceptionNotThrown")); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (SQLServerException e) { assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_InvalidMasterKeyDetails"))); } @@ -175,8 +169,7 @@ public void testJksBadEncryptColumnEncryptionKey(String serverName, String url, try { byte[] emptyCek = new byte[0]; jksp.encryptColumnEncryptionKey(javaKeyPath, Constants.CEK_ALGORITHM, emptyCek); - fail("enclaveProperties: " + enclaveProperties + "\n " - + TestResource.getResource("R_expectedExceptionNotThrown")); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (SQLServerException e) { assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_EmptyColumnEncryptionKey"))); } @@ -187,6 +180,7 @@ public void testJksBadEncryptColumnEncryptionKey(String serverName, String url, */ @ParameterizedTest @MethodSource("enclaveParams") + @Tag(Constants.reqExternalSetup) public void testAkvBadEncryptColumnEncryptionKey(String serverName, String url, String protocol) throws Exception { checkAESetup(serverName, url, protocol); @@ -194,15 +188,13 @@ public void testAkvBadEncryptColumnEncryptionKey(String serverName, String url, try { akv = new SQLServerColumnEncryptionAzureKeyVaultProvider(authenticationCallback); } catch (SQLServerException e) { - fail("enclaveProperties: " + enclaveProperties + "\n " + TestResource.getResource("R_unexpectedException") - + e.getMessage()); + fail(TestResource.getResource("R_unexpectedException") + e.getMessage()); } // null encryptedColumnEncryptionKey try { akv.encryptColumnEncryptionKey(keyIDs[0], Constants.CEK_ALGORITHM, null); - fail("enclaveProperties: " + enclaveProperties + "\n " - + TestResource.getResource("R_expectedExceptionNotThrown")); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (SQLServerException e) { assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_NullColumnEncryptionKey"))); } @@ -211,8 +203,7 @@ public void testAkvBadEncryptColumnEncryptionKey(String serverName, String url, try { byte[] emptyCek = new byte[0]; akv.encryptColumnEncryptionKey(keyIDs[0], Constants.CEK_ALGORITHM, emptyCek); - fail("enclaveProperties: " + enclaveProperties + "\n " - + TestResource.getResource("R_expectedExceptionNotThrown")); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (SQLServerException e) { assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_EmptyCEK"))); } @@ -231,15 +222,13 @@ public void testJksDecryptColumnEncryptionKey(String serverName, String url, Str try { jksp = new SQLServerColumnEncryptionJavaKeyStoreProvider("badkeypath", secret); } catch (SQLServerException e) { - fail("enclaveProperties: " + enclaveProperties + "\n " + TestResource.getResource("R_unexpectedException") - + e.getMessage()); + fail(TestResource.getResource("R_unexpectedException") + e.getMessage()); } // null masterKeyPath try { jksp.decryptColumnEncryptionKey(null, null, null); - fail("enclaveProperties: " + enclaveProperties + "\n " - + TestResource.getResource("R_expectedExceptionNotThrown")); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (SQLServerException e) { assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_InvalidMasterKeyDetails"))); } @@ -248,8 +237,7 @@ public void testJksDecryptColumnEncryptionKey(String serverName, String url, Str try { byte[] emptyCek = new byte[0]; jksp.decryptColumnEncryptionKey("keypath", "algorithm", emptyCek); - fail("enclaveProperties: " + enclaveProperties + "\n " - + TestResource.getResource("R_expectedExceptionNotThrown")); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (SQLServerException e) { assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_KeyStoreNotFound"))); } @@ -257,16 +245,14 @@ public void testJksDecryptColumnEncryptionKey(String serverName, String url, Str try { jksp = new SQLServerColumnEncryptionJavaKeyStoreProvider(javaKeyPath, secret); } catch (SQLServerException e) { - fail("enclaveProperties: " + enclaveProperties + "\n " + TestResource.getResource("R_unexpectedException") - + e.getMessage()); + fail(TestResource.getResource("R_unexpectedException") + e.getMessage()); } // bad cert try { byte[] badCek = new byte[1]; jksp.decryptColumnEncryptionKey(javaKeyAliases, "RSA_OAEP", badCek); - fail("enclaveProperties: " + enclaveProperties + "\n " - + TestResource.getResource("R_expectedExceptionNotThrown")); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (SQLServerException e) { assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_invalidKeyStoreFile"))); } @@ -277,6 +263,7 @@ public void testJksDecryptColumnEncryptionKey(String serverName, String url, Str */ @ParameterizedTest @MethodSource("enclaveParams") + @Tag(Constants.reqExternalSetup) public void testAkvDecryptColumnEncryptionKey(String serverName, String url, String protocol) throws Exception { checkAESetup(serverName, url, protocol); @@ -284,15 +271,13 @@ public void testAkvDecryptColumnEncryptionKey(String serverName, String url, Str try { akv = new SQLServerColumnEncryptionAzureKeyVaultProvider(authenticationCallback); } catch (SQLServerException e) { - fail("enclaveProperties: " + enclaveProperties + "\n " + TestResource.getResource("R_unexpectedException") - + e.getMessage()); + fail(TestResource.getResource("R_unexpectedException") + e.getMessage()); } // null akvpath try { akv.decryptColumnEncryptionKey(null, "", null); - fail("enclaveProperties: " + enclaveProperties + "\n " - + TestResource.getResource("R_expectedExceptionNotThrown")); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (SQLServerException e) { assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_AKVPathNull"))); } @@ -300,8 +285,7 @@ public void testAkvDecryptColumnEncryptionKey(String serverName, String url, Str // invalid akvpath try { akv.decryptColumnEncryptionKey("keypath", "", null); - fail("enclaveProperties: " + enclaveProperties + "\n " - + TestResource.getResource("R_expectedExceptionNotThrown")); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (SQLServerException e) { assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_AKVMasterKeyPathInvalid"))); } @@ -309,8 +293,7 @@ public void testAkvDecryptColumnEncryptionKey(String serverName, String url, Str // invalid akvpath url try { akv.decryptColumnEncryptionKey("http:///^[!#$&-;=?-[]_a-", "", null); - fail("enclaveProperties: " + enclaveProperties + "\n " - + TestResource.getResource("R_expectedExceptionNotThrown")); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (SQLServerException e) { assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_AKVURLInvalid"))); } @@ -318,8 +301,7 @@ public void testAkvDecryptColumnEncryptionKey(String serverName, String url, Str // null encryptedColumnEncryptionKey try { akv.decryptColumnEncryptionKey(keyIDs[0], Constants.CEK_ALGORITHM, null); - fail("enclaveProperties: " + enclaveProperties + "\n " - + TestResource.getResource("R_expectedExceptionNotThrown")); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (SQLServerException e) { assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_NullEncryptedColumnEncryptionKey"))); } @@ -328,8 +310,7 @@ public void testAkvDecryptColumnEncryptionKey(String serverName, String url, Str try { byte[] emptyCek = new byte[0]; akv.decryptColumnEncryptionKey(keyIDs[0], Constants.CEK_ALGORITHM, emptyCek); - fail("enclaveProperties: " + enclaveProperties + "\n " - + TestResource.getResource("R_expectedExceptionNotThrown")); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (SQLServerException e) { assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_EmptyEncryptedColumnEncryptionKey"))); } @@ -338,8 +319,7 @@ public void testAkvDecryptColumnEncryptionKey(String serverName, String url, Str try { byte[] badCek = new byte[1]; akv.decryptColumnEncryptionKey(keyIDs[0], "invalidAlgo", badCek); - fail("enclaveProperties: " + enclaveProperties + "\n " - + TestResource.getResource("R_expectedExceptionNotThrown")); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (SQLServerException e) { assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_InvalidKeyEncryptionAlgorithm"))); } @@ -348,8 +328,7 @@ public void testAkvDecryptColumnEncryptionKey(String serverName, String url, Str try { byte[] badCek = new byte[1]; akv.decryptColumnEncryptionKey(keyIDs[0], Constants.CEK_ALGORITHM, badCek); - fail("enclaveProperties: " + enclaveProperties + "\n " - + TestResource.getResource("R_expectedExceptionNotThrown")); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (SQLServerException e) { assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_InvalidEcryptionAlgorithmVersion"))); } @@ -370,6 +349,24 @@ public void testCharSpecificSetter(String serverName, String url, String protoco String[] values = createCharValues(nullable); testChars(stmt, cekJks, charTable, values, TestCase.NORMAL, false); + } + } + + /** + * Junit test case for char set string for string values for AKV + * + * @throws SQLException + */ + @ParameterizedTest + @MethodSource("enclaveParams") + @Tag(Constants.reqExternalSetup) + public void testCharSpecificSetterAkv(String serverName, String url, String protocol) throws Exception { + checkAESetup(serverName, url, protocol); + + try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + String[] values = createCharValues(nullable); + testChars(stmt, cekAkv, charTable, values, TestCase.NORMAL, false); } } @@ -1949,8 +1946,7 @@ void testGetDate(ResultSet rs, int numberOfColumns, LinkedList values) t break; default: - fail("enclaveProperties: " + enclaveProperties + "\n " - + TestResource.getResource("R_switchFailed")); + fail(TestResource.getResource("R_switchFailed")); } assertTrue( @@ -1962,8 +1958,7 @@ void testGetDate(ResultSet rs, int numberOfColumns, LinkedList values) t } else { - fail("enclaveProperties: " + enclaveProperties + "\n " - + TestResource.getResource("R_resultsetNotInstance")); + fail(TestResource.getResource("R_resultsetNotInstance")); } } } @@ -2164,16 +2159,13 @@ private void testAlterColumnEncryption(SQLServerStatement stmt, String tableName stmtColEncSetting)) { stmt.execute(sql); if (!TestUtils.isAEv2(con)) { - fail("enclaveProperties: " + enclaveProperties + "\n " - + TestResource.getResource("R_expectedExceptionNotThrown")); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } } catch (SQLException e) { if (!TestUtils.isAEv2(con)) { - fail("enclaveProperties: " + enclaveProperties + "\n " - + TestResource.getResource("R_expectedExceptionNotThrown")); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } else { - fail("enclaveProperties: " + enclaveProperties + "\n " - + TestResource.getResource("R_AlterAEv2Error") + e.getMessage() + "Query: " + sql); + fail(TestResource.getResource("R_AlterAEv2Error") + e.getMessage() + "Query: " + sql); } } } @@ -2272,14 +2264,12 @@ private void testRichQuery(SQLServerStatement stmt, String tableName, String tab } break; default: - fail("enclaveProperties: " + enclaveProperties + "\n " - + TestResource.getResource("R_invalidObjectName") + ": " + table[i][2]); + fail(TestResource.getResource("R_invalidObjectName") + ": " + table[i][2]); } try (ResultSet rs = (pstmt.executeQuery())) { if (!TestUtils.isAEv2(con)) { - fail("enclaveProperties: " + enclaveProperties + ": " - + TestResource.getResource("R_expectedExceptionNotThrown")); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } int numberOfColumns = rs.getMetaData().getColumnCount(); @@ -2289,16 +2279,13 @@ private void testRichQuery(SQLServerStatement stmt, String tableName, String tab } } catch (SQLException e) { if (!TestUtils.isAEv2(con)) { - fail("enclaveProperties: " + enclaveProperties + ": " - + TestResource.getResource("R_expectedExceptionNotThrown")); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } else { - fail("enclaveProperties: " + enclaveProperties + "\n " - + TestResource.getResource("R_RichQueryError") + e.getMessage() + "Query: " + sql); + fail(TestResource.getResource("R_RichQueryError") + e.getMessage() + "Query: " + sql); } } } catch (Exception e) { - fail("enclaveProperties: " + enclaveProperties + "\n " - + TestResource.getResource("R_RichQueryError") + e.getMessage() + "Query: " + sql); + fail(TestResource.getResource("R_RichQueryError") + e.getMessage() + "Query: " + sql); } } @@ -2332,14 +2319,12 @@ private void testRichQueryDate(SQLServerStatement stmt, String tableName, String pstmt.setSmallDateTime(1, (Timestamp) values.get(i + 1 / 3)); break; default: - fail("enclaveProperties: " + enclaveProperties + "\n " - + TestResource.getResource("R_invalidObjectName") + ": " + table[i][2]); + fail(TestResource.getResource("R_invalidObjectName") + ": " + table[i][2]); } try (ResultSet rs = (pstmt.executeQuery())) { if (!TestUtils.isAEv2(con)) { - fail("enclaveProperties: " + enclaveProperties + ": " - + TestResource.getResource("R_expectedExceptionNotThrown")); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } int numberOfColumns = rs.getMetaData().getColumnCount(); @@ -2349,16 +2334,13 @@ private void testRichQueryDate(SQLServerStatement stmt, String tableName, String } } catch (SQLException e) { if (!TestUtils.isAEv2(con)) { - fail("enclaveProperties: " + enclaveProperties + ": " - + TestResource.getResource("R_expectedExceptionNotThrown")); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } else { - fail("enclaveProperties: " + enclaveProperties + "\n " - + TestResource.getResource("R_RichQueryError") + e.getMessage() + "Query: " + sql); + fail(TestResource.getResource("R_RichQueryError") + e.getMessage() + "Query: " + sql); } } } catch (Exception e) { - fail("enclaveProperties: " + enclaveProperties + "\n " - + TestResource.getResource("R_RichQueryError") + e.getMessage() + "Query: " + sql); + fail(TestResource.getResource("R_RichQueryError") + e.getMessage() + "Query: " + sql); } } } @@ -2376,14 +2358,12 @@ private void testRichQuery(SQLServerStatement stmt, String tableName, String tab pstmt.setBytes(1, (byte[]) values.get(i + 1 / 3)); break; default: - fail("enclaveProperties: " + enclaveProperties + "\n " - + TestResource.getResource("R_invalidObjectName") + ": " + table[i][2]); + fail(TestResource.getResource("R_invalidObjectName") + ": " + table[i][2]); } try (ResultSet rs = (pstmt.executeQuery())) { if (!TestUtils.isAEv2(con)) { - fail("enclaveProperties: " + enclaveProperties + ": " - + TestResource.getResource("R_expectedExceptionNotThrown")); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } int numberOfColumns = rs.getMetaData().getColumnCount(); @@ -2394,16 +2374,13 @@ private void testRichQuery(SQLServerStatement stmt, String tableName, String tab } } catch (SQLException e) { if (!TestUtils.isAEv2(con)) { - fail("enclaveProperties: " + enclaveProperties + ": " - + TestResource.getResource("R_expectedExceptionNotThrown")); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } else { - fail("enclaveProperties: " + enclaveProperties + "\n " - + TestResource.getResource("R_RichQueryError") + e.getMessage() + "Query: " + sql); + fail(TestResource.getResource("R_RichQueryError") + e.getMessage() + "Query: " + sql); } } } catch (Exception e) { - fail("enclaveProperties: " + enclaveProperties + "\n " - + TestResource.getResource("R_RichQueryError") + e.getMessage() + "Query: " + sql); + fail(TestResource.getResource("R_RichQueryError") + e.getMessage() + "Query: " + sql); } } } @@ -2454,7 +2431,7 @@ void testChars(SQLServerStatement stmt, String cekName, String[][] table, String populateCharNullCase(); break; default: - fail("enclaveProperties: " + enclaveProperties + "\n " + TestResource.getResource("R_switchFailed")); + fail(TestResource.getResource("R_switchFailed")); break; } @@ -2463,8 +2440,7 @@ void testChars(SQLServerStatement stmt, String cekName, String[][] table, String if (isTestEnclave) { if (null == enclaveAttestationUrl || null == enclaveAttestationProtocol) { - fail("enclaveProperties: " + enclaveProperties + "\n " - + TestResource.getResource("R_reqExternalSetup")); + fail(TestResource.getResource("R_reqExternalSetup")); } testAlterColumnEncryption(stmt, CHAR_TABLE_AE, table, cekName); @@ -2493,7 +2469,7 @@ void testBinaries(SQLServerStatement stmt, String cekName, String[][] table, Lin populateBinaryNullCase(); break; default: - fail("enclaveProperties: " + enclaveProperties + "\n " + TestResource.getResource("R_switchFailed")); + fail(TestResource.getResource("R_switchFailed")); break; } @@ -2502,8 +2478,7 @@ void testBinaries(SQLServerStatement stmt, String cekName, String[][] table, Lin if (isTestEnclave) { if (null == enclaveAttestationUrl || null == enclaveAttestationProtocol) { - fail("enclaveProperties: " + enclaveProperties + "\n " - + TestResource.getResource("R_reqExternalSetup")); + fail(TestResource.getResource("R_reqExternalSetup")); } testAlterColumnEncryption(stmt, BINARY_TABLE_AE, table, cekName); @@ -2536,7 +2511,7 @@ void testDates(SQLServerStatement stmt, String cekName, String[][] table, Linked populateDateNullCase(); break; default: - fail("enclaveProperties: " + enclaveProperties + "\n " + TestResource.getResource("R_switchFailed")); + fail(TestResource.getResource("R_switchFailed")); break; } @@ -2545,8 +2520,7 @@ void testDates(SQLServerStatement stmt, String cekName, String[][] table, Linked if (isTestEnclave) { if (null == enclaveAttestationUrl || null == enclaveAttestationProtocol) { - fail("enclaveProperties: " + enclaveProperties + "\n " - + TestResource.getResource("R_reqExternalSetup")); + fail(TestResource.getResource("R_reqExternalSetup")); } testAlterColumnEncryption(stmt, DATE_TABLE_AE, table, cekName); @@ -2575,7 +2549,7 @@ void testNumerics(SQLServerStatement stmt, String cekName, String[][] table, Str isNull = true; break; default: - fail("enclaveProperties: " + enclaveProperties + "\n " + TestResource.getResource("R_switchFailed")); + fail(TestResource.getResource("R_switchFailed")); break; } @@ -2584,8 +2558,7 @@ void testNumerics(SQLServerStatement stmt, String cekName, String[][] table, Str if (isTestEnclave) { if (null == enclaveAttestationUrl || null == enclaveAttestationProtocol) { - fail("enclaveProperties: " + enclaveProperties + "\n " - + TestResource.getResource("R_reqExternalSetup")); + fail(TestResource.getResource("R_reqExternalSetup")); } testAlterColumnEncryption(stmt, NUMERIC_TABLE_AE, table, cekName); @@ -2607,8 +2580,7 @@ public String getAccessToken(String authority, String resource, String scope) { Future future = context.acquireToken(resource, cred, null); result = future.get(); } catch (Exception e) { - fail("enclaveProperties: " + enclaveProperties + "\n " - + TestResource.getResource("R_unexpectedException") + e.getMessage()); + fail(TestResource.getResource("R_unexpectedException") + e.getMessage()); } return result.getAccessToken(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java index 6df71a88f8..67b345a9f2 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java @@ -389,8 +389,7 @@ private void testGetDate(ResultSet rs, int numberOfColumns, String[] dates) thro } else { - fail("enclaveProperties: " + enclaveProperties + "\n" - + TestResource.getResource("R_resultsetNotInstance")); + fail(TestResource.getResource("R_resultsetNotInstance")); } } } From 7ff97dee94ec4144ef22e5d12ba76f1a84ebe3c9 Mon Sep 17 00:00:00 2001 From: lilgreenbird Date: Wed, 9 Sep 2020 16:20:13 -0700 Subject: [PATCH 4/8] enable ADintegrated tests for non-windows --- .../sqlserver/jdbc/SQLServerADAL4JUtils.java | 31 +++++++++++-------- .../sqlserver/jdbc/SQLServerResource.java | 2 +- .../jdbc/fedauth/ConcurrentLoginTest.java | 2 +- .../fedauth/ConnectionSuspensionTest.java | 4 +-- .../jdbc/fedauth/ErrorMessageTest.java | 23 +++++++------- .../sqlserver/jdbc/fedauth/FedauthCommon.java | 2 +- .../sqlserver/jdbc/fedauth/FedauthTest.java | 6 ++-- .../jdbc/fedauth/PooledConnectionTest.java | 4 +-- 8 files changed, 40 insertions(+), 34 deletions(-) diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerADAL4JUtils.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerADAL4JUtils.java index a94ca3cc5e..7767a0fb2e 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerADAL4JUtils.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerADAL4JUtils.java @@ -41,25 +41,30 @@ static SqlFedAuthToken getSqlFedAuthToken(SqlFedAuthInfo fedAuthInfo, String use return new SqlFedAuthToken(authenticationResult.getAccessToken(), authenticationResult.getExpiresOnDate()); } catch (MalformedURLException | InterruptedException e) { throw new SQLServerException(e.getMessage(), e); - } catch (ExecutionException e) { + } catch (Exception e) { MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_ADALExecution")); - Object[] msgArgs = {user, authenticationString}; + Object[] msgArgs = {user, authenticationString, e.getMessage()}; /* * the cause error message uses \\n\\r which does not give correct format change it to \r\n to provide * correct format */ - String correctedErrorMessage = e.getCause().getMessage().replaceAll("\\\\r\\\\n", "\r\n"); - AuthenticationException correctedAuthenticationException = new AuthenticationException( - correctedErrorMessage); + if (null == e.getCause() || null == e.getCause().getMessage()) { + throw new SQLServerException(form.format(msgArgs), null); + } else { + String correctedErrorMessage = e.getCause().getMessage().replaceAll("\\\\r\\\\n", "\r\n"); + AuthenticationException correctedAuthenticationException = new AuthenticationException( + correctedErrorMessage); - /* - * SQLServerException is caused by ExecutionException, which is caused by AuthenticationException to match - * the exception tree before error message correction - */ - ExecutionException correctedExecutionException = new ExecutionException(correctedAuthenticationException); + /* + * SQLServerException is caused by ExecutionException, which is caused by AuthenticationException to + * match the exception tree before error message correction + */ + ExecutionException correctedExecutionException = new ExecutionException( + correctedAuthenticationException); - throw new SQLServerException(form.format(msgArgs), null, 0, correctedExecutionException); + throw new SQLServerException(form.format(msgArgs), null, 0, correctedExecutionException); + } } finally { executorService.shutdown(); } @@ -90,9 +95,9 @@ static SqlFedAuthToken getSqlFedAuthTokenIntegrated(SqlFedAuthInfo fedAuthInfo, return new SqlFedAuthToken(authenticationResult.getAccessToken(), authenticationResult.getExpiresOnDate()); } catch (InterruptedException | IOException e) { throw new SQLServerException(e.getMessage(), e); - } catch (ExecutionException e) { + } catch (Exception e) { MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_ADALExecution")); - Object[] msgArgs = {"", authenticationString}; + Object[] msgArgs = {"", authenticationString, e.getMessage()}; if (null == e.getCause() || null == e.getCause().getMessage()) { // the case when Future's outcome has no AuthenticationResult but exception diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java index a361c0f59c..1acf9cbdd2 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java @@ -404,7 +404,7 @@ protected Object[][] getContents() { "FEDAUTHINFO token stream is not long enough ({0}) to contain the data it claims to."}, {"R_FedAuthInfoDoesNotContainStsurlAndSpn", "FEDAUTHINFO token stream does not contain both STSURL and SPN."}, - {"R_ADALExecution", "Failed to authenticate the user {0} in Active Directory (Authentication={1})."}, + {"R_ADALExecution", "Failed to authenticate the user {0} in Active Directory (Authentication={1}). {2}"}, {"R_UnrequestedFeatureAckReceived", "Unrequested feature acknowledge is received. Feature ID: {0}."}, {"R_FedAuthFeatureAckContainsExtraData", "Federated authentication feature extension ack for ADAL and Security Token includes extra data."}, 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 dbd7b32aef..b637000d22 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ConcurrentLoginTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ConcurrentLoginTest.java @@ -95,7 +95,7 @@ public void testConcurrentLogin() throws Exception { t1.start(); t2.start(); - if (isWindows && enableADIntegrated) { + if (enableADIntegrated) { Thread t3 = new Thread(r3); t3.setUncaughtExceptionHandler(handler); t3.start(); 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 d7d847784d..5cbda65da7 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ConnectionSuspensionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ConnectionSuspensionTest.java @@ -42,7 +42,7 @@ public void testAccessTokenExpiredThenCreateNewStatementADPassword() throws SQLE @Test public void testAccessTokenExpiredThenCreateNewStatementADIntegrated() throws SQLException { - org.junit.Assume.assumeTrue(isWindows && enableADIntegrated); + org.junit.Assume.assumeTrue(enableADIntegrated); testAccessTokenExpiredThenCreateNewStatement(SqlAuthentication.ActiveDirectoryIntegrated); } @@ -107,7 +107,7 @@ public void testAccessTokenExpiredThenExecuteUsingSameStatementADPassword() thro @Test public void testAccessTokenExpiredThenExecuteUsingSameStatementADIntegrated() throws SQLException { - org.junit.Assume.assumeTrue(isWindows && enableADIntegrated); + org.junit.Assume.assumeTrue(enableADIntegrated); testAccessTokenExpiredThenExecuteUsingSameStatement(SqlAuthentication.ActiveDirectoryIntegrated); } 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 49d472eea1..719ff88842 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ErrorMessageTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ErrorMessageTest.java @@ -26,7 +26,7 @@ @Tag(Constants.fedAuth) public class ErrorMessageTest extends FedauthCommon { - String userName = "abc" + azureUserName; + String badUserName = "abc" + azureUserName; String connectionUrl = "jdbc:sqlserver://" + azureServer + ";database=" + azureDatabase; @Test @@ -214,13 +214,14 @@ public void testSQLPasswordWithUntrustedSqlDB() throws SQLException { @Test public void testADPasswordUnregisteredUserWithConnectionStringUserName() throws SQLException { - try (Connection connection = DriverManager.getConnection(connectionUrl + ";userName=" + userName + ";password=" - + azurePassword + ";Authentication=" + SqlAuthentication.ActiveDirectoryPassword.toString())) { + try (Connection connection = DriverManager + .getConnection(connectionUrl + ";userName=" + badUserName + ";password=" + azurePassword + + ";Authentication=" + SqlAuthentication.ActiveDirectoryPassword.toString())) { fail(EXPECTED_EXCEPTION_NOT_THROWN); } catch (SQLServerException e) { assertTrue(INVALID_EXCEPION_MSG + ": " + e.getMessage(), e.getMessage() - .contains(ERR_MSG_FAILED_AUTHENTICATE + " the user " + userName + .contains(ERR_MSG_FAILED_AUTHENTICATE + " the user " + badUserName + " in Active Directory (Authentication=ActiveDirectoryPassword).") && e.getCause().getCause().getMessage().contains(ERR_MSG_SIGNIN_ADD)); } @@ -232,7 +233,7 @@ public void testADPasswordUnregisteredUserWithDatasource() throws SQLException { SQLServerDataSource ds = new SQLServerDataSource(); ds.setServerName(azureServer); ds.setDatabaseName(azureDatabase); - ds.setUser(userName); + ds.setUser(badUserName); ds.setPassword(azurePassword); ds.setAuthentication(SqlAuthentication.ActiveDirectoryPassword.toString()); @@ -241,7 +242,7 @@ public void testADPasswordUnregisteredUserWithDatasource() throws SQLException { } catch (SQLServerException e) { assertTrue(INVALID_EXCEPION_MSG + ": " + e.getMessage(), e.getMessage() - .contains(ERR_MSG_FAILED_AUTHENTICATE + " the user " + userName + .contains(ERR_MSG_FAILED_AUTHENTICATE + " the user " + badUserName + " in Active Directory (Authentication=ActiveDirectoryPassword).") && e.getCause().getCause().getMessage().contains(ERR_MSG_SIGNIN_ADD)); } @@ -249,13 +250,13 @@ public void testADPasswordUnregisteredUserWithDatasource() throws SQLException { @Test public void testADPasswordUnregisteredUserWithConnectionStringUser() throws SQLException { - try (Connection connection = DriverManager.getConnection(connectionUrl + ";user=" + userName + ";password=" + try (Connection connection = DriverManager.getConnection(connectionUrl + ";user=" + badUserName + ";password=" + azurePassword + ";Authentication=" + SqlAuthentication.ActiveDirectoryPassword.toString())) { fail(EXPECTED_EXCEPTION_NOT_THROWN); } catch (SQLServerException e) { assertTrue(INVALID_EXCEPION_MSG + ": " + e.getMessage(), e.getMessage() - .contains(ERR_MSG_FAILED_AUTHENTICATE + " the user " + userName + .contains(ERR_MSG_FAILED_AUTHENTICATE + " the user " + badUserName + " in Active Directory (Authentication=ActiveDirectoryPassword).") && e.getCause().getCause().getMessage().contains(ERR_MSG_SIGNIN_ADD)); } @@ -268,20 +269,20 @@ public void testAuthenticationAgainstSQLServerWithActivedirectorypassword() thro info.put("Authentication", SqlAuthentication.ActiveDirectoryPassword.toString()); try (Connection connection = DriverManager - .getConnection(connectionUrl + ";user=" + userName + ";password=" + azurePassword, info)) { + .getConnection(connectionUrl + ";user=" + badUserName + ";password=" + azurePassword, info)) { fail(EXPECTED_EXCEPTION_NOT_THROWN); } catch (Exception e) { if (!(e instanceof SQLServerException)) { fail(EXPECTED_EXCEPTION_NOT_THROWN); } assertTrue(INVALID_EXCEPION_MSG + ": " + e.getMessage(), e.getMessage().contains(ERR_MSG_FAILED_AUTHENTICATE - + " the user " + userName + " in Active Directory (Authentication=ActiveDirectoryPassword).")); + + " the user " + badUserName + " in Active Directory (Authentication=ActiveDirectoryPassword).")); } } @Test public void testAuthenticationAgainstSQLServerWithActivedirectoryIntegrated() throws SQLException { - org.junit.Assume.assumeTrue(isWindows && enableADIntegrated); + org.junit.Assume.assumeTrue(enableADIntegrated); java.util.Properties info = new Properties(); info.put("TrustServerCertificate", "true"); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthCommon.java b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthCommon.java index 675fa4341b..7854a271c5 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthCommon.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthCommon.java @@ -116,7 +116,7 @@ public static void getConfigs() throws Exception { azureGroupUserName = getConfiguredProperty("azureGroupUserName"); String prop = getConfiguredProperty("enableADIntegrated"); - enableADIntegrated = (isWindows && null != prop && prop.equalsIgnoreCase("true")) ? true : false; + enableADIntegrated = (null != prop && prop.equalsIgnoreCase("true")) ? true : false; adPasswordConnectionStr = "jdbc:sqlserver://" + azureServer + ";database=" + azureDatabase + ";user=" + azureUserName + ";password=" + azurePassword + ";Authentication=" 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 ac383935a3..45308fbaeb 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthTest.java @@ -106,7 +106,7 @@ public void testActiveDirectoryPasswordDS() throws Exception { @Test public void testActiveDirectoryIntegratedDS() throws Exception { - org.junit.Assume.assumeTrue(isWindows && enableADIntegrated); + org.junit.Assume.assumeTrue(enableADIntegrated); SQLServerDataSource ds = new SQLServerDataSource(); ds.setServerName(azureServer); @@ -173,7 +173,7 @@ public void testNotValidSqlPassword() throws SQLException { @Test public void testNotValidActiveDirectoryIntegrated() throws SQLException { - org.junit.Assume.assumeTrue(isWindows && enableADIntegrated); + org.junit.Assume.assumeTrue(enableADIntegrated); testNotValid(SqlAuthentication.ActiveDirectoryIntegrated.toString(), false, true); testNotValid(SqlAuthentication.ActiveDirectoryIntegrated.toString(), true, true); @@ -200,7 +200,7 @@ public void testValidSqlPassword() throws SQLException { @Test public void testValidActiveDirectoryIntegrated() throws SQLException { - org.junit.Assume.assumeTrue(isWindows && enableADIntegrated); + org.junit.Assume.assumeTrue(enableADIntegrated); testValid(SqlAuthentication.ActiveDirectoryIntegrated.toString(), false, true); testValid(SqlAuthentication.ActiveDirectoryIntegrated.toString(), true, true); 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 c4d31c4838..9183b66837 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/PooledConnectionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/PooledConnectionTest.java @@ -58,7 +58,7 @@ public void testPooledConnectionAccessTokenExpiredThenReconnectADPassword() thro @Test public void testPooledConnectionAccessTokenExpiredThenReconnectADIntegrated() throws SQLException { - org.junit.Assume.assumeTrue(isWindows && enableADIntegrated); + org.junit.Assume.assumeTrue(enableADIntegrated); // suspend 5 mins testPooledConnectionAccessTokenExpiredThenReconnect((long) 5 * 60, SqlAuthentication.ActiveDirectoryIntegrated); @@ -132,7 +132,7 @@ public void testPooledConnectionMultiThreadADPassword() throws SQLException { @Test public void testPooledConnectionMultiThreadADIntegrated() throws SQLException { - org.junit.Assume.assumeTrue(isWindows && enableADIntegrated); + org.junit.Assume.assumeTrue(enableADIntegrated); testPooledConnectionMultiThread(secondsBeforeExpiration, SqlAuthentication.ActiveDirectoryIntegrated); } From 7cae3b431dc533e07042f1bbc810995f78b64510 Mon Sep 17 00:00:00 2001 From: lilgreenbird Date: Thu, 10 Sep 2020 22:34:42 -0700 Subject: [PATCH 5/8] fixed user test for kerberos --- .../microsoft/sqlserver/jdbc/fedauth/FedauthCommon.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthCommon.java b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthCommon.java index 7854a271c5..6a9427a788 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthCommon.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthCommon.java @@ -158,7 +158,12 @@ void testUserName(Connection conn, String user, SqlAuthentication authentication if (SqlAuthentication.ActiveDirectoryIntegrated != authentication) { assertTrue(user.equals(rs.getString(1))); } else { - assertTrue(rs.getString(1).contains(System.getProperty("user.name"))); + if (isWindows) { + assertTrue(rs.getString(1).contains(System.getProperty("user.name"))); + } else { + // cannot verify user in kerberos tickets so just check it's not empty + assertTrue(!rs.getString(1).isEmpty()); + } } } } From 0041c40f2b2471e369f9d1e752158bf1776b09f3 Mon Sep 17 00:00:00 2001 From: lilgreenbird Date: Wed, 14 Apr 2021 17:35:12 -0700 Subject: [PATCH 6/8] clear password --- src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java | 7 +------ .../com/microsoft/sqlserver/jdbc/SQLServerConnection.java | 2 ++ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java b/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java index 9ad0256776..1bf1554da4 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java @@ -1734,10 +1734,6 @@ else if (con.getTrustManagerClass() != null) { try { ks.load(is, (null == trustStorePassword) ? null : trustStorePassword.toCharArray()); } finally { - // We are done with the trustStorePassword (if set). Clear it for better security. - con.activeConnectionProperties - .remove(SQLServerDriverStringProperty.TRUST_STORE_PASSWORD.toString()); - // We are also done with the trust store input stream. if (null != is) { try { @@ -4029,8 +4025,7 @@ void writeNonUnicodeReader(Reader reader, long advertisedLength, boolean isDestB do { // Read in next chunk - for (charsToWrite = 0; -1 != charsRead && charsToWrite < currentPacketSize; - charsToWrite += charsRead) { + for (charsToWrite = 0; -1 != charsRead && charsToWrite < currentPacketSize; charsToWrite += charsRead) { try { charsRead = reader.read(streamCharBuffer, charsToWrite, currentPacketSize - charsToWrite); } catch (IOException e) { diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java index 5cc89e46ce..28df3c86ae 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java @@ -4520,6 +4520,8 @@ final void processFedAuthInfo(TDSReader tdsReader, TDSTokenHandler tdsTokenHandl aadPrincipalSecret = ""; activeConnectionProperties.remove(SQLServerDriverStringProperty.AAD_SECURE_PRINCIPAL_SECRET.toString()); + + activeConnectionProperties.remove(SQLServerDriverStringProperty.TRUST_STORE_PASSWORD.toString()); } final class FedAuthTokenCommand extends UninterruptableTDSCommand { From a4723285765053795cdb0d974e204440de9ea72c Mon Sep 17 00:00:00 2001 From: lilgreenbird Date: Wed, 21 Apr 2021 17:33:00 -0700 Subject: [PATCH 7/8] fix --- .../com/microsoft/sqlserver/jdbc/SQLServerConnection.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java index 28df3c86ae..6f0af8df64 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java @@ -2355,6 +2355,8 @@ else if (0 == requestedPacketSize) if (!state.equals(State.Closed)) this.close(); } + + activeConnectionProperties.remove(SQLServerDriverStringProperty.TRUST_STORE_PASSWORD.toString()); } return this; @@ -2824,7 +2826,7 @@ private InetSocketAddress connectHelper(ServerPortPlaceHolder serverInfo, int ti } activeConnectionProperties.remove(SQLServerDriverStringProperty.CLIENT_KEY_PASSWORD.toString()); - + // We have successfully connected, now do the login. logon takes seconds timeout executeCommand(new LogonCommand()); return inetSocketAddress; @@ -4520,8 +4522,6 @@ final void processFedAuthInfo(TDSReader tdsReader, TDSTokenHandler tdsTokenHandl aadPrincipalSecret = ""; activeConnectionProperties.remove(SQLServerDriverStringProperty.AAD_SECURE_PRINCIPAL_SECRET.toString()); - - activeConnectionProperties.remove(SQLServerDriverStringProperty.TRUST_STORE_PASSWORD.toString()); } final class FedAuthTokenCommand extends UninterruptableTDSCommand { From 45139b60261c1d556da01ba7422848570d8530b9 Mon Sep 17 00:00:00 2001 From: lilgreenbird Date: Wed, 21 Apr 2021 17:36:08 -0700 Subject: [PATCH 8/8] formatting --- .../java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java index 6f0af8df64..97cd2a86f2 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java @@ -2826,7 +2826,7 @@ private InetSocketAddress connectHelper(ServerPortPlaceHolder serverInfo, int ti } activeConnectionProperties.remove(SQLServerDriverStringProperty.CLIENT_KEY_PASSWORD.toString()); - + // We have successfully connected, now do the login. logon takes seconds timeout executeCommand(new LogonCommand()); return inetSocketAddress;