diff options
author | Andreas Beeker <kiwiwings@apache.org> | 2021-03-17 22:51:58 +0000 |
---|---|---|
committer | Andreas Beeker <kiwiwings@apache.org> | 2021-03-17 22:51:58 +0000 |
commit | 2ceb5ff55346ee97c3541c9e7bcd8bc5847be9b4 (patch) | |
tree | 54b5728fae97e9f0d125db9265b8800b1e786b91 /src/ooxml/testcases/org/apache | |
parent | 393d3a3ce98b06560b3e6cd0fb4d0ce60f355eaa (diff) | |
download | poi-2ceb5ff55346ee97c3541c9e7bcd8bc5847be9b4.tar.gz poi-2ceb5ff55346ee97c3541c9e7bcd8bc5847be9b4.zip |
#65192 - Allow change of EncryptionMode
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1887764 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/ooxml/testcases/org/apache')
-rw-r--r-- | src/ooxml/testcases/org/apache/poi/poifs/crypt/tests/TestHxxFEncryption.java | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/ooxml/testcases/org/apache/poi/poifs/crypt/tests/TestHxxFEncryption.java b/src/ooxml/testcases/org/apache/poi/poifs/crypt/tests/TestHxxFEncryption.java index 548e12ced9..bf5aebb590 100644 --- a/src/ooxml/testcases/org/apache/poi/poifs/crypt/tests/TestHxxFEncryption.java +++ b/src/ooxml/testcases/org/apache/poi/poifs/crypt/tests/TestHxxFEncryption.java @@ -23,23 +23,34 @@ import static org.apache.poi.POIDataSamples.getSpreadSheetInstance; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.stream.Stream; +import org.apache.poi.hssf.model.WorkbookRecordList; +import org.apache.poi.hssf.record.FilePassRecord; + import org.apache.poi.POIDataSamples; import org.apache.poi.POIDocument; import org.apache.poi.extractor.ExtractorFactory; import org.apache.poi.extractor.POITextExtractor; +import org.apache.poi.hssf.record.Record; import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.poifs.crypt.EncryptionInfo; +import org.apache.poi.poifs.crypt.EncryptionMode; +import org.apache.poi.poifs.crypt.binaryrc4.BinaryRC4EncryptionHeader; import org.apache.poi.poifs.crypt.cryptoapi.CryptoAPIEncryptionHeader; import org.apache.poi.poifs.storage.RawDataUtil; +import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; @@ -167,4 +178,38 @@ class TestHxxFEncryption { Biff8EncryptionKey.setCurrentUserPassword(null); } } + + @Test + public void changeEncryptionMode() throws IOException { + ByteArrayOutputStream bos = new ByteArrayOutputStream(10_000); + + try (HSSFWorkbook wb = new HSSFWorkbook()) { + wb.createSheet().createRow(1).createCell(1).setCellValue("Test"); + Biff8EncryptionKey.setCurrentUserPassword("test1"); + wb.write(bos); + } + + try (HSSFWorkbook wb = new HSSFWorkbook(new ByteArrayInputStream(bos.toByteArray()))) { + assertEquals(EncryptionMode.cryptoAPI, wb.getEncryptionMode()); + wb.setEncryptionMode(EncryptionMode.binaryRC4); + Biff8EncryptionKey.setCurrentUserPassword("test2"); + bos.reset(); + wb.write(bos); + } + + try (HSSFWorkbook wb = new HSSFWorkbook(new ByteArrayInputStream(bos.toByteArray()))) { + assertEquals(EncryptionMode.binaryRC4, wb.getEncryptionMode()); + wb.setEncryptionMode(null); + bos.reset(); + wb.write(bos); + } + + assertNull(Biff8EncryptionKey.getCurrentUserPassword()); + + try (HSSFWorkbook wb = new HSSFWorkbook(new ByteArrayInputStream(bos.toByteArray()))) { + assertNull(wb.getEncryptionMode()); + wb.setEncryptionMode(null); + assertEquals("Test", wb.getSheetAt(0).getRow(1).getCell(1).getStringCellValue()); + } + } } |