[Libreoffice-commits] core.git: Branch 'distro/cib/libreoffice-6-1' - dbaccess/source xmlsecurity/qa
Samuel Mehrbrodt (via logerrit)
logerrit at kemper.freedesktop.org
Fri Jun 26 15:02:19 UTC 2020
dbaccess/source/core/dataaccess/ModelImpl.cxx | 11 ++-
xmlsecurity/qa/unit/signing/data/odb_signed_macros.odb |binary
xmlsecurity/qa/unit/signing/signing.cxx | 47 +++++++++++++++++
3 files changed, 54 insertions(+), 4 deletions(-)
New commits:
commit 8772658ddea8a8c1e405a87c13078eb8efb252d7
Author: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
AuthorDate: Thu May 7 12:03:48 2020 +0200
Commit: Thorsten Behrens <Thorsten.Behrens at CIB.de>
CommitDate: Fri Jun 26 17:01:10 2020 +0200
tdf#97694 Add test for macro signature preservation in Base
Change-Id: I35fb8d499eed66f9a5e208a4778a1f0f12637079
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93630
Tested-by: Jenkins
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
(cherry picked from commit 29cb36cbee9c3ff5e73bc7a6d6a2f365c5c62da7)
diff --git a/dbaccess/source/core/dataaccess/ModelImpl.cxx b/dbaccess/source/core/dataaccess/ModelImpl.cxx
index 95ea39859301..905ec511fc2c 100644
--- a/dbaccess/source/core/dataaccess/ModelImpl.cxx
+++ b/dbaccess/source/core/dataaccess/ModelImpl.cxx
@@ -863,14 +863,17 @@ bool ODatabaseModelImpl::commitStorageIfWriteable_ignoreErrors( const Reference<
aTempFile.EnableKillingFile();
OUString sTmpFileUrl = aTempFile.GetURL();
SignatureState aSignatureState = getScriptingSignatureState();
- if (aSignatureState == SignatureState::OK
- || aSignatureState == SignatureState::NOTVALIDATED
- || aSignatureState == SignatureState::INVALID)
+ OUString sLocation = getDocFileLocation();
+ bool bIsEmbedded = sLocation.startsWith("vnd.sun.star.pkg:") && sLocation.endsWith("/EmbeddedDatabase");
+ if (!bIsEmbedded && !sLocation.isEmpty()
+ && (aSignatureState == SignatureState::OK || aSignatureState == SignatureState::NOTVALIDATED
+ || aSignatureState == SignatureState::INVALID
+ || aSignatureState == SignatureState::UNKNOWN))
{
bTryToPreserveScriptSignature = true;
// We need to first save the file (which removes the macro signature), then add the macro signature again.
// For that, we need a temporary copy of the original file.
- osl::File::RC rc = osl::File::copy(getDocFileLocation(), sTmpFileUrl);
+ osl::File::RC rc = osl::File::copy(sLocation, sTmpFileUrl);
if (rc != osl::FileBase::E_None)
throw uno::RuntimeException("Could not create temp file");
}
diff --git a/xmlsecurity/qa/unit/signing/data/odb_signed_macros.odb b/xmlsecurity/qa/unit/signing/data/odb_signed_macros.odb
new file mode 100644
index 000000000000..3e90f4514599
Binary files /dev/null and b/xmlsecurity/qa/unit/signing/data/odb_signed_macros.odb differ
diff --git a/xmlsecurity/qa/unit/signing/signing.cxx b/xmlsecurity/qa/unit/signing/signing.cxx
index a3142a015000..3876a19b566b 100644
--- a/xmlsecurity/qa/unit/signing/signing.cxx
+++ b/xmlsecurity/qa/unit/signing/signing.cxx
@@ -123,6 +123,7 @@ public:
void testPreserveMacroTemplateSignature12();
void testDropMacroTemplateSignature();
void testPreserveMacroTemplateSignature10();
+ void testPreserveMacroSignatureODB();
CPPUNIT_TEST_SUITE(SigningTest);
CPPUNIT_TEST(testDescription);
@@ -159,6 +160,7 @@ public:
CPPUNIT_TEST(testPreserveMacroTemplateSignature12);
CPPUNIT_TEST(testDropMacroTemplateSignature);
CPPUNIT_TEST(testPreserveMacroTemplateSignature10);
+ CPPUNIT_TEST(testPreserveMacroSignatureODB);
CPPUNIT_TEST_SUITE_END();
private:
@@ -250,6 +252,51 @@ uno::Reference<security::XCertificate> SigningTest::getCertificate(DocumentSigna
return uno::Reference<security::XCertificate>();
}
+void SigningTest::testPreserveMacroSignatureODB()
+{
+ const OUString aURL(m_directories.getURLFromSrc(DATA_DIRECTORY) + "odb_signed_macros.odb");
+ const OUString sLoadMessage = "loading failed: " + aURL;
+
+ // load the file
+ if (mxComponent.is())
+ mxComponent->dispose();
+ mxComponent = loadFromDesktop(aURL, "com.sun.star.sdb.OfficeDatabaseDocument");
+ CPPUNIT_ASSERT_MESSAGE(OUStringToOString(sLoadMessage, RTL_TEXTENCODING_UTF8).getStr(),
+ mxComponent.is());
+
+ // save as ODB
+ utl::TempFile aTempFileSaveAsODB;
+ aTempFileSaveAsODB.EnableKillingFile();
+ try
+ {
+ uno::Reference<frame::XStorable> xDocStorable(mxComponent, uno::UNO_QUERY);
+ uno::Sequence<beans::PropertyValue> descSaveAs(comphelper::InitPropertySequence(
+ { { "FilterName", uno::Any(OUString("StarOffice XML (Base)")) } }));
+ xDocStorable->storeAsURL(aTempFileSaveAsODB.GetURL(), descSaveAs);
+ }
+ catch (...)
+ {
+ CPPUNIT_FAIL("Failed to save ODB file");
+ }
+
+ // Parse the resulting XML.
+ uno::Reference<embed::XStorage> xStorage
+ = comphelper::OStorageHelper::GetStorageOfFormatFromURL(
+ ZIP_STORAGE_FORMAT_STRING, aTempFileSaveAsODB.GetURL(), embed::ElementModes::READ);
+ CPPUNIT_ASSERT(xStorage.is());
+ uno::Reference<embed::XStorage> xMetaInf
+ = xStorage->openStorageElement("META-INF", embed::ElementModes::READ);
+ uno::Reference<io::XInputStream> xInputStream(
+ xMetaInf->openStreamElement("macrosignatures.xml", embed::ElementModes::READ),
+ uno::UNO_QUERY);
+ std::unique_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(xInputStream, true));
+ xmlDocPtr pXmlDoc = parseXmlStream(pStream.get());
+
+ // Make sure the signature is still there
+ assertXPath(pXmlDoc, "//dsig:Signature", "Id",
+ "ID_00a7002f009000bc00ce00f7004400460080002f002e00e400e0003700df00e8");
+}
+
void SigningTest::testDescription()
{
// Create an empty document and store it to a tempfile, finally load it as a storage.
More information about the Libreoffice-commits
mailing list