Seems we have slow connection on the Apache Jenkins instance. Thus allow one specific test to fail with a specific ConnectException as we see this happening sometimes in Jenkins but should not fail the unit test suite of POI because of such infrastructure problems
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1632566 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5692f061a9
commit
a604506683
@ -23,10 +23,7 @@
|
|||||||
================================================================= */
|
================================================================= */
|
||||||
package org.apache.poi.poifs.crypt;
|
package org.apache.poi.poifs.crypt;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.*;
|
||||||
import static org.junit.Assert.assertFalse;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
@ -34,7 +31,7 @@ import java.io.FileOutputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.MalformedURLException;
|
import java.net.ConnectException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
import java.security.Key;
|
import java.security.Key;
|
||||||
@ -94,11 +91,12 @@ public class TestSignatureInfo {
|
|||||||
|
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void initBouncy() throws MalformedURLException {
|
public static void initBouncy() throws IOException {
|
||||||
File bcProvJar = new File("lib/bcprov-ext-jdk15on-1.51.jar");
|
File bcProvJar = new File("lib/bcprov-ext-jdk15on-1.51.jar");
|
||||||
File bcPkixJar = new File("lib/bcpkix-jdk15on-151.jar");
|
File bcPkixJar = new File("lib/bcpkix-jdk15on-151.jar");
|
||||||
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||||
URLClassLoader ucl = new URLClassLoader(new URL[]{bcProvJar.toURI().toURL(),bcPkixJar.toURI().toURL()}, cl);
|
URLClassLoader ucl = new URLClassLoader(new URL[]{bcProvJar.toURI().toURL(),bcPkixJar.toURI().toURL()}, cl);
|
||||||
|
try {
|
||||||
Thread.currentThread().setContextClassLoader(ucl);
|
Thread.currentThread().setContextClassLoader(ucl);
|
||||||
CryptoFunctions.registerBouncyCastle();
|
CryptoFunctions.registerBouncyCastle();
|
||||||
|
|
||||||
@ -107,6 +105,9 @@ public class TestSignatureInfo {
|
|||||||
cal.clear();
|
cal.clear();
|
||||||
cal.setTimeZone(TimeZone.getTimeZone("UTC"));
|
cal.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||||
cal.set(2014, 7, 6, 21, 42, 12);
|
cal.set(2014, 7, 6, 21, 42, 12);
|
||||||
|
} finally {
|
||||||
|
ucl.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -154,6 +155,7 @@ public class TestSignatureInfo {
|
|||||||
|
|
||||||
for (String testFile : testFiles) {
|
for (String testFile : testFiles) {
|
||||||
OPCPackage pkg = OPCPackage.open(testdata.getFile(testFile), PackageAccess.READ);
|
OPCPackage pkg = OPCPackage.open(testdata.getFile(testFile), PackageAccess.READ);
|
||||||
|
try {
|
||||||
SignatureConfig sic = new SignatureConfig();
|
SignatureConfig sic = new SignatureConfig();
|
||||||
sic.setOpcPackage(pkg);
|
sic.setOpcPackage(pkg);
|
||||||
SignatureInfo si = new SignatureInfo();
|
SignatureInfo si = new SignatureInfo();
|
||||||
@ -173,6 +175,9 @@ public class TestSignatureInfo {
|
|||||||
boolean b = si.verifySignature();
|
boolean b = si.verifySignature();
|
||||||
assertTrue("test-file: "+testFile, b);
|
assertTrue("test-file: "+testFile, b);
|
||||||
pkg.revert();
|
pkg.revert();
|
||||||
|
} finally {
|
||||||
|
pkg.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,6 +185,7 @@ public class TestSignatureInfo {
|
|||||||
public void getMultiSigners() throws Exception {
|
public void getMultiSigners() throws Exception {
|
||||||
String testFile = "hello-world-signed-twice.docx";
|
String testFile = "hello-world-signed-twice.docx";
|
||||||
OPCPackage pkg = OPCPackage.open(testdata.getFile(testFile), PackageAccess.READ);
|
OPCPackage pkg = OPCPackage.open(testdata.getFile(testFile), PackageAccess.READ);
|
||||||
|
try {
|
||||||
SignatureConfig sic = new SignatureConfig();
|
SignatureConfig sic = new SignatureConfig();
|
||||||
sic.setOpcPackage(pkg);
|
sic.setOpcPackage(pkg);
|
||||||
SignatureInfo si = new SignatureInfo();
|
SignatureInfo si = new SignatureInfo();
|
||||||
@ -201,6 +207,9 @@ public class TestSignatureInfo {
|
|||||||
boolean b = si.verifySignature();
|
boolean b = si.verifySignature();
|
||||||
assertTrue("test-file: "+testFile, b);
|
assertTrue("test-file: "+testFile, b);
|
||||||
pkg.revert();
|
pkg.revert();
|
||||||
|
} finally {
|
||||||
|
pkg.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -215,6 +224,7 @@ public class TestSignatureInfo {
|
|||||||
public void testManipulation() throws Exception {
|
public void testManipulation() throws Exception {
|
||||||
// sign & validate
|
// sign & validate
|
||||||
String testFile = "hello-world-unsigned.xlsx";
|
String testFile = "hello-world-unsigned.xlsx";
|
||||||
|
@SuppressWarnings("resource") // closed via XSSFWorkbook.close() below ?!
|
||||||
OPCPackage pkg = OPCPackage.open(copy(testdata.getFile(testFile)), PackageAccess.READ_WRITE);
|
OPCPackage pkg = OPCPackage.open(copy(testdata.getFile(testFile)), PackageAccess.READ_WRITE);
|
||||||
sign(pkg, "Test", "CN=Test", 1);
|
sign(pkg, "Test", "CN=Test", 1);
|
||||||
|
|
||||||
@ -298,11 +308,15 @@ public class TestSignatureInfo {
|
|||||||
|
|
||||||
if (mockTsp) {
|
if (mockTsp) {
|
||||||
TimeStampService tspService = new TimeStampService(){
|
TimeStampService tspService = new TimeStampService(){
|
||||||
|
@Override
|
||||||
public byte[] timeStamp(byte[] data, RevocationData revocationData) throws Exception {
|
public byte[] timeStamp(byte[] data, RevocationData revocationData) throws Exception {
|
||||||
revocationData.addCRL(crl);
|
revocationData.addCRL(crl);
|
||||||
return "time-stamp-token".getBytes();
|
return "time-stamp-token".getBytes();
|
||||||
}
|
}
|
||||||
public void setSignatureConfig(SignatureConfig config) {}
|
@Override
|
||||||
|
public void setSignatureConfig(SignatureConfig config) {
|
||||||
|
// empty on purpose
|
||||||
|
}
|
||||||
};
|
};
|
||||||
signatureConfig.setTspService(tspService);
|
signatureConfig.setTspService(tspService);
|
||||||
} else {
|
} else {
|
||||||
@ -327,6 +341,7 @@ public class TestSignatureInfo {
|
|||||||
revocationData.addOCSP(ocspResp.getEncoded());
|
revocationData.addOCSP(ocspResp.getEncoded());
|
||||||
|
|
||||||
RevocationDataService revocationDataService = new RevocationDataService(){
|
RevocationDataService revocationDataService = new RevocationDataService(){
|
||||||
|
@Override
|
||||||
public RevocationData getRevocationData(List<X509Certificate> certificateChain) {
|
public RevocationData getRevocationData(List<X509Certificate> certificateChain) {
|
||||||
return revocationData;
|
return revocationData;
|
||||||
}
|
}
|
||||||
@ -336,7 +351,14 @@ public class TestSignatureInfo {
|
|||||||
// operate
|
// operate
|
||||||
SignatureInfo si = new SignatureInfo();
|
SignatureInfo si = new SignatureInfo();
|
||||||
si.setSignatureConfig(signatureConfig);
|
si.setSignatureConfig(signatureConfig);
|
||||||
|
try {
|
||||||
si.confirmSignature();
|
si.confirmSignature();
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
// only allow a ConnectException because of timeout, we see this in Jenkins from time to time...
|
||||||
|
assertNotNull("Only allowing ConnectException here, but had: " + e, e.getCause());
|
||||||
|
assertTrue("Only allowing ConnectException here, but had: " + e, e.getCause() instanceof ConnectException);
|
||||||
|
assertTrue("Only allowing ConnectException here, but had: " + e, e.getCause().getMessage().contains("timed out"));
|
||||||
|
}
|
||||||
|
|
||||||
// verify
|
// verify
|
||||||
Iterator<SignaturePart> spIter = si.getSignatureParts().iterator();
|
Iterator<SignaturePart> spIter = si.getSignatureParts().iterator();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user