Skip to content

Commit

Permalink
Updated to use junit 5 parameterization (#1236)
Browse files Browse the repository at this point in the history
  • Loading branch information
lilgreenbird authored Jan 31, 2020
1 parent ceb2b5e commit 646816f
Show file tree
Hide file tree
Showing 11 changed files with 893 additions and 478 deletions.
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
inputs:
mavenPomFile: 'pom.xml'
goals: 'clean -Dmssql_jdbc_test_connection_properties=jdbc:sqlserver://$(Target_SQL)$(server_domain);$(database);$(user);$(password); install -Pjre11 -DuserNTLM=$(userNTLM) -DpasswordNTLM=$(passwordNTLM) -DdomainNTLM=$(domainNTLM) -DexcludedGroups=$(Ex_Groups) -Dpkcs12_truststore_password=$(pkcs12_truststore_password) -Dpkcs12_truststore=$(pkcs12_truststore.secureFilePath)
-DapplicationClientID=$(applicationClientID) -DapplicationKey=$(applicationKey) -DkeyID=$(keyID) -DwindowsKeyPath=$(windowsKeyPath) -DenclaveAttestationUrl=$(enclaveAttestationUrl) -DenclaveAttestationProtocol=$(enclaveAttestationProtocol) -DenclaveServer=4(enclaveServer)'
-DapplicationClientID=$(applicationClientID) -DapplicationKey=$(applicationKey) -DkeyID=$(keyID) -DwindowsKeyPath=$(windowsKeyPath) -DenclaveAttestationUrl=$(enclaveAttestationUrl) -DenclaveAttestationProtocol=$(enclaveAttestationProtocol) -DenclaveServer=$(enclaveServer)'
testResultsFiles: '**/TEST-*.xml'
testRunTitle: 'Maven build jre11'
javaHomeOption: Path
Expand Down
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@
<version>${h2.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.6.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
import java.util.LinkedList;
import java.util.Map;
import java.util.Properties;
import java.util.logging.LogManager;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized.Parameters;

import com.microsoft.sqlserver.jdbc.RandomData;
import com.microsoft.sqlserver.jdbc.RandomUtil;
Expand Down Expand Up @@ -55,28 +55,6 @@
*/
@RunWith(JUnitPlatform.class)
public class AESetup extends AbstractTest {
@Parameters
public static String[][] enclaveParams() throws Exception {
setup();

String[][] param = new String[AbstractTest.enclaveServer.length][3];

for (int i = 0; i < AbstractTest.enclaveServer.length; i++) {
param[i][0] = AbstractTest.enclaveServer[i];
param[i][1] = AbstractTest.enclaveAttestationUrl[i];
param[i][2] = AbstractTest.enclaveAttestationProtocol[i];
}

return param;
}

public AESetup(String serverName, String url, String protocol) throws Exception {
enclaveServer = serverName;
enclaveAttestationUrl = url;
enclaveAttestationProtocol = protocol;
setupAE();
}

static String cmkJks = Constants.CMK_NAME + "_JKS";
static String cmkWin = Constants.CMK_NAME + "_WIN";
static String cmkAkv = Constants.CMK_NAME + "_AKV";
Expand All @@ -86,23 +64,24 @@ public AESetup(String serverName, String url, String protocol) throws Exception

static SQLServerStatementColumnEncryptionSetting stmtColEncSetting = null;

public static String AETestConnectionString;
protected static String enclaveAttestationUrl = null;
protected static String enclaveAttestationProtocol = null;
protected static String enclaveServer = null;
static String AETestConnectionString;
static String enclaveProperties = "";

static Properties AEInfo;
static Map<String, SQLServerColumnEncryptionKeyStoreProvider> map = new HashMap<String, SQLServerColumnEncryptionKeyStoreProvider>();

// 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 = RandomUtil.getIdentifier("AETest_");
public static final String CHAR_TABLE_AE = RandomUtil.getIdentifier("JDBCEncryptedChar");
public static final String BINARY_TABLE_AE = RandomUtil.getIdentifier("JDBCEncryptedBinary");
public static final String DATE_TABLE_AE = RandomUtil.getIdentifier("JDBCEncryptedDate");
public static final String NUMERIC_TABLE_AE = RandomUtil.getIdentifier("JDBCEncryptedNumeric");
public static final String SCALE_DATE_TABLE_AE = RandomUtil.getIdentifier("JDBCEncryptedScaleDate");
private static final boolean isSqlLinux = false;

enum ColumnType {
PLAIN,
Expand Down Expand Up @@ -169,33 +148,74 @@ enum ColumnType {
"PlainDecimal decimal(30)", "PlainNumeric numeric(30)"};

/**
* Create connection, statement and generate path of resource file
* This provides the arguments (serverName, enclaveAttestationUrl, enclaveAttestationProtocol) for the parameterized
* tests using MethodSource parameters
*
* @return parameters for the tests
* @throws Exception
*/
@BeforeAll
public static void setupAE() throws Exception {
// skip CI unix tests with localhost servers
if (!connectionString.substring(Constants.JDBC_PREFIX.length()).split(Constants.SEMI_COLON)[0]
.contains("localhost") && null != enclaveServer) {
public static String[][] enclaveParams() throws Exception {
setup();

String[][] param = new String[AbstractTest.enclaveServer.length][3];

for (int i = 0; i < enclaveServer.length; i++) {
param[i][0] = enclaveServer[i];
param[i][1] = null != enclaveAttestationUrl ? enclaveAttestationUrl[i] : null;
param[i][2] = null != enclaveAttestationProtocol ? enclaveAttestationProtocol[i] : null;
}

return param;
}

/**
* Get the AE connection string
*
* @param serverName
* @param url
* @param protocol
*/
void setAEConnectionString(String serverName, String url, String protocol) {
// AEv2 is not supported on Linux servers
if (!isSqlLinux() && null != serverName) {
enclaveProperties = "serverName=" + serverName + ";" + Constants.ENCLAVE_ATTESTATIONURL + "=" + url + ";"
+ Constants.ENCLAVE_ATTESTATIONPROTOCOL + "=" + protocol;
AETestConnectionString = connectionString + ";sendTimeAsDateTime=false" + ";columnEncryptionSetting=enabled"
+ ";serverName=" + enclaveServer + ";" + Constants.ENCLAVE_ATTESTATIONURL + "="
+ enclaveAttestationUrl + ";" + Constants.ENCLAVE_ATTESTATIONPROTOCOL + "="
+ enclaveAttestationProtocol;
+ ";" + enclaveProperties;

// show progress if testing multiple servers
if (enclaveServer.length > 1) {
System.out.println("Testing enclave: " + enclaveProperties);
}
} else {
AETestConnectionString = connectionString + ";sendTimeAsDateTime=false"
+ ";columnEncryptionSetting=enabled";
}
}

if (null == applicationClientID || null == applicationKey || null == keyIDs
|| (isWindows && null == windowsKeyPath)) {
fail(TestResource.getResource("R_reqExternalSetup"));
/**
* Check if AEv2
*
* @param serverName
* @param url
* @param protocol
* @throws SQLException
*/
void checkAEv2(String serverName, String url, String protocol) throws SQLException {
setAEConnectionString(serverName, url, protocol);

try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo)) {
isAEv2 = TestUtils.isAEv2(con);
} catch (SQLException e) {
isAEv2 = false;
} catch (Exception e) {
fail("enclaveProperties: " + enclaveProperties + "\n" + TestResource.getResource("R_unexpectedErrorMessage")
+ e.getMessage());
}
}

readFromFile(Constants.JAVA_KEY_STORE_FILENAME, "Alias name");

dropAll();
void checkAESetup(String serverName, String url, String protocol) throws Exception {
checkAEv2(serverName, url, protocol);

createCMK(cmkJks, Constants.JAVA_KEY_STORE_NAME, javaKeyAliases, Constants.CMK_SIGNATURE);
createCEK(cmkJks, cekJks, jksProvider);
Expand All @@ -205,6 +225,16 @@ public static void setupAE() throws Exception {

createCMK(cmkWin, Constants.WINDOWS_KEY_STORE_NAME, windowsKeyPath, Constants.CMK_SIGNATURE);
createCEK(cmkWin, cekWin, null);
}

@BeforeAll
public static void getProperties() throws Exception {
if (null == applicationClientID || null == applicationKey || null == keyIDs
|| (isWindows && null == windowsKeyPath)) {
fail("enclaveProperties: " + enclaveProperties + "\n" + TestResource.getResource("R_reqExternalSetup"));
}

readFromFile(Constants.JAVA_KEY_STORE_FILENAME, "Alias name");

stmtColEncSetting = SQLServerStatementColumnEncryptionSetting.Enabled;

Expand All @@ -213,6 +243,9 @@ public static void setupAE() throws Exception {
AEInfo.setProperty("keyStoreAuthentication", Constants.JAVA_KEY_STORE_SECRET);
AEInfo.setProperty("keyStoreLocation", javaKeyPath);
AEInfo.setProperty("keyStoreSecret", Constants.JKS_SECRET);

// reset logging to avoid severe logs due to negative testing
LogManager.getLogManager().reset();
}

/**
Expand Down Expand Up @@ -279,7 +312,7 @@ private static void readFromFile(String inputFile, String lookupValue) throws IO
}
}
} catch (IOException e) {
fail(e.getMessage());
fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage());
}
}

Expand Down Expand Up @@ -308,7 +341,7 @@ protected static void createTable(String tableName, String cekName, String table
stmt.execute(sql);
stmt.execute("DBCC FREEPROCCACHE");
} catch (SQLException e) {
fail(e.getMessage());
fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage());
}
}

Expand Down Expand Up @@ -342,7 +375,7 @@ protected static void createPrecisionTable(String tableName, String table[][], S
stmt.execute(sql);
stmt.execute("DBCC FREEPROCCACHE");
} catch (SQLException e) {
fail(e.getMessage());
fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage());
}
}

Expand Down Expand Up @@ -370,7 +403,7 @@ protected static void createScaleTable(String tableName, String table[][], Strin
stmt.execute(sql);
stmt.execute("DBCC FREEPROCCACHE");
} catch (SQLException e) {
fail(e.getMessage());
fail("enclaveProperties: " + enclaveProperties + "\n" + e.getMessage());
}
}

Expand Down
Loading

0 comments on commit 646816f

Please sign in to comment.