diff options
author | Andreas Beeker <kiwiwings@apache.org> | 2018-08-31 00:25:50 +0000 |
---|---|---|
committer | Andreas Beeker <kiwiwings@apache.org> | 2018-08-31 00:25:50 +0000 |
commit | 8ebfec4808cce673b1911d15950200f2d1449b3c (patch) | |
tree | 6e69e00bac5f9256648499d49f57d0853c556634 /src/testcases/org/apache/poi/poifs/crypt | |
parent | e284963051cf5bff3f6b160ae65b56c049c5bfdc (diff) | |
download | poi-8ebfec4808cce673b1911d15950200f2d1449b3c.tar.gz poi-8ebfec4808cce673b1911d15950200f2d1449b3c.zip |
#62649 - Remove OPOIFS* / rename NPOIFS* to POIFS*
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1839709 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache/poi/poifs/crypt')
-rw-r--r-- | src/testcases/org/apache/poi/poifs/crypt/TestXorEncryption.java | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/src/testcases/org/apache/poi/poifs/crypt/TestXorEncryption.java b/src/testcases/org/apache/poi/poifs/crypt/TestXorEncryption.java index 002318b0eb..943de4ad23 100644 --- a/src/testcases/org/apache/poi/poifs/crypt/TestXorEncryption.java +++ b/src/testcases/org/apache/poi/poifs/crypt/TestXorEncryption.java @@ -21,16 +21,19 @@ import static org.hamcrest.core.IsEqual.equalTo; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import org.apache.poi.hssf.HSSFTestDataSamples; +import org.apache.poi.hssf.record.FilePassRecord; import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; -import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; +import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.util.HexRead; -import org.junit.After; +import org.junit.Ignore; import org.junit.Test; public class TestXorEncryption { @@ -38,7 +41,7 @@ public class TestXorEncryption { private static final HSSFTestDataSamples samples = new HSSFTestDataSamples(); @Test - public void testXorEncryption() throws IOException { + public void testXorEncryption() { // Xor-Password: abc // 2.5.343 XORObfuscation // key = 20810 @@ -58,7 +61,7 @@ public class TestXorEncryption { public void testUserFile() throws IOException { File f = samples.getSampleFile("xor-encryption-abc.xls"); Biff8EncryptionKey.setCurrentUserPassword("abc"); - try (NPOIFSFileSystem fs = new NPOIFSFileSystem(f, true); + try (POIFSFileSystem fs = new POIFSFileSystem(f, true); HSSFWorkbook hwb = new HSSFWorkbook(fs.getRoot(), true)) { HSSFSheet sh = hwb.getSheetAt(0); assertEquals(1.0, sh.getRow(0).getCell(0).getNumericCellValue(), 0.0); @@ -68,4 +71,23 @@ public class TestXorEncryption { Biff8EncryptionKey.setCurrentUserPassword(null); } } + + @Test + @Ignore("currently not supported") + public void encrypt() throws IOException { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + try { + try (HSSFWorkbook hwb = HSSFTestDataSamples.openSampleWorkbook("SampleSS.xls")) { + Biff8EncryptionKey.setCurrentUserPassword("abc"); + hwb.getInternalWorkbook().getWorkbookRecordList() + .add(1, new FilePassRecord(EncryptionMode.xor)); + hwb.write(bos); + } + try (HSSFWorkbook hwb = new HSSFWorkbook(new ByteArrayInputStream(bos.toByteArray()))) { + assertEquals(3, hwb.getNumberOfSheets()); + } + } finally { + Biff8EncryptionKey.setCurrentUserPassword(null); + } + } } |