vcl/qa/cppunit/pdfexport/pdfexport2.cxx | 1 xmlsecurity/qa/unit/signing/signing.cxx | 218 +++++++++++++++++--------------- 2 files changed, 120 insertions(+), 99 deletions(-)
New commits: commit 238f8496f9c51565560ab8a45cf6c15b3a8eb17d Author: Xisco Fauli <[email protected]> AuthorDate: Mon Feb 16 18:21:57 2026 +0100 Commit: Xisco Fauli <[email protected]> CommitDate: Tue Feb 17 08:34:31 2026 +0100 vcl, xmlsecurity: only load one document per test Change-Id: If62baa2b3650950fec5b78a4472c4ee5151fe954 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199497 Tested-by: Jenkins Reviewed-by: Xisco Fauli <[email protected]> diff --git a/vcl/qa/cppunit/pdfexport/pdfexport2.cxx b/vcl/qa/cppunit/pdfexport/pdfexport2.cxx index 15aabda2f2bd..4cf9cafce23a 100644 --- a/vcl/qa/cppunit/pdfexport/pdfexport2.cxx +++ b/vcl/qa/cppunit/pdfexport/pdfexport2.cxx @@ -6070,6 +6070,7 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest2, testPDFAttachmentsWithEncryptedFile) aOutputStream.WriteBytes(aBuffer.data(), aBuffer.size()); } + dispose(); // Load the attached document from the temp file UnoApiTest::loadFromURL(aTempFile.GetURL()); diff --git a/xmlsecurity/qa/unit/signing/signing.cxx b/xmlsecurity/qa/unit/signing/signing.cxx index f78c06d259df..68a5520a4903 100644 --- a/xmlsecurity/qa/unit/signing/signing.cxx +++ b/xmlsecurity/qa/unit/signing/signing.cxx @@ -78,6 +78,9 @@ public: virtual void tearDown() override; void registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx) override; + void testPreserveMacroTemplateSignature12(TestFilter eFilterName); + void testPreserveMacroTemplateSignature10(TestFilter eFilterName); + protected: uno::Reference<security::XCertificate> getCertificate(DocumentSignatureManager& rSignatureManager, @@ -1040,6 +1043,7 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testSigningMultipleTimes_ODT) Scheduler::ProcessEventsToIdle(); + dispose(); loadFromURL(maTempFile.GetURL()); SfxBaseModel* pBaseModel = dynamic_cast<SfxBaseModel*>(mxComponent.get()); @@ -1113,6 +1117,7 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testSigningMultipleTimes_OOXML) Scheduler::ProcessEventsToIdle(); + dispose(); loadFromURL(maTempFile.GetURL()); SfxBaseModel* pBaseModel = dynamic_cast<SfxBaseModel*>(mxComponent.get()); @@ -1336,7 +1341,7 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testODFBrokenDsigGPG) #if HAVE_GPGCONF_SOCKETDIR /// Test loading an encrypted ODF document -CPPUNIT_TEST_FIXTURE(SigningTest, testODFEncryptedGPG) +CPPUNIT_TEST_FIXTURE(SigningTest, testODFEncryptedGPG_12) { // ODF1.2 + loext flavour loadFromFile(u"encryptedGPG.odt"); @@ -1344,12 +1349,15 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testODFEncryptedGPG) CPPUNIT_ASSERT(pBaseModel); SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell(); CPPUNIT_ASSERT(pObjectShell); +} +CPPUNIT_TEST_FIXTURE(SigningTest, testODFEncryptedGPG_13) +{ // ODF1.3 flavour loadFromFile(u"encryptedGPG_odf13.odt"); - pBaseModel = dynamic_cast<SfxBaseModel*>(mxComponent.get()); + SfxBaseModel* pBaseModel = dynamic_cast<SfxBaseModel*>(mxComponent.get()); CPPUNIT_ASSERT(pBaseModel); - pObjectShell = pBaseModel->GetObjectShell(); + SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell(); CPPUNIT_ASSERT(pObjectShell); // export and import again @@ -1392,77 +1400,76 @@ SfxObjectShell* SigningTest::assertDocument(const ::CppUnit::SourceLine aSrcLine } /// Test if a macro signature from a OTT 1.2 template is preserved for ODT 1.2 -CPPUNIT_TEST_FIXTURE(SigningTest, testPreserveMacroTemplateSignature12_ODF) +void SigningTest::testPreserveMacroTemplateSignature12(TestFilter eFilterName) { - const TestFilter aFormats[] = { TestFilter::ODT, TestFilter::OTT }; + const OUString aURL(createFileURL(u"tdf42316_odt12.ott")); + const OUString sLoadMessage = "loading failed: " + aURL; - for (TestFilter eFormat : aFormats) - { - const OUString aURL(createFileURL(u"tdf42316_odt12.ott")); - const OUString sLoadMessage = "loading failed: " + aURL; + // create new document from template + loadFromURL(aURL); + CPPUNIT_ASSERT_MESSAGE(OUStringToOString(sLoadMessage, RTL_TEXTENCODING_UTF8).getStr(), + mxComponent.is()); - // load the template as-is to validate signatures - loadFromURL(aURL, comphelper::InitPropertySequence({ { "AsTemplate", uno::Any(false) } })); + // we are somehow a template (?), and have just a valid macro signature + assertDocument(CPPUNIT_SOURCELINE(), TestFilter::OTT, SignatureState::NOSIGNATURES, + SignatureState::OK, ODFVER_012_TEXT); - // we are a template, and have a valid document and macro signature - assertDocument(CPPUNIT_SOURCELINE(), TestFilter::OTT, SignatureState::OK, - SignatureState::OK, ODFVER_012_TEXT); + // FIXME: Error: element "document-signatures" is missing "version" attribute + skipValidation(); - // create new document from template - loadFromURL(aURL); - CPPUNIT_ASSERT_MESSAGE(OUStringToOString(sLoadMessage, RTL_TEXTENCODING_UTF8).getStr(), - mxComponent.is()); + if (eFilterName == TestFilter::ODT) + // save as new ODT document + saveAndReload(eFilterName); + else + { + // save as new OTT template + // load the saved OTT template as-is to validate signatures + saveAndReload(eFilterName, + comphelper::InitPropertySequence({ { "AsTemplate", uno::Any(false) } })); + } - // we are somehow a template (?), and have just a valid macro signature - assertDocument(CPPUNIT_SOURCELINE(), TestFilter::OTT, SignatureState::NOSIGNATURES, - SignatureState::OK, ODFVER_012_TEXT); + // the loaded document is a OTT/ODT with a macro signature + assertDocument(CPPUNIT_SOURCELINE(), eFilterName, SignatureState::NOSIGNATURES, + SignatureState::OK, ODFVER_014_TEXT); - // FIXME: Error: element "document-signatures" is missing "version" attribute - skipValidation(); + // save as new OTT template + // load the template as-is to validate signatures + saveAndReload(TestFilter::OTT, + comphelper::InitPropertySequence({ { "AsTemplate", uno::Any(false) } })); - if (eFormat == TestFilter::ODT) - // save as new ODT document - saveAndReload(eFormat); - else - { - // save as new OTT template - save(eFormat); + // the loaded document is a OTT with a valid macro signature + assertDocument(CPPUNIT_SOURCELINE(), TestFilter::OTT, SignatureState::NOSIGNATURES, + SignatureState::OK, ODFVER_014_TEXT); +} - // load the saved OTT template as-is to validate signatures - loadFromURL(maTempFile.GetURL(), - comphelper::InitPropertySequence({ { "AsTemplate", uno::Any(false) } })); - } +CPPUNIT_TEST_FIXTURE(SigningTest, testPreserveMacroTemplateSignature12_Template) +{ + const OUString aURL(createFileURL(u"tdf42316_odt12.ott")); - // the loaded document is a OTT/ODT with a macro signature - assertDocument(CPPUNIT_SOURCELINE(), eFormat, SignatureState::NOSIGNATURES, - SignatureState::OK, ODFVER_014_TEXT); + // load the template as-is to validate signatures + loadFromURL(aURL, comphelper::InitPropertySequence({ { "AsTemplate", uno::Any(false) } })); - // save as new OTT template - save(TestFilter::OTT); + // we are a template, and have a valid document and macro signature + assertDocument(CPPUNIT_SOURCELINE(), TestFilter::OTT, SignatureState::OK, SignatureState::OK, + ODFVER_012_TEXT); +} - // load the template as-is to validate signatures - loadFromURL(maTempFile.GetURL(), - comphelper::InitPropertySequence({ { "AsTemplate", uno::Any(false) } })); +CPPUNIT_TEST_FIXTURE(SigningTest, testPreserveMacroTemplateSignature12_ODT) +{ + testPreserveMacroTemplateSignature12(TestFilter::ODT); +} - // the loaded document is a OTT with a valid macro signature - assertDocument(CPPUNIT_SOURCELINE(), TestFilter::OTT, SignatureState::NOSIGNATURES, - SignatureState::OK, ODFVER_014_TEXT); - } +CPPUNIT_TEST_FIXTURE(SigningTest, testPreserveMacroTemplateSignature12_OTT) +{ + testPreserveMacroTemplateSignature12(TestFilter::OTT); } /// Test if a macro signature from an OTT 1.0 is dropped for ODT 1.2 -CPPUNIT_TEST_FIXTURE(SigningTest, testDropMacroTemplateSignature) +CPPUNIT_TEST_FIXTURE(SigningTest, testDropMacroTemplateSignature_document) { const OUString aURL(createFileURL(u"tdf42316.ott")); const OUString sLoadMessage = "loading failed: " + aURL; - // load the template as-is to validate signatures - loadFromURL(aURL, comphelper::InitPropertySequence({ { "AsTemplate", uno::Any(false) } })); - - // we are a template, and have a non-invalid macro signature - assertDocument(CPPUNIT_SOURCELINE(), TestFilter::OTT, SignatureState::NOSIGNATURES, - SignatureState::NOTVALIDATED, OUString()); - // create new document from template loadFromURL(aURL); CPPUNIT_ASSERT_MESSAGE(OUStringToOString(sLoadMessage, RTL_TEXTENCODING_UTF8).getStr(), @@ -1478,6 +1485,11 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testDropMacroTemplateSignature) // the loaded document is a 1.2 ODT without any signatures assertDocument(CPPUNIT_SOURCELINE(), TestFilter::ODT, SignatureState::NOSIGNATURES, SignatureState::NOSIGNATURES, ODFVER_014_TEXT); +} + +CPPUNIT_TEST_FIXTURE(SigningTest, testDropMacroTemplateSignature_template) +{ + const OUString aURL(createFileURL(u"tdf42316.ott")); // load the template as-is to validate signatures loadFromURL(aURL, comphelper::InitPropertySequence({ { "AsTemplate", uno::Any(false) } })); @@ -1487,11 +1499,9 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testDropMacroTemplateSignature) SignatureState::NOTVALIDATED, OUString()); // save as new OTT template - save(TestFilter::OTT); - // load the template as-is to validate signatures - loadFromURL(maTempFile.GetURL(), - comphelper::InitPropertySequence({ { "AsTemplate", uno::Any(false) } })); + saveAndReload(TestFilter::OTT, + comphelper::InitPropertySequence({ { "AsTemplate", uno::Any(false) } })); // the loaded document is a 1.2 OTT without any signatures assertDocument(CPPUNIT_SOURCELINE(), TestFilter::OTT, SignatureState::NOSIGNATURES, @@ -1499,64 +1509,74 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testDropMacroTemplateSignature) } /// Test if a macro signature from a OTT 1.0 template is preserved for ODT 1.0 -CPPUNIT_TEST_FIXTURE(SigningTest, testPreserveMacroTemplateSignature10) +void SigningTest::testPreserveMacroTemplateSignature10(TestFilter eFilterName) { // set ODF version 1.0 / 1.1 as default comphelper::ScopeGuard g([]() { SetODFDefaultVersion(SvtSaveOptions::ODFVER_LATEST); }); SetODFDefaultVersion(SvtSaveOptions::ODFVER_011); - const TestFilter aFormats[] = { TestFilter::ODT, TestFilter::OTT }; + const OUString aURL(createFileURL(u"tdf42316.ott")); + const OUString sLoadMessage = "loading failed: " + aURL; - for (TestFilter eFormat : aFormats) - { - const OUString aURL(createFileURL(u"tdf42316.ott")); - const OUString sLoadMessage = "loading failed: " + aURL; + // create new document from template + loadFromURL(aURL); + CPPUNIT_ASSERT_MESSAGE(OUStringToOString(sLoadMessage, RTL_TEXTENCODING_UTF8).getStr(), + mxComponent.is()); + + // we are somehow a template (?), and have just a valid macro signature + assertDocument(CPPUNIT_SOURCELINE(), TestFilter::OTT, SignatureState::NOSIGNATURES, + SignatureState::NOTVALIDATED, OUString()); - // load the template as-is to validate signatures - loadFromURL(aURL, comphelper::InitPropertySequence({ { "AsTemplate", uno::Any(false) } })); + // FIXME: Error: element "manifest:manifest" is missing "version" attribute + skipValidation(); - // we are a template, and have a non-invalid macro signature - assertDocument(CPPUNIT_SOURCELINE(), TestFilter::OTT, SignatureState::NOSIGNATURES, - SignatureState::NOTVALIDATED, OUString()); + if (eFilterName == TestFilter::ODT) + // save as new ODT document + saveAndReload(eFilterName); + else + { + // save as new OTT template + // load the saved OTT template as-is to validate signatures + saveAndReload(TestFilter::OTT, + comphelper::InitPropertySequence({ { "AsTemplate", uno::Any(false) } })); + } - // create new document from template - loadFromURL(aURL); - CPPUNIT_ASSERT_MESSAGE(OUStringToOString(sLoadMessage, RTL_TEXTENCODING_UTF8).getStr(), - mxComponent.is()); + assertDocument(CPPUNIT_SOURCELINE(), eFilterName, SignatureState::NOSIGNATURES, + SignatureState::NOTVALIDATED, OUString()); - // we are somehow a template (?), and have just a valid macro signature - assertDocument(CPPUNIT_SOURCELINE(), TestFilter::OTT, SignatureState::NOSIGNATURES, - SignatureState::NOTVALIDATED, OUString()); + // load the template as-is to validate signatures + saveAndReload(TestFilter::OTT, + comphelper::InitPropertySequence({ { "AsTemplate", uno::Any(false) } })); - // FIXME: Error: element "manifest:manifest" is missing "version" attribute - skipValidation(); + // the loaded document is a OTT with a non-invalid macro signature + assertDocument(CPPUNIT_SOURCELINE(), TestFilter::OTT, SignatureState::NOSIGNATURES, + SignatureState::NOTVALIDATED, OUString()); +} - if (eFormat == TestFilter::ODT) - // save as new ODT document - saveAndReload(eFormat); - else - { - // save as new OTT template - save(TestFilter::OTT); +CPPUNIT_TEST_FIXTURE(SigningTest, testPreserveMacroTemplateSignature10_Template) +{ + // set ODF version 1.0 / 1.1 as default + comphelper::ScopeGuard g([]() { SetODFDefaultVersion(SvtSaveOptions::ODFVER_LATEST); }); + SetODFDefaultVersion(SvtSaveOptions::ODFVER_011); - // load the saved OTT template as-is to validate signatures - loadFromURL(maTempFile.GetURL(), - comphelper::InitPropertySequence({ { "AsTemplate", uno::Any(false) } })); - } + const OUString aURL(createFileURL(u"tdf42316.ott")); - assertDocument(CPPUNIT_SOURCELINE(), eFormat, SignatureState::NOSIGNATURES, - SignatureState::NOTVALIDATED, OUString()); + // load the template as-is to validate signatures + loadFromURL(aURL, comphelper::InitPropertySequence({ { "AsTemplate", uno::Any(false) } })); - save(TestFilter::OTT); + // we are a template, and have a non-invalid macro signature + assertDocument(CPPUNIT_SOURCELINE(), TestFilter::OTT, SignatureState::NOSIGNATURES, + SignatureState::NOTVALIDATED, OUString()); +} - // load the template as-is to validate signatures - loadFromURL(maTempFile.GetURL(), - comphelper::InitPropertySequence({ { "AsTemplate", uno::Any(false) } })); +CPPUNIT_TEST_FIXTURE(SigningTest, testPreserveMacroTemplateSignature10_ODT) +{ + testPreserveMacroTemplateSignature10(TestFilter::ODT); +} - // the loaded document is a OTT with a non-invalid macro signature - assertDocument(CPPUNIT_SOURCELINE(), TestFilter::OTT, SignatureState::NOSIGNATURES, - SignatureState::NOTVALIDATED, OUString()); - } +CPPUNIT_TEST_FIXTURE(SigningTest, testPreserveMacroTemplateSignature10_OTT) +{ + testPreserveMacroTemplateSignature10(TestFilter::OTT); } #endif
