In general, you can perform all tests with both unprotected and password protected
PDF documents. Passwords have to be declared with the tag <assertThat />
.
The general syntax looks like this:
<!-- Tags for tests with passwords: --> <hasEncryptionLength /> <hasOwnerPassword /> <hasUserPassword /> <!-- Access to encrypted PDF documents: --> <assertThat testDocument=".." (required) testPassword=".." (required if the PDF under test is encrypted) masterDocument=".." (required if a master PDF is used) masterPassword=".." (required if the master PDF is encrypted) />
This syntax is the same for “user password” and “owner password”.
Opening a document with one password is already a test.
But you can verify the other password using the tags
<hasOwnerPassword />
or <hasUserPassword />
:
<!-- Verify the owner-password of the document: --> <testcase name="hasOwnerPassword"> <assertThat testDocument="content/diverseContentOnMultiplePages_encrypted.pdf" testPassword="user-password" > <hasOwnerPassword>owner-password</hasOwnerPassword> </assertThat> </testcase>
<!-- Verify the user-password of the document: --> <testcase name="hasUserPassword"> <assertThat testDocument="content/diverseContentOnMultiplePages_encrypted.pdf" testPassword="owner-password" > <hasUserPassword>user-password</hasUserPassword> </assertThat> </testcase>
Usually it's bad practice to hard code passwords in the source code, but it's OK for test passwords in test environments. “Hard coded” also means that the password never changes.
This example shows how to verify the encryption length:
<testcase name="hasEncryptionLength"> <assertThat testDocument="content/diverseContentOnMultiplePages_encrypted.pdf" testPassword="user-password" > <hasEncryptionLength>128</hasEncryptionLength> </assertThat> </testcase>