Skip to content

Commit

Permalink
TST: Decrypt file which is not encrypted
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinThoma committed Jul 22, 2022
1 parent aaac604 commit be51df3
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion tests/test_encryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import pytest

import PyPDF2
from PyPDF2 import PdfReader
from PyPDF2._encryption import CryptRC4
from PyPDF2.errors import DependencyError
from PyPDF2.errors import DependencyError, PdfReadError

try:
from Crypto.Cipher import AES # noqa: F401
Expand Down Expand Up @@ -153,3 +154,10 @@ def test_encrypt_decrypt_class(cryptcls):
key = bytes(0 for _ in range(128)) # b"secret key"
crypt = cryptcls(key)
assert crypt.decrypt(crypt.encrypt(message)) == message


def test_decrypt_not_decrypted_pdf():
path = os.path.join(RESOURCE_ROOT, "crazyones.pdf")
with pytest.raises(PdfReadError) as exc:
PdfReader(path, password="nonexistant")
assert exc.value.args[0] == "Not encrypted file"

0 comments on commit be51df3

Please sign in to comment.