diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2020-06-19 17:56:54 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2020-06-29 09:10:45 +0200 |
commit | bd9bb7c4f1d64404743d42b813fe59fff5ec9abd (patch) | |
tree | 818f10606bf1450aa8d2bc3896a39885bf943393 /unotest | |
parent | 5b7b7731a2d1941d39cd10c0b12dab427d2cea07 (diff) |
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@gmail.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'unotest')
-rw-r--r-- | unotest/source/cpp/macros_test.cxx | 64 |
1 files changed, 64 insertions, 0 deletions
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: */ |