import org.apache.poi.xwpf.usermodel.XWPFDocument;\r
\r
public class TestXWPFBugs extends TestCase {\r
- /**\r
- * A word document that's encrypted with non-standard\r
- * Encryption options, and no cspname section. See bug 53475\r
- */\r
- public void test53475() throws Exception {\r
- try {\r
- Biff8EncryptionKey.setCurrentUserPassword("solrcell");\r
- File file = POIDataSamples.getDocumentInstance().getFile("bug53475-password-is-solrcell.docx");\r
- NPOIFSFileSystem filesystem = new NPOIFSFileSystem(file, true);\r
- \r
- // Check the encryption details\r
- EncryptionInfo info = new EncryptionInfo(filesystem);\r
- assertEquals(128, info.getHeader().getKeySize());\r
- assertEquals(EncryptionHeader.ALGORITHM_AES_128, info.getHeader().getAlgorithm());\r
- assertEquals(EncryptionHeader.HASH_SHA1, info.getHeader().getHashAlgorithm());\r
- \r
- // Check it can be decoded\r
- Decryptor d = Decryptor.getInstance(info); \r
- assertTrue("Unable to process: document is encrypted", d.verifyPassword("solrcell"));\r
- \r
- // Check we can read the word document in that\r
- InputStream dataStream = d.getDataStream(filesystem);\r
- OPCPackage opc = OPCPackage.open(dataStream);\r
- XWPFDocument doc = new XWPFDocument(opc);\r
- XWPFWordExtractor ex = new XWPFWordExtractor(doc);\r
- String text = ex.getText();\r
- assertNotNull(text);\r
- assertEquals("This is password protected Word document.", text.trim());\r
- ex.close();\r
- } finally {\r
- Biff8EncryptionKey.setCurrentUserPassword(null);\r
- }\r
- }\r
+ /**\r
+ * A word document that's encrypted with non-standard\r
+ * Encryption options, and no cspname section. See bug 53475\r
+ */\r
+ public void test53475() throws Exception {\r
+ try {\r
+ Biff8EncryptionKey.setCurrentUserPassword("solrcell");\r
+ File file = POIDataSamples.getDocumentInstance().getFile("bug53475-password-is-solrcell.docx");\r
+ NPOIFSFileSystem filesystem = new NPOIFSFileSystem(file, true);\r
+\r
+ // Check the encryption details\r
+ EncryptionInfo info = new EncryptionInfo(filesystem);\r
+ assertEquals(128, info.getHeader().getKeySize());\r
+ assertEquals(EncryptionHeader.ALGORITHM_AES_128, info.getHeader().getAlgorithm());\r
+ assertEquals(EncryptionHeader.HASH_SHA1, info.getHeader().getHashAlgorithm());\r
+\r
+ // Check it can be decoded\r
+ Decryptor d = Decryptor.getInstance(info); \r
+ assertTrue("Unable to process: document is encrypted", d.verifyPassword("solrcell"));\r
+\r
+ // Check we can read the word document in that\r
+ InputStream dataStream = d.getDataStream(filesystem);\r
+ OPCPackage opc = OPCPackage.open(dataStream);\r
+ XWPFDocument doc = new XWPFDocument(opc);\r
+ XWPFWordExtractor ex = new XWPFWordExtractor(doc);\r
+ String text = ex.getText();\r
+ assertNotNull(text);\r
+ assertEquals("This is password protected Word document.", text.trim());\r
+ ex.close();\r
+ } finally {\r
+ Biff8EncryptionKey.setCurrentUserPassword(null);\r
+ }\r
+ }\r
}\r