[Libreoffice-commits] core.git: Branch 'libreoffice-6-3' - sfx2/source xmlsecurity/qa
Jan-Marek Glogowski (via logerrit)
logerrit at kemper.freedesktop.org
Thu Oct 17 08:53:24 UTC 2019
sfx2/source/doc/objstor.cxx | 15 +-
xmlsecurity/qa/unit/signing/signing.cxx | 181 ++++++++++++++++++++++++++++----
2 files changed, 174 insertions(+), 22 deletions(-)
New commits:
commit 7b405877b0fa0145513ac0294ab51cf57e6108c6
Author: Jan-Marek Glogowski <jan-marek.glogowski at extern.cib.de>
AuthorDate: Fri Oct 11 13:09:59 2019 +0200
Commit: Michael Stahl <michael.stahl at cib.de>
CommitDate: Thu Oct 17 10:52:45 2019 +0200
tdf#42316 handle saving to template filters
This extends the filter comparison from commit c3a1c83ff5af
("tdf#42316 preserve macro signature of templates").
The original patch just stripped "_template" from the source
filter to find equal document types, which just enables the
"template => document" case. This patch also strips the
"_template" from the target filter, which fixes the "document
or template => template" cases.
This also extends the signing save tests:
* OTT 1.2 => OTT 1.2 - preserve
* ODT 1.2 => OTT 1.2 - preserve
* OTT 1.0 => OTT 1.0 - preserve
* ODT 1.0 => OTT 1.0 - preserve
* OTT 1.0 => OTT 1.2 - drop
Change-Id: Ie297258a4d9f9aa4beb25786c6ba240b6f16f49b
Reviewed-on: https://gerrit.libreoffice.org/80654
Tested-by: Jenkins
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
(cherry picked from commit 4aa6e2cb2245eddab87fb451add94159a7604246)
Reviewed-on: https://gerrit.libreoffice.org/80910
Reviewed-by: Michael Stahl <michael.stahl at cib.de>
diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx
index 651258d1fdec..b3092cd1cce8 100644
--- a/sfx2/source/doc/objstor.cxx
+++ b/sfx2/source/doc/objstor.cxx
@@ -1091,6 +1091,15 @@ private:
};
}
+static OUString lcl_strip_template(const OUString &aString)
+{
+ static const OUString sPostfix("_template");
+ OUString sRes(aString);
+ if (sRes.endsWith(sPostfix))
+ sRes = sRes.copy(0, sRes.getLength() - sPostfix.getLength());
+ return sRes;
+}
+
bool SfxObjectShell::SaveTo_Impl
(
SfxMedium &rMedium, // Medium, in which it will be stored
@@ -1170,10 +1179,8 @@ bool SfxObjectShell::SaveTo_Impl
// preserve only if the same filter has been used
// for templates, strip the _template from the filter name for comparison
- OUString aMediumFilter = pMedium->GetFilter()->GetFilterName();
- if (aMediumFilter.endsWith("_template"))
- aMediumFilter = aMediumFilter.copy(0, aMediumFilter.getLength() - 9);
- bTryToPreserveScriptSignature = pMedium->GetFilter() && pFilter && aMediumFilter == pFilter->GetFilterName();
+ const OUString aMediumFilter = lcl_strip_template(pMedium->GetFilter()->GetFilterName());
+ bTryToPreserveScriptSignature = pMedium->GetFilter() && pFilter && aMediumFilter == lcl_strip_template(pFilter->GetFilterName());
// signatures were specified in ODF 1.2 but were used since much longer.
// LO will still correctly validate an old style signature on an ODF 1.2
diff --git a/xmlsecurity/qa/unit/signing/signing.cxx b/xmlsecurity/qa/unit/signing/signing.cxx
index 5eeefc56b3c0..4225f92eacf5 100644
--- a/xmlsecurity/qa/unit/signing/signing.cxx
+++ b/xmlsecurity/qa/unit/signing/signing.cxx
@@ -996,7 +996,7 @@ 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)
+CPPUNIT_TEST_FIXTURE(SigningTest, testPreserveMacroTemplateSignature12_ODF)
{
const OUString aURL(m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf42316_odt12.ott");
const OUString sLoadMessage = "loading failed: " + aURL;
@@ -1010,12 +1010,12 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testPreserveMacroTemplateSignature12)
// we are a template, and have a valid document and macro signature
assertDocument(CPPUNIT_SOURCELINE(), "writer8_template", SignatureState::OK, SignatureState::OK,
ODFVER_012_TEXT);
- mxComponent->dispose();
// create new document from template
// we can't use createDoc / MacrosTest::loadFromDesktop, because ALWAYS_EXECUTE_NO_WARN
// won't verify the signature for templates, so the resulting document won't be able to
// preserve the templates signature.
+ mxComponent->dispose();
mxComponent = mxDesktop->loadComponentFromURL(
aURL, "_default", 0,
comphelper::InitPropertySequence(
@@ -1029,26 +1029,80 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testPreserveMacroTemplateSignature12)
SignatureState::OK, ODFVER_012_TEXT);
// save as new ODT document
- utl::TempFile aTempFileSaveAs;
- aTempFileSaveAs.EnableKillingFile();
+ utl::TempFile aTempFileSaveAsODT;
+ aTempFileSaveAsODT.EnableKillingFile();
try
{
uno::Reference<frame::XStorable> xDocStorable(mxComponent, uno::UNO_QUERY);
uno::Sequence<beans::PropertyValue> descSaveAs(
comphelper::InitPropertySequence({ { "FilterName", uno::Any(OUString("writer8")) } }));
- xDocStorable->storeAsURL(aTempFileSaveAs.GetURL(), descSaveAs);
+ xDocStorable->storeAsURL(aTempFileSaveAsODT.GetURL(), descSaveAs);
}
catch (...)
{
CPPUNIT_FAIL("Failed to save ODT document");
}
- // load saved document
- createDoc(aTempFileSaveAs.GetURL());
+ // save as new OTT template
+ utl::TempFile aTempFileSaveAsOTT;
+ aTempFileSaveAsOTT.EnableKillingFile();
+ try
+ {
+ uno::Reference<frame::XStorable> xDocStorable(mxComponent, uno::UNO_QUERY);
+ uno::Sequence<beans::PropertyValue> descSaveAs(comphelper::InitPropertySequence(
+ { { "FilterName", uno::Any(OUString("writer8_template")) } }));
+ xDocStorable->storeAsURL(aTempFileSaveAsOTT.GetURL(), descSaveAs);
+ }
+ catch (...)
+ {
+ CPPUNIT_FAIL("Failed to save OTT template");
+ }
+
+ // load the saved OTT template as-is to validate signatures
+ mxComponent->dispose();
+ mxComponent
+ = loadFromDesktop(aTempFileSaveAsOTT.GetURL(), OUString(),
+ comphelper::InitPropertySequence({ { "AsTemplate", uno::Any(false) } }));
+ CPPUNIT_ASSERT_MESSAGE(OUStringToOString(sLoadMessage, RTL_TEXTENCODING_UTF8).getStr(),
+ mxComponent.is());
+
+ // the loaded document is a OTT with a valid macro signature
+ assertDocument(CPPUNIT_SOURCELINE(), "writer8_template", SignatureState::NOSIGNATURES,
+ SignatureState::OK, ODFVER_012_TEXT);
+
+ // load saved ODT document
+ createDoc(aTempFileSaveAsODT.GetURL());
// the loaded document is a ODT with a macro signature
assertDocument(CPPUNIT_SOURCELINE(), "writer8", SignatureState::NOSIGNATURES,
SignatureState::OK, ODFVER_012_TEXT);
+
+ // save as new OTT template
+ utl::TempFile aTempFileSaveAsODT_OTT;
+ aTempFileSaveAsODT_OTT.EnableKillingFile();
+ try
+ {
+ uno::Reference<frame::XStorable> xDocStorable(mxComponent, uno::UNO_QUERY);
+ uno::Sequence<beans::PropertyValue> descSaveAs(comphelper::InitPropertySequence(
+ { { "FilterName", uno::Any(OUString("writer8_template")) } }));
+ xDocStorable->storeAsURL(aTempFileSaveAsODT_OTT.GetURL(), descSaveAs);
+ }
+ catch (...)
+ {
+ CPPUNIT_FAIL("Failed to save OTT template");
+ }
+
+ // load the template as-is to validate signatures
+ mxComponent->dispose();
+ mxComponent
+ = loadFromDesktop(aTempFileSaveAsODT_OTT.GetURL(), OUString(),
+ comphelper::InitPropertySequence({ { "AsTemplate", uno::Any(false) } }));
+ CPPUNIT_ASSERT_MESSAGE(OUStringToOString(sLoadMessage, RTL_TEXTENCODING_UTF8).getStr(),
+ mxComponent.is());
+
+ // the loaded document is a OTT with a valid macro signature
+ assertDocument(CPPUNIT_SOURCELINE(), "writer8_template", SignatureState::NOSIGNATURES,
+ SignatureState::OK, ODFVER_012_TEXT);
}
/// Test if a macro signature from an OTT 1.0 is dropped for ODT 1.2
@@ -1063,15 +1117,15 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testDropMacroTemplateSignature)
CPPUNIT_ASSERT_MESSAGE(OUStringToOString(sLoadMessage, RTL_TEXTENCODING_UTF8).getStr(),
mxComponent.is());
- // we are a template, and have a valid document and macro signature
+ // we are a template, and have a non-invalid macro signature
assertDocument(CPPUNIT_SOURCELINE(), "writer8_template", SignatureState::NOSIGNATURES,
SignatureState::NOTVALIDATED, OUString());
- mxComponent->dispose();
// create new document from template
// we can't use createDoc / MacrosTest::loadFromDesktop, because ALWAYS_EXECUTE_NO_WARN
// won't verify the signature for templates, so the resulting document won't be able to
// preserve the templates signature.
+ mxComponent->dispose();
mxComponent = mxDesktop->loadComponentFromURL(
aURL, "_default", 0,
comphelper::InitPropertySequence(
@@ -1105,6 +1159,44 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testDropMacroTemplateSignature)
// the loaded document is a 1.2 ODT without any signatures
assertDocument(CPPUNIT_SOURCELINE(), "writer8", SignatureState::NOSIGNATURES,
SignatureState::NOSIGNATURES, ODFVER_012_TEXT);
+
+ // load the template as-is to validate signatures
+ mxComponent->dispose();
+ mxComponent = loadFromDesktop(
+ aURL, OUString(), comphelper::InitPropertySequence({ { "AsTemplate", uno::Any(false) } }));
+ CPPUNIT_ASSERT_MESSAGE(OUStringToOString(sLoadMessage, RTL_TEXTENCODING_UTF8).getStr(),
+ mxComponent.is());
+
+ // we are a template, and have a non-invalid macro signature
+ assertDocument(CPPUNIT_SOURCELINE(), "writer8_template", SignatureState::NOSIGNATURES,
+ SignatureState::NOTVALIDATED, OUString());
+
+ // save as new OTT template
+ utl::TempFile aTempFileSaveAsOTT;
+ aTempFileSaveAsOTT.EnableKillingFile();
+ try
+ {
+ uno::Reference<frame::XStorable> xDocStorable(mxComponent, uno::UNO_QUERY);
+ uno::Sequence<beans::PropertyValue> descSaveAs(comphelper::InitPropertySequence(
+ { { "FilterName", uno::Any(OUString("writer8_template")) } }));
+ xDocStorable->storeAsURL(aTempFileSaveAsOTT.GetURL(), descSaveAs);
+ }
+ catch (...)
+ {
+ CPPUNIT_FAIL("Failed to save OTT template");
+ }
+
+ // load the template as-is to validate signatures
+ mxComponent->dispose();
+ mxComponent
+ = loadFromDesktop(aTempFileSaveAsOTT.GetURL(), OUString(),
+ comphelper::InitPropertySequence({ { "AsTemplate", uno::Any(false) } }));
+ CPPUNIT_ASSERT_MESSAGE(OUStringToOString(sLoadMessage, RTL_TEXTENCODING_UTF8).getStr(),
+ mxComponent.is());
+
+ // the loaded document is a 1.2 OTT without any signatures
+ assertDocument(CPPUNIT_SOURCELINE(), "writer8_template", SignatureState::NOSIGNATURES,
+ SignatureState::NOSIGNATURES, ODFVER_012_TEXT);
}
class Resetter
@@ -1155,16 +1247,15 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testPreserveMacroTemplateSignature10)
CPPUNIT_ASSERT_MESSAGE(OUStringToOString(sLoadMessage, RTL_TEXTENCODING_UTF8).getStr(),
mxComponent.is());
- // we are a template, and have a valid document and macro signature
+ // we are a template, and have a non-invalid macro signature
assertDocument(CPPUNIT_SOURCELINE(), "writer8_template", SignatureState::NOSIGNATURES,
SignatureState::NOTVALIDATED, OUString());
- mxComponent->dispose();
-
// create new document from template
// we can't use createDoc / MacrosTest::loadFromDesktop, because ALWAYS_EXECUTE_NO_WARN
// won't verify the signature for templates, so the resulting document won't be able to
// preserve the templates signature.
+ mxComponent->dispose();
mxComponent = mxDesktop->loadComponentFromURL(
aURL, "_default", 0,
comphelper::InitPropertySequence(
@@ -1178,26 +1269,80 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testPreserveMacroTemplateSignature10)
SignatureState::NOTVALIDATED, OUString());
// save as new ODT document
- utl::TempFile aTempFileSaveAs;
- aTempFileSaveAs.EnableKillingFile();
+ utl::TempFile aTempFileSaveAsODT;
+ aTempFileSaveAsODT.EnableKillingFile();
try
{
uno::Reference<frame::XStorable> xDocStorable(mxComponent, uno::UNO_QUERY);
uno::Sequence<beans::PropertyValue> descSaveAs(
comphelper::InitPropertySequence({ { "FilterName", uno::Any(OUString("writer8")) } }));
- xDocStorable->storeAsURL(aTempFileSaveAs.GetURL(), descSaveAs);
+ xDocStorable->storeAsURL(aTempFileSaveAsODT.GetURL(), descSaveAs);
}
catch (...)
{
CPPUNIT_FAIL("Failed to save ODT document");
}
- // load saved document
- createDoc(aTempFileSaveAs.GetURL());
+ // save as new OTT template
+ utl::TempFile aTempFileSaveAsOTT;
+ aTempFileSaveAsOTT.EnableKillingFile();
+ try
+ {
+ uno::Reference<frame::XStorable> xDocStorable(mxComponent, uno::UNO_QUERY);
+ uno::Sequence<beans::PropertyValue> descSaveAs(comphelper::InitPropertySequence(
+ { { "FilterName", uno::Any(OUString("writer8_template")) } }));
+ xDocStorable->storeAsURL(aTempFileSaveAsOTT.GetURL(), descSaveAs);
+ }
+ catch (...)
+ {
+ CPPUNIT_FAIL("Failed to save OTT template");
+ }
- // the loaded document is a ODT with a macro signature
+ // load the saved OTT template as-is to validate signatures
+ mxComponent->dispose();
+ mxComponent
+ = loadFromDesktop(aTempFileSaveAsOTT.GetURL(), OUString(),
+ comphelper::InitPropertySequence({ { "AsTemplate", uno::Any(false) } }));
+ CPPUNIT_ASSERT_MESSAGE(OUStringToOString(sLoadMessage, RTL_TEXTENCODING_UTF8).getStr(),
+ mxComponent.is());
+
+ // the loaded document is a OTT with a non-invalid macro signature
+ assertDocument(CPPUNIT_SOURCELINE(), "writer8_template", SignatureState::NOSIGNATURES,
+ SignatureState::NOTVALIDATED, OUString());
+
+ // load saved ODT document
+ createDoc(aTempFileSaveAsODT.GetURL());
+
+ // the loaded document is a ODT with a non-invalid macro signature
assertDocument(CPPUNIT_SOURCELINE(), "writer8", SignatureState::NOSIGNATURES,
SignatureState::NOTVALIDATED, OUString());
+
+ // save as new OTT template
+ utl::TempFile aTempFileSaveAsODT_OTT;
+ aTempFileSaveAsODT_OTT.EnableKillingFile();
+ try
+ {
+ uno::Reference<frame::XStorable> xDocStorable(mxComponent, uno::UNO_QUERY);
+ uno::Sequence<beans::PropertyValue> descSaveAs(comphelper::InitPropertySequence(
+ { { "FilterName", uno::Any(OUString("writer8_template")) } }));
+ xDocStorable->storeAsURL(aTempFileSaveAsODT_OTT.GetURL(), descSaveAs);
+ }
+ catch (...)
+ {
+ CPPUNIT_FAIL("Failed to save OTT template");
+ }
+
+ // load the template as-is to validate signatures
+ mxComponent->dispose();
+ mxComponent
+ = loadFromDesktop(aTempFileSaveAsODT_OTT.GetURL(), OUString(),
+ comphelper::InitPropertySequence({ { "AsTemplate", uno::Any(false) } }));
+ CPPUNIT_ASSERT_MESSAGE(OUStringToOString(sLoadMessage, RTL_TEXTENCODING_UTF8).getStr(),
+ mxComponent.is());
+
+ // the loaded document is a OTT with a non-invalid macro signature
+ assertDocument(CPPUNIT_SOURCELINE(), "writer8_template", SignatureState::NOSIGNATURES,
+ SignatureState::NOTVALIDATED, OUString());
}
#endif
More information about the Libreoffice-commits
mailing list