From e78b5e9861de1549c3ed889821e67931d92424b7 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Thu, 13 Oct 2016 13:14:04 +0200 Subject: CppunitTest_xmlsecurity_signing: add PDF tests 3 cases: a good and a bad signature, also a document without a signature. Disable on Windows for now, as the non-NSS part in PDFDocument is not implemented yet. Fails without e.g. the previous commit, due to not initializing NSS properly. Change-Id: I3f100bd035ac899db22001b2744d1cb3abe5beaf Reviewed-on: https://gerrit.libreoffice.org/29764 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- xmlsecurity/qa/unit/signing/data/bad.pdf | Bin 0 -> 57587 bytes xmlsecurity/qa/unit/signing/data/good.pdf | Bin 0 -> 57587 bytes xmlsecurity/qa/unit/signing/data/no.pdf | Bin 0 -> 6865 bytes xmlsecurity/qa/unit/signing/signing.cxx | 52 ++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+) create mode 100644 xmlsecurity/qa/unit/signing/data/bad.pdf create mode 100644 xmlsecurity/qa/unit/signing/data/good.pdf create mode 100644 xmlsecurity/qa/unit/signing/data/no.pdf (limited to 'xmlsecurity/qa') diff --git a/xmlsecurity/qa/unit/signing/data/bad.pdf b/xmlsecurity/qa/unit/signing/data/bad.pdf new file mode 100644 index 000000000000..f3f056f2bffa Binary files /dev/null and b/xmlsecurity/qa/unit/signing/data/bad.pdf differ diff --git a/xmlsecurity/qa/unit/signing/data/good.pdf b/xmlsecurity/qa/unit/signing/data/good.pdf new file mode 100644 index 000000000000..4a506c1e119e Binary files /dev/null and b/xmlsecurity/qa/unit/signing/data/good.pdf differ diff --git a/xmlsecurity/qa/unit/signing/data/no.pdf b/xmlsecurity/qa/unit/signing/data/no.pdf new file mode 100644 index 000000000000..5d552421a4cb Binary files /dev/null and b/xmlsecurity/qa/unit/signing/data/no.pdf differ diff --git a/xmlsecurity/qa/unit/signing/signing.cxx b/xmlsecurity/qa/unit/signing/signing.cxx index 0f12c66aa7a5..c357a2d60b5b 100644 --- a/xmlsecurity/qa/unit/signing/signing.cxx +++ b/xmlsecurity/qa/unit/signing/signing.cxx @@ -76,6 +76,12 @@ public: void testOOXMLRemove(); /// Test removing all signatures from a document. void testOOXMLRemoveAll(); + /// Test a typical PDF where the signature is good. + void testPDFGood(); + /// Test a typical PDF where the signature is bad. + void testPDFBad(); + /// Test a typical PDF which is not signed. + void testPDFNo(); void test96097Calc(); void test96097Doc(); @@ -90,6 +96,9 @@ public: CPPUNIT_TEST(testOOXMLAppend); CPPUNIT_TEST(testOOXMLRemove); CPPUNIT_TEST(testOOXMLRemoveAll); + CPPUNIT_TEST(testPDFGood); + CPPUNIT_TEST(testPDFBad); + CPPUNIT_TEST(testPDFNo); CPPUNIT_TEST(test96097Calc); CPPUNIT_TEST(test96097Doc); CPPUNIT_TEST_SUITE_END(); @@ -390,6 +399,49 @@ void SigningTest::testOOXMLBroken() CPPUNIT_ASSERT_EQUAL(static_cast(SignatureState::BROKEN), static_cast(pObjectShell->GetDocumentSignatureState())); } +void SigningTest::testPDFGood() +{ +#ifndef _WIN32 + createDoc(m_directories.getURLFromSrc(DATA_DIRECTORY) + "good.pdf"); + SfxBaseModel* pBaseModel = dynamic_cast(mxComponent.get()); + CPPUNIT_ASSERT(pBaseModel); + SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell(); + CPPUNIT_ASSERT(pObjectShell); + // We expect NOTVALIDATED in case the root CA is not imported on the system, and OK otherwise, so accept both. + SignatureState nActual = pObjectShell->GetDocumentSignatureState(); + CPPUNIT_ASSERT_MESSAGE( + (OString::number( + static_cast::type>(nActual)) + .getStr()), + (nActual == SignatureState::NOTVALIDATED + || nActual == SignatureState::OK)); +#endif +} + +void SigningTest::testPDFBad() +{ +#ifndef _WIN32 + createDoc(m_directories.getURLFromSrc(DATA_DIRECTORY) + "bad.pdf"); + SfxBaseModel* pBaseModel = dynamic_cast(mxComponent.get()); + CPPUNIT_ASSERT(pBaseModel); + SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell(); + CPPUNIT_ASSERT(pObjectShell); + CPPUNIT_ASSERT_EQUAL(static_cast(SignatureState::BROKEN), static_cast(pObjectShell->GetDocumentSignatureState())); +#endif +} + +void SigningTest::testPDFNo() +{ +#ifndef _WIN32 + createDoc(m_directories.getURLFromSrc(DATA_DIRECTORY) + "no.pdf"); + SfxBaseModel* pBaseModel = dynamic_cast(mxComponent.get()); + CPPUNIT_ASSERT(pBaseModel); + SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell(); + CPPUNIT_ASSERT(pObjectShell); + CPPUNIT_ASSERT_EQUAL(static_cast(SignatureState::NOSIGNATURES), static_cast(pObjectShell->GetDocumentSignatureState())); +#endif +} + void SigningTest::test96097Calc() { createCalc(m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf96097.ods"); -- cgit v1.2.3