poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From one...@apache.org
Subject svn commit: r1763998 - /poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/TestWorkbookProtection.java
Date Sun, 09 Oct 2016 19:03:49 GMT
Author: onealj
Date: Sun Oct  9 19:03:49 2016
New Revision: 1763998

URL: http://svn.apache.org/viewvc?rev=1763998&view=rev
Log:
bug 60230: add disabled unit test from PJ Fanning for a roundtrip write/read of an encrypted
XSSFWorkbook

Modified:
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/TestWorkbookProtection.java

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/TestWorkbookProtection.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/TestWorkbookProtection.java?rev=1763998&r1=1763997&r2=1763998&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/TestWorkbookProtection.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/TestWorkbookProtection.java Sun Oct
 9 19:03:49 2016
@@ -23,9 +23,26 @@ import static org.junit.Assert.assertFal
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+
+import org.apache.poi.openxml4j.opc.OPCPackage;
 import org.apache.poi.poifs.crypt.CryptoFunctions;
+import org.apache.poi.poifs.crypt.Decryptor;
+import org.apache.poi.poifs.crypt.EncryptionInfo;
+import org.apache.poi.poifs.crypt.EncryptionMode;
+import org.apache.poi.poifs.crypt.Encryptor;
 import org.apache.poi.poifs.crypt.HashAlgorithm;
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.apache.poi.util.IOUtils;
+import org.apache.poi.util.TempFile;
+import org.apache.poi.xssf.usermodel.XSSFCell;
+import org.apache.poi.xssf.usermodel.XSSFRow;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.junit.Ignore;
 import org.junit.Test;
 
 public class TestWorkbookProtection {
@@ -171,4 +188,46 @@ public class TestWorkbookProtection {
 		assertTrue(wb.isRevisionLocked());
 		assertTrue(wb.validateRevisionsPassword("test"));
 	}
+    
+    @Ignore("bug 60230: currently failing due to regression from bug 59857 r1762726")
+    @Test
+    public void testEncryptDecrypt() throws Exception {
+        final String password = "abc123";
+        final String sheetName = "TestSheet1";
+        final String cellValue = "customZipEntrySource";
+        XSSFWorkbook workbook = new XSSFWorkbook();
+        XSSFSheet sheet1 = workbook.createSheet(sheetName);
+        XSSFRow row1 = sheet1.createRow(1);
+        XSSFCell cell1 = row1.createCell(1);
+        cell1.setCellValue(cellValue);
+        File tf1 = TempFile.createTempFile("poitest", ".xlsx");
+        FileOutputStream fos1 = new FileOutputStream(tf1);
+        workbook.write(fos1);
+        IOUtils.closeQuietly(fos1);
+        POIFSFileSystem poiFileSystem = new POIFSFileSystem();
+        EncryptionInfo encryptionInfo = new EncryptionInfo(EncryptionMode.agile);
+        Encryptor enc = encryptionInfo.getEncryptor();
+        enc.confirmPassword(password);
+        OPCPackage opc = OPCPackage.open(new FileInputStream(tf1));
+        try {
+            OutputStream os = enc.getDataStream(poiFileSystem);
+            opc.save(os);
+            IOUtils.closeQuietly(os);
+        } finally {
+            IOUtils.closeQuietly(opc);
+        }
+        tf1.delete();
+        FileOutputStream fos2 = new FileOutputStream(tf1);
+        poiFileSystem.writeFilesystem(fos2);
+        IOUtils.closeQuietly(fos2);
+        workbook.close();
+        POIFSFileSystem poiFileSystem2 = new POIFSFileSystem(new FileInputStream(tf1));
+        EncryptionInfo encryptionInfo2 = new EncryptionInfo(poiFileSystem2);
+        Decryptor decryptor = encryptionInfo2.getDecryptor();
+        decryptor.verifyPassword(password);
+        XSSFWorkbook workbook2 = new XSSFWorkbook(decryptor.getDataStream(poiFileSystem2));
+        workbook2.close();
+        tf1.delete();
+    }
+
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message