Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
rene-ye committed Feb 12, 2020
1 parent 62d2e64 commit e05c67e
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 16 deletions.
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
reqExternalSetup - For tests requiring external setup (excluded by default)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Default testing enabled with SQL Server 2019 (SQLv15) -->
<excludedGroups>xSQLv12, xSQLv14, NTLM, reqExternalSetup</excludedGroups>
<excludedGroups>xSQLv12, xSQLv15, NTLM, reqExternalSetup</excludedGroups>

<!-- Use -preview for preview release, leave empty for official release.-->
<releaseExt></releaseExt>
Expand All @@ -68,8 +68,8 @@
<google.gson.version>2.8.6</google.gson.version>

<!-- JUnit Test Dependencies -->
<junit.platform.version>1.6.0</junit.platform.version>
<junit.jupiter.version>5.6.0</junit.jupiter.version>
<junit.platform.version>[1.3.2, 1.5.2]</junit.platform.version>
<junit.jupiter.version>5.5.2</junit.jupiter.version>
<hikaricp.version>3.4.1</hikaricp.version>
<dbcp2.version>2.7.0</dbcp2.version>
<slf4j.nop.version>1.7.29</slf4j.nop.version>
Expand Down Expand Up @@ -172,7 +172,7 @@
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.3.2</version>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -263,7 +263,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<version>3.0.0-M1</version>
<configuration>
<!-- Exclude [xJDBC42] For tests not compatible with JDBC 4.2 Specifications -->
<excludedGroups>${excludedGroups}, xJDBC42</excludedGroups>
Expand Down Expand Up @@ -402,7 +402,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<version>3.0.0-M1</version>
<configuration>
<forkCount>3</forkCount>
<reuseForks>true</reuseForks>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,10 @@ public static void setupAETest() throws Exception {
param[i][1] = url;
param[i][2] = protocol;

setAEConnectionString(serverName, url, protocol);
/*
* Note: This means all servers must either be non-AEv2 or AEv2. Mixing will cause bugs/errors
*/
checkAESetup(serverName, url, protocol);

createCMK(cmkJks, Constants.JAVA_KEY_STORE_NAME, javaKeyAliases, Constants.CMK_SIGNATURE);
createCEK(cmkJks, cekJks, jksProvider);
Expand All @@ -231,9 +234,28 @@ public static void setupAETest() throws Exception {
createCEK(cmkWin, cekWin, null);
}
}

isAEv2 = enclaveServer.length > 0;
}

/**
* Setup AE connection string and check setup
*
* @param serverName
* @param url
* @param protocol
* @throws SQLException
*/
static 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());
}
}


/**
* Dropping all CMKs and CEKs and any open resources. Technically, dropAll depends on the state of the class so it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import com.microsoft.sqlserver.jdbc.EnclavePackageTest;
import com.microsoft.sqlserver.jdbc.SQLServerConnection;
import com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement;
import com.microsoft.sqlserver.jdbc.SQLServerStatement;
import com.microsoft.sqlserver.jdbc.TestResource;
import com.microsoft.sqlserver.jdbc.TestUtils;
Expand All @@ -32,7 +33,7 @@
@Tag(Constants.xAzureSQLDW)
@Tag(Constants.xAzureSQLDB)
@Tag(Constants.reqExternalSetup)
public class EnclaveTest extends JDBCEncryptionDecryptionTest {
public class EnclaveTest extends AESetup {
private boolean nullable = false;

/**
Expand Down Expand Up @@ -153,7 +154,7 @@ public void testAEv2NotSupported(String serverName, String url, String protocol)
@ParameterizedTest
@MethodSource("enclaveParams")
public void testAEv2Disabled(String serverName, String url, String protocol) throws Exception {
setAEConnectionString(serverName, url, protocol);
setAEConnectionString(serverName, null, null);
// connection string w/o AEv2
String testConnectionString = TestUtils.removeProperty(AETestConnectionString,
Constants.ENCLAVE_ATTESTATIONURL);
Expand All @@ -162,11 +163,29 @@ 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, JDBCEncryptionDecryptionTest.TestCase.NORMAL, true);

TestUtils.dropTableIfExists(CHAR_TABLE_AE, stmt);
createTable(CHAR_TABLE_AE, cekJks, charTable);
populateCharNormalCase(values);
for (int i = 0; i < charTable.length; i++) {
// alter deterministic to randomized
String sql = "ALTER TABLE " + CHAR_TABLE_AE + " ALTER COLUMN " + ColumnType.DETERMINISTIC.name()
+ charTable[i][0] + " " + charTable[i][1]
+ String.format(encryptSql, ColumnType.RANDOMIZED.name(), cekJks) + ")";
try (SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql,
stmtColEncSetting)) {
pstmt.execute();
fail(TestResource.getResource("R_expectedExceptionNotThrown"));
}
}
fail(TestResource.getResource("R_expectedExceptionNotThrown"));
} catch (Throwable e) {
// testChars called fail()
assertTrue(e.getMessage().contains(TestResource.getResource("R_AlterAEv2Error")));
assertTrue(e.getMessage().contains(TestResource.getResource("R_enclaveNotEnabled")));
} finally {
try (SQLServerConnection con = PrepUtil.getConnection(testConnectionString);
SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) {
TestUtils.dropTableIfExists(CHAR_TABLE_AE, stmt);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2115,7 +2115,7 @@ private void testAlterColumnEncryption(SQLServerStatement stmt, String tableName
+ String.format(encryptSql, ColumnType.RANDOMIZED.name(), cekName) + ")";
try (SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql,
stmtColEncSetting)) {
stmt.execute(sql);
pstmt.execute(sql);
if (!TestUtils.isAEv2(con)) {
fail(TestResource.getResource("R_expectedExceptionNotThrown"));
}
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/com/microsoft/sqlserver/jdbc/TestResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,6 @@ protected Object[][] getContents() {
{"R_resultSetEmpty", "Result set is empty."}, {"R_AlterAEv2Error", "Alter Column Encryption failed."},
{"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_invalidEnclaveType", "Invalid enclave type {0}."},
{"R_enclaveNotEnabled", "The statement triggers enclave computations, but a column encryption key, needed for the computations, has not been found inside the enclave."}};
}

0 comments on commit e05c67e

Please sign in to comment.