Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Feature | Cleanup Always Encrypted with secure enclaves tests #1262

Merged
merged 34 commits into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
c97b863
Fix AEv2 tests exclude for reqExternalSetup and cleanup (#1247)
lilgreenbird Feb 5, 2020
931158f
skip AKV test properly
lilgreenbird Feb 5, 2020
397d3e8
removed enclave properties string to failed errors as enclave tests c…
lilgreenbird Feb 5, 2020
54b5a19
Fix | Add null check for getObject() with LocalTime and LocalDate (#1…
peterbae Feb 8, 2020
672b7d6
added all AKV tests to use reqExternalSetup tag so they will be skipp…
lilgreenbird Feb 10, 2020
08d8ae3
Optimize callablestatement test
rene-ye Feb 10, 2020
7c67ebd
stop checking AE all the time, also add some tags
rene-ye Feb 12, 2020
62d2e64
some changes
rene-ye Feb 12, 2020
e05c67e
test
rene-ye Feb 12, 2020
8979de2
Revert "test"
rene-ye Feb 12, 2020
89609f8
Revert "some changes"
rene-ye Feb 13, 2020
2f048f3
delete everythign
rene-ye Feb 13, 2020
80013a3
add aev2 stuff
rene-ye Feb 13, 2020
ff33988
fix index out of bounds
rene-ye Feb 13, 2020
1ce8158
Merge branch 'dev' of https://github.com/Microsoft/mssql-jdbc into junit
rene-ye Feb 13, 2020
4793f81
fix errors
rene-ye Feb 13, 2020
67aa997
Remove test that doesn't belong
rene-ye Feb 14, 2020
8d6f6a5
revert surefire plugin
rene-ye Feb 14, 2020
7525958
fix exclude
rene-ye Feb 14, 2020
abc42ed
Merge branch 'dev' of https://github.com/microsoft/mssql-jdbc into junit
rene-ye Apr 2, 2020
f70a0b2
revert table creation logic
rene-ye Apr 7, 2020
0437d1c
fixes
rene-ye Apr 7, 2020
0c0726b
alter
rene-ye Apr 7, 2020
8193c68
z
rene-ye Apr 7, 2020
42dbb30
z
rene-ye Apr 8, 2020
bedd0ad
zz
rene-ye Apr 8, 2020
97408bc
temp
rene-ye Apr 8, 2020
817cf6c
zzz
rene-ye Apr 8, 2020
f3ceffa
zzz
rene-ye Apr 8, 2020
11a1198
Merge branch 'dev' of https://github.com/Microsoft/mssql-jdbc into junit
rene-ye Apr 8, 2020
5ca3c58
re-add print
rene-ye Apr 8, 2020
0d27d52
address comments
rene-ye Apr 14, 2020
3c25da5
Don't use pstmt
rene-ye Apr 14, 2020
dc3f11f
put expected values first
rene-ye Apr 15, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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