From a6da1ae6eea9e10117c75afedd3b5f724a665c1e Mon Sep 17 00:00:00 2001 From: v-reye Date: Wed, 15 Apr 2020 14:30:53 -0700 Subject: [PATCH] Feature | Cleanup Always Encrypted with secure enclaves tests (#1262) * Fix AEv2 tests exclude for reqExternalSetup and cleanup (#1247) * skip AKV test properly * removed enclave properties string to failed errors as enclave tests could be skipped * Fix | Add null check for getObject() with LocalTime and LocalDate (#1250) * 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 * Optimize callablestatement test * stop checking AE all the time, also add some tags * some changes * test * Revert "test" This reverts commit e05c67ed652c3796789afca27e71ac61657615ea. * Revert "some changes" This reverts commit 62d2e64a821bd68daf09e589ca000f2d92f9be39. * delete everythign * add aev2 stuff * fix index out of bounds * fix errors * Remove test that doesn't belong * revert surefire plugin * fix exclude * revert table creation logic * fixes * alter * z * z * zz * temp * zzz * zzz * re-add print * address comments * Don't use pstmt * put expected values first Co-authored-by: lilgreenbird Co-authored-by: Peter Bae Co-authored-by: rene-ye --- .../jdbc/ISQLServerEnclaveProvider.java | 2 +- .../jdbc/AlwaysEncrypted/AESetup.java | 59 +- .../CallableStatementTest.java | 58 -- .../jdbc/AlwaysEncrypted/EnclaveTest.java | 776 ++++-------------- .../JDBCEncryptionDecryptionTest.java | 168 ++-- .../AlwaysEncrypted/PrecisionScaleTest.java | 20 +- .../RegressionAlwaysEncryptedTest.java | 6 +- .../sqlserver/jdbc/EnclavePackageTest.java | 12 +- .../sqlserver/jdbc/TestResource.java | 3 +- .../microsoft/sqlserver/jdbc/TestUtils.java | 1 + 10 files changed, 261 insertions(+), 844 deletions(-) diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerEnclaveProvider.java b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerEnclaveProvider.java index 50edb7000..ff9d436d3 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerEnclaveProvider.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerEnclaveProvider.java @@ -317,7 +317,7 @@ private byte[] adjustBigInt(byte[] b) throws IOException { if (b.length < BIG_INTEGER_SIZE) { ByteArrayOutputStream output = new ByteArrayOutputStream(); for (int i = 0; i < BIG_INTEGER_SIZE - b.length; i++) { - output.write(new byte[] {0}); + output.write(0); } output.write(b); b = output.toByteArray(); 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 10437c5f9..a740a32f9 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java @@ -73,8 +73,6 @@ public class AESetup extends AbstractTest { // test that only run on Windows will be skipped static boolean isWindows = System.getProperty("os.name").startsWith("Windows"); - protected static boolean isAEv2 = false; - public static final String tableName = TestUtils .escapeSingleQuotes(AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("AETest_"))); public static final String CHAR_TABLE_AE = TestUtils @@ -126,6 +124,10 @@ enum ColumnType { {"SmallMoney", "smallmoney", "SMALLMONEY"}, {"Money", "money", "MONEY"}, {"Decimal2", "decimal(28,4)", "DECIMAL"}, {"Numeric2", "numeric(28,4)", "DECIMAL"},}; + static String numericTableSimple[][] = {{"Int", "int", "INT"}}; + + static String varcharTableSimple[][] = {{"Varchar", "varchar(20) COLLATE LATIN1_GENERAL_BIN2", "VARCHAR"}}; + // CREATE TABLE tableName (columns) NULL" static String createSql = "CREATE TABLE %s (%s)"; @@ -191,26 +193,6 @@ static void setAEConnectionString(String serverName, String url, String protocol } } - /** - * Setup AE connection string and check setup - * - * @param serverName - * @param url - * @param protocol - * @throws SQLException - */ - void checkAESetup(String serverName, String url, String protocol) throws Exception { - setAEConnectionString(serverName, url, protocol); - - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo)) { - isAEv2 = TestUtils.isAEv2(con); - } catch (SQLException e) { - isAEv2 = false; - } catch (Exception e) { - fail(TestResource.getResource("R_unexpectedErrorMessage") + e.getMessage()); - } - } - @BeforeAll public static void setupAETest() throws Exception { readFromFile(Constants.JAVA_KEY_STORE_FILENAME, "Alias name"); @@ -1959,4 +1941,37 @@ private static void dropCMK(String cmkName, Statement stmt) throws SQLException + " drop column master key " + cmkName + " end"; stmt.execute(cekSql); } + + /** + * Alter Column encryption on deterministic columns to randomized - this will trigger enclave to re-encrypt + * + * @param stmt + * @param tableName + * @param table + * @param cekName + * @throws SQLException + */ + protected void testAlterColumnEncryption(SQLServerStatement stmt, String tableName, String table[][], + String cekName) throws SQLException { + try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo)) { + for (int i = 0; i < table.length; i++) { + // alter deterministic to randomized + String sql = "ALTER TABLE " + tableName + " ALTER COLUMN " + ColumnType.DETERMINISTIC.name() + + table[i][0] + " " + table[i][1] + + String.format(encryptSql, ColumnType.RANDOMIZED.name(), cekName) + ")"; + try { + stmt.execute(sql); + if (!TestUtils.isAEv2(con)) { + fail(TestResource.getResource("R_expectedExceptionNotThrown")); + } + } catch (SQLException e) { + if (!TestUtils.isAEv2(con)) { + fail(e.getMessage()); + } else { + fail(TestResource.getResource("R_AlterAEv2Error") + e.getMessage() + "Query: " + sql); + } + } + } + } + } } 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 e1eaa251e..b7e7881ab 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java @@ -127,15 +127,11 @@ public class CallableStatementTest extends AESetup { */ @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(); createSPTables(cekJks); @@ -165,9 +161,6 @@ public static void dropAll() throws Exception { @ParameterizedTest @MethodSource("enclaveParams") public void testMultiInsertionSelection(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); - initCallableStatementTest(); - createMultiInsertionSelection(); MultiInsertionSelection(); } @@ -175,9 +168,6 @@ public void testMultiInsertionSelection(String serverName, String url, String pr @ParameterizedTest @MethodSource("enclaveParams") public void testInputProcedureNumeric(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); - initCallableStatementTest(); - createInputProcedure(); testInputProcedure("{call " + inputProcedure + "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}", numericValues); } @@ -185,9 +175,6 @@ public void testInputProcedureNumeric(String serverName, String url, String prot @ParameterizedTest @MethodSource("enclaveParams") public void testInputProcedureChar(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); - initCallableStatementTest(); - createInputProcedure2(); testInputProcedure2("{call " + inputProcedure2 + "(?,?,?,?,?,?,?,?)}"); } @@ -195,9 +182,6 @@ public void testInputProcedureChar(String serverName, String url, String protoco @ParameterizedTest @MethodSource("enclaveParams") public void testEncryptedOutputNumericParams(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); - initCallableStatementTest(); - createOutputProcedure(); testOutputProcedureRandomOrder("{call " + outputProcedure + "(?,?,?,?,?,?,?)}", numericValues); testOutputProcedureInorder("{call " + outputProcedure + "(?,?,?,?,?,?,?)}", numericValues); @@ -209,9 +193,6 @@ public void testEncryptedOutputNumericParams(String serverName, String url, Stri @MethodSource("enclaveParams") public void testUnencryptedAndEncryptedNumericOutputParams(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); - initCallableStatementTest(); - createOutputProcedure2(); testOutputProcedure2RandomOrder("{call " + outputProcedure2 + "(?,?,?,?,?,?,?,?,?,?)}", numericValues); testOutputProcedure2Inorder("{call " + outputProcedure2 + "(?,?,?,?,?,?,?,?,?,?)}", numericValues); @@ -222,9 +203,6 @@ public void testUnencryptedAndEncryptedNumericOutputParams(String serverName, St @MethodSource("enclaveParams") public void testEncryptedOutputParamsFromDifferentTables(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); - initCallableStatementTest(); - createOutputProcedure3(); testOutputProcedure3RandomOrder("{call " + outputProcedure3 + "(?,?)}"); testOutputProcedure3Inorder("{call " + outputProcedure3 + "(?,?)}"); @@ -234,9 +212,6 @@ public void testEncryptedOutputParamsFromDifferentTables(String serverName, Stri @ParameterizedTest @MethodSource("enclaveParams") public void testInOutProcedure(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); - initCallableStatementTest(); - createInOutProcedure(); testInOutProcedure("{call " + inoutProcedure + "(?)}"); testInOutProcedure("exec " + inoutProcedure + " ?"); @@ -245,9 +220,6 @@ public void testInOutProcedure(String serverName, String url, String protocol) t @ParameterizedTest @MethodSource("enclaveParams") public void testMixedProcedure(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); - initCallableStatementTest(); - createMixedProcedure(); testMixedProcedure("{ ? = call " + mixedProcedure + "(?,?,?)}"); } @@ -255,9 +227,6 @@ public void testMixedProcedure(String serverName, String url, String protocol) t @ParameterizedTest @MethodSource("enclaveParams") public void testUnencryptedAndEncryptedIOParams(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); - initCallableStatementTest(); - // unencrypted input and output parameter // encrypted input and output parameter createMixedProcedure2(); @@ -268,9 +237,6 @@ public void testUnencryptedAndEncryptedIOParams(String serverName, String url, S @ParameterizedTest @MethodSource("enclaveParams") public void testUnencryptedIOParams(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); - initCallableStatementTest(); - createMixedProcedure3(); testMixedProcedure3RandomOrder("{call " + mixedProcedure3 + "(?,?,?,?)}"); testMixedProcedure3Inorder("{call " + mixedProcedure3 + "(?,?,?,?)}"); @@ -280,9 +246,6 @@ public void testUnencryptedIOParams(String serverName, String url, String protoc @ParameterizedTest @MethodSource("enclaveParams") public void testVariousIOParams(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); - initCallableStatementTest(); - createmixedProcedureNumericPrecisionScale(); testmixedProcedureNumericPrecisionScaleInorder("{call " + mixedProcedureNumericPrecisionScale + "(?,?,?,?)}"); testmixedProcedureNumericPrecisionScaleParameterName( @@ -292,9 +255,6 @@ public void testVariousIOParams(String serverName, String url, String protocol) @ParameterizedTest @MethodSource("enclaveParams") public void testOutputProcedureChar(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); - initCallableStatementTest(); - createOutputProcedureChar(); testOutputProcedureCharInorder("{call " + outputProcedureChar + "(?,?,?,?,?,?,?,?,?)}"); testOutputProcedureCharInorderObject("{call " + outputProcedureChar + "(?,?,?,?,?,?,?,?,?)}"); @@ -303,9 +263,6 @@ public void testOutputProcedureChar(String serverName, String url, String protoc @ParameterizedTest @MethodSource("enclaveParams") public void testOutputProcedureNumeric(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); - initCallableStatementTest(); - createOutputProcedureNumeric(); testOutputProcedureNumericInorder("{call " + outputProcedureNumeric + "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}"); testcoerctionsOutputProcedureNumericInorder( @@ -315,9 +272,6 @@ public void testOutputProcedureNumeric(String serverName, String url, String pro @ParameterizedTest @MethodSource("enclaveParams") public void testOutputProcedureBinary(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); - initCallableStatementTest(); - createOutputProcedureBinary(); testOutputProcedureBinaryInorder("{call " + outputProcedureBinary + "(?,?,?,?,?)}"); testOutputProcedureBinaryInorderObject("{call " + outputProcedureBinary + "(?,?,?,?,?)}"); @@ -327,9 +281,6 @@ public void testOutputProcedureBinary(String serverName, String url, String prot @ParameterizedTest @MethodSource("enclaveParams") public void testOutputProcedureDate(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); - initCallableStatementTest(); - createOutputProcedureDate(); testOutputProcedureDateInorder("{call " + outputProcedureDate + "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}"); testOutputProcedureDateInorderObject("{call " + outputProcedureDate + "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}"); @@ -338,9 +289,6 @@ public void testOutputProcedureDate(String serverName, String url, String protoc @ParameterizedTest @MethodSource("enclaveParams") public void testMixedProcedureDateScale(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); - initCallableStatementTest(); - createMixedProcedureDateScale(); testMixedProcedureDateScaleInorder("{call " + outputProcedureDateScale + "(?,?,?,?,?,?)}"); testMixedProcedureDateScaleWithParameterName("{call " + outputProcedureDateScale + "(?,?,?,?,?,?)}"); @@ -349,9 +297,6 @@ public void testMixedProcedureDateScale(String serverName, String url, String pr @ParameterizedTest @MethodSource("enclaveParams") public void testOutputProcedureBatch(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); - initCallableStatementTest(); - createOutputProcedureBatch(); testOutputProcedureBatchInorder("{call " + outputProcedureBatch + "(?,?,?,?)}"); } @@ -359,9 +304,6 @@ public void testOutputProcedureBatch(String serverName, String url, String proto @ParameterizedTest @MethodSource("enclaveParams") public void testOutputProcedure4(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); - initCallableStatementTest(); - createOutputProcedure4(); } 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 259125c11..9bfe29e9e 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/EnclaveTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/EnclaveTest.java @@ -4,15 +4,18 @@ */ package com.microsoft.sqlserver.jdbc.AlwaysEncrypted; +import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; +import java.sql.Connection; +import java.sql.DriverManager; import java.sql.ParameterMetaData; import java.sql.PreparedStatement; +import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; -import java.util.LinkedList; +import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Tag; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; @@ -20,7 +23,6 @@ import org.junit.runners.Parameterized; import com.microsoft.sqlserver.jdbc.EnclavePackageTest; -import com.microsoft.sqlserver.jdbc.RandomData; import com.microsoft.sqlserver.jdbc.SQLServerConnection; import com.microsoft.sqlserver.jdbc.SQLServerStatement; import com.microsoft.sqlserver.jdbc.TestResource; @@ -39,9 +41,7 @@ @Tag(Constants.xAzureSQLDW) @Tag(Constants.xAzureSQLDB) @Tag(Constants.reqExternalSetup) -public class EnclaveTest extends JDBCEncryptionDecryptionTest { - private boolean nullable = false; - +public class EnclaveTest extends AESetup { /** * Tests basic connection. * @@ -50,10 +50,8 @@ public class EnclaveTest extends JDBCEncryptionDecryptionTest { @ParameterizedTest @MethodSource("enclaveParams") public void testBasicConnection(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); - org.junit.Assume.assumeTrue(isAEv2); - - EnclavePackageTest.testBasicConnection(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); + EnclavePackageTest.testBasicConnection(AETestConnectionString, protocol); } /** @@ -64,9 +62,6 @@ public void testBasicConnection(String serverName, String url, String protocol) @ParameterizedTest @MethodSource("enclaveParams") public void testInvalidProperties(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); - org.junit.Assume.assumeFalse(isAEv2); - EnclavePackageTest.testInvalidProperties(serverName, url, protocol); } @@ -76,9 +71,6 @@ public void testInvalidProperties(String serverName, String url, String protocol @ParameterizedTest @MethodSource("enclaveParams") public void testVerifyCMKNoEnclave(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); - org.junit.Assume.assumeTrue(isAEv2); - EnclavePackageTest.testVerifyCMKNoEnclave(); } @@ -88,9 +80,6 @@ public void testVerifyCMKNoEnclave(String serverName, String url, String protoco @ParameterizedTest @MethodSource("enclaveParams") public void testVerifyCMKUntrusted(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); - org.junit.Assume.assumeTrue(isAEv2); - EnclavePackageTest.testVerifyCMKUntrusted(); } @@ -100,9 +89,6 @@ public void testVerifyCMKUntrusted(String serverName, String url, String protoco @ParameterizedTest @MethodSource("enclaveParams") public void testGetEnclavePackage(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); - org.junit.Assume.assumeTrue(isAEv2); - EnclavePackageTest.testGetEnclavePackage(); } @@ -112,9 +98,6 @@ public void testGetEnclavePackage(String serverName, String url, String protocol @ParameterizedTest @MethodSource("enclaveParams") public void testInvalidEnclaveSession(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); - org.junit.Assume.assumeTrue(isAEv2); - EnclavePackageTest.testInvalidEnclaveSession(serverName, url, protocol); } @@ -124,9 +107,6 @@ public void testInvalidEnclaveSession(String serverName, String url, String prot @ParameterizedTest @MethodSource("enclaveParams") public void testNullSessionSecret(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); - org.junit.Assume.assumeTrue(isAEv2); - EnclavePackageTest.testNullSessionSecret(); } @@ -136,9 +116,6 @@ public void testNullSessionSecret(String serverName, String url, String protocol @ParameterizedTest @MethodSource("enclaveParams") public void testBadSessionSecret(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); - org.junit.Assume.assumeTrue(isAEv2); - EnclavePackageTest.testBadSessionSecret(); } @@ -148,9 +125,6 @@ public void testBadSessionSecret(String serverName, String url, String protocol) @ParameterizedTest @MethodSource("enclaveParams") public void testNullAttestationResponse(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); - org.junit.Assume.assumeTrue(isAEv2); - EnclavePackageTest.testNullAttestationResponse(); } @@ -160,9 +134,6 @@ public void testNullAttestationResponse(String serverName, String url, String pr @ParameterizedTest @MethodSource("enclaveParams") public void testBadAttestationResponse(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); - org.junit.Assume.assumeTrue(isAEv2); - EnclavePackageTest.testBadAttestationResponse(); } @@ -172,9 +143,6 @@ public void testBadAttestationResponse(String serverName, String url, String pro @ParameterizedTest @MethodSource("enclaveParams") public void testBadCertSignature(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); - org.junit.Assume.assumeTrue(isAEv2); - EnclavePackageTest.testBadCertSignature(); } @@ -184,9 +152,17 @@ public void testBadCertSignature(String serverName, String url, String protocol) @ParameterizedTest @MethodSource("enclaveParams") public void testAEv2NotSupported(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); - org.junit.Assume.assumeFalse(isAEv2); + setAEConnectionString(serverName, url, protocol); + boolean isAEv2 = false; + try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo)) { + isAEv2 = TestUtils.isAEv2(con); + } catch (SQLException e) { + isAEv2 = false; + } catch (Exception e) { + fail(TestResource.getResource("R_unexpectedErrorMessage") + e.getMessage()); + } + org.junit.Assume.assumeFalse(isAEv2); EnclavePackageTest.testAEv2NotSupported(serverName, url, protocol); } @@ -196,8 +172,7 @@ public void testAEv2NotSupported(String serverName, String url, String protocol) @ParameterizedTest @MethodSource("enclaveParams") public void testAEv2Disabled(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); - org.junit.Assume.assumeFalse(isAEv2); + setAEConnectionString(serverName, url, protocol); // connection string w/o AEv2 String testConnectionString = TestUtils.removeProperty(AETestConnectionString, @@ -206,8 +181,11 @@ public void testAEv2Disabled(String serverName, String url, String protocol) thr try (SQLServerConnection con = PrepUtil.getConnection(testConnectionString); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - String[] values = createCharValues(nullable); - testChars(stmt, cekJks, charTable, values, TestCase.NORMAL, true); + String[] values = createCharValues(false); + TestUtils.dropTableIfExists(CHAR_TABLE_AE, stmt); + createTable(CHAR_TABLE_AE, cekJks, charTable); + populateCharNormalCase(values); + testAlterColumnEncryption(stmt, CHAR_TABLE_AE, charTable, cekJks); fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (Throwable e) { // testChars called fail() @@ -215,647 +193,171 @@ public void testAEv2Disabled(String serverName, String url, String protocol) thr } } - /** - * Test case for char set string for string values - * - * @throws Exception - */ - @ParameterizedTest - @MethodSource("enclaveParams") - public void testCharSpecificSetter(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.NORMAL, true); - testChars(stmt, cekAkv, charTable, values, TestCase.NORMAL, true); - } - } - - /** - * Test case for char set string for string values using windows certificate store - * - * @throws SQLException - */ - @ParameterizedTest - @MethodSource("enclaveParams") - public void testCharSpecificSetterWindows(String serverName, String url, String protocol) throws Exception { - org.junit.Assume.assumeTrue(System.getProperty("os.name").startsWith("Windows")); - - checkAESetup(serverName, url, protocol); - - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); - SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - String[] values = createCharValues(nullable); - - testChars(stmt, cekWin, charTable, values, TestCase.NORMAL, true); - } - } - - /** - * Test case for char set object for string values - * - * @throws SQLException - */ - @ParameterizedTest - @MethodSource("enclaveParams") - public void testCharSetObject(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, true); - testChars(stmt, cekAkv, charTable, values, TestCase.SETOBJECT, true); - } - } - - /** - * Test case for char set object for jdbc string values - * - * @throws SQLException - */ - @ParameterizedTest - @MethodSource("enclaveParams") - 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 = createCharValues(nullable); - - testChars(stmt, cekJks, charTable, values, TestCase.SETOBJECT_WITH_JDBCTYPES, true); - testChars(stmt, cekAkv, charTable, values, TestCase.SETOBJECT_WITH_JDBCTYPES, true); - } - } - - /** - * Test case for char set string for null values - * - * @throws SQLException - */ - @ParameterizedTest - @MethodSource("enclaveParams") - 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.NORMAL, true); - testChars(stmt, cekAkv, charTable, values, TestCase.NORMAL, true); - } - } - - /** - * Test case for char set object for null values - * - * @throws SQLException - */ - @ParameterizedTest - @MethodSource("enclaveParams") - 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()) { - String[] values = {null, null, null, null, null, null, null, null, null}; - - testChars(stmt, cekJks, charTable, values, TestCase.SETOBJECT, true); - testChars(stmt, cekAkv, charTable, values, TestCase.SETOBJECT, true); - } - } - - /** - * Test case for char set null for null values - * - * @throws SQLException - */ - @ParameterizedTest - @MethodSource("enclaveParams") - 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()) { - String[] values = {null, null, null, null, null, null, null, null, null}; - - testChars(stmt, cekJks, charTable, values, TestCase.NULL, true); - testChars(stmt, cekAkv, charTable, values, TestCase.NULL, true); - } - } - - /** - * Test case for binary set binary for binary values - * - * @throws SQLException - */ - @ParameterizedTest - @MethodSource("enclaveParams") - 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(false); - - testBinaries(stmt, cekJks, binaryTable, values, TestCase.NORMAL, true); - testBinaries(stmt, cekAkv, binaryTable, values, TestCase.NORMAL, true); - } - } - - /** - * Test case for binary set binary for binary values using windows certificate store - * - * @throws SQLException - */ - @ParameterizedTest - @MethodSource("enclaveParams") - public void testBinarySpecificSetterWindows(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); - org.junit.Assume.assumeTrue(System.getProperty("os.name").startsWith("Windows")); - - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); - SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - LinkedList values = createBinaryValues(false); - - testBinaries(stmt, cekWin, binaryTable, values, TestCase.NORMAL, true); - } - } - - /** - * Test case for binary set object for binary values - * - * @throws SQLException - */ - @ParameterizedTest - @MethodSource("enclaveParams") - 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 = createBinaryValues(false); - - testBinaries(stmt, cekJks, binaryTable, values, TestCase.SETOBJECT, true); - testBinaries(stmt, cekAkv, binaryTable, values, TestCase.SETOBJECT, true); - } - } - - /** - * Test case for binary set null for binary values - * - * @throws SQLException - */ - @ParameterizedTest - @MethodSource("enclaveParams") - 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 = createBinaryValues(true); - - testBinaries(stmt, cekJks, binaryTable, values, TestCase.NULL, true); - testBinaries(stmt, cekAkv, binaryTable, values, TestCase.NULL, true); - } - } - - /** - * Test case for binary set binary for null values - * - * @throws SQLException - */ - @ParameterizedTest - @MethodSource("enclaveParams") - 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()) { - LinkedList values = createBinaryValues(true); - - testBinaries(stmt, cekJks, binaryTable, values, TestCase.NORMAL, true); - testBinaries(stmt, cekAkv, binaryTable, values, TestCase.NORMAL, true); - } - } - - /** - * Test case for binary set object for null values - * - * @throws SQLException - */ - @ParameterizedTest - @MethodSource("enclaveParams") - public void testBinarysetObjectNull(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); - - testBinaries(stmt, cekJks, binaryTable, values, TestCase.SETOBJECT_NULL, true); - testBinaries(stmt, cekAkv, binaryTable, values, TestCase.SETOBJECT_NULL, true); - } - } - - /** - * Test case for binary set object for jdbc type binary values - * - * @throws SQLException - */ - @ParameterizedTest - @MethodSource("enclaveParams") - 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); - - testBinaries(stmt, cekJks, binaryTable, values, TestCase.SETOBJECT_WITH_JDBCTYPES, true); - testBinaries(stmt, cekAkv, binaryTable, values, TestCase.SETOBJECT_WITH_JDBCTYPES, true); - } - } - - /** - * Test case for date set date for date values - * - * @throws SQLException - */ - @ParameterizedTest - @MethodSource("enclaveParams") - 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()) { - LinkedList values = createTemporalTypes(nullable); - - testDates(stmt, cekJks, dateTable, values, TestCase.NORMAL, true); - testDates(stmt, cekAkv, dateTable, values, TestCase.NORMAL, true); - } - } - - /** - * Test case for date set date for date values using windows certificate store - * - * @throws SQLException - */ - @ParameterizedTest - @MethodSource("enclaveParams") - public void testDateSpecificSetterWindows(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); - org.junit.Assume.assumeTrue(System.getProperty("os.name").startsWith("Windows")); - - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); - SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - LinkedList values = createTemporalTypes(nullable); - - testDates(stmt, cekWin, dateTable, values, TestCase.NORMAL, true); - } - } - - /** - * 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, true); - testDates(stmt, cekAkv, dateTable, values, TestCase.SETOBJECT, true); - } - } - - /** - * 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, true); - testDates(stmt, cekAkv, dateTable, values, TestCase.SETOBJECT_WITH_JAVATYPES, true); - } - } - - /** - * 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, true); - testDates(stmt, cekAkv, dateTable, values, TestCase.SETOBJECT_WITH_JDBCTYPES, true); - } - } - - /** - * 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, true); - testDates(stmt, cekAkv, dateTable, values, TestCase.NORMAL, true); - } - } - - /** - * 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, true); - testDates(stmt, cekAkv, dateTable, values, TestCase.NULL, true); - } - - nullable = false; - RandomData.returnNull = false; - } - - /** - * 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, true); - testDates(stmt, cekAkv, dateTable, values, TestCase.SETOBJECT_NULL, true); - } - - nullable = false; - RandomData.returnNull = false; - } - - /** - * 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, true); - testNumerics(stmt, cekAkv, numericTable, values1, values2, TestCase.NORMAL, true); - } - } - - /** - * Test case for numeric set numeric for numeric values using windows certificate store - * - * @throws SQLException - */ - @ParameterizedTest - @MethodSource("enclaveParams") - public void testNumericSpecificSetterWindows(String serverName, String url, String protocol) throws Exception { - org.junit.Assume.assumeTrue(System.getProperty("os.name").startsWith("Windows")); - - 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, true); - } - } - - /** - * Test case for numeric set object for numeric values F - * - * @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, true); - testNumerics(stmt, cekAkv, numericTable, values1, values2, TestCase.SETOBJECT, true); - } - } - - /** - * Test case for numeric set object for jdbc type numeric values - * - * @throws SQLException + /* + * Tests alter column encryption on char tables */ @ParameterizedTest @MethodSource("enclaveParams") - public void testNumericSetObjectWithJDBCTypes(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + public void testChar(String serverName, String url, String protocol) throws Exception { + setAEConnectionString(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, true); - testNumerics(stmt, cekAkv, numericTable, values1, values2, TestCase.SETOBJECT_WITH_JDBCTYPES, true); + TestUtils.dropTableIfExists(CHAR_TABLE_AE, stmt); + createTable(CHAR_TABLE_AE, cekJks, charTable); + populateCharNormalCase(createCharValues(false)); + testAlterColumnEncryption(stmt, CHAR_TABLE_AE, charTable, cekJks); } } - /** - * Test case for numeric set numeric for max numeric values - * - * @throws SQLException + /* + * Tests alter column encryption on char tables with AKV */ @ParameterizedTest @MethodSource("enclaveParams") - public void testNumericSpecificSetterMaxValue(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + public void testCharAkv(String serverName, String url, String protocol) throws Exception { + setAEConnectionString(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, true); - testNumerics(stmt, cekAkv, numericTable, values1, values2, TestCase.NORMAL, true); + TestUtils.dropTableIfExists(CHAR_TABLE_AE, stmt); + createTable(CHAR_TABLE_AE, cekAkv, charTable); + populateCharNormalCase(createCharValues(false)); + testAlterColumnEncryption(stmt, CHAR_TABLE_AE, charTable, cekAkv); } } /** - * Test case for numeric set numeric for min numeric values + * Test FMTOnly with Always Encrypted * * @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, true); - testNumerics(stmt, cekAkv, numericTable, values1, values2, TestCase.NORMAL, true); + public void testAEFMTOnly(String serverName, String url, String protocol) throws Exception { + setAEConnectionString(serverName, url, protocol); + try (SQLServerConnection c = PrepUtil.getConnection(AETestConnectionString + ";useFmtOnly=true", AEInfo); + Statement s = c.createStatement()) { + createTable(NUMERIC_TABLE_AE, cekJks, numericTable); + String sql = "insert into " + NUMERIC_TABLE_AE + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + try (PreparedStatement p = c.prepareStatement(sql)) { + ParameterMetaData pmd = p.getParameterMetaData(); + assertTrue(48 == pmd.getParameterCount()); + } } } /** - * Test case for numeric set numeric for null values - * - * @throws SQLException + * Test alter column */ @ParameterizedTest @MethodSource("enclaveParams") - public void testNumericSpecificSetterNull(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, cekJks, numericTable, values1, values2, TestCase.NULL, true); - testNumerics(stmt, cekAkv, numericTable, values1, values2, TestCase.NULL, true); + public void testAlter(String serverName, String url, String protocol) throws Exception { + setAEConnectionString(serverName, url, protocol); + try (SQLServerConnection c = PrepUtil.getConnection(AETestConnectionString, AEInfo); + Statement s = c.createStatement()) { + createTable(CHAR_TABLE_AE, cekJks, varcharTableSimple); + PreparedStatement pstmt = c.prepareStatement("INSERT INTO " + CHAR_TABLE_AE + " VALUES (?,?,?)"); + pstmt.setString(1, "a"); + pstmt.setString(2, "b"); + pstmt.setString(3, "test"); + pstmt.execute(); + pstmt = c.prepareStatement("ALTER TABLE " + CHAR_TABLE_AE + + " ALTER COLUMN RandomizedVarchar VARCHAR(20) NULL WITH (ONLINE = ON)"); + pstmt.execute(); } - - nullable = false; - RandomData.returnNull = false; } /** - * Test case for numeric set object for null values - * - * @throws SQLException + * Rich Query with number compare */ @ParameterizedTest @MethodSource("enclaveParams") - public void testNumericSpecificSetterSetObjectNull(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, cekJks, numericTable, values1, values2, TestCase.NULL, true); - testNumerics(stmt, cekAkv, numericTable, values1, values2, TestCase.NULL, true); + public void testNumericRichQuery(String serverName, String url, String protocol) throws Exception { + setAEConnectionString(serverName, url, protocol); + try (SQLServerConnection c = PrepUtil.getConnection(AETestConnectionString, AEInfo); + Statement s = c.createStatement()) { + createTable(NUMERIC_TABLE_AE, cekJks, numericTableSimple); + PreparedStatement pstmt = c.prepareStatement("INSERT INTO " + NUMERIC_TABLE_AE + " VALUES (?,?,?)"); + pstmt.setInt(1, 1); + pstmt.setInt(2, 2); + pstmt.setInt(3, 3); + pstmt.execute(); + pstmt = c.prepareStatement("SELECT * FROM " + NUMERIC_TABLE_AE + " WHERE RANDOMIZEDInt = ?"); + pstmt.setInt(1, 3); + try (ResultSet rs = pstmt.executeQuery()) { + while (rs.next()) { + assertTrue(1 == rs.getInt(1)); + assertTrue(2 == rs.getInt(2)); + assertTrue(3 == rs.getInt(3)); + } + } } - - nullable = false; - RandomData.returnNull = false; } /** - * Test case for numeric set numeric for null normalization values - * - * @throws SQLException + * Rich Query with string compare */ @ParameterizedTest @MethodSource("enclaveParams") - public void testNumericNormalization(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, cekJks, numericTable, values1, values2, TestCase.NORMAL, true); - testNumerics(stmt, cekAkv, numericTable, values1, values2, TestCase.NORMAL, true); + public void testStringRichQuery(String serverName, String url, String protocol) throws Exception { + setAEConnectionString(serverName, url, protocol); + try (SQLServerConnection c = PrepUtil.getConnection(AETestConnectionString, AEInfo); + Statement s = c.createStatement()) { + createTable(CHAR_TABLE_AE, cekJks, varcharTableSimple); + PreparedStatement pstmt = c.prepareStatement("INSERT INTO " + CHAR_TABLE_AE + " VALUES (?,?,?)"); + pstmt.setString(1, "a"); + pstmt.setString(2, "b"); + pstmt.setString(3, "test"); + pstmt.execute(); + pstmt = c.prepareStatement("SELECT * FROM " + CHAR_TABLE_AE + " WHERE RANDOMIZEDVarchar LIKE ?"); + pstmt.setString(1, "t%"); + try (ResultSet rs = pstmt.executeQuery()) { + while (rs.next()) { + assertTrue(rs.getString(1).equalsIgnoreCase("a")); + assertTrue(rs.getString(2).equalsIgnoreCase("b")); + assertTrue(rs.getString(3).equalsIgnoreCase("test")); + } + } } } - + /** - * Test FMTOnly with Always Encrypted - * - * @throws SQLException + * Test alter column with a non AEv2 connection */ @ParameterizedTest @MethodSource("enclaveParams") - public void testAEFMTOnly(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); - try (SQLServerConnection c = PrepUtil.getConnection(AETestConnectionString + ";useFmtOnly=true", AEInfo); + public void testAlterNoEncrypt(String serverName, String url, String protocol) throws Exception { + setAEConnectionString(serverName, url, protocol); + try (SQLServerConnection c = PrepUtil.getConnection(AETestConnectionString, AEInfo); Statement s = c.createStatement()) { - createTable(NUMERIC_TABLE_AE, cekJks, numericTable); - String sql = "insert into " + NUMERIC_TABLE_AE + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?" + ")"; - try (PreparedStatement p = c.prepareStatement(sql)) { - ParameterMetaData pmd = p.getParameterMetaData(); - assertTrue(pmd.getParameterCount() == 48); - } + createTable(CHAR_TABLE_AE, cekJks, varcharTableSimple); + PreparedStatement pstmt = c.prepareStatement("INSERT INTO " + CHAR_TABLE_AE + " VALUES (?,?,?)"); + pstmt.setString(1, "a"); + pstmt.setString(2, "b"); + pstmt.setString(3, "test"); + pstmt.execute(); + } + String testConnectionString = TestUtils.removeProperty(AETestConnectionString, + Constants.ENCLAVE_ATTESTATIONURL); + testConnectionString = TestUtils.removeProperty(testConnectionString, Constants.ENCLAVE_ATTESTATIONPROTOCOL); + try (Connection c = DriverManager.getConnection(testConnectionString)) { + PreparedStatement pstmt = c.prepareStatement("ALTER TABLE " + CHAR_TABLE_AE + + " ALTER COLUMN RandomizedVarchar VARCHAR(20) NULL WITH (ONLINE = ON)"); + pstmt.execute(); + } catch (SQLException e) { + assertTrue(e.getMessage().contains(TestResource.getResource("R_enclaveNotEnabled"))); + } + } + + @AfterAll + public static void dropAll() throws Exception { + try (Statement stmt = connection.createStatement()) { + 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(SCALE_DATE_TABLE_AE, stmt); } } } 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 3b617b490..ba4125f05 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java @@ -73,7 +73,7 @@ enum TestCase { @ParameterizedTest @MethodSource("enclaveParams") public void testJksName(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try { SQLServerColumnEncryptionJavaKeyStoreProvider jksp = new SQLServerColumnEncryptionJavaKeyStoreProvider( @@ -92,7 +92,7 @@ public void testJksName(String serverName, String url, String protocol) throws E @ParameterizedTest @MethodSource("enclaveParams") public void testAkvName(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try { SQLServerColumnEncryptionAzureKeyVaultProvider akv = new SQLServerColumnEncryptionAzureKeyVaultProvider( @@ -112,7 +112,7 @@ public void testAkvName(String serverName, String url, String protocol) throws E @ParameterizedTest @MethodSource("enclaveParams") public void testBadJks(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try { SQLServerColumnEncryptionJavaKeyStoreProvider jksp = new SQLServerColumnEncryptionJavaKeyStoreProvider(null, @@ -130,7 +130,7 @@ public void testBadJks(String serverName, String url, String protocol) throws Ex @ParameterizedTest @MethodSource("enclaveParams") public void testBadAkv(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try { SQLServerColumnEncryptionAzureKeyVaultProvider akv = new SQLServerColumnEncryptionAzureKeyVaultProvider( @@ -147,7 +147,7 @@ public void testBadAkv(String serverName, String url, String protocol) throws Ex @ParameterizedTest @MethodSource("enclaveParams") public void testJksBadEncryptColumnEncryptionKey(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); SQLServerColumnEncryptionJavaKeyStoreProvider jksp = null; char[] secret = new char[1]; @@ -182,7 +182,7 @@ public void testJksBadEncryptColumnEncryptionKey(String serverName, String url, @MethodSource("enclaveParams") @Tag(Constants.reqExternalSetup) public void testAkvBadEncryptColumnEncryptionKey(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); SQLServerColumnEncryptionAzureKeyVaultProvider akv = null; try { @@ -215,7 +215,7 @@ public void testAkvBadEncryptColumnEncryptionKey(String serverName, String url, @ParameterizedTest @MethodSource("enclaveParams") public void testJksDecryptColumnEncryptionKey(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); SQLServerColumnEncryptionJavaKeyStoreProvider jksp = null; char[] secret = new char[1]; @@ -265,7 +265,7 @@ public void testJksDecryptColumnEncryptionKey(String serverName, String url, Str @MethodSource("enclaveParams") @Tag(Constants.reqExternalSetup) public void testAkvDecryptColumnEncryptionKey(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); SQLServerColumnEncryptionAzureKeyVaultProvider akv = null; try { @@ -342,7 +342,7 @@ public void testAkvDecryptColumnEncryptionKey(String serverName, String url, Str @ParameterizedTest @MethodSource("enclaveParams") public void testCharSpecificSetter(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -361,7 +361,7 @@ public void testCharSpecificSetter(String serverName, String url, String protoco @MethodSource("enclaveParams") @Tag(Constants.reqExternalSetup) public void testCharSpecificSetterAkv(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -380,7 +380,7 @@ public void testCharSpecificSetterAkv(String serverName, String url, String prot @MethodSource("enclaveParams") @Tag(Constants.reqExternalSetup) public void testCharSpecificSetterWindows(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); org.junit.Assume.assumeTrue(isWindows); @@ -401,7 +401,7 @@ public void testCharSpecificSetterWindows(String serverName, String url, String @MethodSource("enclaveParams") @Tag(Constants.reqExternalSetup) public void testCharSetObjectAkv(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -419,7 +419,7 @@ public void testCharSetObjectAkv(String serverName, String url, String protocol) @ParameterizedTest @MethodSource("enclaveParams") public void testCharSetObject(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -438,7 +438,7 @@ public void testCharSetObject(String serverName, String url, String protocol) th @MethodSource("enclaveParams") @Tag(Constants.reqExternalSetup) public void testCharSetObjectWithJDBCTypesAkv(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -456,7 +456,7 @@ public void testCharSetObjectWithJDBCTypesAkv(String serverName, String url, Str @ParameterizedTest @MethodSource("enclaveParams") public void testCharSetObjectWithJDBCTypes(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -475,7 +475,7 @@ public void testCharSetObjectWithJDBCTypes(String serverName, String url, String @MethodSource("enclaveParams") @Tag(Constants.reqExternalSetup) public void testCharSpecificSetterNullAkv(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -493,7 +493,7 @@ public void testCharSpecificSetterNullAkv(String serverName, String url, String @ParameterizedTest @MethodSource("enclaveParams") public void testCharSpecificSetterNull(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -512,7 +512,7 @@ public void testCharSpecificSetterNull(String serverName, String url, String pro @MethodSource("enclaveParams") @Tag(Constants.reqExternalSetup) public void testCharSetObjectNullAkv(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -530,7 +530,7 @@ public void testCharSetObjectNullAkv(String serverName, String url, String proto @ParameterizedTest @MethodSource("enclaveParams") public void testCharSetObjectNull(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -549,7 +549,7 @@ public void testCharSetObjectNull(String serverName, String url, String protocol @MethodSource("enclaveParams") @Tag(Constants.reqExternalSetup) public void testCharSetNullAkv(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -567,7 +567,7 @@ public void testCharSetNullAkv(String serverName, String url, String protocol) t @ParameterizedTest @MethodSource("enclaveParams") public void testCharSetNull(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -586,7 +586,7 @@ public void testCharSetNull(String serverName, String url, String protocol) thro @MethodSource("enclaveParams") @Tag(Constants.reqExternalSetup) public void testBinarySpecificSetterAkv(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -604,7 +604,7 @@ public void testBinarySpecificSetterAkv(String serverName, String url, String pr @ParameterizedTest @MethodSource("enclaveParams") public void testBinarySpecificSetter(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -625,7 +625,7 @@ public void testBinarySpecificSetter(String serverName, String url, String proto public void testBinarySpecificSetterWindows(String serverName, String url, String protocol) throws Exception { org.junit.Assume.assumeTrue(isWindows); - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -644,7 +644,7 @@ public void testBinarySpecificSetterWindows(String serverName, String url, Strin @MethodSource("enclaveParams") @Tag(Constants.reqExternalSetup) public void testBinarySetobjectAkv(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -662,7 +662,7 @@ public void testBinarySetobjectAkv(String serverName, String url, String protoco @ParameterizedTest @MethodSource("enclaveParams") public void testBinarySetobject(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -681,7 +681,7 @@ public void testBinarySetobject(String serverName, String url, String protocol) @MethodSource("enclaveParams") @Tag(Constants.reqExternalSetup) public void testBinarySetNullAkv(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -699,7 +699,7 @@ public void testBinarySetNullAkv(String serverName, String url, String protocol) @ParameterizedTest @MethodSource("enclaveParams") public void testBinarySetNull(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -718,7 +718,7 @@ public void testBinarySetNull(String serverName, String url, String protocol) th @MethodSource("enclaveParams") @Tag(Constants.reqExternalSetup) public void testBinarySpecificSetterNullAkv(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -736,7 +736,7 @@ public void testBinarySpecificSetterNullAkv(String serverName, String url, Strin @ParameterizedTest @MethodSource("enclaveParams") public void testBinarySpecificSetterNull(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -755,7 +755,7 @@ public void testBinarySpecificSetterNull(String serverName, String url, String p @MethodSource("enclaveParams") @Tag(Constants.reqExternalSetup) public void testBinarysetObjectNullAkv(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -773,7 +773,7 @@ public void testBinarysetObjectNullAkv(String serverName, String url, String pro @ParameterizedTest @MethodSource("enclaveParams") public void testBinarysetObjectNull(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -792,7 +792,7 @@ public void testBinarysetObjectNull(String serverName, String url, String protoc @MethodSource("enclaveParams") @Tag(Constants.reqExternalSetup) public void testBinarySetObjectWithJDBCTypesAkv(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { LinkedList values = createBinaryValues(false); @@ -809,7 +809,7 @@ public void testBinarySetObjectWithJDBCTypesAkv(String serverName, String url, S @ParameterizedTest @MethodSource("enclaveParams") public void testBinarySetObjectWithJDBCTypes(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { LinkedList values = createBinaryValues(false); @@ -827,7 +827,7 @@ public void testBinarySetObjectWithJDBCTypes(String serverName, String url, Stri @MethodSource("enclaveParams") @Tag(Constants.reqExternalSetup) public void testDateSpecificSetterAkv(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -845,7 +845,7 @@ public void testDateSpecificSetterAkv(String serverName, String url, String prot @ParameterizedTest @MethodSource("enclaveParams") public void testDateSpecificSetter(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -866,7 +866,7 @@ public void testDateSpecificSetter(String serverName, String url, String protoco public void testDateSpecificSetterWindows(String serverName, String url, String protocol) throws Exception { org.junit.Assume.assumeTrue(isWindows); - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -885,7 +885,7 @@ public void testDateSpecificSetterWindows(String serverName, String url, String @MethodSource("enclaveParams") @Tag(Constants.reqExternalSetup) public void testDateSetObjectAkv(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -903,7 +903,7 @@ public void testDateSetObjectAkv(String serverName, String url, String protocol) @ParameterizedTest @MethodSource("enclaveParams") public void testDateSetObject(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -922,7 +922,7 @@ public void testDateSetObject(String serverName, String url, String protocol) th @MethodSource("enclaveParams") @Tag(Constants.reqExternalSetup) public void testDateSetObjectWithJavaTypeAkv(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -940,7 +940,7 @@ public void testDateSetObjectWithJavaTypeAkv(String serverName, String url, Stri @ParameterizedTest @MethodSource("enclaveParams") public void testDateSetObjectWithJavaType(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -959,7 +959,7 @@ public void testDateSetObjectWithJavaType(String serverName, String url, String @MethodSource("enclaveParams") @Tag(Constants.reqExternalSetup) public void testDateSetObjectWithJDBCTypeAkv(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -977,7 +977,7 @@ public void testDateSetObjectWithJDBCTypeAkv(String serverName, String url, Stri @ParameterizedTest @MethodSource("enclaveParams") public void testDateSetObjectWithJDBCType(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -996,7 +996,7 @@ public void testDateSetObjectWithJDBCType(String serverName, String url, String @MethodSource("enclaveParams") @Tag(Constants.reqExternalSetup) public void testDateSpecificSetterMinMaxValueAkv(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -1015,7 +1015,7 @@ public void testDateSpecificSetterMinMaxValueAkv(String serverName, String url, @ParameterizedTest @MethodSource("enclaveParams") public void testDateSpecificSetterMinMaxValue(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -1035,7 +1035,7 @@ public void testDateSpecificSetterMinMaxValue(String serverName, String url, Str @MethodSource("enclaveParams") @Tag(Constants.reqExternalSetup) public void testDateSetNullAkv(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -1058,7 +1058,7 @@ public void testDateSetNullAkv(String serverName, String url, String protocol) t @ParameterizedTest @MethodSource("enclaveParams") public void testDateSetNull(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -1082,7 +1082,7 @@ public void testDateSetNull(String serverName, String url, String protocol) thro @MethodSource("enclaveParams") @Tag(Constants.reqExternalSetup) public void testDateSetObjectNullAkv(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); RandomData.returnNull = true; nullable = true; @@ -1106,7 +1106,7 @@ public void testDateSetObjectNullAkv(String serverName, String url, String proto @ParameterizedTest @MethodSource("enclaveParams") public void testDateSetObjectNull(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); RandomData.returnNull = true; nullable = true; @@ -1131,7 +1131,7 @@ public void testDateSetObjectNull(String serverName, String url, String protocol @MethodSource("enclaveParams") @Tag(Constants.reqExternalSetup) public void testNumericSpecificSetterAkv(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -1152,7 +1152,7 @@ public void testNumericSpecificSetterAkv(String serverName, String url, String p @ParameterizedTest @MethodSource("enclaveParams") public void testNumericSpecificSetter(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -1176,7 +1176,7 @@ public void testNumericSpecificSetter(String serverName, String url, String prot public void testNumericSpecificSetterWindows(String serverName, String url, String protocol) throws Exception { org.junit.Assume.assumeTrue(isWindows); - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -1198,7 +1198,7 @@ public void testNumericSpecificSetterWindows(String serverName, String url, Stri @MethodSource("enclaveParams") @Tag(Constants.reqExternalSetup) public void testNumericSetObjectAkv(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -1218,7 +1218,7 @@ public void testNumericSetObjectAkv(String serverName, String url, String protoc @ParameterizedTest @MethodSource("enclaveParams") public void testNumericSetObject(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -1239,7 +1239,7 @@ public void testNumericSetObject(String serverName, String url, String protocol) @MethodSource("enclaveParams") @Tag(Constants.reqExternalSetup) public void testNumericSetObjectWithJDBCTypesAkv(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -1259,7 +1259,7 @@ public void testNumericSetObjectWithJDBCTypesAkv(String serverName, String url, @ParameterizedTest @MethodSource("enclaveParams") public void testNumericSetObjectWithJDBCTypes(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -1280,7 +1280,7 @@ public void testNumericSetObjectWithJDBCTypes(String serverName, String url, Str @MethodSource("enclaveParams") @Tag(Constants.reqExternalSetup) public void testNumericSpecificSetterMaxValueAkv(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -1306,7 +1306,7 @@ public void testNumericSpecificSetterMaxValueAkv(String serverName, String url, @ParameterizedTest @MethodSource("enclaveParams") public void testNumericSpecificSetterMaxValue(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -1333,7 +1333,7 @@ public void testNumericSpecificSetterMaxValue(String serverName, String url, Str @MethodSource("enclaveParams") @Tag(Constants.reqExternalSetup) public void testNumericSpecificSetterMinValueAkv(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -1358,7 +1358,7 @@ public void testNumericSpecificSetterMinValueAkv(String serverName, String url, @ParameterizedTest @MethodSource("enclaveParams") public void testNumericSpecificSetterMinValue(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -1384,7 +1384,7 @@ public void testNumericSpecificSetterMinValue(String serverName, String url, Str @MethodSource("enclaveParams") @Tag(Constants.reqExternalSetup) public void testNumericSpecificSetterNullAkv(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -1409,7 +1409,7 @@ public void testNumericSpecificSetterNullAkv(String serverName, String url, Stri @ParameterizedTest @MethodSource("enclaveParams") public void testNumericSpecificSetterNull(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -1436,7 +1436,7 @@ public void testNumericSpecificSetterNull(String serverName, String url, String @Tag(Constants.reqExternalSetup) public void testNumericSpecificSetterSetObjectNullAkv(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { nullable = true; @@ -1461,7 +1461,7 @@ public void testNumericSpecificSetterSetObjectNullAkv(String serverName, String @MethodSource("enclaveParams") public void testNumericSpecificSetterSetObjectNull(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { nullable = true; @@ -1486,7 +1486,7 @@ public void testNumericSpecificSetterSetObjectNull(String serverName, String url @MethodSource("enclaveParams") @Tag(Constants.reqExternalSetup) public void testNumericNormalizationAkv(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -1509,7 +1509,7 @@ public void testNumericNormalizationAkv(String serverName, String url, String pr @ParameterizedTest @MethodSource("enclaveParams") public void testNumericNormalization(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { @@ -1535,7 +1535,7 @@ public void testNumericNormalization(String serverName, String url, String proto @ParameterizedTest @MethodSource("enclaveParams") public void testAEFMTOnly(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection c = PrepUtil.getConnection(AETestConnectionString + ";useFmtOnly=true", AEInfo); Statement s = c.createStatement()) { @@ -1872,40 +1872,6 @@ void testNumeric(Statement stmt, String[] numericValues, boolean isNull) throws } } - /** - * Alter Column encryption on deterministic columns to randomized - this will trigger enclave to re-encrypt - * - * @param stmt - * @param tableName - * @param table - * @param values - * @throws SQLException - */ - private void testAlterColumnEncryption(SQLServerStatement stmt, String tableName, String table[][], - String cekName) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo)) { - for (int i = 0; i < table.length; i++) { - // alter deterministic to randomized - 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)) { - stmt.execute(sql); - if (!TestUtils.isAEv2(con)) { - fail(TestResource.getResource("R_expectedExceptionNotThrown")); - } - } catch (SQLException e) { - if (!TestUtils.isAEv2(con)) { - fail(TestResource.getResource("R_expectedExceptionNotThrown")); - } else { - fail(TestResource.getResource("R_AlterAEv2Error") + e.getMessage() + "Query: " + sql); - } - } - } - } - } - private void testRichQuery(SQLServerStatement stmt, String tableName, String table[][], String[] values) throws SQLException { try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo)) { 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 67b345a9f..ba6f1bae1 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java @@ -76,7 +76,7 @@ public class PrecisionScaleTest extends AESetup { @ParameterizedTest @MethodSource("enclaveParams") public void testNumericPrecision8Scale2(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { dropTables(stmt); @@ -94,8 +94,7 @@ public void testNumericPrecision8Scale2(String serverName, String url, String pr @ParameterizedTest @MethodSource("enclaveParams") public void testDateScale2(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); - + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { dropTables(stmt); @@ -116,8 +115,7 @@ public void testDateScale2(String serverName, String url, String protocol) throw @ParameterizedTest @MethodSource("enclaveParams") public void testNumericPrecision8Scale0(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); - + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { dropTables(stmt); @@ -135,8 +133,7 @@ public void testNumericPrecision8Scale0(String serverName, String url, String pr @ParameterizedTest @MethodSource("enclaveParams") public void testDateScale0(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); - + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { dropTables(stmt); @@ -158,8 +155,7 @@ public void testDateScale0(String serverName, String url, String protocol) throw @ParameterizedTest @MethodSource("enclaveParams") public void testNumericPrecision8Scale2Null(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); - + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { dropTables(stmt); @@ -177,8 +173,7 @@ public void testNumericPrecision8Scale2Null(String serverName, String url, Strin @ParameterizedTest @MethodSource("enclaveParams") public void testDateScale2Null(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); - + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { dropTables(stmt); @@ -196,8 +191,7 @@ public void testDateScale2Null(String serverName, String url, String protocol) t @ParameterizedTest @MethodSource("enclaveParams") public void testDateScale5Null(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); - + setAEConnectionString(serverName, url, protocol); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { dropTables(stmt); 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 8b45b1735..d1656eef3 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/RegressionAlwaysEncryptedTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/RegressionAlwaysEncryptedTest.java @@ -41,8 +41,7 @@ public class RegressionAlwaysEncryptedTest extends AESetup { @ParameterizedTest @MethodSource("enclaveParams") public void alwaysEncrypted1(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); - + setAEConnectionString(serverName, url, protocol); try (Connection connection = PrepUtil.getConnection( AETestConnectionString + ";trustservercertificate=true;columnEncryptionSetting=enabled;", AEInfo); Statement stmt = connection.createStatement()) { @@ -72,8 +71,7 @@ public void alwaysEncrypted1(String serverName, String url, String protocol) thr @ParameterizedTest @MethodSource("enclaveParams") public void alwaysEncrypted2(String serverName, String url, String protocol) throws Exception { - checkAESetup(serverName, url, protocol); - + setAEConnectionString(serverName, url, protocol); try (Connection connection = PrepUtil.getConnection( AETestConnectionString + ";trustservercertificate=true;columnEncryptionSetting=enabled;", AEInfo); Statement stmt = connection.createStatement()) { diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/EnclavePackageTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/EnclavePackageTest.java index 5a87eb87c..10e4d82fc 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/EnclavePackageTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/EnclavePackageTest.java @@ -212,21 +212,19 @@ public static void setAEConnectionString(String url, String protocol) throws Exc * @throws SQLException * when an error occurs */ - public static void testBasicConnection(String serverName, String url, String protocol) throws Exception { - setAEConnectionString(url, protocol); - + public static void testBasicConnection(String cString, String protocol) throws Exception { SQLServerDataSource dsLocal = new SQLServerDataSource(); - AbstractTest.updateDataSource(connectionStringEnclave, dsLocal); + AbstractTest.updateDataSource(cString, dsLocal); SQLServerDataSource dsXA = new SQLServerXADataSource(); - AbstractTest.updateDataSource(connectionStringEnclave, dsXA); + AbstractTest.updateDataSource(cString, dsXA); SQLServerDataSource dsPool = new SQLServerConnectionPoolDataSource(); - AbstractTest.updateDataSource(connectionStringEnclave, dsPool); + AbstractTest.updateDataSource(cString, dsPool); try (Connection con1 = dsLocal.getConnection(); Connection con2 = dsXA.getConnection(); Connection con3 = dsPool.getConnection(); - Connection con4 = PrepUtil.getConnection(connectionStringEnclave)) { + Connection con4 = PrepUtil.getConnection(cString)) { if (TestUtils.isAEv2(con1)) { verifyEnclaveEnabled(con1, protocol); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/TestResource.java b/src/test/java/com/microsoft/sqlserver/jdbc/TestResource.java index 488091591..3eb6ddaaa 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/TestResource.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/TestResource.java @@ -185,5 +185,6 @@ protected Object[][] getContents() { {"R_RichQueryError", "Rich query failed."}, {"R_reqExternalSetup", "External setup for test required."}, {"R_invalidEnclaveSessionFailed", "invalidate enclave session failed."}, {"R_invalidEnclaveType", "Invalid enclave type {0}."}, - {"R_keystorePassword", "keystore password was incorrect"}}; + {"R_keystorePassword", "keystore password was incorrect"}, + {"R_enclaveNotEnabled", "The statement triggers enclave computations"}}; } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/TestUtils.java b/src/test/java/com/microsoft/sqlserver/jdbc/TestUtils.java index 330a4148f..b293b5a87 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/TestUtils.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/TestUtils.java @@ -276,6 +276,7 @@ public static void dropTableIfExists(String tableName, java.sql.Statement stmt) /** * Deletes the contents of a table. + * * @param con * @param tableName * @throws SQLException