From c14096c5a87dabcc7483c5ff7bcd7014ee3a0319 Mon Sep 17 00:00:00 2001 From: Thomas <> Date: Mon, 17 Oct 2022 14:48:29 +0200 Subject: test(sigblock): add jUnit test to check title attribute of signer name --- ...CertificateAndRequestParameterResolverTest.java | 121 +++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 pdf-as-lib/src/test/java/at/gv/egiz/pdfas/lib/test/stamping/CertificateAndRequestParameterResolverTest.java (limited to 'pdf-as-lib/src/test/java/at/gv/egiz/pdfas/lib') diff --git a/pdf-as-lib/src/test/java/at/gv/egiz/pdfas/lib/test/stamping/CertificateAndRequestParameterResolverTest.java b/pdf-as-lib/src/test/java/at/gv/egiz/pdfas/lib/test/stamping/CertificateAndRequestParameterResolverTest.java new file mode 100644 index 00000000..68222881 --- /dev/null +++ b/pdf-as-lib/src/test/java/at/gv/egiz/pdfas/lib/test/stamping/CertificateAndRequestParameterResolverTest.java @@ -0,0 +1,121 @@ +package at.gv.egiz.pdfas.lib.test.stamping; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.security.cert.CertificateException; +import java.util.Map; +import java.util.Vector; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +import com.google.gson.annotations.SerializedName; + +import at.gv.egiz.pdfas.common.settings.DefaultSignatureProfileSettings; +import at.gv.egiz.pdfas.common.settings.ISettings; +import at.gv.egiz.pdfas.common.settings.SignatureProfileSettings; +import at.gv.egiz.pdfas.lib.api.sign.SignParameter; +import at.gv.egiz.pdfas.lib.impl.SignParameterImpl; +import at.gv.egiz.pdfas.lib.impl.stamping.CertificateAndRequestParameterResolver; +import at.gv.egiz.pdfas.lib.impl.stamping.ValueResolver; +import at.gv.egiz.pdfas.lib.impl.status.ICertificateProvider; +import at.gv.egiz.pdfas.lib.impl.status.OperationStatus; +import iaik.x509.X509Certificate; + +@RunWith(JUnit4.class) +public class CertificateAndRequestParameterResolverTest { + + private OperationStatus opStatus; + private SignatureProfileSettings sigProfileSetting; + + @Before + public void initialize() { + SignParameter signParams = new SignParameterImpl(null, null, null); + opStatus = new OperationStatus(buildDummySettings(), signParams , null); + + sigProfileSetting = new SignatureProfileSettings("test", buildDummySettings()); + + } + + @Test + public void signerWithTitleOld() throws CertificateException, IOException { + X509Certificate cert = new X509Certificate( + CertificateAndRequestParameterResolverTest.class.getResourceAsStream( + "/data/Hermann_Peyerl.20210930-20260930.SerNo651789F5.cer")); + ValueResolver resolver = new ValueResolver(buildCertProvider(cert), opStatus); + + String result = resolver.resolve("", + "${subject.T != null ? (subject.T + \" \") : \"\"}${subject.CN}", + sigProfileSetting); + assertEquals("wrong signer Name", "Hermann Peyerl", result); + + } + + @Test + public void signerWithTitle() throws CertificateException, IOException { + X509Certificate cert = new X509Certificate( + CertificateAndRequestParameterResolverTest.class.getResourceAsStream( + "/data/Hermann_Peyerl.20210930-20260930.SerNo651789F5.cer")); + ValueResolver resolver = new ValueResolver(buildCertProvider(cert), opStatus); + + String result = resolver.resolve("", + "${subject.title != null ? (subject.title + \" \") : \"\"}${subject.CN}", + sigProfileSetting); + assertEquals("wrong signer Name", "A.Univ.Prof.DDr. Hermann Peyerl", result); + + } + + private ICertificateProvider buildCertProvider(final X509Certificate cert) { + return new ICertificateProvider() { + + @Override + public X509Certificate getCertificate() { + return cert; + } + }; + } + + private ISettings buildDummySettings() { + return new ISettings() { + + @Override + public boolean hasValue(String key) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean hasPrefix(String prefix) { + // TODO Auto-generated method stub + return false; + } + + @Override + public String getWorkingDirectory() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Map getValuesPrefix(String prefix) { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getValue(String key) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Vector getFirstLevelKeys(String prefix) { + // TODO Auto-generated method stub + return null; + } + }; + } +} -- cgit v1.2.3