summaryrefslogtreecommitdiff
path: root/xmlsecurity
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2016-03-07 12:30:26 +0100
committerMiklos Vajna <vmiklos@collabora.co.uk>2016-07-07 17:42:32 +0200
commit6e2cf4462eaaf5046398742a795f8bf3f1f776a2 (patch)
tree9ac34b1c0933832ef0726b379cc5f6292e7274cc /xmlsecurity
parentb7bc8cbc299b154e0e10f239a2318bdef418c54b (diff)
CppunitTest_xmlsecurity_signing: add remove all testcase
Fails without the previous commit. Change-Id: I7606b9a5ef3509077b1a3a6e884f0e2bb4c79614 (cherry picked from commit 88b1a724311a2f9b2c75e8ea9c1494be61433371)
Diffstat (limited to 'xmlsecurity')
-rw-r--r--xmlsecurity/qa/unit/signing/signing.cxx46
1 files changed, 46 insertions, 0 deletions
diff --git a/xmlsecurity/qa/unit/signing/signing.cxx b/xmlsecurity/qa/unit/signing/signing.cxx
index aa77fa00b1db..1894cb9cec62 100644
--- a/xmlsecurity/qa/unit/signing/signing.cxx
+++ b/xmlsecurity/qa/unit/signing/signing.cxx
@@ -36,6 +36,7 @@
#include <sfx2/sfxbasemodel.hxx>
#include <sfx2/objsh.hxx>
#include <osl/file.hxx>
+#include <comphelper/ofopxmlhelper.hxx>
#include <xmlsecurity/documentsignaturehelper.hxx>
#include <xmlsecurity/xmlsignaturehelper.hxx>
@@ -69,6 +70,8 @@ public:
void testOOXMLAppend();
/// Test removing a signature from existing ones.
void testOOXMLRemove();
+ /// Test removing all signatures from a document.
+ void testOOXMLRemoveAll();
CPPUNIT_TEST_SUITE(SigningTest);
CPPUNIT_TEST(testDescription);
@@ -77,6 +80,7 @@ public:
CPPUNIT_TEST(testOOXMLDescription);
CPPUNIT_TEST(testOOXMLAppend);
CPPUNIT_TEST(testOOXMLRemove);
+ CPPUNIT_TEST(testOOXMLRemoveAll);
CPPUNIT_TEST_SUITE_END();
private:
@@ -253,6 +257,48 @@ void SigningTest::testOOXMLRemove()
CPPUNIT_ASSERT_EQUAL(OUString("purpose1"), rInformations[0].ouDescription);
}
+void SigningTest::testOOXMLRemoveAll()
+{
+ // Copy the test document to a temporary file, as it'll be modified.
+ utl::TempFile aTempFile;
+ aTempFile.EnableKillingFile();
+ OUString aURL = aTempFile.GetURL();
+ osl::File::copy(getURLFromSrc(DATA_DIRECTORY) + "partial.docx", aURL);
+ // Load the test document as a storage and read its single signature.
+ DocumentSignatureManager aManager(mxComponentContext, SignatureModeDocumentContent);
+ CPPUNIT_ASSERT(aManager.maSignatureHelper.Init());
+ uno::Reference <embed::XStorage> xStorage = comphelper::OStorageHelper::GetStorageOfFormatFromURL(ZIP_STORAGE_FORMAT_STRING, aURL, embed::ElementModes::READWRITE);
+ CPPUNIT_ASSERT(xStorage.is());
+ aManager.mxStore = xStorage;
+ aManager.maSignatureHelper.SetStorage(xStorage, "1.2");
+ aManager.read(/*bUseTempStream=*/false);
+ std::vector<SignatureInformation>& rInformations = aManager.maCurrentSignatureInformations;
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rInformations.size());
+
+ // Then remove the only signature in the document.
+ uno::Reference<security::XCertificate> xCertificate = getCertificate(aManager.maSignatureHelper);
+ CPPUNIT_ASSERT(xCertificate.is());
+ aManager.remove(0);
+ aManager.read(/*bUseTempStream=*/true);
+ aManager.write();
+
+ // Make sure that the signature count is zero and the whole signature storage is removed completely.
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), rInformations.size());
+ uno::Reference<container::XNameAccess> xNameAccess(xStorage, uno::UNO_QUERY);
+ CPPUNIT_ASSERT(!xNameAccess->hasByName("_xmlsignatures"));
+
+ // And that content types no longer contains signature types.
+ sal_Int32 nOpenMode = embed::ElementModes::READWRITE;
+ uno::Reference<io::XStream> xStream(xStorage->openStreamElement("[Content_Types].xml", nOpenMode), uno::UNO_QUERY);
+ uno::Reference<io::XInputStream> xInputStream = xStream->getInputStream();
+ uno::Sequence< uno::Sequence<beans::StringPair> > aContentTypeInfo = comphelper::OFOPXMLHelper::ReadContentTypeSequence(xInputStream, mxComponentContext);
+ uno::Sequence<beans::StringPair>& rOverrides = aContentTypeInfo[1];
+ CPPUNIT_ASSERT_EQUAL(rOverrides.end(), std::find_if(rOverrides.begin(), rOverrides.end(), [](const beans::StringPair& rPair)
+ {
+ return rPair.First.startsWith("/_xmlsignatures/sig");
+ }));
+}
+
void SigningTest::testOOXMLPartial()
{
createDoc(getURLFromSrc(DATA_DIRECTORY) + "partial.docx");