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

Fix | Close resources and skip AE tests by default #1315

Merged
merged 3 commits into from
Apr 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
clientCertAuth - - For tests requiring client certificate authentication setup (excluded by default)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Default testing enabled with SQL Server 2019 (SQLv15) -->
<excludedGroups>xSQLv15,NTLM,MSI,reqExternalSetup,clientCertAuth</excludedGroups>
<excludedGroups>xSQLv12,xSQLv15,NTLM,MSI,reqExternalSetup,clientCertAuth</excludedGroups>

<!-- Use -preview for preview release, leave empty for official release.-->
<releaseExt>-preview</releaseExt>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ static KeyManager[] getKeyManagerFromFile(String certPath, String keyPath,
private static KeyManager[] readPKCS12Certificate(String certPath,
String keyPassword) throws NoSuchAlgorithmException, CertificateException, FileNotFoundException, IOException, UnrecoverableKeyException, KeyStoreException, SQLServerException {
KeyStore keystore = KeyStore.getInstance(PKCS12_ALG);
try {
keystore.load(new FileInputStream(certPath), keyPassword.toCharArray());
try (FileInputStream certStream = new FileInputStream(certPath)) {
keystore.load(certStream, keyPassword.toCharArray());
} catch (FileNotFoundException e) {
throw new SQLServerException(SQLServerException.getErrString("R_clientCertError"), null, 0, null);
}
Expand Down Expand Up @@ -203,10 +203,12 @@ private static PrivateKey loadPrivateKeyFromPVK(String keyPath,
}
}

private static Certificate loadCertificate(String certificatePem) throws IOException, GeneralSecurityException, SQLServerException {
private static Certificate loadCertificate(
String certificatePem) throws IOException, GeneralSecurityException, SQLServerException {
CertificateFactory certificateFactory = CertificateFactory.getInstance("X509");
InputStream certstream = fileToStream(certificatePem);
return certificateFactory.generateCertificate(certstream);
try (InputStream certStream = fileToStream(certificatePem)) {
return certificateFactory.generateCertificate(certStream);
}
}

private static PrivateKey loadPrivateKey(String privateKeyPemPath,
Expand Down Expand Up @@ -268,24 +270,12 @@ private static BigInteger getBigInteger(ByteBuffer buffer, int length) {
}

private static InputStream fileToStream(String fname) throws IOException, SQLServerException {
FileInputStream fis = null;
DataInputStream dis = null;
try {
fis = new FileInputStream(fname);
dis = new DataInputStream(fis);
try (FileInputStream fis = new FileInputStream(fname); DataInputStream dis = new DataInputStream(fis)) {
byte[] bytes = new byte[dis.available()];
dis.readFully(bytes);
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
return bais;
} catch (FileNotFoundException e) {
return new ByteArrayInputStream(bytes);
} catch (FileNotFoundException e) {
throw new SQLServerException(SQLServerException.getErrString("R_clientCertError"), null, 0, null);
} finally {
if (null != dis) {
dis.close();
}
if (null != fis) {
fis.close();
}
}
}

Expand Down