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

use TestUtil to find path of certdir #1643

Merged
merged 3 commits into from Dec 7, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -7,6 +7,7 @@

import org.postgresql.ssl.LazyKeyManager;
import org.postgresql.ssl.PKCS12KeyManager;
import org.postgresql.test.TestUtil;

import org.junit.Assert;
import org.junit.Test;
Expand All @@ -15,6 +16,7 @@
import java.io.IOException;
import java.security.PrivateKey;
import java.security.cert.X509Certificate;
import java.util.Properties;

import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
Expand All @@ -25,8 +27,12 @@ public class LazyKeyManagerTest {

@Test
public void testLoadP12Key() throws Exception {
String certdir = "../certdir/";
PKCS12KeyManager pkcs12KeyManager = new PKCS12KeyManager(certdir + "goodclient.p12", new TestCallbackHandler("sslpwd"));

Properties prop = TestUtil.loadPropertyFiles("ssltest.properties");
File certDirFile = TestUtil.getFile(prop.getProperty("certdir"));
String certdir = certDirFile.getAbsolutePath();

PKCS12KeyManager pkcs12KeyManager = new PKCS12KeyManager(certdir + "/goodclient.p12", new TestCallbackHandler("sslpwd"));
PrivateKey pk = pkcs12KeyManager.getPrivateKey("user");
Assert.assertNotNull(pk);
X509Certificate[] chain = pkcs12KeyManager.getCertificateChain("user");
Expand All @@ -35,10 +41,13 @@ public void testLoadP12Key() throws Exception {

@Test
public void testLoadKey() throws Exception {
String certdir = "../certdir/";
String path = new File("./").getAbsolutePath();
LazyKeyManager lazyKeyManager = new LazyKeyManager(certdir + "goodclient.crt",
certdir + "goodclient.pk8", new TestCallbackHandler("sslpwd"), true);

Properties prop = TestUtil.loadPropertyFiles("ssltest.properties");
File certDirFile = TestUtil.getFile(prop.getProperty("certdir"));
String certdir = certDirFile.getAbsolutePath();

LazyKeyManager lazyKeyManager = new LazyKeyManager(certdir + "/goodclient.crt",
certdir + "/goodclient.pk8", new TestCallbackHandler("sslpwd"), true);
PrivateKey pk = lazyKeyManager.getPrivateKey("user");
Assert.assertNotNull(pk);
}
Expand Down