diff options
author | Michael Meeks <michael.meeks@collabora.com> | 2019-08-03 18:53:15 -0400 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2019-08-05 12:03:59 -0400 |
commit | 430778af918608709b0fd12fae6693aec62fbd70 (patch) | |
tree | 71139c280612acafbfe052e44e4a020d1f148b01 | |
parent | LOK: Enable embedding images in text/html format output (diff) | |
download | core-430778af918608709b0fd12fae6693aec62fbd70.tar.gz core-430778af918608709b0fd12fae6693aec62fbd70.zip |
Fix certificate test mis-merging.
Change-Id: Iea997c8eab371f278d181de0cc61323a25f0d1ae
-rw-r--r-- | desktop/qa/desktop_lib/test_desktop_lib.cxx | 264 |
1 files changed, 80 insertions, 184 deletions
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index de11c867412b..9101619f9ef1 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -2346,7 +2346,6 @@ void DesktopLOKTest::testInsertCertificate_DER_ODT() CPPUNIT_ASSERT_EQUAL(int(1), nState); } - void DesktopLOKTest::testInsertCertificate_PEM_ODT() { comphelper::LibreOfficeKit::setActive(); @@ -2370,7 +2369,23 @@ void DesktopLOKTest::testInsertCertificate_PEM_ODT() std::vector<unsigned char> aPrivateKey; { - readFileIntoByteVector("rootCA.der", aCertificate); + 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())); @@ -2391,6 +2406,66 @@ 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("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); +} + void DesktopLOKTest::testSignDocument_PEM_PDF() { comphelper::LibreOfficeKit::setActive(); @@ -2575,192 +2650,13 @@ void DesktopLOKTest::testComplexSelection() CPPUNIT_ASSERT_EQUAL(static_cast<int>(LOK_SELTYPE_COMPLEX), pDocument->pClass->getSelectionType(pDocument)); } -void DesktopLOKTest::testInsertCertificate_PEM_ODT() -{ - comphelper::LibreOfficeKit::setActive(); - - // Load the document, save it into a temp file and load that file again - LibLODocument_Impl* pDocument = loadDoc("blank_text.odt"); - utl::TempFile aTempFile; - aTempFile.EnableKillingFile(); - CPPUNIT_ASSERT(pDocument->pClass->saveAs(pDocument, aTempFile.GetURL().toUtf8().getStr(), "odt", 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(1), nState); - - 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 { -void DesktopLOKTest::testSignDocument_PEM_PDF() +constexpr size_t classOffset(int i) { - comphelper::LibreOfficeKit::setActive(); - - // Load the document, save it into a temp file and load that file again - LibLODocument_Impl* pDocument = loadDoc("blank_text.odt"); - utl::TempFile aTempFile; - aTempFile.EnableKillingFile(); - - 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); - } - - CPPUNIT_ASSERT(pDocument->pClass->saveAs(pDocument, aTempFile.GetURL().toUtf8().getStr(), "pdf", nullptr)); - - closeDoc(); - - Scheduler::ProcessEventsToIdle(); - - readFileIntoByteVector("test-cert-signing.pem", aCertificate); - readFileIntoByteVector("test-PK-signing.pem", aPrivateKey); - - LibLibreOffice_Impl aOffice; - bool bResult = aOffice.m_pOfficeClass->signDocument(&aOffice, aTempFile.GetURL().toUtf8().getStr(), - aCertificate.data(), int(aCertificate.size()), - aPrivateKey.data(), int(aPrivateKey.size())); - - CPPUNIT_ASSERT(bResult); - - comphelper::LibreOfficeKit::setActive(false); + return sizeof(static_cast<struct _LibreOfficeKitClass*>(nullptr)->nSize) + i * sizeof(void*); } -namespace { - constexpr size_t documentClassOffset(int i) { return sizeof(static_cast<struct _LibreOfficeKitDocumentClass*>(nullptr)->nSize) + i * sizeof(void*); |