[Libreoffice-commits] core.git: xmlsecurity/qa
Miklos Vajna
vmiklos at collabora.co.uk
Thu Oct 13 14:10:51 UTC 2016
xmlsecurity/qa/unit/signing/data/bad.pdf |binary
xmlsecurity/qa/unit/signing/data/good.pdf |binary
xmlsecurity/qa/unit/signing/data/no.pdf |binary
xmlsecurity/qa/unit/signing/signing.cxx | 52 ++++++++++++++++++++++++++++++
4 files changed, 52 insertions(+)
New commits:
commit e78b5e9861de1549c3ed889821e67931d92424b7
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Thu Oct 13 13:14:04 2016 +0200
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 <vmiklos at collabora.co.uk>
Tested-by: Jenkins <ci at libreoffice.org>
diff --git a/xmlsecurity/qa/unit/signing/data/bad.pdf b/xmlsecurity/qa/unit/signing/data/bad.pdf
new file mode 100644
index 0000000..f3f056f
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 0000000..4a506c1
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 0000000..5d55242
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 0f12c66a..c357a2d 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<int>(SignatureState::BROKEN), static_cast<int>(pObjectShell->GetDocumentSignatureState()));
}
+void SigningTest::testPDFGood()
+{
+#ifndef _WIN32
+ createDoc(m_directories.getURLFromSrc(DATA_DIRECTORY) + "good.pdf");
+ SfxBaseModel* pBaseModel = dynamic_cast<SfxBaseModel*>(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<std::underlying_type<SignatureState>::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<SfxBaseModel*>(mxComponent.get());
+ CPPUNIT_ASSERT(pBaseModel);
+ SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell();
+ CPPUNIT_ASSERT(pObjectShell);
+ CPPUNIT_ASSERT_EQUAL(static_cast<int>(SignatureState::BROKEN), static_cast<int>(pObjectShell->GetDocumentSignatureState()));
+#endif
+}
+
+void SigningTest::testPDFNo()
+{
+#ifndef _WIN32
+ createDoc(m_directories.getURLFromSrc(DATA_DIRECTORY) + "no.pdf");
+ SfxBaseModel* pBaseModel = dynamic_cast<SfxBaseModel*>(mxComponent.get());
+ CPPUNIT_ASSERT(pBaseModel);
+ SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell();
+ CPPUNIT_ASSERT(pObjectShell);
+ CPPUNIT_ASSERT_EQUAL(static_cast<int>(SignatureState::NOSIGNATURES), static_cast<int>(pObjectShell->GetDocumentSignatureState()));
+#endif
+}
+
void SigningTest::test96097Calc()
{
createCalc(m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf96097.ods");
More information about the Libreoffice-commits
mailing list