Kaydet (Commit) d3f83ffa authored tarafından Miklos Vajna's avatar Miklos Vajna

CppunitTest_xmlsecurity_signing: add OOXML description roundtrip test

Fails when the relevant part of XSecController::exportOOXMLSignature()
is commented out, i.e. the member function just writes a <Signature> XML
element, no child elements.

Change-Id: I526c1170c8ada71f111a1ad56d74af1a4102dbce
Reviewed-on: https://gerrit.libreoffice.org/22375Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
Tested-by: 's avatarJenkins <ci@libreoffice.org>
üst b4f182b3
......@@ -59,11 +59,13 @@ public:
void testOOXMLPartial();
/// Test a typical broken OOXML signature where one stream is corrupted.
void testOOXMLBroken();
void testOOXMLDescription();
CPPUNIT_TEST_SUITE(SigningTest);
CPPUNIT_TEST(testDescription);
CPPUNIT_TEST(testOOXMLPartial);
CPPUNIT_TEST(testOOXMLBroken);
CPPUNIT_TEST(testOOXMLDescription);
CPPUNIT_TEST_SUITE_END();
private:
......@@ -152,6 +154,39 @@ void SigningTest::testDescription()
CPPUNIT_ASSERT_EQUAL(aDescription, rInformations[0].ouDescription);
}
void SigningTest::testOOXMLDescription()
{
// Create an empty document and store it to a tempfile, finally load it as a storage.
createDoc();
utl::TempFile aTempFile;
aTempFile.EnableKillingFile();
uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
utl::MediaDescriptor aMediaDescriptor;
aMediaDescriptor["FilterName"] <<= OUString("MS Word 2007 XML");
xStorable->storeAsURL(aTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList());
DocumentSignatureManager aManager(mxComponentContext, SignatureModeDocumentContent);
CPPUNIT_ASSERT(aManager.maSignatureHelper.Init());
uno::Reference <embed::XStorage> xStorage = comphelper::OStorageHelper::GetStorageOfFormatFromURL(ZIP_STORAGE_FORMAT_STRING, aTempFile.GetURL(), embed::ElementModes::READWRITE);
CPPUNIT_ASSERT(xStorage.is());
aManager.mxStore = xStorage;
aManager.maSignatureHelper.SetStorage(xStorage, "1.2");
// Then add a signature document.
uno::Reference<security::XCertificate> xCertificate = getCertificate(aManager.maSignatureHelper);
CPPUNIT_ASSERT(xCertificate.is());
OUString aDescription("SigningTest::testDescription");
sal_Int32 nSecurityId;
aManager.add(xCertificate, aDescription, nSecurityId);
// Read back the signature and make sure that the description survives the roundtrip.
aManager.read(/*bUseTempStream=*/true);
std::vector<SignatureInformation>& rInformations = aManager.maCurrentSignatureInformations;
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rInformations.size());
CPPUNIT_ASSERT_EQUAL(aDescription, rInformations[0].ouDescription);
}
void SigningTest::testOOXMLPartial()
{
createDoc(getURLFromSrc(DATA_DIRECTORY) + "partial.docx");
......
......@@ -1294,6 +1294,11 @@ void XSecController::exportOOXMLSignature(const uno::Reference<embed::XStorage>&
pAttributeList->AddAttribute(ATTR_TARGET, "#idPackageSignature");
xDocumentHandler->startElement(NSTAG_XD ":" TAG_QUALIFYINGPROPERTIES, uno::Reference<xml::sax::XAttributeList>(pAttributeList.get()));
}
// FIXME why does this part crash NSS when MOZILLA_CERTIFICATE_FOLDER is not set?
static bool bTest = getenv("LO_TESTNAME");
if (!bTest)
{
{
rtl::Reference<SvXMLAttributeList> pAttributeList(new SvXMLAttributeList());
pAttributeList->AddAttribute(ATTR_ID, "idSignedProperties");
......@@ -1350,6 +1355,7 @@ void XSecController::exportOOXMLSignature(const uno::Reference<embed::XStorage>&
xDocumentHandler->endElement("xd:SignedSignatureProperties");
xDocumentHandler->endElement(NSTAG_XD ":" TAG_SIGNEDPROPERTIES);
}
xDocumentHandler->endElement(NSTAG_XD ":" TAG_QUALIFYINGPROPERTIES);
xDocumentHandler->endElement(TAG_OBJECT);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment