summaryrefslogtreecommitdiff
path: root/xmlsecurity
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2016-03-04 11:18:17 +0100
committerMiklos Vajna <vmiklos@collabora.co.uk>2016-07-07 17:42:24 +0200
commitbacc2fe9a3361899f2db0aacba0f2945377735da (patch)
tree47a4e58da4ed8d3a9f5bb7a2c42418682ec0c37c /xmlsecurity
parent5e77d0963af0168d46145f6e3b3c8f08279130cb (diff)
CppunitTest_xmlsecurity_signing: add signature append testcase
Fails with e.g. commit 963264a417ce807201f0021fc6000ce7d6cf0245 (xmlsecurity OOXML export: don't loose old signatures when adding a new one, 2016-03-03) reverted. Change-Id: Ia2b0f3d8914bca14075481f5ac8cd4c0033d26c1 (cherry picked from commit 78a209b951d2f6e6bb3001b45c242a85fcf9ebb0)
Diffstat (limited to 'xmlsecurity')
-rw-r--r--xmlsecurity/qa/unit/signing/signing.cxx31
1 files changed, 30 insertions, 1 deletions
diff --git a/xmlsecurity/qa/unit/signing/signing.cxx b/xmlsecurity/qa/unit/signing/signing.cxx
index d9aec730472e..5d97d7114654 100644
--- a/xmlsecurity/qa/unit/signing/signing.cxx
+++ b/xmlsecurity/qa/unit/signing/signing.cxx
@@ -64,12 +64,15 @@ public:
/// Test a typical broken OOXML signature where one stream is corrupted.
void testOOXMLBroken();
void testOOXMLDescription();
+ /// Test appending a new signature next to an existing one.
+ void testOOXMLAppend();
CPPUNIT_TEST_SUITE(SigningTest);
CPPUNIT_TEST(testDescription);
CPPUNIT_TEST(testOOXMLPartial);
CPPUNIT_TEST(testOOXMLBroken);
CPPUNIT_TEST(testOOXMLDescription);
+ CPPUNIT_TEST(testOOXMLAppend);
CPPUNIT_TEST_SUITE_END();
private:
@@ -177,7 +180,7 @@ void SigningTest::testOOXMLDescription()
aManager.mxStore = xStorage;
aManager.maSignatureHelper.SetStorage(xStorage, "1.2");
- // Then add a signature document.
+ // Then add a document signature.
uno::Reference<security::XCertificate> xCertificate = getCertificate(aManager.maSignatureHelper);
CPPUNIT_ASSERT(xCertificate.is());
OUString aDescription("SigningTest::testDescription");
@@ -191,6 +194,32 @@ void SigningTest::testOOXMLDescription()
CPPUNIT_ASSERT_EQUAL(aDescription, rInformations[0].ouDescription);
}
+void SigningTest::testOOXMLAppend()
+{
+ // Load the test document as a storage and read its single signature.
+ DocumentSignatureManager aManager(mxComponentContext, SignatureModeDocumentContent);
+ CPPUNIT_ASSERT(aManager.maSignatureHelper.Init());
+ OUString aURL = getURLFromSrc(DATA_DIRECTORY) + "partial.docx";
+ 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 add a second document signature.
+ uno::Reference<security::XCertificate> xCertificate = getCertificate(aManager.maSignatureHelper);
+ CPPUNIT_ASSERT(xCertificate.is());
+ sal_Int32 nSecurityId;
+ aManager.add(xCertificate, OUString(), nSecurityId);
+
+ // Read back the signatures and make sure that we have the expected amount.
+ aManager.read(/*bUseTempStream=*/true);
+ // This was 1: the original signature was lost.
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), rInformations.size());
+}
+
void SigningTest::testOOXMLPartial()
{
createDoc(getURLFromSrc(DATA_DIRECTORY) + "partial.docx");