From 1be82e61c0acf4d7380dcee3e3fcaaa8a8386f1b Mon Sep 17 00:00:00 2001 From: Alexander Marsalek Date: Wed, 14 Apr 2021 19:05:02 +0200 Subject: added sbp check --- .../test/mains/SignatureBlockParameterTest.java | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 pdf-as-lib/src/test/java/at/gv/egiz/pdfas/lib/test/mains/SignatureBlockParameterTest.java (limited to 'pdf-as-lib/src/test/java/at') 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 new file mode 100644 index 00000000..3c76ce11 --- /dev/null +++ b/pdf-as-lib/src/test/java/at/gv/egiz/pdfas/lib/test/mains/SignatureBlockParameterTest.java @@ -0,0 +1,51 @@ +package at.gv.egiz.pdfas.lib.test.mains; + +import at.gv.egiz.pdfas.common.utils.CheckSignatureBlockParameters; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@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);} + } + @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);} + } + @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);} + } + @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 boolean checkValid(String s, String regex) { + return CheckSignatureBlockParameters.isValid(s, regex); + } +} -- cgit v1.2.3