diff options
author | Alexander Marsalek <amarsalek@iaik.tugraz.at> | 2021-06-25 09:12:35 +0200 |
---|---|---|
committer | Alexander Marsalek <amarsalek@iaik.tugraz.at> | 2021-06-25 09:12:35 +0200 |
commit | 252703c09a6ab591382d443cda5e7a910ff1d584 (patch) | |
tree | 3e0d1440653088e0eff038b90b02d5584d38ad0d /pdf-as-cli/src/test | |
parent | c6bc4b4960fce3dbca9db119c583712a13731b6e (diff) | |
download | pdf-as-4-252703c09a6ab591382d443cda5e7a910ff1d584.tar.gz pdf-as-4-252703c09a6ab591382d443cda5e7a910ff1d584.tar.bz2 pdf-as-4-252703c09a6ab591382d443cda5e7a910ff1d584.zip |
test for issue #47
Diffstat (limited to 'pdf-as-cli/src/test')
2 files changed, 52 insertions, 0 deletions
diff --git a/pdf-as-cli/src/test/java/at/gv/egiz/pdfas/cli/test/SignaturBlockParameterTest.java b/pdf-as-cli/src/test/java/at/gv/egiz/pdfas/cli/test/SignaturBlockParameterTest.java index 5689b080..f723a6c1 100644 --- a/pdf-as-cli/src/test/java/at/gv/egiz/pdfas/cli/test/SignaturBlockParameterTest.java +++ b/pdf-as-cli/src/test/java/at/gv/egiz/pdfas/cli/test/SignaturBlockParameterTest.java @@ -231,6 +231,42 @@ public class SignaturBlockParameterTest { //expected:<TEST123 test bar[] 123 c TEST123 Andre...> but was:<TEST123 test bar[äöÜ] 123 c TEST123 Andre...> } + + @Test + public void testWithTextAfterVariable() throws IOException, PDFASError, PdfAsException { + + PdfAs pdfas = PdfAsFactory.createPdfAs(new File(getPath("pdfas-config"))); + Configuration config = pdfas.getConfiguration(); + + + byte[] input = IOUtils.toByteArray(new FileInputStream(getPath("simple_rotated_0.pdf"))); + + IPlainSigner signer = new PAdESSignerKeystore(getPath("test.p12"), KS_ALIAS, KS_PASS, KS_KEY_PASS, KS_TYPE); + + String profile = "SIGNATURBLOCK_DE_NOTE_DYNAMIC_WITH_TEXT_AFTER_VARIABLE"; + System.out.println("Testing " + profile); + + DataSource source = new ByteArrayDataSource(input); + String outFile = getPath("out") + "/" + profile + "-umlaute.pdf"; + FileOutputStream fos = new FileOutputStream(outFile); + SignParameter signParameter = PdfAsFactory.createSignParameter( + config, source, fos); + + Map<String, String> map = new HashMap<>(); + map.put("subject", "TEST123"); + map.put("foo", "baräöÜ"); + signParameter.setDynamicSignatureBlockArguments(map); + signParameter.setPlainSigner(signer); + signParameter.setSignatureProfileId(profile); + + SignResult result = pdfas.sign(signParameter); + + fos.close(); + String name = getName(outFile, "PDF-AS Signatur1"); + Assert.assertEquals("Andreas Fitzek ECC text after variable", name); + //expected:<TEST123 test bar[] 123 c TEST123 Andre...> but was:<TEST123 test bar[äöÜ] 123 c TEST123 Andre...> + } + private String getName(String fileName, String sigFieldName) throws IOException { PDDocument pdDoc = PDDocument.load(new File(fileName)); PDSignature signature = null; diff --git a/pdf-as-cli/src/test/resources/pdfas-config/cfg/profiles/SIGNATURBLOCK_DE_NOTE_DYNAMIC_WITH_TEXT_AFTER_VARIABLE.properties b/pdf-as-cli/src/test/resources/pdfas-config/cfg/profiles/SIGNATURBLOCK_DE_NOTE_DYNAMIC_WITH_TEXT_AFTER_VARIABLE.properties new file mode 100644 index 00000000..bf904b1c --- /dev/null +++ b/pdf-as-cli/src/test/resources/pdfas-config/cfg/profiles/SIGNATURBLOCK_DE_NOTE_DYNAMIC_WITH_TEXT_AFTER_VARIABLE.properties @@ -0,0 +1,16 @@ +###################################################################################################
+# PROFIL: Standardsignatur Deutsch, mit Hinweistext
+
+sig_obj.SIGNATURBLOCK_DE_NOTE_DYNAMIC_WITH_TEXT_AFTER_VARIABLE.description=Standardsignatur Deutsch, mit Hinweistext
+sig_obj.SIGNATURBLOCK_DE_NOTE_DYNAMIC_WITH_TEXT_AFTER_VARIABLE.parent=BASE_NORMAL_NOTE
+sig_obj.types.SIGNATURBLOCK_DE_NOTE_DYNAMIC_WITH_TEXT_AFTER_VARIABLE=on
+
+
+sig_obj.SIGNATURBLOCK_DE_NOTE_DYNAMIC_WITH_TEXT_AFTER_VARIABLE.value.SIG_SUBJECT=${subject.T != null ? (subject.T + " ") : ""}${subject.CN} text after variable
+sig_obj.SIGNATURBLOCK_DE_NOTE_DYNAMIC_WITH_TEXT_AFTER_VARIABLE.value.SIG_ISSUER=${issuer.T != null ? (issuer.T + " ") : ""}${issuer.CN}
+sig_obj.SIGNATURBLOCK_DE_NOTE_DYNAMIC_WITH_TEXT_AFTER_VARIABLE.value.SIG_NUMBER=${sn}
+sig_obj.SIGNATURBLOCK_DE_NOTE_DYNAMIC_WITH_TEXT_AFTER_VARIABLE.value.SIG_META=Informationen zur Pr\u00FCfung der \
+ elektronischen Signatur finden Sie unter: https://www.signaturpruefung.gv.at
+
+#---------------------- INFO TABLE -------------------------
+sig_obj.SIGNATURBLOCK_DE_NOTE_DYNAMIC_WITH_TEXT_AFTER_VARIABLE.table.info.ColsWidth=1 5
\ No newline at end of file |