aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2015-06-24 08:53:25 +0000
committerDominik Stadler <centic@apache.org>2015-06-24 08:53:25 +0000
commitdfca03ec0313b57ee359456b1b06540962682012 (patch)
tree73863c325aed83adf05402a74279a6a1bce2bdda
parent4a8093dc4ff6cd8cfd5e8c8121738128507a683b (diff)
downloadpoi-dfca03ec0313b57ee359456b1b06540962682012.tar.gz
poi-dfca03ec0313b57ee359456b1b06540962682012.zip
Fix test to find the exception-text in all cases
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1687212 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java42
1 files changed, 26 insertions, 16 deletions
diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java
index 2383455fce..2f857933e7 100644
--- a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java
+++ b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java
@@ -721,15 +721,9 @@ public final class TestPackage {
// depending if this executed via "ant test" or within eclipse
// maybe a difference in JDK ...
} catch (InvalidFormatException e) {
- if(!e.getMessage().equals("Zip bomb detected! Exiting.")) {
- throw new IllegalStateException(e);
- }
+ checkForZipBombException(e);
} catch (POIXMLException e) {
- InvocationTargetException t = (InvocationTargetException)e.getCause();
- IOException t2 = (IOException)t.getTargetException();
- if(!t2.getMessage().equals("Zip bomb detected! Exiting.")) {
- throw new IllegalStateException(e);
- }
+ checkForZipBombException(e);
}
// check max entry size ouf of bounds
@@ -739,15 +733,9 @@ public final class TestPackage {
wb = WorkbookFactory.create(file, null, true);
wb.close();
} catch (InvalidFormatException e) {
- if(!e.getMessage().equals("Zip bomb detected! Exiting.")) {
- throw new IllegalStateException(e);
- }
+ checkForZipBombException(e);
} catch (POIXMLException e) {
- InvocationTargetException t = (InvocationTargetException)e.getCause();
- IOException t2 = (IOException)t.getTargetException();
- if(!t2.getMessage().equals("Zip bomb detected! Exiting.")) {
- throw new IllegalStateException(e);
- }
+ checkForZipBombException(e);
}
} finally {
// reset otherwise a lot of ooxml tests will fail
@@ -755,4 +743,26 @@ public final class TestPackage {
ZipSecureFile.setMaxEntrySize(0xFFFFFFFFl);
}
}
+
+ private void checkForZipBombException(Throwable e) {
+ if(e instanceof InvocationTargetException) {
+ InvocationTargetException t = (InvocationTargetException)e;
+ IOException t2 = (IOException)t.getTargetException();
+ if("Zip bomb detected! Exiting.".equals(t2.getMessage())) {
+ return;
+ }
+ }
+
+ if ("Zip bomb detected! Exiting.".equals(e.getMessage())) {
+ return;
+ }
+
+ // recursively check the causes for the message as it can be nested further down in the exception-tree
+ if(e.getCause() != null && e.getCause() != e) {
+ checkForZipBombException(e.getCause());
+ return;
+ }
+
+ throw new IllegalStateException("Expected to catch an Exception because of a detected Zip Bomb, but did not find the related error message in the exception", e);
+ }
}