1#include <QtTest/QTest>
2
3#include <poppler-qt6.h>
4
5class TestPassword : public QObject
6{
7 Q_OBJECT
8public:
9 explicit TestPassword(QObject *parent = nullptr) : QObject(parent) { }
10private slots:
11 void password1();
12 void password1a();
13 void password2();
14 void password2a();
15 void password2b();
16 void password3();
17 void password4();
18 void password4b();
19 void password5();
20};
21
22// BUG:4557
23void TestPassword::password1()
24{
25 std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(filePath: QString::fromUtf8(TESTDATADIR "/unittestcases/Gday garçon - open.pdf"), ownerPassword: "", userPassword: QString::fromUtf8(utf8: "garçon").toLatin1()); // clazy:exclude=qstring-allocations
26 QVERIFY(doc);
27 QVERIFY(!doc->isLocked());
28}
29
30void TestPassword::password1a()
31{
32 std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(filePath: QString::fromUtf8(TESTDATADIR "/unittestcases/Gday garçon - open.pdf")); // clazy:exclude=qstring-allocations
33 QVERIFY(doc);
34 QVERIFY(doc->isLocked());
35 QVERIFY(!doc->unlock("", QString::fromUtf8("garçon").toLatin1())); // clazy:exclude=qstring-allocations
36 QVERIFY(!doc->isLocked());
37}
38
39void TestPassword::password2()
40{
41 std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(filePath: QString::fromUtf8(TESTDATADIR "/unittestcases/Gday garçon - owner.pdf"), ownerPassword: QString::fromUtf8(utf8: "garçon").toLatin1(), userPassword: ""); // clazy:exclude=qstring-allocations
42 QVERIFY(doc);
43 QVERIFY(!doc->isLocked());
44}
45
46void TestPassword::password2a()
47{
48 std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(filePath: QString::fromUtf8(TESTDATADIR "/unittestcases/Gday garçon - owner.pdf"), ownerPassword: QString::fromUtf8(utf8: "garçon").toLatin1()); // clazy:exclude=qstring-allocations
49 QVERIFY(doc);
50 QVERIFY(!doc->isLocked());
51}
52
53void TestPassword::password2b()
54{
55 std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(filePath: QString::fromUtf8(TESTDATADIR "/unittestcases/Gday garçon - owner.pdf"));
56 QVERIFY(doc);
57 QVERIFY(!doc->isLocked());
58 QVERIFY(!doc->unlock(QString::fromUtf8("garçon").toLatin1(), "")); // clazy:exclude=qstring-allocations
59 QVERIFY(!doc->isLocked());
60}
61
62void TestPassword::password3()
63{
64 std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(filePath: QString::fromUtf8(TESTDATADIR "/unittestcases/PasswordEncrypted.pdf"));
65 QVERIFY(doc);
66 QVERIFY(doc->isLocked());
67 QVERIFY(!doc->unlock("", "password"));
68 QVERIFY(!doc->isLocked());
69}
70
71// issue 690
72void TestPassword::password4()
73{
74 std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(filePath: QString::fromUtf8(TESTDATADIR "/unittestcases/encrypted-256.pdf"));
75 QVERIFY(doc);
76 QVERIFY(doc->isLocked());
77 QVERIFY(!doc->unlock("owner-secret", ""));
78 QVERIFY(!doc->isLocked());
79}
80
81// issue 690
82void TestPassword::password4b()
83{
84 std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(filePath: QString::fromUtf8(TESTDATADIR "/unittestcases/encrypted-256.pdf"));
85 QVERIFY(doc);
86 QVERIFY(doc->isLocked());
87 QVERIFY(!doc->unlock("", "user-secret"));
88 QVERIFY(!doc->isLocked());
89}
90
91void TestPassword::password5()
92{
93 std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(filePath: QString::fromUtf8(TESTDATADIR "/unittestcases/PasswordEncryptedReconstructed.pdf"));
94 QVERIFY(doc);
95 QVERIFY(doc->isLocked());
96 QVERIFY(!doc->unlock("", "test"));
97 QVERIFY(!doc->isLocked());
98}
99
100QTEST_GUILESS_MAIN(TestPassword)
101#include "check_password.moc"
102

source code of poppler/qt6/tests/check_password.cpp