Skip to content

Commit

Permalink
Feature | Cleanup Always Encrypted with secure enclaves tests (#1262)
Browse files Browse the repository at this point in the history
* 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 e05c67e.

* Revert "some changes"

This reverts commit 62d2e64.

* 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 <v-susanh@microsoft.com>
Co-authored-by: Peter Bae <v-hyba@microsoft.com>
Co-authored-by: rene-ye <rene-ye@users.noreply.github.com>
  • Loading branch information
4 people authored Apr 15, 2020
1 parent 947b537 commit a6da1ae
Show file tree
Hide file tree
Showing 10 changed files with 261 additions and 844 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)";

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -165,39 +161,27 @@ 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();
}

@ParameterizedTest
@MethodSource("enclaveParams")
public void testInputProcedureNumeric(String serverName, String url, String protocol) throws Exception {
checkAESetup(serverName, url, protocol);
initCallableStatementTest();

createInputProcedure();
testInputProcedure("{call " + inputProcedure + "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}", numericValues);
}

@ParameterizedTest
@MethodSource("enclaveParams")
public void testInputProcedureChar(String serverName, String url, String protocol) throws Exception {
checkAESetup(serverName, url, protocol);
initCallableStatementTest();

createInputProcedure2();
testInputProcedure2("{call " + inputProcedure2 + "(?,?,?,?,?,?,?,?)}");
}

@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);
Expand All @@ -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);
Expand All @@ -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 + "(?,?)}");
Expand All @@ -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 + " ?");
Expand All @@ -245,19 +220,13 @@ 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 + "(?,?,?)}");
}

@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();
Expand All @@ -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 + "(?,?,?,?)}");
Expand All @@ -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(
Expand All @@ -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 + "(?,?,?,?,?,?,?,?,?)}");
Expand All @@ -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(
Expand All @@ -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 + "(?,?,?,?,?)}");
Expand All @@ -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 + "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}");
Expand All @@ -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 + "(?,?,?,?,?,?)}");
Expand All @@ -349,19 +297,13 @@ 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 + "(?,?,?,?)}");
}

@ParameterizedTest
@MethodSource("enclaveParams")
public void testOutputProcedure4(String serverName, String url, String protocol) throws Exception {
checkAESetup(serverName, url, protocol);
initCallableStatementTest();

createOutputProcedure4();
}

Expand Down
Loading

0 comments on commit a6da1ae

Please sign in to comment.