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:37 UTC
svn commit: r1880499 -
/pdfbox/branches/2.0/examples/src/test/java/org/apache/pdfbox/examples/pdmodel/TestCreateSignature.java
Author: tilman
Date: Sat Aug 1 09:21:37 2020
New Revision: 1880499
URL: http://svn.apache.org/viewvc?rev=1880499&view=rev
Log:
PDFBOX-3017: methods that don't use the external signing toggling feature should run only once
Modified:
pdfbox/branches/2.0/examples/src/test/java/org/apache/pdfbox/examples/pdmodel/TestCreateSignature.java
Modified: pdfbox/branches/2.0/examples/src/test/java/org/apache/pdfbox/examples/pdmodel/TestCreateSignature.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/examples/src/test/java/org/apache/pdfbox/examples/pdmodel/TestCreateSignature.java?rev=1880499&r1=1880498&r2=1880499&view=diff
==============================================================================
--- pdfbox/branches/2.0/examples/src/test/java/org/apache/pdfbox/examples/pdmodel/TestCreateSignature.java (original)
+++ pdfbox/branches/2.0/examples/src/test/java/org/apache/pdfbox/examples/pdmodel/TestCreateSignature.java Sat Aug 1 09:21:37 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();
@@ -648,6 +652,10 @@ public class TestCreateSignature
@Test
public void testPDFBox4784() throws Exception
{
+ if (!externallySign)
+ {
+ return;
+ }
Date signingTime = new Date();
byte[] defaultSignedOne = signEncrypted(null, signingTime);
@@ -679,11 +687,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));
@@ -740,6 +751,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('.'));
@@ -899,12 +914,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();
}