]> source.dussan.org Git - poi.git/commitdiff
Try to catch more network-unavailable cases in TestSignatureInfo
authorDominik Stadler <centic@apache.org>
Thu, 5 May 2016 12:22:23 +0000 (12:22 +0000)
committerDominik Stadler <centic@apache.org>
Thu, 5 May 2016 12:22:23 +0000 (12:22 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1742422 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/testcases/org/apache/poi/poifs/crypt/TestSignatureInfo.java

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