summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/unotest/macros_test.hxx12
-rw-r--r--test/signing-keys/cert8.db (renamed from xmlsecurity/qa/unit/signing/data/cert8.db)bin65536 -> 65536 bytes
-rw-r--r--test/signing-keys/key3.db (renamed from xmlsecurity/qa/unit/signing/data/key3.db)bin16384 -> 16384 bytes
-rw-r--r--test/signing-keys/pubring.gpg (renamed from xmlsecurity/qa/unit/signing/data/pubring.gpg)bin3060 -> 3060 bytes
-rw-r--r--test/signing-keys/random_seed (renamed from xmlsecurity/qa/unit/signing/data/random_seed)0
-rw-r--r--test/signing-keys/secring.gpg (renamed from xmlsecurity/qa/unit/signing/data/secring.gpg)bin3832 -> 3832 bytes
-rw-r--r--test/signing-keys/trustdb.gpg (renamed from xmlsecurity/qa/unit/signing/data/trustdb.gpg)bin1360 -> 1360 bytes
-rw-r--r--unotest/source/cpp/macros_test.cxx65
-rw-r--r--xmlsecurity/qa/unit/pdfsigning/data/cert8.dbbin65536 -> 0 bytes
-rw-r--r--xmlsecurity/qa/unit/pdfsigning/data/key3.dbbin16384 -> 0 bytes
-rw-r--r--xmlsecurity/qa/unit/pdfsigning/pdfsigning.cxx21
-rw-r--r--xmlsecurity/qa/unit/signing/signing.cxx56
12 files changed, 88 insertions, 66 deletions
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
index 95e58ffe5b92..95e58ffe5b92 100644
--- a/xmlsecurity/qa/unit/signing/data/cert8.db
+++ b/test/signing-keys/cert8.db
Binary files differ
diff --git a/xmlsecurity/qa/unit/signing/data/key3.db b/test/signing-keys/key3.db
index f449e60a667f..f449e60a667f 100644
--- a/xmlsecurity/qa/unit/signing/data/key3.db
+++ b/test/signing-keys/key3.db
Binary files differ
diff --git a/xmlsecurity/qa/unit/signing/data/pubring.gpg b/test/signing-keys/pubring.gpg
index 007ea98afd55..007ea98afd55 100644
--- a/xmlsecurity/qa/unit/signing/data/pubring.gpg
+++ b/test/signing-keys/pubring.gpg
Binary files differ
diff --git a/xmlsecurity/qa/unit/signing/data/random_seed b/test/signing-keys/random_seed
index 8e68109a880e..8e68109a880e 100644
--- a/xmlsecurity/qa/unit/signing/data/random_seed
+++ b/test/signing-keys/random_seed
diff --git a/xmlsecurity/qa/unit/signing/data/secring.gpg b/test/signing-keys/secring.gpg
index f7626df5aee3..f7626df5aee3 100644
--- a/xmlsecurity/qa/unit/signing/data/secring.gpg
+++ b/test/signing-keys/secring.gpg
Binary files differ
diff --git a/xmlsecurity/qa/unit/signing/data/trustdb.gpg b/test/signing-keys/trustdb.gpg
index 1966b5374cfb..1966b5374cfb 100644
--- a/xmlsecurity/qa/unit/signing/data/trustdb.gpg
+++ b/test/signing-keys/trustdb.gpg
Binary files differ
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
--- a/xmlsecurity/qa/unit/pdfsigning/data/cert8.db
+++ /dev/null
Binary files 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
--- a/xmlsecurity/qa/unit/pdfsigning/data/key3.db
+++ /dev/null
Binary files 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();
}