1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <sal/config.h>
12 #include <test/unoapixml_test.hxx>
14 #include <com/sun/star/embed/XStorage.hpp>
15 #include <com/sun/star/frame/Desktop.hpp>
16 #include <com/sun/star/frame/XStorable.hpp>
17 #include <com/sun/star/util/XCloseable.hpp>
18 #include <com/sun/star/xml/crypto/SEInitializer.hpp>
20 #include <comphelper/propertysequence.hxx>
21 #include <unotools/tempfile.hxx>
22 #include <unotools/ucbstreamhelper.hxx>
23 #include <comphelper/storagehelper.hxx>
24 #include <osl/file.hxx>
25 #include <osl/process.h>
26 #include <osl/thread.hxx>
30 /// Testsuite for the document signing feature.
31 class SigningTest2
: public UnoApiXmlTest
35 void registerNamespaces(xmlXPathContextPtr
& pXmlXpathCtx
) override
;
38 SigningTest2::SigningTest2()
39 : UnoApiXmlTest("/xmlsecurity/qa/unit/signing/data/")
43 /// Test if a macro signature from a ODF Database is preserved when saving
44 CPPUNIT_TEST_FIXTURE(SigningTest2
, testPreserveMacroSignatureODB
)
46 loadFromURL(u
"odb_signed_macros.odb");
49 save("StarOffice XML (Base)");
51 // Parse the resulting XML.
52 uno::Reference
<embed::XStorage
> xStorage
53 = comphelper::OStorageHelper::GetStorageOfFormatFromURL(
54 ZIP_STORAGE_FORMAT_STRING
, maTempFile
.GetURL(), embed::ElementModes::READ
);
55 CPPUNIT_ASSERT(xStorage
.is());
56 uno::Reference
<embed::XStorage
> xMetaInf
57 = xStorage
->openStorageElement("META-INF", embed::ElementModes::READ
);
58 uno::Reference
<io::XInputStream
> xInputStream(
59 xMetaInf
->openStreamElement("macrosignatures.xml", embed::ElementModes::READ
),
61 std::unique_ptr
<SvStream
> pStream(utl::UcbStreamHelper::CreateStream(xInputStream
, true));
62 xmlDocUniquePtr pXmlDoc
= parseXmlStream(pStream
.get());
64 // Make sure the signature is still there
65 assertXPath(pXmlDoc
, "//dsig:Signature", "Id",
66 "ID_00a7002f009000bc00ce00f7004400460080002f002e00e400e0003700df00e8");
69 void SigningTest2::registerNamespaces(xmlXPathContextPtr
& pXmlXpathCtx
)
71 xmlXPathRegisterNs(pXmlXpathCtx
, BAD_CAST("odfds"),
72 BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:digitalsignature:1.0"));
73 xmlXPathRegisterNs(pXmlXpathCtx
, BAD_CAST("dsig"),
74 BAD_CAST("http://www.w3.org/2000/09/xmldsig#"));
75 xmlXPathRegisterNs(pXmlXpathCtx
, BAD_CAST("xd"), BAD_CAST("http://uri.etsi.org/01903/v1.3.2#"));
78 CPPUNIT_PLUGIN_IMPLEMENT();
80 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */