diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-03-07 12:30:26 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-03-07 15:00:14 +0100 |
commit | 88b1a724311a2f9b2c75e8ea9c1494be61433371 (patch) | |
tree | 6065b36c0500da4c089bf5e255a0d9a0d74e87c0 /xmlsecurity | |
parent | 1a04b1e4f2086bfdeaba04d7b67e8b8e21e5037f (diff) |
CppunitTest_xmlsecurity_signing: add remove all testcase
Fails without the previous commit.
Change-Id: I7606b9a5ef3509077b1a3a6e884f0e2bb4c79614
Diffstat (limited to 'xmlsecurity')
-rw-r--r-- | xmlsecurity/qa/unit/signing/signing.cxx | 46 |
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"); |