]> source.dussan.org Git - poi.git/commitdiff
Ensure that the ThreadLocal-Biff-Password is reset correctly after each usage, we...
authorDominik Stadler <centic@apache.org>
Tue, 22 Sep 2015 19:50:37 +0000 (19:50 +0000)
committerDominik Stadler <centic@apache.org>
Tue, 22 Sep 2015 19:50:37 +0000 (19:50 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1704710 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/record/RecordFactoryInputStream.java
src/ooxml/java/org/apache/poi/ss/usermodel/WorkbookFactory.java
src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocumentEncryption.java
src/testcases/org/apache/poi/hssf/eventusermodel/TestHSSFEventFactory.java
src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java
src/testcases/org/apache/poi/hssf/record/TestRecordFactoryInputStream.java
src/testcases/org/apache/poi/hssf/record/crypto/TestXorEncryption.java
src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java

index 61aa24769bb426a3a4ac48d73516843526cb91dc..263bdeeee3e0e8ce6725b19b87587ab50f79dc0a 100644 (file)
@@ -55,8 +55,6 @@ public final class RecordFactoryInputStream {
                private final Record _lastRecord;
                private final boolean _hasBOFRecord;
 
-               private static POILogger log = POILogFactory.getLogger(StreamEncryptionInfo.class);
-               
                public StreamEncryptionInfo(RecordInputStream rs, List<Record> outputRecs) {
                        Record rec;
                        rs.nextRecord();
index 8188b0287d831ff0033a5bd5c89519ce0dd91c72..1817b176a235ad50301dc0ca2d9d4f226c32eecc 100644 (file)
@@ -121,9 +121,11 @@ public class WorkbookFactory {
         if (password != null) {
             Biff8EncryptionKey.setCurrentUserPassword(password);
         }
-        Workbook wb = new HSSFWorkbook(root, true);
-        Biff8EncryptionKey.setCurrentUserPassword(null);
-        return wb;
+        try {
+            return new HSSFWorkbook(root, true);
+        } finally {
+            Biff8EncryptionKey.setCurrentUserPassword(null);
+        }
     }
 
     /**
index e27c808f6a2a3ce2eb235ca8d04cbafb545afbf7..b7e6ea947bbf79ce425a6dfd0f8b8df07f8db96d 100644 (file)
@@ -47,6 +47,7 @@ import org.apache.poi.poifs.crypt.HashAlgorithm;
 import org.apache.poi.poifs.crypt.cryptoapi.CryptoAPIEncryptionHeader;\r
 import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;\r
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;\r
+import org.junit.After;\r
 import org.junit.Before;\r
 import org.junit.Test;\r
 \r
@@ -57,6 +58,7 @@ public class TestDocumentEncryption {
     POIDataSamples slTests = POIDataSamples.getSlideShowInstance();\r
 \r
     @Before\r
+    @After  // also afterwards to not affect other tests running in the same JVM\r
     public void resetPassword() {\r
         Biff8EncryptionKey.setCurrentUserPassword(null);\r
     }\r
index 0a111beaa6d252d507a70337fc268c0b3396b2d9..08c1babe04f6ce22278269446e2d5ef2e6350cbd 100644 (file)
@@ -36,6 +36,7 @@ import org.apache.poi.hssf.record.SelectionRecord;
 import org.apache.poi.hssf.record.WindowTwoRecord;
 import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.junit.After;
 
 /**
  * Testing for {@link HSSFEventFactory}
@@ -45,6 +46,12 @@ public final class TestHSSFEventFactory extends TestCase {
         return HSSFTestDataSamples.openSampleFileStream(sampleFileName);
     }
 
+    // to not affect other tests running in the same JVM
+    @After
+    public void resetPassword() {
+        Biff8EncryptionKey.setCurrentUserPassword(null);
+    }
+
     public void testWithMissingRecords() throws Exception {
 
         HSSFRequest req = new HSSFRequest();
index 15f4a3cb0bbb2c361035bae429b019c42632226d..2a5698881db9e8d83614a7d01b78d39508419ed5 100644 (file)
@@ -32,12 +32,18 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.poifs.filesystem.DirectoryNode;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 import org.apache.poi.util.LocaleUtil;
+import org.junit.After;
 import org.junit.Test;
 
 /**
  *
  */
 public final class TestExcelExtractor {
+    // to not affect other tests running in the same JVM
+    @After
+    public void resetPassword() {
+        Biff8EncryptionKey.setCurrentUserPassword(null);
+    }
 
        @SuppressWarnings("resource")
     private static ExcelExtractor createExtractor(String sampleFileName) throws IOException {
index c2ad641bcb1ba2f4148af208decfe0f4abdb24d1..0e441e195378ddc1b9731a5ad07fe1dd2b19c5ff 100644 (file)
@@ -25,6 +25,7 @@ import java.io.ByteArrayInputStream;
 import org.apache.poi.EncryptedDocumentException;
 import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
 import org.apache.poi.util.HexRead;
+import org.junit.After;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -35,6 +36,11 @@ import org.junit.rules.ExpectedException;
  * @author Josh Micich
  */
 public final class TestRecordFactoryInputStream {
+    // to not affect other tests running in the same JVM
+    @After
+    public void resetPassword() {
+        Biff8EncryptionKey.setCurrentUserPassword(null);
+    }
 
        /**
         * Hex dump of a BOF record and most of a FILEPASS record.
index e763a183008d58d7b7ad256468bb7113116b50e2..e79f2fcc6e17d7f2d88a76b8f151dab240074ae6 100644 (file)
@@ -27,12 +27,19 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.poifs.crypt.CryptoFunctions;\r
 import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;\r
 import org.apache.poi.util.HexRead;\r
+import org.junit.After;\r
 import org.junit.Test;\r
 \r
 public class TestXorEncryption {\r
     \r
     private static HSSFTestDataSamples samples = new HSSFTestDataSamples();\r
     \r
+    // to not affect other tests running in the same JVM\r
+    @After\r
+    public void resetPassword() {\r
+        Biff8EncryptionKey.setCurrentUserPassword(null);\r
+    }\r
+\r
     @Test\r
     public void testXorEncryption() throws Exception {\r
         // Xor-Password: abc\r
index 3b753bc8a8936fcbff1fa9d338fdaed29254228a..37d592f6942f910c89a01f2c1d1377eb9fedcf61 100644 (file)
@@ -74,6 +74,7 @@ import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.usermodel.Workbook;
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.util.LocaleUtil;
+import org.junit.After;
 import org.junit.Ignore;
 import org.junit.Test;
 
@@ -85,6 +86,11 @@ import org.junit.Test;
  *  define the test in the base class {@link BaseTestBugzillaIssues}</b>
  */
 public final class TestBugs extends BaseTestBugzillaIssues {
+    // to not affect other tests running in the same JVM
+    @After
+    public void resetPassword() {
+        Biff8EncryptionKey.setCurrentUserPassword(null);
+    }
 
     public TestBugs() {
         super(HSSFITestDataProvider.instance);