diff options
author | Thomas <> | 2022-10-17 14:48:29 +0200 |
---|---|---|
committer | Thomas <> | 2023-01-12 15:25:34 +0100 |
commit | c14096c5a87dabcc7483c5ff7bcd7014ee3a0319 (patch) | |
tree | d7c863ff85d4b0657e2587fc9d33ad9704a39672 /pdf-as-lib/src | |
parent | 061129ed699a214818e7f62e2850fbe3b8b7b0ab (diff) | |
download | pdf-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')
2 files changed, 154 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; + } + }; + } +} diff --git a/pdf-as-lib/src/test/resources/data/Hermann_Peyerl.20210930-20260930.SerNo651789F5.cer b/pdf-as-lib/src/test/resources/data/Hermann_Peyerl.20210930-20260930.SerNo651789F5.cer new file mode 100644 index 00000000..39f609dc --- /dev/null +++ b/pdf-as-lib/src/test/resources/data/Hermann_Peyerl.20210930-20260930.SerNo651789F5.cer @@ -0,0 +1,33 @@ +-----BEGIN CERTIFICATE----- +MIIFrzCCA5egAwIBAgIEZReJ9TANBgkqhkiG9w0BAQsFADCBnTELMAkGA1UEBhMC
+QVQxSDBGBgNVBAoMP0EtVHJ1c3QgR2VzLiBmLiBTaWNoZXJoZWl0c3N5c3RlbWUg
+aW0gZWxla3RyLiBEYXRlbnZlcmtlaHIgR21iSDEhMB8GA1UECwwYYS1zaWduLXBy
+ZW1pdW0tbW9iaWxlLTA1MSEwHwYDVQQDDBhhLXNpZ24tcHJlbWl1bS1tb2JpbGUt
+MDUwHhcNMjEwOTMwMDc1MjE1WhcNMjYwOTMwMDc1MjE1WjB7MQswCQYDVQQGEwJB
+VDEXMBUGA1UEAwwOSGVybWFubiBQZXllcmwxDzANBgNVBAQMBlBleWVybDEQMA4G
+A1UEKgwHSGVybWFubjEVMBMGA1UEBRMMNTc1NDcwMTM4NzUxMRkwFwYDVQQMDBBB
+LlVuaXYuUHJvZi5ERHIuMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE8blARx8X
+uWDpWxlZdka0fig4zuAwnw6bqbtDZWccS/y9L8+bkt50X2XOi0+e1wXVTmuuVYTz
+rC3bCi29DEKB/KOCAeEwggHdMH0GCCsGAQUFBwEBBHEwbzBEBggrBgEFBQcwAoY4
+aHR0cDovL3d3dy5hLXRydXN0LmF0L2NlcnRzL2Etc2lnbi1wcmVtaXVtLW1vYmls
+ZS0wNS5jcnQwJwYIKwYBBQUHMAGGG2h0d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