You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2020/08/01 09:21:30 UTC

svn commit: r1880497 - /pdfbox/branches/issue45/examples/src/test/java/org/apache/pdfbox/examples/pdmodel/TestCreateSignature.java

Author: tilman
Date: Sat Aug  1 09:21:29 2020
New Revision: 1880497

URL: http://svn.apache.org/viewvc?rev=1880497&view=rev
Log:
PDFBOX-3017: methods that don't use the external signing toggling feature should run only once

Modified:
    pdfbox/branches/issue45/examples/src/test/java/org/apache/pdfbox/examples/pdmodel/TestCreateSignature.java

Modified: pdfbox/branches/issue45/examples/src/test/java/org/apache/pdfbox/examples/pdmodel/TestCreateSignature.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/issue45/examples/src/test/java/org/apache/pdfbox/examples/pdmodel/TestCreateSignature.java?rev=1880497&r1=1880496&r2=1880497&view=diff
==============================================================================
--- pdfbox/branches/issue45/examples/src/test/java/org/apache/pdfbox/examples/pdmodel/TestCreateSignature.java (original)
+++ pdfbox/branches/issue45/examples/src/test/java/org/apache/pdfbox/examples/pdmodel/TestCreateSignature.java Sat Aug  1 09:21:29 2020
@@ -278,6 +278,10 @@ public class TestCreateSignature
             throws IOException, CMSException, OperatorCreationException, GeneralSecurityException,
                    TSPException, CertificateVerificationException
     {
+        if (externallySign)
+        {
+            return; // runs only once, independent of externallySign
+        }
         if (tsa == null || tsa.isEmpty())
         {
             System.err.println("No TSA URL defined, test skipped");
@@ -400,7 +404,7 @@ public class TestCreateSignature
         CreateVisibleSignature signing2 = new CreateVisibleSignature(keystore, password.toCharArray());
         signing2.setVisibleSignDesigner(filenameSigned1, 0, 0, -50, fis, 1);
         signing2.setVisibleSignatureProperties("name", "location", "Security", 0, 1, true);
-        signing2.setExternalSigning(externallySign);
+        signing2.setExternalSigning(true);
         signing2.signPDF(new File(filenameSigned1), new File(filenameSigned2), null, "Signature1");
         fis.close();
 
@@ -687,6 +691,10 @@ public class TestCreateSignature
     @Test
     public void testPDFBox4784() throws Exception
     {
+        if (!externallySign)
+        {
+            return;
+        }
         Date signingTime = new Date();
 
         byte[] defaultSignedOne = signEncrypted(null, signingTime);
@@ -718,11 +726,14 @@ public class TestCreateSignature
     public void testCRL() throws IOException, CMSException, CertificateException, TSPException,
             OperatorCreationException, CertificateVerificationException, NoSuchAlgorithmException
     {
+        if (externallySign)
+        {
+            return; // runs only once, independent of externallySign
+        }
         String hexSignature;
-        BufferedReader bfr = 
-            new BufferedReader(new InputStreamReader(new FileInputStream(inDir + "hexsignature.txt")));
-        
-            hexSignature = bfr.readLine();
+        BufferedReader bfr
+                = new BufferedReader(new InputStreamReader(new FileInputStream(inDir + "hexsignature.txt")));
+        hexSignature = bfr.readLine();
         bfr.close();
 
         CMSSignedData signedData = new CMSSignedData(Hex.decodeHex(hexSignature));
@@ -779,6 +790,10 @@ public class TestCreateSignature
     public void testAddValidationInformation()
             throws IOException, GeneralSecurityException, OCSPException, OperatorCreationException, CMSException
     {
+        if (externallySign)
+        {
+            return; // runs only once, independent of externallySign
+        }
         File inFile = new File("target/pdfs", "QV_RCA1_RCA3_CPCPS_V4_11.pdf");
         String name = inFile.getName();
         String substring = name.substring(0, name.lastIndexOf('.'));
@@ -938,12 +953,6 @@ public class TestCreateSignature
             Assert.assertEquals("OCSP certificate is not in the VRI array", certHolder2, ocspCertHolder);
         }
 
-        // TODO - split testCreateSignature (one with parameter, one without)
-        //      - possibly DRY on certificate factory
-        //      - split into smaller methods?
-        //      - try-with-resources
-        //      - branches
-        
         doc.close();
     }