add certificate reader test

This commit is contained in:
Jörg Prante 2023-03-21 19:46:35 +01:00
parent c37ff23865
commit 94f14e86cc
2 changed files with 34 additions and 0 deletions

View file

@ -0,0 +1,24 @@
package org.xbib.net.security;
import java.io.InputStream;
import java.security.cert.X509Certificate;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.junit.jupiter.api.Test;
public class CertificateReaderTest {
private static final Logger logger = Logger.getLogger(CertificateReaderTest.class.getName());
@Test
public void testCert() throws Exception {
InputStream inputStream = getClass().getResourceAsStream("/test.crt");
if (inputStream != null) {
CertificateReader certificateReader = new CertificateReader();
X509Certificate certificate = certificateReader.readCertificate(inputStream);
logger.log(Level.INFO, "" + certificate.getSerialNumber());
logger.log(Level.INFO, "not before = " + certificate.getNotBefore());
logger.log(Level.INFO, "not after = " + certificate.getNotAfter());
}
}
}

View file

@ -87,4 +87,14 @@ public class PrivateKeyReaderTest {
assertEquals("PKCS#8", privateKey.getFormat()); assertEquals("PKCS#8", privateKey.getFormat());
assertEquals("RSA", privateKey.getAlgorithm()); assertEquals("RSA", privateKey.getAlgorithm());
} }
@Test
public void testKey() throws Exception {
InputStream inputStream = getClass().getResourceAsStream("/test.key");
if (inputStream != null) {
PrivateKeyReader privateKeyReader = new PrivateKeyReader();
PrivateKey privateKey = privateKeyReader.readPrivateKey(inputStream, null);
assertEquals("PKCS#8", privateKey.getFormat());
}
}
} }