Tests/LibPDF: Add test for AES-encrypted PDF

I created this by typing "sup" into TextEdit.app on macOS 13.4,
hitting Cmd-P to bring up the print dialog, clicked the PDF button
at the bottom, changed Title and Author to "sup", clicked
"Security Options…", and checked "Require password to open document"
(with password "sup").

This file tests several things:
- It has a compressed stream as first object. This used to make the
  linearization dict detection logic assert.
- It uses AES as encryption key using version 4 of the encryption
  dict. This used to not be implemented.
This commit is contained in:
Nico Weber 2023-07-11 10:49:38 -04:00 committed by Andreas Kling
parent e0887dd045
commit 2061ee2632
Notes: sideshowbarker 2024-07-16 22:17:03 +09:00
3 changed files with 10 additions and 0 deletions

View file

@ -10,6 +10,7 @@ set(TEST_FILES
complex.pdf
linearized.pdf
non-linearized.pdf
password-is-sup.pdf
type1.pdf
)
install(FILES ${TEST_FILES} DESTINATION home/anon/Documents/pdf)

View file

@ -48,3 +48,12 @@ TEST_CASE(truncated_pdf_header_issue_10717)
auto document = PDF::Document::create(string.bytes());
EXPECT(document.is_error());
}
TEST_CASE(encrypted_with_aes)
{
auto file = MUST(Core::MappedFile::map("password-is-sup.pdf"sv));
auto document = MUST(PDF::Document::create(file->bytes()));
EXPECT(document->security_handler()->try_provide_user_password("sup"sv));
MUST(document->initialize());
EXPECT_EQ(document->get_page_count(), 1U);
}

Binary file not shown.