From d58a849179138ec0d68fc4bc1b2437d1d269a308 Mon Sep 17 00:00:00 2001 From: Martin Thoma Date: Sat, 16 Apr 2022 07:53:33 +0200 Subject: [PATCH] TST: Regression test for #327 Credits to Denis Osipov: https://github.com/py-pdf/PyPDF2/pull/359#issuecomment-1092022338 Co-authored-by: Denis Osipov --- Resources/encrypted-file.pdf | Bin 0 -> 7714 bytes Tests/test_page.py | 2 +- Tests/test_pagerange.py | 1 + Tests/test_reader.py | 22 +++++++++++++++++++--- 4 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 Resources/encrypted-file.pdf diff --git a/Resources/encrypted-file.pdf b/Resources/encrypted-file.pdf new file mode 100644 index 0000000000000000000000000000000000000000..c300a5fed51be204af893010d8ee5d357fdeefc1 GIT binary patch literal 7714 zcmaiZc|6o@_rDakMv^U*7(0ns%!=%L_AOarjERwTj4fHROZG%rBO&{mT~hWnOW6t8 z%9b_aJJWMN&)xmp-|z2t{V}iWI-hf$^?j~+z0Tp+QB)R%h#>&{EiYQ?TdG>p0Z+4dVas=1*@SKr|Ev{>!x$R@1-5`2v4KonNu!1H=UpZY?@Uv)49OV<8t#Mu z-Nq4-=9QrL_Yw{AE$!r)K3uPt*05@J&n$S+o(VF2BZ?`nNUmlS(Zg7Rm zfj`P6#@xHx;H`U3uQBHerT@*!%0GI~*9dvt znmht7O;{|!?OpC$-7ZVsnl=xyGpBF;7+iO`*Y{~(<(1VuhtfWlkr7LMX30_0_G+6h z(e@U7Yooo>>sFONPUmrR_=a9*+@yOX@o{P_jguVy2Vxe;dUo6#!TsET>fqbBF?o!LI` zC@z>?AG~Jd;IR#OA88h3uz4nG*Uzy)Qz}%0K{a8rQLZAhR@2zM=*KZJ?lFvgPn!st z-#BLCn5=qqYyA|x6A_A@6}DWs3{beibB1Hu8Nw{pCH5kWrSH}0>W`|$vMx6Kd(^pm zk5Tds563&BD_?osT-9I@fp34vV0YN)>$E=0M}^%YD4bJT?&8zIXCy}Dji@~i*^Mwf zHI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CgG_HzO+Oz*l<4*c>&4#9cej#n z{CIOij8+nQxKX2Z_DqmTaI6#yKGk@zk@06}y1S(6lcS!uH^8!H9Qt3kx{Qr(%hVOv zygqPAXiw0IZ51l!#^@KH8Y-*bugq}Pt6hY!xdhv9UvD-2Eael}`@g^f{Z|bCg8-1e zn-!4^2Lpl|?iW=apAU&L`lN$kx za|J@k%z7YAoHZUpMnBmiI2tZS!arIZ2?irkNEi?WgNUI}Xe2@$iA2MpD07es!O6{; zG{Mm)MHu7g>P!}n^#UpAlPba;kHzV!$b-~?L{jvnr9lcL(@DBrf#lJT-f!?H8$+&W zlA!+>>I(RWb%4LjBVG7qAK4^w$Zz1ST}^?%d>|hcoZQG!`b`Dow{g=i9SRsyEj!te z;$cH_|5rEwAZ=%yqa2p}ESUaF7RdOP3DD8a-u_=dV3KSNjH8XvEbE-Xfbidf{qLy| z$q5D0u!{8RNP$U@pqw0BSqX|#gutO-akxBG9)SRZ!3y%yzp`iThQ92%9E*X9NJsc@~AU!8166Sx^ z767E=h$VPAlg@u4Tg~x~6A2mBz3b}c00fahE~iAw9s~hKDJp}}3W_Kad{Iz{yfOr= b3`3Di#+8U65Pzi|2|>dF{QOGV%7Fg?P7Y>t literal 0 HcmV?d00001 diff --git a/Tests/test_page.py b/Tests/test_page.py index bed852080..6e4400403 100644 --- a/Tests/test_page.py +++ b/Tests/test_page.py @@ -30,7 +30,7 @@ "libreoffice-writer-password", "imagemagick-images", "imagemagick-lzw", - "reportlab-inline-image" + "reportlab-inline-image", ], ) def test_page_operations(pdf_path, password): diff --git a/Tests/test_pagerange.py b/Tests/test_pagerange.py index b90feef00..dd3c97954 100644 --- a/Tests/test_pagerange.py +++ b/Tests/test_pagerange.py @@ -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") diff --git a/Tests/test_reader.py b/Tests/test_reader.py index a58130d80..be6cdc77f 100644 --- a/Tests/test_reader.py +++ b/Tests/test_reader.py @@ -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( @@ -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): @@ -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)