xmlsecurity/CppunitTest_xmlsecurity_signing.mk | 1 xmlsecurity/qa/unit/signing/data/signature-forgery-cdh-lfh.docx |binary xmlsecurity/qa/unit/signing/signing.cxx | 27 ++++++++++ 3 files changed, 28 insertions(+)
New commits: commit 99a66089865188ac1466297df0155d8a44db0150 Author: Michael Stahl <[email protected]> AuthorDate: Wed Jul 3 18:00:38 2024 +0200 Commit: Michael Stahl <[email protected]> CommitDate: Thu Jan 29 16:16:15 2026 +0100 xmlsecurity: add unit test with docx that can only be opened with repair Change-Id: I4f705dd2124383a90b69d04d8b2de0e37f83a495 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170053 Tested-by: Michael Stahl <[email protected]> Reviewed-by: Michael Stahl <[email protected]> (cherry picked from commit 81e0b7e7c05d324fb77da7eda0d736fac5526b3e) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173628 Reviewed-by: Xisco Fauli <[email protected]> Tested-by: Jenkins (cherry picked from commit 1729a7fa059c52f12b342cd40ed55435e52bb5f2) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/198351 Reviewed-by: Michael Stahl <[email protected]> Tested-by: Jenkins CollaboraOffice <[email protected]> diff --git a/xmlsecurity/CppunitTest_xmlsecurity_signing.mk b/xmlsecurity/CppunitTest_xmlsecurity_signing.mk index 7339800107a7..37d1c2a7dea7 100644 --- a/xmlsecurity/CppunitTest_xmlsecurity_signing.mk +++ b/xmlsecurity/CppunitTest_xmlsecurity_signing.mk @@ -26,6 +26,7 @@ $(eval $(call gb_CppunitTest_use_libraries,xmlsecurity_signing, \ subsequenttest \ test \ tl \ + ucbhelper \ unotest \ utl \ vcl \ diff --git a/xmlsecurity/qa/unit/signing/data/signature-forgery-cdh-lfh.docx b/xmlsecurity/qa/unit/signing/data/signature-forgery-cdh-lfh.docx new file mode 100644 index 000000000000..532705ecf0b5 Binary files /dev/null and b/xmlsecurity/qa/unit/signing/data/signature-forgery-cdh-lfh.docx differ diff --git a/xmlsecurity/qa/unit/signing/signing.cxx b/xmlsecurity/qa/unit/signing/signing.cxx index d8518ece0f9b..27d6d1480cfe 100644 --- a/xmlsecurity/qa/unit/signing/signing.cxx +++ b/xmlsecurity/qa/unit/signing/signing.cxx @@ -20,6 +20,7 @@ #include <test/unoapixml_test.hxx> #include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/document/BrokenPackageRequest.hpp> #include <com/sun/star/embed/XStorage.hpp> #include <com/sun/star/embed/XTransactedObject.hpp> #include <com/sun/star/frame/Desktop.hpp> @@ -50,6 +51,7 @@ #include <biginteger.hxx> #include <certificate.hxx> #include <xsecctl.hxx> +#include <ucbhelper/interceptedinteraction.hxx> #include <sfx2/docfile.hxx> #include <sfx2/docfilt.hxx> #include <officecfg/Office/Common.hxx> @@ -1175,6 +1177,31 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testODFUntrustedGoodGPG) SignatureState::NOTVALIDATED, nActual); } +CPPUNIT_TEST_FIXTURE(SigningTest, testInvalidZIP) +{ + // set RepairPackage via interaction handler, same as soffice does + // - if it's passed to load the behavior is different, oddly enough. + std::vector<::ucbhelper::InterceptedInteraction::InterceptedRequest> interceptions{ + { css::uno::Any(css::document::BrokenPackageRequest()), + cppu::UnoType<css::task::XInteractionApprove>::get(), 0 }, + }; + ::rtl::Reference<ucbhelper::InterceptedInteraction> pIH(new ucbhelper::InterceptedInteraction); + pIH->setInterceptions(std::move(interceptions)); + + uno::Sequence<beans::PropertyValue> args = { comphelper::makePropertyValue( + "InteractionHandler", uno::Reference<task::XInteractionHandler>(pIH)) }; + loadWithParams(createFileURL(u"signature-forgery-cdh-lfh.docx"), args); + SfxBaseModel* pBaseModel = dynamic_cast<SfxBaseModel*>(mxComponent.get()); + CPPUNIT_ASSERT(pBaseModel); + SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell(); + CPPUNIT_ASSERT(pObjectShell); + // the problem was that the document Zip structure is interpreted + // misleadingly in RepairPackage case, but signature was still returned + // as partially valid. + CPPUNIT_ASSERT_EQUAL(static_cast<int>(SignatureState::BROKEN), + static_cast<int>(pObjectShell->GetDocumentSignatureState())); +} + /// Test a typical broken ODF signature where one stream is corrupted. CPPUNIT_TEST_FIXTURE(SigningTest, testODFBrokenStreamGPG) {
