Skip to content
Permalink
Browse files
use TestUtil to find path of certdir (#1643)
* use TestUtil to find path of certdir
  • Loading branch information
davecramer committed Dec 7, 2019
1 parent 03fdf75 commit 4a8a85445a739bc9bdaa9660f1d9b9a17d129267
Showing with 15 additions and 6 deletions.
  1. +15 −6 pgjdbc/src/test/java/org/postgresql/test/ssl/LazyKeyManagerTest.java
@@ -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;
@@ -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;
@@ -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");
@@ -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);
}

0 comments on commit 4a8a854

Please sign in to comment.