Try to catch more network-unavailable cases in TestSignatureInfo

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1742422 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2016-05-05 12:22:23 +00:00
parent 26de463419
commit 56c5bd05e1

View File

@ -36,10 +36,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ConnectException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.*;
import java.security.Key;
import java.security.KeyPair;
import java.security.KeyStore;
@ -82,13 +79,13 @@ import org.apache.xmlbeans.XmlObject;
import org.bouncycastle.asn1.x509.KeyUsage;
import org.bouncycastle.cert.ocsp.OCSPResp;
import org.etsi.uri.x01903.v13.DigestAlgAndValueType;
import org.etsi.uri.x01903.v13.QualifyingPropertiesType;
import org.junit.Assume;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.w3.x2000.x09.xmldsig.ReferenceType;
import org.w3.x2000.x09.xmldsig.SignatureDocument;
import org.etsi.uri.x01903.v13.QualifyingPropertiesType;
import org.junit.Assume;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.w3.x2000.x09.xmldsig.ReferenceType;
import org.w3.x2000.x09.xmldsig.SignatureDocument;
import org.w3c.dom.Document;
public class TestSignatureInfo {
@ -105,6 +102,7 @@ public class TestSignatureInfo {
/*** TODO : set cal to now ... only set to fixed date for debugging ... */
cal = LocaleUtil.getLocaleCalendar(LocaleUtil.TIMEZONE_UTC);
assertNotNull(cal);
// cal.set(2014, 7, 6, 21, 42, 12);
// cal.clear(Calendar.MILLISECOND);
@ -390,10 +388,11 @@ public class TestSignatureInfo {
if(e.getCause() == null) {
throw e;
}
if(!(e.getCause() instanceof ConnectException)) {
if(!(e.getCause() instanceof ConnectException) && !(e.getCause() instanceof SocketTimeoutException)) {
throw e;
}
assertTrue("Only allowing ConnectException with 'timed out' as message here, but had: " + e, e.getCause().getMessage().contains("timed out"));
assertTrue("Only allowing ConnectException with 'timed out' as message here, but had: " + e,
e.getCause().getMessage().contains("timed out"));
}
// verify
@ -577,28 +576,31 @@ public class TestSignatureInfo {
si.confirmSignature();
assertTrue("invalid signature", si.verifySignature());
pkg.close();
}
@Test
@Ignore
public void testMultiSign() throws Exception {
initKeyPair("KeyA", "CN=KeyA");
KeyPair keyPairA = keyPair;
X509Certificate x509A = x509;
initKeyPair("KeyB", "CN=KeyB");
KeyPair keyPairB = keyPair;
X509Certificate x509B = x509;
File tpl = copy(testdata.getFile("bug58630.xlsx"));
OPCPackage pkg = OPCPackage.open(tpl);
SignatureConfig signatureConfig = new SignatureConfig();
}
private void sign(OPCPackage pkgCopy, String alias, String signerDn, int signerCount) throws Exception {
initKeyPair(alias, signerDn);
pkg.close();
}
@Test
@Ignore
public void testMultiSign() throws Exception {
initKeyPair("KeyA", "CN=KeyA");
//KeyPair keyPairA = keyPair;
//X509Certificate x509A = x509;
initKeyPair("KeyB", "CN=KeyB");
//KeyPair keyPairB = keyPair;
//X509Certificate x509B = x509;
File tpl = copy(testdata.getFile("bug58630.xlsx"));
OPCPackage pkg = OPCPackage.open(tpl);
try {
//SignatureConfig signatureConfig = new SignatureConfig();
assertNotNull(pkg);
} finally {
pkg.close();
}
}
private void sign(OPCPackage pkgCopy, String alias, String signerDn, int signerCount) throws Exception {
initKeyPair(alias, signerDn);
SignatureConfig signatureConfig = new SignatureConfig();
signatureConfig.setKey(keyPair.getPrivate());