From 4c3c658e2594d1f1a5eab530d744d62a1f22d269 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Wed, 20 Dec 2023 10:34:51 -0500 Subject: Fix tests with password-protected files --- qpdf/qtest/encryption.test | 11 ++++++----- qpdf/qtest/pages-tree.test | 2 +- qpdf/qtest/qpdfjob.test | 43 ++++++++++++++++++++++--------------------- qpdf/qtest/split-pages.test | 12 ++++++------ 4 files changed, 35 insertions(+), 33 deletions(-) diff --git a/qpdf/qtest/encryption.test b/qpdf/qtest/encryption.test index 1403a72e..fb4f993b 100644 --- a/qpdf/qtest/encryption.test +++ b/qpdf/qtest/encryption.test @@ -373,9 +373,9 @@ $td->runtest("show-encryption works invalid password", $td->NORMALIZE_NEWLINES); my @cenc = ( - [11, 'hybrid-xref.pdf', "''", 'r2', "", ""], - [12, 'hybrid-xref.pdf', "''", 'r3', "", ""], - [15, 'hybrid-xref.pdf', "''", 'r4', "", ""], + [11, 'hybrid-xref.pdf', "''", 'r2', "", "user1"], + [12, 'hybrid-xref.pdf', "''", 'r3', "", "user2"], + [15, 'hybrid-xref.pdf', "''", 'r4', "", "user2"], [17, 'hybrid-xref.pdf', "''", 'r5', "", "owner3"], [18, 'hybrid-xref.pdf', "''", 'r6', "", "user4"], [13, 'c-r2.pdf', 'user1', 'decrypt with user', @@ -404,7 +404,7 @@ foreach my $d (@cenc) if (-f $pdf_outfile) { $td->runtest("check $description content", - {$td->COMMAND => "qpdf-test-compare a.pdf $pdf_outfile"}, + {$td->COMMAND => "qpdf-test-compare a.pdf $pdf_outfile $checkpass"}, {$td->FILE => $pdf_outfile, $td->EXIT_STATUS => 0}); } else @@ -413,7 +413,8 @@ foreach my $d (@cenc) # /Perms static, so we have no way to predictably create a # /V=5 encrypted file. It's not worth adding this...the test # suite is adequate without having a statically predictable - # file. + # file. (qpdf-test-compare ignores /Perms, but it's not worth + # adding output files for these cases.) $td->runtest("check $description", {$td->COMMAND => "qpdf --check a.pdf --password=$checkpass"}, diff --git a/qpdf/qtest/pages-tree.test b/qpdf/qtest/pages-tree.test index 68b35a73..2ec00e29 100644 --- a/qpdf/qtest/pages-tree.test +++ b/qpdf/qtest/pages-tree.test @@ -24,7 +24,7 @@ $td->runtest("linearize duplicated pages", $td->EXIT_STATUS => 3}, $td->NORMALIZE_NEWLINES); $td->runtest("compare files", - {$td->COMMAND => "qpdf-test-compare a.pdf"}, + {$td->COMMAND => "qpdf-test-compare a.pdf linearize-duplicate-page.pdf"}, {$td->FILE => "linearize-duplicate-page.pdf", $td->EXIT_STATUS => 0}); $td->runtest("extract duplicated pages", {$td->COMMAND => diff --git a/qpdf/qtest/qpdfjob.test b/qpdf/qtest/qpdfjob.test index 51f87b8f..57ad608a 100644 --- a/qpdf/qtest/qpdfjob.test +++ b/qpdf/qtest/qpdfjob.test @@ -30,18 +30,18 @@ my @bad_json = ( "json-error" ); my @good_json = ( - "choice-match", - "input-file-password", - "empty-input", - "replace-input", - "encrypt-40", - "encrypt-128", - "encrypt-256-with-restrictions", - "add-attachments", - "copy-attachments", - "underlay-overlay", - "underlay-overlay-password", - "misc-options", + ["choice-match", ""], + ["input-file-password", "user"], + ["empty-input", ""], + ["replace-input", ""], + ["encrypt-40", "u"], + ["encrypt-128", "u"], + ["encrypt-256-with-restrictions", "u"], + ["add-attachments", ""], + ["copy-attachments", ""], + ["underlay-overlay", ""], + ["underlay-overlay-password", ""], + ["misc-options", ""], ); my $n_tests = 11 + scalar(@bad_json) + (2 * scalar(@good_json)); @@ -56,28 +56,29 @@ foreach my $i (@bad_json) foreach my $i (@good_json) { - if ($i eq 'replace-input') + my ($base, $pass) = @$i; + if ($base eq 'replace-input') { copy("minimal.pdf", 'a.pdf'); } - $td->runtest("QPDFJob good json: $i", - {$td->COMMAND => "qpdf --job-json-file=job-json-$i.json"}, + $td->runtest("QPDFJob good json: $base", + {$td->COMMAND => "qpdf --job-json-file=job-json-$base.json"}, {$td->STRING => "", $td->EXIT_STATUS => 0}, $td->NORMALIZE_NEWLINES); - if ($i =~ m/encrypt-256/) + if ($base =~ m/encrypt-256/) { - $td->runtest("check encryption $i", + $td->runtest("check encryption $base", {$td->COMMAND => "qpdf a.pdf --password=u" . " --job-json-file=job-show-encryption.json"}, - {$td->FILE => "job-json-$i.out", $td->EXIT_STATUS => 0}, + {$td->FILE => "job-json-$base.out", $td->EXIT_STATUS => 0}, $td->NORMALIZE_NEWLINES); } else { - $td->runtest("check good json $i output", - {$td->COMMAND => "qpdf-test-compare a.pdf job-json-$i.pdf"}, - {$td->FILE => "job-json-$i.pdf", $td->EXIT_STATUS => 0}); + $td->runtest("check good json $base output", + {$td->COMMAND => "qpdf-test-compare a.pdf job-json-$base.pdf $pass"}, + {$td->FILE => "job-json-$base.pdf", $td->EXIT_STATUS => 0}); } } diff --git a/qpdf/qtest/split-pages.test b/qpdf/qtest/split-pages.test index 46515c4f..455a4ed3 100644 --- a/qpdf/qtest/split-pages.test +++ b/qpdf/qtest/split-pages.test @@ -70,8 +70,8 @@ $td->runtest("split page with labels", foreach my $i (qw(01-06 07-11)) { $td->runtest("check output ($i)", - {$td->FILE => "split-out-labels-$i.pdf"}, - {$td->FILE => "labels-split-$i.pdf"}); + {$td->COMMAND => "qpdf-test-compare split-out-labels-$i.pdf labels-split-$i.pdf"}, + {$td->FILE => "labels-split-$i.pdf", $td->EXIT_STATUS => 0}); } # See comments in TODO about these expected failures. Search for @@ -121,8 +121,8 @@ foreach my $d (@sp_cases) my $expected = $actual; $expected =~ s/split-out/split-exp/; $td->runtest("check output page $i ($description)", - {$td->FILE => $actual}, - {$td->FILE => $expected}); + {$td->COMMAND => "qpdf-test-compare $actual $expected u"}, + {$td->FILE => $expected, $td->EXIT_STATUS => 0}); } } @@ -201,8 +201,8 @@ foreach my $d (@fo_resources) {$td->STRING => "", $td->EXIT_STATUS => 0}, $td->NORMALIZE_NEWLINES); $td->runtest("check output ($f)", - {$td->FILE => "a.pdf"}, - {$td->FILE => "$f-out.pdf"}); + {$td->COMMAND => "qpdf-test-compare a.pdf $f-out.pdf"}, + {$td->FILE => "$f-out.pdf", $td->EXIT_STATUS => 0}); if ($compare) { compare_pdfs($td, "$f.pdf", "a.pdf"); -- cgit v1.2.3-54-g00ecf