aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-lib/src/test/java/at/gv
diff options
context:
space:
mode:
authorThomas <>2022-10-17 14:48:29 +0200
committerThomas <>2023-01-12 15:25:34 +0100
commitc14096c5a87dabcc7483c5ff7bcd7014ee3a0319 (patch)
treed7c863ff85d4b0657e2587fc9d33ad9704a39672 /pdf-as-lib/src/test/java/at/gv
parent061129ed699a214818e7f62e2850fbe3b8b7b0ab (diff)
downloadpdf-as-4-c14096c5a87dabcc7483c5ff7bcd7014ee3a0319.tar.gz
pdf-as-4-c14096c5a87dabcc7483c5ff7bcd7014ee3a0319.tar.bz2
pdf-as-4-c14096c5a87dabcc7483c5ff7bcd7014ee3a0319.zip
test(sigblock): add jUnit test to check title attribute of signer name
Diffstat (limited to 'pdf-as-lib/src/test/java/at/gv')
-rw-r--r--pdf-as-lib/src/test/java/at/gv/egiz/pdfas/lib/test/stamping/CertificateAndRequestParameterResolverTest.java121
1 files changed, 121 insertions, 0 deletions
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<String, String> 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<String> getFirstLevelKeys(String prefix) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ };
+ }
+}