pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1635212 - /pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestPublicKeyEncryption.java
Date Wed, 29 Oct 2014 17:27:14 GMT
Author: tilman
Date: Wed Oct 29 17:27:14 2014
New Revision: 1635212

URL: http://svn.apache.org/r1635212
Log:
PDFBOX-2460: improved test to check for correct exception message as suggested by Ralf Hauser;
code cleanup

Modified:
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestPublicKeyEncryption.java

Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestPublicKeyEncryption.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestPublicKeyEncryption.java?rev=1635212&r1=1635211&r2=1635212&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestPublicKeyEncryption.java
(original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestPublicKeyEncryption.java
Wed Oct 29 17:27:14 2014
@@ -31,6 +31,7 @@ import org.apache.pdfbox.pdmodel.encrypt
 import org.apache.pdfbox.pdmodel.encryption.PublicKeyProtectionPolicy;
 import org.apache.pdfbox.pdmodel.encryption.PublicKeyRecipient;
 import junit.framework.TestCase;
+import org.apache.pdfbox.pdmodel.encryption.PublicKeySecurityHandler;
 import org.junit.Assert;
 
 /**
@@ -128,20 +129,25 @@ public class TestPublicKeyEncryption ext
         policy.addRecipient(recipient1);
         document.protect(policy);
 
-        PDDocument encrypted = reload(document);
+        PDDocument encryptedDoc = reload(document);
         try 
         {
-            Assert.assertTrue(encrypted.isEncrypted());
-            encrypted.openProtection(decryption2);
+            Assert.assertTrue(encryptedDoc.isEncrypted());
+            PublicKeySecurityHandler securityHandler
+                    = (PublicKeySecurityHandler) encryptedDoc.getEncryption().getSecurityHandler();
+            securityHandler.setVerbose(true);
+            encryptedDoc.openProtection(decryption2);
             fail("No exception when using an incorrect decryption key");
         }
         catch (IOException ex)
         {
-            // do nothing
+            String msg = ex.getMessage();
+            Assert.assertTrue("not the expected exception: " + msg, 
+                    msg.contains("serial-#: rid 2 vs. cert 3"));
         }
         finally 
         {
-            encrypted.close();
+            encryptedDoc.close();
         }
     }
 
@@ -158,14 +164,14 @@ public class TestPublicKeyEncryption ext
         policy.addRecipient(recipient1);
         document.protect(policy);
 
-        PDDocument encrypted = reload(document);
+        PDDocument encryptedDoc = reload(document);
         try 
         {
-            Assert.assertTrue(encrypted.isEncrypted());
-            encrypted.openProtection(decryption1);
+            Assert.assertTrue(encryptedDoc.isEncrypted());
+            encryptedDoc.openProtection(decryption1);
 
             AccessPermission permission =
-                encrypted.getCurrentAccessPermission();
+                encryptedDoc.getCurrentAccessPermission();
             Assert.assertFalse(permission.canAssembleDocument());
             Assert.assertFalse(permission.canExtractContent());
             Assert.assertTrue(permission.canExtractForAccessibility());
@@ -177,7 +183,7 @@ public class TestPublicKeyEncryption ext
         } 
         finally 
         {
-            encrypted.close();
+            encryptedDoc.close();
         }
     }
 
@@ -195,13 +201,13 @@ public class TestPublicKeyEncryption ext
         document.protect(policy);
 
         // open first time
-        PDDocument encrypted1 = reload(document);
+        PDDocument encryptedDoc1 = reload(document);
         try 
         {
-            encrypted1.openProtection(decryption1);
+            encryptedDoc1.openProtection(decryption1);
 
             AccessPermission permission =
-                encrypted1.getCurrentAccessPermission();
+                encryptedDoc1.getCurrentAccessPermission();
             Assert.assertFalse(permission.canAssembleDocument());
             Assert.assertFalse(permission.canExtractContent());
             Assert.assertTrue(permission.canExtractForAccessibility());
@@ -213,17 +219,17 @@ public class TestPublicKeyEncryption ext
         } 
         finally 
         {
-            encrypted1.close();
+            encryptedDoc1.close();
         }
 
         // open second time
-        PDDocument encrypted2 = reload(document);
+        PDDocument encryptedDoc2 = reload(document);
         try 
         {
-            encrypted2.openProtection(decryption2);
+            encryptedDoc2.openProtection(decryption2);
 
             AccessPermission permission =
-                encrypted2.getCurrentAccessPermission();
+                encryptedDoc2.getCurrentAccessPermission();
             Assert.assertFalse(permission.canAssembleDocument());
             Assert.assertFalse(permission.canExtractContent());
             Assert.assertTrue(permission.canExtractForAccessibility());
@@ -235,7 +241,7 @@ public class TestPublicKeyEncryption ext
         } 
         finally 
         {
-            encrypted2.close();
+            encryptedDoc2.close();
         }
     }
 



Mime
View raw message