include/unotest/macros_test.hxx | 1 + unotest/source/cpp/macros_test.cxx | 12 +++++++----- xmlsecurity/qa/unit/signing/signing.cxx | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-)
New commits: commit 9888bb3dbb7ca558e0b440314bdb24bc60843bb0 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Tue Mar 1 11:50:29 2022 +0300 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Tue Mar 1 15:17:55 2022 +0100 Fix the test failing when invalid certificate is in cert store testSigningMultipleTimes_ODT was failing for me locally because of an expired certificate present in my store. Change-Id: Ie3dfb9ee1a110259ba747a03fc28c205df2eea91 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130743 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/include/unotest/macros_test.hxx b/include/unotest/macros_test.hxx index c6c810ad108b..6a476cf0ec40 100644 --- a/include/unotest/macros_test.hxx +++ b/include/unotest/macros_test.hxx @@ -93,6 +93,7 @@ public: void setUpNssGpg(const test::Directories& rDirectories, const OUString& rTestName); void tearDownNssGpg(); + static bool IsValid(const css::uno::Reference<css::security::XCertificate>& cert); static css::uno::Reference<css::security::XCertificate> GetValidCertificate( const css::uno::Sequence<css::uno::Reference<css::security::XCertificate>>& certs); diff --git a/unotest/source/cpp/macros_test.cxx b/unotest/source/cpp/macros_test.cxx index 81738dc6dafe..f30cbcdac3ea 100644 --- a/unotest/source/cpp/macros_test.cxx +++ b/unotest/source/cpp/macros_test.cxx @@ -172,14 +172,16 @@ void MacrosTest::tearDownNssGpg() #endif } +bool MacrosTest::IsValid(const css::uno::Reference<css::security::XCertificate>& cert) +{ + return DateTime(DateTime::SYSTEM) + .IsBetween(cert->getNotValidBefore(), cert->getNotValidAfter()); +} + css::uno::Reference<css::security::XCertificate> MacrosTest::GetValidCertificate( const css::uno::Sequence<css::uno::Reference<css::security::XCertificate>>& certs) { - auto it - = std::find_if(certs.begin(), certs.end(), [now = DateTime(DateTime::SYSTEM)](auto& xCert) { - return now.IsBetween(xCert->getNotValidBefore(), xCert->getNotValidAfter()); - }); - if (it != certs.end()) + if (auto it = std::find_if(certs.begin(), certs.end(), IsValid); it != certs.end()) return *it; return {}; } diff --git a/xmlsecurity/qa/unit/signing/signing.cxx b/xmlsecurity/qa/unit/signing/signing.cxx index 38643a0b3098..90d0edf8973e 100644 --- a/xmlsecurity/qa/unit/signing/signing.cxx +++ b/xmlsecurity/qa/unit/signing/signing.cxx @@ -159,7 +159,7 @@ SigningTest::getCertificate(DocumentSignatureManager& rSignatureManager, { auto pCertificate = dynamic_cast<xmlsecurity::Certificate*>(xCertificate.get()); CPPUNIT_ASSERT(pCertificate); - if (pCertificate->getSignatureMethodAlgorithm() == eAlgo) + if (pCertificate->getSignatureMethodAlgorithm() == eAlgo && IsValid(xCertificate)) return xCertificate; } return uno::Reference<security::XCertificate>();