summaryrefslogtreecommitdiff
path: root/xmlsecurity
diff options
context:
space:
mode:
authorSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>2020-05-07 12:03:48 +0200
committerThorsten Behrens <Thorsten.Behrens@CIB.de>2020-06-26 17:01:10 +0200
commit8772658ddea8a8c1e405a87c13078eb8efb252d7 (patch)
tree61dd4c0a4648fb72c2bd7db3feac95fac021980c /xmlsecurity
parenta0b9a10f720a51b6c06fceb1bee031cc3e060fb1 (diff)
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@cib.de> (cherry picked from commit 29cb36cbee9c3ff5e73bc7a6d6a2f365c5c62da7)
Diffstat (limited to 'xmlsecurity')
-rw-r--r--xmlsecurity/qa/unit/signing/data/odb_signed_macros.odbbin0 -> 8823 bytes
-rw-r--r--xmlsecurity/qa/unit/signing/signing.cxx47
2 files changed, 47 insertions, 0 deletions
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
--- /dev/null
+++ b/xmlsecurity/qa/unit/signing/data/odb_signed_macros.odb
Binary files 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.