[Libreoffice-commits] core.git: include/unotest test/signing-keys unotest/source xmlsecurity/qa

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Fri Jun 19 20:32:48 UTC 2020


 dev/null                                      |binary
 include/unotest/macros_test.hxx               |   12 ++++
 unotest/source/cpp/macros_test.cxx            |   65 ++++++++++++++++++++++++++
 xmlsecurity/qa/unit/pdfsigning/pdfsigning.cxx |   21 +++-----
 xmlsecurity/qa/unit/signing/signing.cxx       |   56 ----------------------
 5 files changed, 88 insertions(+), 66 deletions(-)

New commits:
commit 81c0b6410ae7a604a97994c7f31113f24665167f
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Fri Jun 19 17:56:54 2020 +0200
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Fri Jun 19 22:32:16 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/.
    
    Change-Id: If5ce8269bb72f503263727d8255fe856742dfa60
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96745
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
    Tested-by: Jenkins

diff --git a/include/unotest/macros_test.hxx b/include/unotest/macros_test.hxx
index c60ea1fe97ce..2960dc0fbb23 100644
--- a/include/unotest/macros_test.hxx
+++ b/include/unotest/macros_test.hxx
@@ -13,6 +13,7 @@
 #include <sal/config.h>
 
 #include <memory>
+#include <config_gpgme.h>
 #include <rtl/ustring.hxx>
 #include <unotest/detail/unotestdllapi.hxx>
 
@@ -27,6 +28,11 @@ struct TestMacroInfo
 
 class BasicDLL;
 
+namespace test
+{
+class Directories;
+}
+
 namespace unotest {
 
 class OOO_DLLPUBLIC_UNOTEST MacrosTest
@@ -43,11 +49,17 @@ public:
                     const OUString& rCommand,
                     const css::uno::Sequence<css::beans::PropertyValue>& rPropertyValues);
 
+    void setUpNssGpg(const test::Directories& rDirectories, const OUString& rTestName);
+    void tearDownNssGpg();
+
 protected:
     css::uno::Reference< css::frame::XDesktop2> mxDesktop;
 
 private:
     std::unique_ptr<BasicDLL> mpDll;
+#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 20c56950fcaf..dfd7d758153f 100644
--- a/unotest/source/cpp/macros_test.cxx
+++ b/unotest/source/cpp/macros_test.cxx
@@ -19,6 +19,10 @@
 #include <cppunit/TestAssert.h>
 #include <comphelper/sequence.hxx>
 #include <comphelper/processfactory.hxx>
+#include <unotest/directories.hxx>
+#include <osl/file.hxx>
+#include <osl/process.h>
+#include <osl/thread.h>
 
 using namespace css;
 
@@ -76,6 +80,67 @@ void MacrosTest::dispatchCommand(const uno::Reference<lang::XComponent>& xCompon
 
     xDispatchHelper->executeDispatch(xFrame, rCommand, OUString(), 0, rPropertyValues);
 }
+
+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 7e61e7dc2c87..0936897d6b5d 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:
     /**
@@ -54,6 +55,7 @@ protected:
 public:
     PDFSigningTest();
     void setUp() override;
+    void tearDown() override;
 };
 
 PDFSigningTest::PDFSigningTest() {}
@@ -61,18 +63,13 @@ PDFSigningTest::PDFSigningTest() {}
 void PDFSigningTest::setUp()
 {
     test::BootstrapFixture::setUp();
+    MacrosTest::setUpNssGpg(m_directories, "xmlsecurity_pdfsigning");
+}
 
-#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
+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 4373a5a5bb26..0f03befea47d 100644
--- a/xmlsecurity/qa/unit/signing/signing.cxx
+++ b/xmlsecurity/qa/unit/signing/signing.cxx
@@ -78,10 +78,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;
@@ -106,48 +102,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.
     mxDesktop.set(frame::Desktop::create(mxComponentContext));
@@ -160,14 +115,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