Skip to content

Commit

Permalink
use TestUtil to find path of certdir (#1643)
Browse files Browse the repository at this point in the history
* use TestUtil to find path of certdir
  • Loading branch information
davecramer committed Dec 7, 2019
1 parent 03fdf75 commit 4a8a854
Showing 1 changed file with 15 additions and 6 deletions.
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

0 comments on commit 4a8a854

Please sign in to comment.