Skip to content

Commit

Permalink
TST: Regression test for #327
Browse files Browse the repository at this point in the history
Credits to Denis Osipov:
#359 (comment)

Co-authored-by: Denis Osipov <[email protected]>
  • Loading branch information
MartinThoma and denis-osipov committed Apr 16, 2022
1 parent bd7500d commit d58a849
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
Binary file added Resources/encrypted-file.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion Tests/test_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"libreoffice-writer-password",
"imagemagick-images",
"imagemagick-lzw",
"reportlab-inline-image"
"reportlab-inline-image",
],
)
def test_page_operations(pdf_path, password):
Expand Down
1 change: 1 addition & 0 deletions Tests/test_pagerange.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def test_parse_filename_page_ranges_err():

def test_page_range_help():
from PyPDF2.pagerange import PAGE_RANGE_HELP

assert len(PAGE_RANGE_HELP) > 20
assert "0:3" in PAGE_RANGE_HELP
assert PAGE_RANGE_HELP.endswith("\n")
22 changes: 19 additions & 3 deletions Tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def test_read_metadata(pdf_path, expected):
docinfo = reader.getDocumentInfo()
metadict = dict(docinfo)
assert metadict == expected
if '/Title' in metadict:
assert metadict['/Title'] == docinfo.title
if "/Title" in metadict:
assert metadict["/Title"] == docinfo.title


@pytest.mark.parametrize(
Expand Down Expand Up @@ -120,7 +120,7 @@ def test_get_outlines(src, outline_elements):
],
)
def test_get_images(src, nb_images):
src =os.path.join(RESOURCE_ROOT, src)
src = os.path.join(RESOURCE_ROOT, src)
reader = PdfFileReader(src)

with pytest.raises(TypeError):
Expand Down Expand Up @@ -207,3 +207,19 @@ def test_issue297():
path = os.path.join(RESOURCE_ROOT, "issue-297.pdf")
reader = PdfFileReader(path, "rb")
reader.getPage(0)


def test_get_page_of_encrypted_file():
"""
Check if we can read a page of an encrypted file.
This is a regression test for issue 327:
IndexError for getPage() of decrypted file
"""
path = os.path.join(RESOURCE_ROOT, "encrypted-file.pdf")
reader = PdfFileReader(path)

# Password is correct:)
reader.decrypt("test")

reader.getPage(0)

0 comments on commit d58a849

Please sign in to comment.