[Libreoffice-commits] core.git: desktop/qa desktop/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Nov 6 16:22:03 UTC 2018


 desktop/qa/data/signed.odt                  |binary
 desktop/qa/desktop_lib/test_desktop_lib.cxx |   50 ++++++++++++++++++++++++++--
 desktop/source/lib/init.cxx                 |    2 +
 3 files changed, 49 insertions(+), 3 deletions(-)

New commits:
commit 28a698db6f604137443053144dde94c9e553c0ef
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Wed Oct 24 11:29:32 2018 +0200
Commit:     Miklos Vajna <vmiklos at collabora.co.uk>
CommitDate: Tue Nov 6 17:20:41 2018 +0100

    lok: trigger sign. verification in getSignatureState + update test
    
    As the certificate chain can be added after the document was
    opened, we need to trigger signature verification every time the
    LOK API method getSignatureState is called.
    
    In addition update the tests so that they check the status of a
    document that's not signed, a document that was signed but the
    certificate chain is not available so the verification fails and
    later adding the certificate chain and the verification returns
    an OK status.
    
    Change-Id: I44578d0cece5bfc4a2e43fbbcd68b5ea1ccbc38b
    Reviewed-on: https://gerrit.libreoffice.org/62276
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>

diff --git a/desktop/qa/data/signed.odt b/desktop/qa/data/signed.odt
new file mode 100644
index 000000000000..49bd9dd240fe
Binary files /dev/null and b/desktop/qa/data/signed.odt differ
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index ab0e98033b55..389d84a0cc31 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -118,7 +118,8 @@ public:
     void testCommentsCallbacksWriter();
     void testRunMacro();
     void testExtractParameter();
-    void testGetSignatureState();
+    void testGetSignatureState_NonSigned();
+    void testGetSignatureState_Signed();
     void testInsertCertificate();
     void testABI();
 
@@ -163,7 +164,8 @@ public:
     CPPUNIT_TEST(testCommentsCallbacksWriter);
     CPPUNIT_TEST(testRunMacro);
     CPPUNIT_TEST(testExtractParameter);
-    CPPUNIT_TEST(testGetSignatureState);
+    CPPUNIT_TEST(testGetSignatureState_Signed);
+    CPPUNIT_TEST(testGetSignatureState_NonSigned);
     CPPUNIT_TEST(testInsertCertificate);
     CPPUNIT_TEST(testABI);
     CPPUNIT_TEST_SUITE_END();
@@ -2246,7 +2248,49 @@ void DesktopLOKTest::testExtractParameter()
     comphelper::LibreOfficeKit::setActive(false);
 }
 
-void DesktopLOKTest::testGetSignatureState()
+void DesktopLOKTest::testGetSignatureState_Signed()
+{
+    comphelper::LibreOfficeKit::setActive();
+    LibLODocument_Impl* pDocument = loadDoc("signed.odt");
+    Scheduler::ProcessEventsToIdle();
+    pDocument->m_pDocumentClass->initializeForRendering(pDocument, "{}");
+    int nState = pDocument->m_pDocumentClass->getSignatureState(pDocument);
+    CPPUNIT_ASSERT_EQUAL(int(4), nState);
+
+    {
+        OUString aCertificateURL;
+        createFileURL("rootCA.der", aCertificateURL);
+        SvFileStream aCertificateStream(aCertificateURL, StreamMode::READ);
+        std::vector<unsigned char> aCertificate;
+        aCertificate.resize(aCertificateStream.remainingSize());
+        aCertificateStream.ReadBytes(aCertificate.data(), aCertificateStream.remainingSize());
+
+        bool bResult = pDocument->m_pDocumentClass->addCertificate(
+                            pDocument, aCertificate.data(), int(aCertificate.size()));
+        CPPUNIT_ASSERT(bResult);
+    }
+
+    {
+        OUString aCertificateURL;
+        createFileURL("intermediateRootCA.der", aCertificateURL);
+        SvFileStream aCertificateStream(aCertificateURL, StreamMode::READ);
+        std::vector<unsigned char> aCertificate;
+        aCertificate.resize(aCertificateStream.remainingSize());
+        aCertificateStream.ReadBytes(aCertificate.data(), aCertificateStream.remainingSize());
+
+
+        bool bResult = pDocument->m_pDocumentClass->addCertificate(
+                            pDocument, aCertificate.data(), int(aCertificate.size()));
+        CPPUNIT_ASSERT(bResult);
+    }
+
+    nState = pDocument->m_pDocumentClass->getSignatureState(pDocument);
+    CPPUNIT_ASSERT_EQUAL(int(1), nState);
+
+    comphelper::LibreOfficeKit::setActive(false);
+}
+
+void DesktopLOKTest::testGetSignatureState_NonSigned()
 {
     comphelper::LibreOfficeKit::setActive();
     LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index cc49f86e6d85..faf1dfa40936 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -3752,6 +3752,8 @@ static int doc_getSignatureState(LibreOfficeKitDocument* pThis)
     if (!pObjectShell)
         return int(SignatureState::UNKNOWN);
 
+    pObjectShell->RecheckSignature(false);
+
     return int(pObjectShell->GetDocumentSignatureState());
 }
 


More information about the Libreoffice-commits mailing list