summaryrefslogtreecommitdiff
path: root/xmlsecurity
diff options
context:
space:
mode:
authorGuillaume Smaha <guillaume.smaha@gmail.com>2016-04-25 18:39:27 +0200
committerjan iversen <jani@documentfoundation.org>2016-04-28 07:20:05 +0000
commit4d2bb795820ef30f230605194207a3bd50299127 (patch)
treefcfbb3c5a67805547a3b161e6c6357d3ed823ceb /xmlsecurity
parentb4bbca013ee4ba5bf8ea1211ee795121d7af9ade (diff)
Unit test for tdf#96097: Can't save/pointer null
Change-Id: I56af30142bba8579ca7f24bbbb2d12390832051b Reviewed-on: https://gerrit.libreoffice.org/24372 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: jan iversen <jani@documentfoundation.org>
Diffstat (limited to 'xmlsecurity')
-rw-r--r--xmlsecurity/qa/unit/signing/data/tdf96097.odsbin0 -> 13767 bytes
-rw-r--r--xmlsecurity/qa/unit/signing/data/tdf96097.odtbin0 -> 11791 bytes
-rw-r--r--xmlsecurity/qa/unit/signing/signing.cxx111
3 files changed, 111 insertions, 0 deletions
diff --git a/xmlsecurity/qa/unit/signing/data/tdf96097.ods b/xmlsecurity/qa/unit/signing/data/tdf96097.ods
new file mode 100644
index 000000000000..58d1b2c771de
--- /dev/null
+++ b/xmlsecurity/qa/unit/signing/data/tdf96097.ods
Binary files differ
diff --git a/xmlsecurity/qa/unit/signing/data/tdf96097.odt b/xmlsecurity/qa/unit/signing/data/tdf96097.odt
new file mode 100644
index 000000000000..f0356513c389
--- /dev/null
+++ b/xmlsecurity/qa/unit/signing/data/tdf96097.odt
Binary files differ
diff --git a/xmlsecurity/qa/unit/signing/signing.cxx b/xmlsecurity/qa/unit/signing/signing.cxx
index 83fdd8d8aa5f..45308d218b3a 100644
--- a/xmlsecurity/qa/unit/signing/signing.cxx
+++ b/xmlsecurity/qa/unit/signing/signing.cxx
@@ -76,6 +76,8 @@ public:
void testOOXMLRemove();
/// Test removing all signatures from a document.
void testOOXMLRemoveAll();
+ void test96097Calc();
+ void test96097Doc();
CPPUNIT_TEST_SUITE(SigningTest);
CPPUNIT_TEST(testDescription);
@@ -88,10 +90,13 @@ public:
CPPUNIT_TEST(testOOXMLAppend);
CPPUNIT_TEST(testOOXMLRemove);
CPPUNIT_TEST(testOOXMLRemoveAll);
+ CPPUNIT_TEST(test96097Calc);
+ CPPUNIT_TEST(test96097Doc);
CPPUNIT_TEST_SUITE_END();
private:
void createDoc(const OUString& rURL = OUString());
+ void createCalc(const OUString& rURL = OUString());
uno::Reference<security::XCertificate> getCertificate(XMLSignatureHelper& rSignatureHelper);
};
@@ -125,6 +130,16 @@ void SigningTest::createDoc(const OUString& rURL)
mxComponent = loadFromDesktop(rURL, "com.sun.star.text.TextDocument");
}
+void SigningTest::createCalc(const OUString& rURL)
+{
+ if (mxComponent.is())
+ mxComponent->dispose();
+ if (rURL.isEmpty())
+ mxComponent = loadFromDesktop("private:factory/swriter", "com.sun.star.sheet.SpreadsheetDocument");
+ else
+ mxComponent = loadFromDesktop(rURL, "com.sun.star.sheet.SpreadsheetDocument");
+}
+
uno::Reference<security::XCertificate> SigningTest::getCertificate(XMLSignatureHelper& rSignatureHelper)
{
uno::Reference<xml::crypto::XSecurityEnvironment> xSecurityEnvironment = rSignatureHelper.GetSecurityEnvironment();
@@ -364,6 +379,102 @@ void SigningTest::testOOXMLBroken()
CPPUNIT_ASSERT_EQUAL(static_cast<int>(SignatureState::BROKEN), static_cast<int>(pObjectShell->GetDocumentSignatureState()));
}
+void SigningTest::test96097Calc()
+{
+ createCalc(m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf96097.ods");
+ SfxBaseModel* pBaseModel = dynamic_cast<SfxBaseModel*>(mxComponent.get());
+ CPPUNIT_ASSERT_MESSAGE("Failed to access document base model", pBaseModel);
+
+ SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell();
+ CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pObjectShell);
+
+ SignatureState nActual = pObjectShell->GetScriptingSignatureState();
+ CPPUNIT_ASSERT_MESSAGE(
+ (OString::number(
+ static_cast<std::underlying_type<SignatureState>::type>(nActual))
+ .getStr()),
+ (nActual == SignatureState::OK
+ || nActual == SignatureState::NOTVALIDATED
+ || nActual == SignatureState::INVALID));
+
+
+ uno::Reference<frame::XStorable> xDocStorable(mxComponent, uno::UNO_QUERY_THROW);
+ CPPUNIT_ASSERT(xDocStorable.is());
+
+ // Save a copy
+ utl::TempFile aTempFileSaveCopy;
+ aTempFileSaveCopy.EnableKillingFile();
+ uno::Sequence<beans::PropertyValue> descSaveACopy(2);
+ descSaveACopy[0].Name = "SaveACopy";
+ descSaveACopy[0].Value <<= uno::makeAny(true);
+ descSaveACopy[1].Name = "FilterName";
+ descSaveACopy[1].Value <<= OUString("calc8");
+ xDocStorable->storeToURL(aTempFileSaveCopy.GetURL(), descSaveACopy);
+
+ try
+ {
+ // Save As
+ utl::TempFile aTempFileSaveAs;
+ aTempFileSaveAs.EnableKillingFile();
+ uno::Sequence<beans::PropertyValue> descSaveAs(1);
+ descSaveAs[0].Name = "FilterName";
+ descSaveAs[0].Value <<= OUString("calc8");
+ xDocStorable->storeAsURL(aTempFileSaveAs.GetURL(), descSaveAs);
+ }
+ catch(...)
+ {
+ CPPUNIT_FAIL("Fail to save as the document");
+ }
+}
+
+void SigningTest::test96097Doc()
+{
+ createDoc(m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf96097.odt");
+ SfxBaseModel* pBaseModel = dynamic_cast<SfxBaseModel*>(mxComponent.get());
+ CPPUNIT_ASSERT(pBaseModel);
+ SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell();
+ CPPUNIT_ASSERT(pObjectShell);
+
+ SignatureState nActual = pObjectShell->GetScriptingSignatureState();
+ CPPUNIT_ASSERT_MESSAGE(
+ (OString::number(
+ static_cast<std::underlying_type<SignatureState>::type>(nActual))
+ .getStr()),
+ (nActual == SignatureState::OK
+ || nActual == SignatureState::NOTVALIDATED
+ || nActual == SignatureState::INVALID));
+
+
+
+ uno::Reference<frame::XStorable> xDocStorable(mxComponent, uno::UNO_QUERY_THROW);
+ CPPUNIT_ASSERT(xDocStorable.is());
+
+ // Save a copy
+ utl::TempFile aTempFileSaveCopy;
+ aTempFileSaveCopy.EnableKillingFile();
+ uno::Sequence<beans::PropertyValue> descSaveACopy(2);
+ descSaveACopy[0].Name = "SaveACopy";
+ descSaveACopy[0].Value <<= uno::makeAny(true);
+ descSaveACopy[1].Name = "FilterName";
+ descSaveACopy[1].Value <<= OUString("writer8");
+ xDocStorable->storeToURL(aTempFileSaveCopy.GetURL(), descSaveACopy);
+
+ try
+ {
+ // Save As
+ utl::TempFile aTempFileSaveAs;
+ aTempFileSaveAs.EnableKillingFile();
+ uno::Sequence<beans::PropertyValue> descSaveAs(1);
+ descSaveAs[0].Name = "FilterName";
+ descSaveAs[0].Value <<= OUString("writer8");
+ xDocStorable->storeAsURL(aTempFileSaveAs.GetURL(), descSaveAs);
+ }
+ catch(...)
+ {
+ CPPUNIT_FAIL("Fail to save as the document");
+ }
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(SigningTest);
CPPUNIT_PLUGIN_IMPLEMENT();