aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Marsalek <amarsalek@iaik.tugraz.at>2021-06-23 14:51:45 +0200
committerAlexander Marsalek <amarsalek@iaik.tugraz.at>2021-06-23 16:23:18 +0200
commitc6bc4b4960fce3dbca9db119c583712a13731b6e (patch)
tree7961035e32a64976c2c06974280dcead930c3c86
parent262a0691d871882ff5b68afeb198b6e91293e704 (diff)
downloadpdf-as-4-c6bc4b4960fce3dbca9db119c583712a13731b6e.tar.gz
pdf-as-4-c6bc4b4960fce3dbca9db119c583712a13731b6e.tar.bz2
pdf-as-4-c6bc4b4960fce3dbca9db119c583712a13731b6e.zip
more tests
-rw-r--r--pdf-as-cli/src/test/java/at/gv/egiz/pdfas/cli/test/SignaturBlockParameterTest.java36
-rw-r--r--pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/DefaultSignatureProfileSettings.java6
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/PdfAsFactory.java4
-rw-r--r--pdf-as-lib/src/test/java/at/gv/egiz/pdfas/lib/test/mains/SignatureBlockParameterTest.java93
4 files changed, 98 insertions, 41 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 7b29b535..5689b080 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
@@ -106,7 +106,6 @@ public class SignaturBlockParameterTest {
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);
@@ -197,6 +196,41 @@ public class SignaturBlockParameterTest {
}
+ @Test
+ public void testWithUmlaute() 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";
+ 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("TEST123 test baräöÜ 123 c TEST123 Andreas Fitzek ECC", 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-common/src/main/java/at/gv/egiz/pdfas/common/settings/DefaultSignatureProfileSettings.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/DefaultSignatureProfileSettings.java
index d01ea0b3..ff9c6d0f 100644
--- a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/DefaultSignatureProfileSettings.java
+++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/DefaultSignatureProfileSettings.java
@@ -66,8 +66,10 @@ public class DefaultSignatureProfileSettings {
public static final String VALUE_SIG_DATE_DEFAULT = "yyyy-MM-dd'T'HH:mm:ssXXX";
public static final String SIG_BLOCK_PARAMETER_DEFAULT_KEY_REGEX = "^([A-za-z]){1,20}$";
- public static final String SIG_BLOCK_PARAMETER_DEFAULT_VALUE_REGEX = "^([\\p{Print}-_\u00e4\u00f6\u00fc\u00c4\u00d6\u00dc]){1,100}$";
-
+// public static final String SIG_BLOCK_PARAMETER_DEFAULT_VALUE_REGEX = "^([\\p{Print}-ß_'\\+\\!\u00e4\u00f6\u00fc" +
+// "\u00c4\u00d6\u00dc]){1,100}$";
+public static final String SIG_BLOCK_PARAMETER_DEFAULT_VALUE_REGEX = "^([\\p{Print}ߧ€\u00e4\u00f6\u00fc\u00c4\u00d6" +
+ "\u00dc]){1,100}$";
static {
profileSettings.put(KEY_SIG_SUBJECT, new SignatureProfileEntry(KEY_SIG_SUBJECT, KEY_SIG_SUBJECT_DEFAULT, VALUE_SIG_SUBJECT_DEFAULT) );
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/PdfAsFactory.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/PdfAsFactory.java
index b5600729..b2845959 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/PdfAsFactory.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/PdfAsFactory.java
@@ -401,9 +401,9 @@ public class PdfAsFactory implements IConfigurationConstants {
jarAttributes = mainAttributes;
return mainAttributes;
} catch (Exception e) {
- jarAttributes = new Attributes();
+
}
- return null;
+ return new Attributes();
}
/**
diff --git a/pdf-as-lib/src/test/java/at/gv/egiz/pdfas/lib/test/mains/SignatureBlockParameterTest.java b/pdf-as-lib/src/test/java/at/gv/egiz/pdfas/lib/test/mains/SignatureBlockParameterTest.java
index 1cebd8ef..23422e8e 100644
--- a/pdf-as-lib/src/test/java/at/gv/egiz/pdfas/lib/test/mains/SignatureBlockParameterTest.java
+++ b/pdf-as-lib/src/test/java/at/gv/egiz/pdfas/lib/test/mains/SignatureBlockParameterTest.java
@@ -5,59 +5,80 @@ import at.gv.egiz.pdfas.common.utils.CheckSignatureBlockParameters;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
-
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
@RunWith(JUnit4.class)
public class SignatureBlockParameterTest {
-
@Test
public void testKeyInvalid() {
- if(checkValid( "aaaaaaaaaaaaaaaaaaaaa" , "^([A-za-z]){1,20}$") == true){assert(false);}
- if(checkValid( "" , "^([A-za-z]){1,20}$") == true){assert(false);}
- if(checkValid( "a9" , "^([A-za-z]){1,20}$") == true){assert(false);}
+ assertFalse(checkValid( "aaaaaaaaaaaaaaaaaaaaa" , "^([A-za-z]){1,20}$"));
+ assertFalse(checkValid( "" , "^([A-za-z]){1,20}$"));
+ assertFalse(checkValid( "a9" , "^([A-za-z]){1,20}$"));
}
+
@Test
public void testKeyValid() {
- if(checkValid( "aaa" +"aa", "^([A-za-z]){1,20}$") == false){assert(false);}
- if(checkValid( "aaa" , "^([A-za-z]){1,20}$") == false){assert(false);}
- if(checkValid( "aaaaaaaaaaaaaaaaaaaa", "^([A-za-z]){1,20}$") == false){assert(false);}
- if(checkValid( "AA", "^([A-za-z]){1,20}$") == false){assert(false);}
+ assertTrue(checkValid( "aaa" +"aa", "^([A-za-z]){1,20}$"));
+ assertTrue(checkValid( "aaa" , "^([A-za-z]){1,20}$"));
+ assertTrue(checkValid( "aaaaaaaaaaaaaaaaaaaa", "^([A-za-z]){1,20}$"));
+ assertTrue(checkValid( "AA", "^([A-za-z]){1,20}$"));
}
+
@Test
public void testValueValid() {
- if(checkValid( "aaa" +"aa", "^([\\p{Print}]){1,100}$") == false){assert(false);}
- if(checkValid( "aaa" , "^([\\p{Print}]){1,100}$") == false){assert(false);}
- if(checkValid( "a!\"$%&/()[]=?aa" , "^([\\p{Print}]){1,100}$") == false){assert(false);}
- if(checkValid( "a!\"$%&/()[]=?aa-_,;.:[]|{}" , "^([\\p{Print}]){1,100}$") == false){assert(false);}
-// if(checkValid( "a!\"§$%&/()=?aa" , "^([\\p{Print}]){1,100}$") == false){assert(false);}
- if(checkValid( "aa!%&/()=?a" , "^([\\p{Print}]){1,100}$") == false){assert(false);}
- if(checkValid( "a{\"a!%&/()=?a" , "^([\\p{Print}]){1,100}$") == false){assert(false);}
- if(checkValid( "BB" , "^([\\p{Print}]){1,100}$") == false){assert(false);}
- if(checkValid( "BB " , "^([\\p{Print}]){1,100}$") == false){assert(false);}
+ assertTrue(checkValid( "aaa" +"aa", "^([\\p{Print}]){1,100}$"));
+ assertTrue(checkValid( "aaa" , "^([\\p{Print}]){1,100}$"));
+ assertTrue(checkValid( "a!\"$%&/()[]=?aa-_,;.:[]|{}" , "^([\\p{Print}]){1,100}$"));
+// assertTrue(checkValid( "a!\"§$%&/()=?aa" , "^([\\p{Print}]){1,100}$"));
+ assertTrue(checkValid( "aa!%&/()=?a" , "^([\\p{Print}]){1,100}$"));
+ assertTrue(checkValid( "a{\"a!%&/()=?a" , "^([\\p{Print}]){1,100}$"));
+ assertTrue(checkValid( "BB" , "^([\\p{Print}]){1,100}$"));
+ assertTrue(checkValid( "BB " , "^([\\p{Print}]){1,100}$"));
}
+
@Test
- public void testValueInvalid() {
- if(checkValid((char) 13 +"aaa" +"aa", "^([\\p{Print}]){1,100}$") == true){assert(false);}
- if(checkValid((char) 13 +"", "^([\\p{Print}]){1,100}$") == true){assert(false);}
- if(checkValid( "aaa" +(char) 13, "^([\\p{Print}]){1,100}$") == true){assert(false);}
- if(checkValid("", "^([\\p{Print}]){1,100}$") == true){assert(false);}
- if(checkValid("a", "^([\\p{Print}]){2,100}$") == true){assert(false);}
- if(checkValid("aaa"+(char) 13 +"aa", "^([\\p{Print}]){1,100}$") == true){assert(false);}
+ public void testValueValidWithDefaultRegex() {
+ assertTrue(checkValid( "aaa" +"aa", DefaultSignatureProfileSettings.SIG_BLOCK_PARAMETER_DEFAULT_VALUE_REGEX));
+ assertTrue(checkValid( "aaa" , DefaultSignatureProfileSettings.SIG_BLOCK_PARAMETER_DEFAULT_VALUE_REGEX));
+ assertTrue(checkValid( "a!\"$%&/()[]=?aa-_,;.:[]|{}" , DefaultSignatureProfileSettings.SIG_BLOCK_PARAMETER_DEFAULT_VALUE_REGEX));
+// assertTrue(checkValid( "a!\"§$%&/()=?aa" , DefaultSignatureProfileSettings.SIG_BLOCK_PARAMETER_DEFAULT_VALUE_REGEX));
+ assertTrue(checkValid( "aa!%&/()=?a" , DefaultSignatureProfileSettings.SIG_BLOCK_PARAMETER_DEFAULT_VALUE_REGEX));
+ assertTrue(checkValid( "a{\"a!%&/()=?a" , DefaultSignatureProfileSettings.SIG_BLOCK_PARAMETER_DEFAULT_VALUE_REGEX));
+ assertTrue(checkValid( "BB" , DefaultSignatureProfileSettings.SIG_BLOCK_PARAMETER_DEFAULT_VALUE_REGEX));
+ assertTrue(checkValid( "BB " , DefaultSignatureProfileSettings.SIG_BLOCK_PARAMETER_DEFAULT_VALUE_REGEX));
+ assertTrue(checkValid("! €%&/()?`$\"§", DefaultSignatureProfileSettings.SIG_BLOCK_PARAMETER_DEFAULT_VALUE_REGEX));
+ assertTrue(checkValid("€", DefaultSignatureProfileSettings.SIG_BLOCK_PARAMETER_DEFAULT_VALUE_REGEX));
+ assertTrue(checkValid("$", DefaultSignatureProfileSettings.SIG_BLOCK_PARAMETER_DEFAULT_VALUE_REGEX));
+ assertTrue(checkValid("! €\"§$%&/()=?`", DefaultSignatureProfileSettings.SIG_BLOCK_PARAMETER_DEFAULT_VALUE_REGEX));
+ assertTrue(checkValid("#", DefaultSignatureProfileSettings.SIG_BLOCK_PARAMETER_DEFAULT_VALUE_REGEX));
+ assertTrue(checkValid("-_", DefaultSignatureProfileSettings.SIG_BLOCK_PARAMETER_DEFAULT_VALUE_REGEX));
+ assertTrue(checkValid("'", DefaultSignatureProfileSettings.SIG_BLOCK_PARAMETER_DEFAULT_VALUE_REGEX));
+ assertTrue(checkValid("abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!#-_ß?+#*",
+ DefaultSignatureProfileSettings.SIG_BLOCK_PARAMETER_DEFAULT_VALUE_REGEX));
+ }
+ @Test
+ public void testValueInvalid() {
+ assertFalse(checkValid((char) 13 +"aaa" +"aa", "^([\\p{Print}]){1,100}$"));
+ assertFalse(checkValid((char) 13 +"", "^([\\p{Print}]){1,100}$"));
+ assertFalse(checkValid( "aaa" +(char) 13, "^([\\p{Print}]){1,100}$"));
+ assertFalse(checkValid("", "^([\\p{Print}]){1,100}$"));
+ assertFalse(checkValid("a", "^([\\p{Print}]){2,100}$"));
+ assertFalse(checkValid("aaa"+(char) 13 +"aa", "^([\\p{Print}]){1,100}$"));
}
+
@Test
public void testUmlauteValid() {
- if(checkValid( "ä", DefaultSignatureProfileSettings.SIG_BLOCK_PARAMETER_DEFAULT_VALUE_REGEX) == false){assert(false);}
- if(checkValid( "ö", DefaultSignatureProfileSettings.SIG_BLOCK_PARAMETER_DEFAULT_VALUE_REGEX) == false){assert(false);}
- if(checkValid( "ü", DefaultSignatureProfileSettings.SIG_BLOCK_PARAMETER_DEFAULT_VALUE_REGEX) == false){assert(false);}
- if(checkValid( "Ä", DefaultSignatureProfileSettings.SIG_BLOCK_PARAMETER_DEFAULT_VALUE_REGEX) == false){assert(false);}
- if(checkValid( "Ö", DefaultSignatureProfileSettings.SIG_BLOCK_PARAMETER_DEFAULT_VALUE_REGEX) == false){assert(false);}
- if(checkValid( "Ü", DefaultSignatureProfileSettings.SIG_BLOCK_PARAMETER_DEFAULT_VALUE_REGEX) == false){assert(false);}
- if(checkValid( "ÄÖÜöäüjhsbdjej", DefaultSignatureProfileSettings.SIG_BLOCK_PARAMETER_DEFAULT_VALUE_REGEX) == false){assert(false);}
- if(checkValid( "aauacnhuisdc Ä Ü Ö aaxsa ö aÜaÖa",
- DefaultSignatureProfileSettings.SIG_BLOCK_PARAMETER_DEFAULT_VALUE_REGEX) == false){assert(false);}
- if(checkValid( "NMS Güssing", DefaultSignatureProfileSettings.SIG_BLOCK_PARAMETER_DEFAULT_VALUE_REGEX) == false){assert(false);}
-
+ assertTrue(checkValid( "ä", DefaultSignatureProfileSettings.SIG_BLOCK_PARAMETER_DEFAULT_VALUE_REGEX));
+ assertTrue(checkValid( "ö", DefaultSignatureProfileSettings.SIG_BLOCK_PARAMETER_DEFAULT_VALUE_REGEX));
+ assertTrue(checkValid( "ü", DefaultSignatureProfileSettings.SIG_BLOCK_PARAMETER_DEFAULT_VALUE_REGEX));
+ assertTrue(checkValid( "Ä", DefaultSignatureProfileSettings.SIG_BLOCK_PARAMETER_DEFAULT_VALUE_REGEX));
+ assertTrue(checkValid( "Ö", DefaultSignatureProfileSettings.SIG_BLOCK_PARAMETER_DEFAULT_VALUE_REGEX));
+ assertTrue(checkValid( "Ü", DefaultSignatureProfileSettings.SIG_BLOCK_PARAMETER_DEFAULT_VALUE_REGEX));
+ assertTrue(checkValid( "ÄÖÜöäüjhsbdjej", DefaultSignatureProfileSettings.SIG_BLOCK_PARAMETER_DEFAULT_VALUE_REGEX));
+ assertTrue(checkValid( "aauacnhuisdc Ä Ü Ö aaxsa ö aÜaÖa", DefaultSignatureProfileSettings.SIG_BLOCK_PARAMETER_DEFAULT_VALUE_REGEX));
+ assertTrue(checkValid( "NMS Güssing", DefaultSignatureProfileSettings.SIG_BLOCK_PARAMETER_DEFAULT_VALUE_REGEX));
}
public boolean checkValid(String s, String regex) {