[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.4' - 2 commits - include/unotest sfx2/source test/signing-keys unotest/source xmlsecurity/qa

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Mon Jun 29 07:11:20 UTC 2020


 dev/null                                      |binary
 include/unotest/macros_test.hxx               |   13 +++++
 sfx2/source/doc/objserv.cxx                   |    9 +++
 unotest/source/cpp/macros_test.cxx            |   64 ++++++++++++++++++++++++++
 xmlsecurity/qa/unit/pdfsigning/pdfsigning.cxx |   22 ++++----
 xmlsecurity/qa/unit/signing/signing.cxx       |   56 ----------------------
 6 files changed, 98 insertions(+), 66 deletions(-)

New commits:
commit cb7e8552329f7b65e0b938c12568d6aa61fff65b
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Wed Jun 24 10:17:14 2020 +0200
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Mon Jun 29 09:11:01 2020 +0200

    sd signature line: support signing multiple times
    
    Reload the document after signing. This way in case the signature line
    is not exported correctly, we notice it immediately. Also the infobar
    state gets reset, allowing a next signature to be added.
    
    (cherry picked from commit 1904251af5944f8e9c277be1dffe387f85b52626)
    
    Change-Id: Iaeaf4c9aebadbd63b44a0620d345cd0dd0214f30
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97254
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>

diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx
index 09e4bba8bde8..b931ed90c3e7 100644
--- a/sfx2/source/doc/objserv.cxx
+++ b/sfx2/source/doc/objserv.cxx
@@ -478,6 +478,15 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq)
                 if (xCertificate.is())
                 {
                     SignDocumentContentUsingCertificate(xCertificate);
+
+                    // Reload to show how the PDF actually looks like after signing. This also
+                    // changes "finish signing" on the infobar back to "sign document" as a side
+                    // effect.
+                    SfxViewFrame* pFrame = GetFrame();
+                    if (pFrame)
+                    {
+                        pFrame->GetDispatcher()->Execute(SID_RELOAD);
+                    }
                 }
                 else
                 {
commit bd9bb7c4f1d64404743d42b813fe59fff5ec9abd
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Fri Jun 19 17:56:54 2020 +0200
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Mon Jun 29 09:10:45 2020 +0200

    Move data for signing tests to test/
    
    This was duplicated under xmlsecurity and made it hard to have test code
    outside xmlsecurity, even if the core of the pdf signing is nowadays
    under svl/.
    
    (cherry picked from commit 81c0b6410ae7a604a97994c7f31113f24665167f)
    
    Conflicts:
            include/unotest/macros_test.hxx
            unotest/source/cpp/macros_test.cxx
            xmlsecurity/qa/unit/pdfsigning/pdfsigning.cxx
    
    Change-Id: If5ce8269bb72f503263727d8255fe856742dfa60
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97253
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>

diff --git a/include/unotest/macros_test.hxx b/include/unotest/macros_test.hxx
index 6ec5c25167df..aa098d6a2178 100644
--- a/include/unotest/macros_test.hxx
+++ b/include/unotest/macros_test.hxx
@@ -10,6 +10,7 @@
 #ifndef INCLUDED_UNOTEST_MACROS_TEST_HXX
 #define INCLUDED_UNOTEST_MACROS_TEST_HXX
 
+#include <config_gpgme.h>
 #include <rtl/ustring.hxx>
 #include <unotest/detail/unotestdllapi.hxx>
 
@@ -22,6 +23,11 @@ struct TestMacroInfo
     OUString sMacroUrl;
 };
 
+namespace test
+{
+class Directories;
+}
+
 namespace unotest {
 
 class OOO_DLLPUBLIC_UNOTEST MacrosTest
@@ -32,6 +38,13 @@ public:
 
 protected:
     css::uno::Reference< css::frame::XDesktop2> mxDesktop;
+    void setUpNssGpg(const test::Directories& rDirectories, const OUString& rTestName);
+    void tearDownNssGpg();
+
+private:
+#if HAVE_GPGCONF_SOCKETDIR
+    OString m_gpgconfCommandPrefix;
+#endif
 };
 
 }
diff --git a/xmlsecurity/qa/unit/signing/data/cert8.db b/test/signing-keys/cert8.db
similarity index 100%
rename from xmlsecurity/qa/unit/signing/data/cert8.db
rename to test/signing-keys/cert8.db
diff --git a/xmlsecurity/qa/unit/signing/data/key3.db b/test/signing-keys/key3.db
similarity index 100%
rename from xmlsecurity/qa/unit/signing/data/key3.db
rename to test/signing-keys/key3.db
diff --git a/xmlsecurity/qa/unit/signing/data/pubring.gpg b/test/signing-keys/pubring.gpg
similarity index 100%
rename from xmlsecurity/qa/unit/signing/data/pubring.gpg
rename to test/signing-keys/pubring.gpg
diff --git a/xmlsecurity/qa/unit/signing/data/random_seed b/test/signing-keys/random_seed
similarity index 100%
rename from xmlsecurity/qa/unit/signing/data/random_seed
rename to test/signing-keys/random_seed
diff --git a/xmlsecurity/qa/unit/signing/data/secring.gpg b/test/signing-keys/secring.gpg
similarity index 100%
rename from xmlsecurity/qa/unit/signing/data/secring.gpg
rename to test/signing-keys/secring.gpg
diff --git a/xmlsecurity/qa/unit/signing/data/trustdb.gpg b/test/signing-keys/trustdb.gpg
similarity index 100%
rename from xmlsecurity/qa/unit/signing/data/trustdb.gpg
rename to test/signing-keys/trustdb.gpg
diff --git a/unotest/source/cpp/macros_test.cxx b/unotest/source/cpp/macros_test.cxx
index ffc2b970393c..e25fc8fd2f67 100644
--- a/unotest/source/cpp/macros_test.cxx
+++ b/unotest/source/cpp/macros_test.cxx
@@ -17,6 +17,10 @@
 #include <cppunit/TestAssert.h>
 #include <rtl/ustrbuf.hxx>
 #include <comphelper/sequence.hxx>
+#include <unotest/directories.hxx>
+#include <osl/file.hxx>
+#include <osl/process.h>
+#include <osl/thread.h>
 
 using namespace css;
 
@@ -51,6 +55,66 @@ uno::Reference<css::lang::XComponent> MacrosTest::loadFromDesktop(const OUString
     return xComponent;
 }
 
+void MacrosTest::setUpNssGpg(const test::Directories& rDirectories, const OUString& rTestName)
+{
+    OUString aSourceDir = rDirectories.getURLFromSrc("/test/signing-keys/");
+    OUString aTargetDir = rDirectories.getURLFromWorkdir("CppunitTest/" + rTestName + ".test.user");
+
+    // Set up cert8.db in workdir/CppunitTest/
+    osl::File::copy(aSourceDir + "cert8.db", aTargetDir + "/cert8.db");
+    osl::File::copy(aSourceDir + "key3.db", aTargetDir + "/key3.db");
+
+    // Make gpg use our own defined setup & keys
+    osl::File::copy(aSourceDir + "pubring.gpg", aTargetDir + "/pubring.gpg");
+    osl::File::copy(aSourceDir + "random_seed", aTargetDir + "/random_seed");
+    osl::File::copy(aSourceDir + "secring.gpg", aTargetDir + "/secring.gpg");
+    osl::File::copy(aSourceDir + "trustdb.gpg", aTargetDir + "/trustdb.gpg");
+
+    OUString aTargetPath;
+    osl::FileBase::getSystemPathFromFileURL(aTargetDir, aTargetPath);
+
+#ifndef _WIN32
+    OUString mozCertVar("MOZILLA_CERTIFICATE_FOLDER");
+    osl_setEnvironment(mozCertVar.pData, aTargetPath.pData);
+#endif
+    OUString gpgHomeVar("GNUPGHOME");
+    osl_setEnvironment(gpgHomeVar.pData, aTargetPath.pData);
+
+#if HAVE_GPGCONF_SOCKETDIR
+    auto const ldPath = std::getenv("LIBO_LD_PATH");
+    m_gpgconfCommandPrefix
+        = ldPath == nullptr ? OString() : OStringLiteral("LD_LIBRARY_PATH=") + ldPath + " ";
+    OString path;
+    bool ok = aTargetPath.convertToString(&path, osl_getThreadTextEncoding(),
+                                          RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
+                                              | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR);
+    // if conversion fails, at least provide a best-effort conversion in the message here, for
+    // context
+    CPPUNIT_ASSERT_MESSAGE(OUStringToOString(aTargetPath, RTL_TEXTENCODING_UTF8).getStr(), ok);
+    m_gpgconfCommandPrefix += "GNUPGHOME=" + path + " " GPGME_GPGCONF;
+    // HAVE_GPGCONF_SOCKETDIR is only defined in configure.ac for Linux for now, so (a) std::system
+    // behavior will conform to POSIX (and the relevant env var to set is named LD_LIBRARY_PATH), and
+    // (b) gpgconf --create-socketdir should return zero:
+    OString cmd = m_gpgconfCommandPrefix + " --create-socketdir";
+    int res = std::system(cmd.getStr());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE(cmd.getStr(), 0, res);
+#else
+    (void)this;
+#endif
+}
+
+void MacrosTest::tearDownNssGpg()
+{
+#if HAVE_GPGCONF_SOCKETDIR
+    // HAVE_GPGCONF_SOCKETDIR is only defined in configure.ac for Linux for now, so (a) std::system
+    // behavior will conform to POSIX, and (b) gpgconf --remove-socketdir should return zero:
+    OString cmd = m_gpgconfCommandPrefix + " --remove-socketdir";
+    int res = std::system(cmd.getStr());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE(cmd.getStr(), 0, res);
+#else
+    (void)this;
+#endif
+}
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmlsecurity/qa/unit/pdfsigning/data/cert8.db b/xmlsecurity/qa/unit/pdfsigning/data/cert8.db
deleted file mode 100644
index 8354fd309e3a..000000000000
Binary files a/xmlsecurity/qa/unit/pdfsigning/data/cert8.db and /dev/null differ
diff --git a/xmlsecurity/qa/unit/pdfsigning/data/key3.db b/xmlsecurity/qa/unit/pdfsigning/data/key3.db
deleted file mode 100644
index 8ab32c28d584..000000000000
Binary files a/xmlsecurity/qa/unit/pdfsigning/data/key3.db and /dev/null differ
diff --git a/xmlsecurity/qa/unit/pdfsigning/pdfsigning.cxx b/xmlsecurity/qa/unit/pdfsigning/pdfsigning.cxx
index 97e0b7d28f97..dc037f47b33f 100644
--- a/xmlsecurity/qa/unit/pdfsigning/pdfsigning.cxx
+++ b/xmlsecurity/qa/unit/pdfsigning/pdfsigning.cxx
@@ -14,6 +14,7 @@
 #include <osl/file.hxx>
 #include <sal/log.hxx>
 #include <test/bootstrapfixture.hxx>
+#include <unotest/macros_test.hxx>
 #include <tools/datetime.hxx>
 #include <unotools/streamwrap.hxx>
 #include <unotools/ucbstreamhelper.hxx>
@@ -36,7 +37,7 @@ char const DATA_DIRECTORY[] = "/xmlsecurity/qa/unit/pdfsigning/data/";
 }
 
 /// Testsuite for the PDF signing feature.
-class PDFSigningTest : public test::BootstrapFixture
+class PDFSigningTest : public test::BootstrapFixture, public unotest::MacrosTest
 {
 protected:
     uno::Reference<uno::XComponentContext> mxComponentContext;
@@ -56,6 +57,7 @@ protected:
 public:
     PDFSigningTest();
     void setUp() override;
+    void tearDown() override;
 };
 
 PDFSigningTest::PDFSigningTest() {}
@@ -66,17 +68,13 @@ void PDFSigningTest::setUp()
 
     mxComponentContext.set(comphelper::getComponentContext(getMultiServiceFactory()));
 
-#ifndef _WIN32
-    // Set up cert8.db and key3.db in workdir/CppunitTest/
-    OUString aSourceDir = m_directories.getURLFromSrc(DATA_DIRECTORY);
-    OUString aTargetDir
-        = m_directories.getURLFromWorkdir("/CppunitTest/xmlsecurity_pdfsigning.test.user/");
-    osl::File::copy(aSourceDir + "cert8.db", aTargetDir + "cert8.db");
-    osl::File::copy(aSourceDir + "key3.db", aTargetDir + "key3.db");
-    OUString aTargetPath;
-    osl::FileBase::getSystemPathFromFileURL(aTargetDir, aTargetPath);
-    setenv("MOZILLA_CERTIFICATE_FOLDER", aTargetPath.toUtf8().getStr(), 1);
-#endif
+    MacrosTest::setUpNssGpg(m_directories, "xmlsecurity_pdfsigning");
+}
+
+void PDFSigningTest::tearDown()
+{
+    MacrosTest::tearDownNssGpg();
+    test::BootstrapFixture::tearDown();
 }
 
 std::vector<SignatureInformation> PDFSigningTest::verify(const OUString& rURL, size_t nCount,
diff --git a/xmlsecurity/qa/unit/signing/signing.cxx b/xmlsecurity/qa/unit/signing/signing.cxx
index 04eb91e8822b..8c124a18fc23 100644
--- a/xmlsecurity/qa/unit/signing/signing.cxx
+++ b/xmlsecurity/qa/unit/signing/signing.cxx
@@ -80,10 +80,6 @@ protected:
     uno::Reference<xml::crypto::XSEInitializer> mxSEInitializer;
     uno::Reference<xml::crypto::XXMLSecurityContext> mxSecurityContext;
 
-#if HAVE_GPGCONF_SOCKETDIR
-    OString m_gpgconfCommandPrefix;
-#endif
-
 public:
     SigningTest();
     virtual void setUp() override;
@@ -108,48 +104,7 @@ SigningTest::SigningTest() {}
 void SigningTest::setUp()
 {
     test::BootstrapFixture::setUp();
-
-    OUString aSourceDir = m_directories.getURLFromSrc(DATA_DIRECTORY);
-    OUString aTargetDir
-        = m_directories.getURLFromWorkdir("CppunitTest/xmlsecurity_signing.test.user");
-
-    // Set up cert8.db in workdir/CppunitTest/
-    osl::File::copy(aSourceDir + "cert8.db", aTargetDir + "/cert8.db");
-    osl::File::copy(aSourceDir + "key3.db", aTargetDir + "/key3.db");
-
-    // Make gpg use our own defined setup & keys
-    osl::File::copy(aSourceDir + "pubring.gpg", aTargetDir + "/pubring.gpg");
-    osl::File::copy(aSourceDir + "random_seed", aTargetDir + "/random_seed");
-    osl::File::copy(aSourceDir + "secring.gpg", aTargetDir + "/secring.gpg");
-    osl::File::copy(aSourceDir + "trustdb.gpg", aTargetDir + "/trustdb.gpg");
-
-    OUString aTargetPath;
-    osl::FileBase::getSystemPathFromFileURL(aTargetDir, aTargetPath);
-
-    OUString mozCertVar("MOZILLA_CERTIFICATE_FOLDER");
-    osl_setEnvironment(mozCertVar.pData, aTargetPath.pData);
-    OUString gpgHomeVar("GNUPGHOME");
-    osl_setEnvironment(gpgHomeVar.pData, aTargetPath.pData);
-
-#if HAVE_GPGCONF_SOCKETDIR
-    auto const ldPath = std::getenv("LIBO_LD_PATH");
-    m_gpgconfCommandPrefix
-        = ldPath == nullptr ? OString() : OStringLiteral("LD_LIBRARY_PATH=") + ldPath + " ";
-    OString path;
-    bool ok = aTargetPath.convertToString(&path, osl_getThreadTextEncoding(),
-                                          RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
-                                              | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR);
-    // if conversion fails, at least provide a best-effort conversion in the message here, for
-    // context
-    CPPUNIT_ASSERT_MESSAGE(OUStringToOString(aTargetPath, RTL_TEXTENCODING_UTF8).getStr(), ok);
-    m_gpgconfCommandPrefix += "GNUPGHOME=" + path + " " GPGME_GPGCONF;
-    // HAVE_GPGCONF_SOCKETDIR is only defined in configure.ac for Linux for now, so (a) std::system
-    // behavior will conform to POSIX (and the relevant env var to set is named LD_LIBRARY_PATH), and
-    // (b) gpgconf --create-socketdir should return zero:
-    OString cmd = m_gpgconfCommandPrefix + " --create-socketdir";
-    int res = std::system(cmd.getStr());
-    CPPUNIT_ASSERT_EQUAL_MESSAGE(cmd.getStr(), 0, res);
-#endif
+    MacrosTest::setUpNssGpg(m_directories, "xmlsecurity_signing");
 
     // Initialize crypto after setting up the environment variables.
     mxComponentContext.set(comphelper::getComponentContext(getMultiServiceFactory()));
@@ -163,14 +118,7 @@ void SigningTest::tearDown()
     if (mxComponent.is())
         mxComponent->dispose();
 
-#if HAVE_GPGCONF_SOCKETDIR
-    // HAVE_GPGCONF_SOCKETDIR is only defined in configure.ac for Linux for now, so (a) std::system
-    // behavior will conform to POSIX, and (b) gpgconf --remove-socketdir should return zero:
-    OString cmd = m_gpgconfCommandPrefix + " --remove-socketdir";
-    int res = std::system(cmd.getStr());
-    CPPUNIT_ASSERT_EQUAL_MESSAGE(cmd.getStr(), 0, res);
-#endif
-
+    MacrosTest::tearDownNssGpg();
     test::BootstrapFixture::tearDown();
 }
 


More information about the Libreoffice-commits mailing list