diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2018-12-26 20:46:16 +0100 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2019-08-05 12:03:54 -0400 |
commit | cd0221e26986cee3909d24510794f2d5bd23233d (patch) | |
tree | d072d7a841153d0019af32f359472f44fd7ed034 | |
parent | 5ec07d325625dfa6b646d02ebc2c63a8ac5d8f8f (diff) |
lok: add test signing DOCX -> testInsertCertificate_PEM_DOCX
Change-Id: I1918041793935b012e60fe64073480ed4b9581d5
Reviewed-on: https://gerrit.libreoffice.org/65630
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r-- | desktop/qa/data/blank_text.docx | bin | 0 -> 4065 bytes | |||
-rw-r--r-- | desktop/qa/desktop_lib/test_desktop_lib.cxx | 107 |
2 files changed, 63 insertions, 44 deletions
diff --git a/desktop/qa/data/blank_text.docx b/desktop/qa/data/blank_text.docx Binary files differnew file mode 100644 index 000000000000..028a35b6ca58 --- /dev/null +++ b/desktop/qa/data/blank_text.docx diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index b65f81e516c5..5fb735838cb8 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -2391,50 +2391,6 @@ void DesktopLOKTest::testInsertCertificate_PEM_ODT() CPPUNIT_ASSERT_EQUAL(int(1), nState); } -void DesktopLOKTest::testInsertCertificate_PEM_DOCX() -{ - comphelper::LibreOfficeKit::setActive(); - - // Load the document, save it into a temp file and load that file again - LibLODocument_Impl* pDocument = loadDoc("blank_text.docx"); - utl::TempFile aTempFile; - aTempFile.EnableKillingFile(); - CPPUNIT_ASSERT(pDocument->pClass->saveAs(pDocument, aTempFile.GetURL().toUtf8().getStr(), "docx", nullptr)); - closeDoc(); - - mxComponent = loadFromDesktop(aTempFile.GetURL(), "com.sun.star.text.TextDocument"); - pDocument = new LibLODocument_Impl(mxComponent); - - Scheduler::ProcessEventsToIdle(); - CPPUNIT_ASSERT(mxComponent.is()); - pDocument->m_pDocumentClass->initializeForRendering(pDocument, "{}"); - Scheduler::ProcessEventsToIdle(); - - std::vector<unsigned char> aCertificate; - std::vector<unsigned char> aPrivateKey; - - { - readFileIntoByteVector("test-cert-chain-1.pem", aCertificate); - - bool bResult = pDocument->m_pDocumentClass->addCertificate( - pDocument, aCertificate.data(), int(aCertificate.size())); - CPPUNIT_ASSERT(bResult); - } - - { - readFileIntoByteVector("certificate.der", aCertificate); - readFileIntoByteVector("certificatePrivateKey.der", aPrivateKey); - - bool bResult = pDocument->m_pDocumentClass->insertCertificate(pDocument, - aCertificate.data(), int(aCertificate.size()), - aPrivateKey.data(), int(aPrivateKey.size())); - CPPUNIT_ASSERT(bResult); - } - - int nState = pDocument->m_pDocumentClass->getSignatureState(pDocument); - CPPUNIT_ASSERT_EQUAL(int(5), nState); -} - void DesktopLOKTest::testSignDocument_PEM_PDF() { comphelper::LibreOfficeKit::setActive(); @@ -2680,6 +2636,69 @@ void DesktopLOKTest::testInsertCertificate_PEM_ODT() comphelper::LibreOfficeKit::setActive(false); } + +void DesktopLOKTest::testInsertCertificate_PEM_DOCX() +{ + comphelper::LibreOfficeKit::setActive(); + + // Load the document, save it into a temp file and load that file again + LibLODocument_Impl* pDocument = loadDoc("blank_text.docx"); + utl::TempFile aTempFile; + aTempFile.EnableKillingFile(); + CPPUNIT_ASSERT(pDocument->pClass->saveAs(pDocument, aTempFile.GetURL().toUtf8().getStr(), "docx", nullptr)); + closeDoc(); + + mxComponent = loadFromDesktop(aTempFile.GetURL(), "com.sun.star.text.TextDocument"); + pDocument = new LibLODocument_Impl(mxComponent); + + Scheduler::ProcessEventsToIdle(); + CPPUNIT_ASSERT(mxComponent.is()); + pDocument->m_pDocumentClass->initializeForRendering(pDocument, "{}"); + Scheduler::ProcessEventsToIdle(); + + std::vector<unsigned char> aCertificate; + std::vector<unsigned char> aPrivateKey; + + { + readFileIntoByteVector("test-cert-chain-1.pem", aCertificate); + + bool bResult = pDocument->m_pDocumentClass->addCertificate( + pDocument, aCertificate.data(), int(aCertificate.size())); + CPPUNIT_ASSERT(bResult); + } + + { + readFileIntoByteVector("test-cert-chain-2.pem", aCertificate); + + bool bResult = pDocument->m_pDocumentClass->addCertificate( + pDocument, aCertificate.data(), int(aCertificate.size())); + CPPUNIT_ASSERT(bResult); + } + + { + readFileIntoByteVector("test-cert-chain-3.pem", aCertificate); + + bool bResult = pDocument->m_pDocumentClass->addCertificate( + pDocument, aCertificate.data(), int(aCertificate.size())); + CPPUNIT_ASSERT(bResult); + } + + { + readFileIntoByteVector("test-cert-signing.pem", aCertificate); + readFileIntoByteVector("test-PK-signing.pem", aPrivateKey); + + bool bResult = pDocument->m_pDocumentClass->insertCertificate(pDocument, + aCertificate.data(), int(aCertificate.size()), + aPrivateKey.data(), int(aPrivateKey.size())); + CPPUNIT_ASSERT(bResult); + } + + int nState = pDocument->m_pDocumentClass->getSignatureState(pDocument); + CPPUNIT_ASSERT_EQUAL(int(5), nState); + + comphelper::LibreOfficeKit::setActive(false); +} + namespace { constexpr size_t documentClassOffset(int i) |