summaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2018-12-26 20:46:16 +0100
committerTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2019-01-03 07:34:23 +0100
commitec17d9778b26f762af30c964a6170d4933cdcea4 (patch)
tree28b6e7f2405a4694f6392da4237eb2322cd7b156 /desktop
parente41179f81ba8e8fd5b44e5d1dc0484a120f1e401 (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> (cherry picked from commit 936f6a85649c0fd71eee484e7399d445f4040586)
Diffstat (limited to 'desktop')
-rw-r--r--desktop/qa/data/blank_text.docxbin0 -> 4065 bytes
-rw-r--r--desktop/qa/desktop_lib/test_desktop_lib.cxx64
2 files changed, 64 insertions, 0 deletions
diff --git a/desktop/qa/data/blank_text.docx b/desktop/qa/data/blank_text.docx
new file mode 100644
index 000000000000..028a35b6ca58
--- /dev/null
+++ b/desktop/qa/data/blank_text.docx
Binary files differ
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index 18e20c8fd4d7..78f064a49c0a 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -124,6 +124,7 @@ public:
void testGetSignatureState_Signed();
void testInsertCertificate_DER_ODT();
void testInsertCertificate_PEM_ODT();
+ void testInsertCertificate_PEM_DOCX();
void testABI();
CPPUNIT_TEST_SUITE(DesktopLOKTest);
@@ -171,6 +172,7 @@ public:
CPPUNIT_TEST(testGetSignatureState_NonSigned);
CPPUNIT_TEST(testInsertCertificate_DER_ODT);
CPPUNIT_TEST(testInsertCertificate_PEM_ODT);
+ CPPUNIT_TEST(testInsertCertificate_PEM_DOCX);
CPPUNIT_TEST(testABI);
CPPUNIT_TEST_SUITE_END();
@@ -2420,6 +2422,68 @@ 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 {
size_t documentClassOffset(int i)