Ensure that the ThreadLocal-Biff-Password is reset correctly after each usage, we had some unit tests failing sporadically due to this
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1704710 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ef8cf4bdcc
commit
5e6b975b1c
@ -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();
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -47,6 +47,7 @@ import org.apache.poi.poifs.crypt.HashAlgorithm;
|
||||
import org.apache.poi.poifs.crypt.cryptoapi.CryptoAPIEncryptionHeader;
|
||||
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
|
||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -57,6 +58,7 @@ public class TestDocumentEncryption {
|
||||
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
|
||||
|
||||
@Before
|
||||
@After // also afterwards to not affect other tests running in the same JVM
|
||||
public void resetPassword() {
|
||||
Biff8EncryptionKey.setCurrentUserPassword(null);
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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 {
|
||||
|
@ -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.
|
||||
|
@ -27,12 +27,19 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.poifs.crypt.CryptoFunctions;
|
||||
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
|
||||
import org.apache.poi.util.HexRead;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestXorEncryption {
|
||||
|
||||
private static HSSFTestDataSamples samples = new HSSFTestDataSamples();
|
||||
|
||||
// to not affect other tests running in the same JVM
|
||||
@After
|
||||
public void resetPassword() {
|
||||
Biff8EncryptionKey.setCurrentUserPassword(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testXorEncryption() throws Exception {
|
||||
// Xor-Password: abc
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user