[Libreoffice-commits] core.git: solenv/clang-format xmlsecurity/qa

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Nov 13 14:06:54 UTC 2018


 solenv/clang-format/blacklist           |    1 
 xmlsecurity/qa/unit/signing/signing.cxx |  265 +++++++++++++++++---------------
 2 files changed, 147 insertions(+), 119 deletions(-)

New commits:
commit 4866a441cab472c1f44360abdc7074097aad1a26
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Tue Nov 13 12:28:46 2018 +0100
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Tue Nov 13 15:06:31 2018 +0100

    CppunitTest_xmlsecurity_signing: turn on clang-format for this file
    
    This had manual consistent formatting. Recently it was broken, so bring
    back consisency by using clang-format.
    
    (And move the "if conversion fails" comment above
    CPPUNIT_ASSERT_MESSAGE() to avoid the need for an over-indented
    comment.)
    
    Change-Id: Id6a9231c044d7282c84a21152ffdfdcb8af3690d
    Reviewed-on: https://gerrit.libreoffice.org/63327
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
    Tested-by: Jenkins

diff --git a/solenv/clang-format/blacklist b/solenv/clang-format/blacklist
index b8eac28b471d..475e66ae2c35 100644
--- a/solenv/clang-format/blacklist
+++ b/solenv/clang-format/blacklist
@@ -19459,7 +19459,6 @@ xmlsecurity/inc/xsecfwdllapi.h
 xmlsecurity/inc/xsecgpgdllapi.h
 xmlsecurity/inc/xsecxmlsecdllapi.h
 xmlsecurity/qa/certext/SanCertExt.cxx
-xmlsecurity/qa/unit/signing/signing.cxx
 xmlsecurity/qa/unit/xmlsecurity-dialogs-test.cxx
 xmlsecurity/source/component/certificatecontainer.cxx
 xmlsecurity/source/component/certificatecontainer.hxx
diff --git a/xmlsecurity/qa/unit/signing/signing.cxx b/xmlsecurity/qa/unit/signing/signing.cxx
index 3b33990af540..ef5bbbda05ff 100644
--- a/xmlsecurity/qa/unit/signing/signing.cxx
+++ b/xmlsecurity/qa/unit/signing/signing.cxx
@@ -160,20 +160,20 @@ public:
 private:
     void createDoc(const OUString& rURL);
     void createCalc(const OUString& rURL);
-    uno::Reference<security::XCertificate> getCertificate(DocumentSignatureManager& rSignatureManager, svl::crypto::SignatureMethodAlgorithm eAlgo);
+    uno::Reference<security::XCertificate>
+    getCertificate(DocumentSignatureManager& rSignatureManager,
+                   svl::crypto::SignatureMethodAlgorithm eAlgo);
 };
 
-SigningTest::SigningTest()
-{
-}
+SigningTest::SigningTest() {}
 
 void SigningTest::setUp()
 {
     test::BootstrapFixture::setUp();
 
     OUString aSourceDir = m_directories.getURLFromSrc(DATA_DIRECTORY);
-    OUString aTargetDir = m_directories.getURLFromWorkdir(
-                              "CppunitTest/xmlsecurity_signing.test.user");
+    OUString aTargetDir
+        = m_directories.getURLFromWorkdir("CppunitTest/xmlsecurity_signing.test.user");
 
     // Set up cert8.db in workdir/CppunitTest/
     osl::File::copy(aSourceDir + "cert8.db", aTargetDir + "/cert8.db");
@@ -195,12 +195,12 @@ void SigningTest::setUp()
 
 #if HAVE_GPGCONF_SOCKETDIR
     OString path;
-    bool ok = aTargetPath.convertToString(
-        &path, osl_getThreadTextEncoding(),
-        RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR);
+    bool ok = aTargetPath.convertToString(&path, osl_getThreadTextEncoding(),
+                                          RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
+                                              | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR);
+    // if conversion fails, at least provide a best-effort conversion in the message here, for
+    // context
     CPPUNIT_ASSERT_MESSAGE(OUStringToOString(aTargetPath, RTL_TEXTENCODING_UTF8).getStr(), ok);
-        // if conversion fails, at least provide a best-effort conversion in the message here, for
-        // context
     m_gpgconfCommandPrefix = "GNUPGHOME=" + path + " " GPGME_GPGCONF;
     // HAVE_GPGCONF_SOCKETDIR is only defined in configure.ac for Linux for now, so (a) std::system
     // behavior will conform to POSIX, and (b) gpgconf --create-socketdir should return zero:
@@ -247,15 +247,20 @@ void SigningTest::createCalc(const OUString& rURL)
     if (mxComponent.is())
         mxComponent->dispose();
     if (rURL.isEmpty())
-        mxComponent = loadFromDesktop("private:factory/swriter", "com.sun.star.sheet.SpreadsheetDocument");
+        mxComponent
+            = loadFromDesktop("private:factory/swriter", "com.sun.star.sheet.SpreadsheetDocument");
     else
         mxComponent = loadFromDesktop(rURL, "com.sun.star.sheet.SpreadsheetDocument");
 }
 
-uno::Reference<security::XCertificate> SigningTest::getCertificate(DocumentSignatureManager& rSignatureManager, svl::crypto::SignatureMethodAlgorithm eAlgo)
+uno::Reference<security::XCertificate>
+SigningTest::getCertificate(DocumentSignatureManager& rSignatureManager,
+                            svl::crypto::SignatureMethodAlgorithm eAlgo)
 {
-    uno::Reference<xml::crypto::XSecurityEnvironment> xSecurityEnvironment = rSignatureManager.getSecurityEnvironment();
-    uno::Sequence<uno::Reference<security::XCertificate>> aCertificates = xSecurityEnvironment->getPersonalCertificates();
+    uno::Reference<xml::crypto::XSecurityEnvironment> xSecurityEnvironment
+        = rSignatureManager.getSecurityEnvironment();
+    uno::Sequence<uno::Reference<security::XCertificate>> aCertificates
+        = xSecurityEnvironment->getPersonalCertificates();
 
     for (const auto& xCertificate : aCertificates)
     {
@@ -281,13 +286,16 @@ void SigningTest::testDescription()
 
     DocumentSignatureManager aManager(mxComponentContext, DocumentSignatureMode::Content);
     CPPUNIT_ASSERT(aManager.init());
-    uno::Reference <embed::XStorage> xStorage = comphelper::OStorageHelper::GetStorageOfFormatFromURL(ZIP_STORAGE_FORMAT_STRING, aTempFile.GetURL(), embed::ElementModes::READWRITE);
+    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, svl::crypto::SignatureMethodAlgorithm::RSA);
+    uno::Reference<security::XCertificate> xCertificate
+        = getCertificate(aManager, svl::crypto::SignatureMethodAlgorithm::RSA);
     if (!xCertificate.is())
         return;
     OUString aDescription("SigningTest::testDescription");
@@ -315,13 +323,16 @@ void SigningTest::testECDSA()
 
     DocumentSignatureManager aManager(mxComponentContext, DocumentSignatureMode::Content);
     CPPUNIT_ASSERT(aManager.init());
-    uno::Reference <embed::XStorage> xStorage = comphelper::OStorageHelper::GetStorageOfFormatFromURL(ZIP_STORAGE_FORMAT_STRING, aTempFile.GetURL(), embed::ElementModes::READWRITE);
+    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.
-    uno::Reference<security::XCertificate> xCertificate = getCertificate(aManager, svl::crypto::SignatureMethodAlgorithm::ECDSA);
+    uno::Reference<security::XCertificate> xCertificate
+        = getCertificate(aManager, svl::crypto::SignatureMethodAlgorithm::ECDSA);
     if (!xCertificate.is())
         return;
     OUString aDescription;
@@ -334,7 +345,8 @@ void SigningTest::testECDSA()
     CPPUNIT_ASSERT_EQUAL(static_cast<std::size_t>(1), rInformations.size());
     // This was SecurityOperationStatus_UNKNOWN, signing with an ECDSA key was
     // broken.
-    CPPUNIT_ASSERT_EQUAL(css::xml::crypto::SecurityOperationStatus_OPERATION_SUCCEEDED, rInformations[0].nStatus);
+    CPPUNIT_ASSERT_EQUAL(css::xml::crypto::SecurityOperationStatus_OPERATION_SUCCEEDED,
+                         rInformations[0].nStatus);
 }
 
 void SigningTest::testECDSAOOXML()
@@ -353,7 +365,7 @@ void SigningTest::testECDSAOOXML()
     CPPUNIT_ASSERT(aManager.init());
     uno::Reference<embed::XStorage> xStorage
         = comphelper::OStorageHelper::GetStorageOfFormatFromURL(
-              ZIP_STORAGE_FORMAT_STRING, aTempFile.GetURL(), embed::ElementModes::READWRITE);
+            ZIP_STORAGE_FORMAT_STRING, aTempFile.GetURL(), embed::ElementModes::READWRITE);
     CPPUNIT_ASSERT(xStorage.is());
     aManager.mxStore = xStorage;
     aManager.maSignatureHelper.SetStorage(xStorage, "1.2");
@@ -393,7 +405,8 @@ void SigningTest::testECDSAPDF()
 
     DocumentSignatureManager aManager(mxComponentContext, DocumentSignatureMode::Content);
     CPPUNIT_ASSERT(aManager.init());
-    std::unique_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(aTempFile.GetURL(), StreamMode::READ | StreamMode::WRITE));
+    std::unique_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(
+        aTempFile.GetURL(), StreamMode::READ | StreamMode::WRITE));
     uno::Reference<io::XStream> xStream(new utl::OStreamWrapper(*pStream));
     CPPUNIT_ASSERT(xStream.is());
     aManager.mxSignatureStream = xStream;
@@ -432,13 +445,16 @@ void SigningTest::testOOXMLDescription()
 
     DocumentSignatureManager aManager(mxComponentContext, DocumentSignatureMode::Content);
     CPPUNIT_ASSERT(aManager.init());
-    uno::Reference <embed::XStorage> xStorage = comphelper::OStorageHelper::GetStorageOfFormatFromURL(ZIP_STORAGE_FORMAT_STRING, aTempFile.GetURL(), embed::ElementModes::READWRITE);
+    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 document signature.
-    uno::Reference<security::XCertificate> xCertificate = getCertificate(aManager, svl::crypto::SignatureMethodAlgorithm::RSA);
+    uno::Reference<security::XCertificate> xCertificate
+        = getCertificate(aManager, svl::crypto::SignatureMethodAlgorithm::RSA);
     if (!xCertificate.is())
         return;
     OUString aDescription("SigningTest::testDescription");
@@ -458,12 +474,15 @@ void SigningTest::testOOXMLAppend()
     utl::TempFile aTempFile;
     aTempFile.EnableKillingFile();
     OUString aURL = aTempFile.GetURL();
-    CPPUNIT_ASSERT_EQUAL(osl::File::RC::E_None,
-                         osl::File::copy(m_directories.getURLFromSrc(DATA_DIRECTORY) + "partial.docx", aURL));
+    CPPUNIT_ASSERT_EQUAL(
+        osl::File::RC::E_None,
+        osl::File::copy(m_directories.getURLFromSrc(DATA_DIRECTORY) + "partial.docx", aURL));
     // Load the test document as a storage and read its single signature.
     DocumentSignatureManager aManager(mxComponentContext, DocumentSignatureMode::Content);
     CPPUNIT_ASSERT(aManager.init());
-    uno::Reference <embed::XStorage> xStorage = comphelper::OStorageHelper::GetStorageOfFormatFromURL(ZIP_STORAGE_FORMAT_STRING, aURL, embed::ElementModes::READWRITE);
+    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");
@@ -472,7 +491,8 @@ void SigningTest::testOOXMLAppend()
     CPPUNIT_ASSERT_EQUAL(static_cast<std::size_t>(1), rInformations.size());
 
     // Then add a second document signature.
-    uno::Reference<security::XCertificate> xCertificate = getCertificate(aManager, svl::crypto::SignatureMethodAlgorithm::RSA);
+    uno::Reference<security::XCertificate> xCertificate
+        = getCertificate(aManager, svl::crypto::SignatureMethodAlgorithm::RSA);
     if (!xCertificate.is())
         return;
     sal_Int32 nSecurityId;
@@ -495,7 +515,9 @@ void SigningTest::testOOXMLRemove()
     CPPUNIT_ASSERT_EQUAL(
         osl::File::RC::E_None,
         osl::File::copy(m_directories.getURLFromSrc(DATA_DIRECTORY) + "multi.docx", aURL));
-    uno::Reference <embed::XStorage> xStorage = comphelper::OStorageHelper::GetStorageOfFormatFromURL(ZIP_STORAGE_FORMAT_STRING, aURL, embed::ElementModes::READWRITE);
+    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");
@@ -504,7 +526,8 @@ void SigningTest::testOOXMLRemove()
     CPPUNIT_ASSERT_EQUAL(static_cast<std::size_t>(2), rInformations.size());
 
     // Then remove the last added signature.
-    uno::Reference<security::XCertificate> xCertificate = getCertificate(aManager, svl::crypto::SignatureMethodAlgorithm::RSA);
+    uno::Reference<security::XCertificate> xCertificate
+        = getCertificate(aManager, svl::crypto::SignatureMethodAlgorithm::RSA);
     if (!xCertificate.is())
         return;
     aManager.remove(0);
@@ -521,12 +544,15 @@ void SigningTest::testOOXMLRemoveAll()
     utl::TempFile aTempFile;
     aTempFile.EnableKillingFile();
     OUString aURL = aTempFile.GetURL();
-    CPPUNIT_ASSERT_EQUAL(osl::File::RC::E_None,
-                         osl::File::copy(m_directories.getURLFromSrc(DATA_DIRECTORY) + "partial.docx", aURL));
+    CPPUNIT_ASSERT_EQUAL(
+        osl::File::RC::E_None,
+        osl::File::copy(m_directories.getURLFromSrc(DATA_DIRECTORY) + "partial.docx", aURL));
     // Load the test document as a storage and read its single signature.
     DocumentSignatureManager aManager(mxComponentContext, DocumentSignatureMode::Content);
     CPPUNIT_ASSERT(aManager.init());
-    uno::Reference <embed::XStorage> xStorage = comphelper::OStorageHelper::GetStorageOfFormatFromURL(ZIP_STORAGE_FORMAT_STRING, aURL, embed::ElementModes::READWRITE);
+    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");
@@ -535,7 +561,8 @@ void SigningTest::testOOXMLRemoveAll()
     CPPUNIT_ASSERT_EQUAL(static_cast<std::size_t>(1), rInformations.size());
 
     // Then remove the only signature in the document.
-    uno::Reference<security::XCertificate> xCertificate = getCertificate(aManager, svl::crypto::SignatureMethodAlgorithm::RSA);
+    uno::Reference<security::XCertificate> xCertificate
+        = getCertificate(aManager, svl::crypto::SignatureMethodAlgorithm::RSA);
     if (!xCertificate.is())
         return;
     aManager.remove(0);
@@ -548,14 +575,17 @@ void SigningTest::testOOXMLRemoveAll()
     CPPUNIT_ASSERT(!xNameAccess->hasByName("_xmlsignatures"));
 
     // And that content types no longer contains signature types.
-    uno::Reference<io::XStream> xStream(xStorage->openStreamElement("[Content_Types].xml", embed::ElementModes::READWRITE), uno::UNO_QUERY);
+    uno::Reference<io::XStream> xStream(
+        xStorage->openStreamElement("[Content_Types].xml", embed::ElementModes::READWRITE),
+        uno::UNO_QUERY);
     uno::Reference<io::XInputStream> xInputStream = xStream->getInputStream();
-    uno::Sequence< uno::Sequence<beans::StringPair> > aContentTypeInfo = comphelper::OFOPXMLHelper::ReadContentTypeSequence(xInputStream, mxComponentContext);
+    uno::Sequence<uno::Sequence<beans::StringPair>> aContentTypeInfo
+        = comphelper::OFOPXMLHelper::ReadContentTypeSequence(xInputStream, mxComponentContext);
     uno::Sequence<beans::StringPair>& rOverrides = aContentTypeInfo[1];
-    CPPUNIT_ASSERT(std::none_of(rOverrides.begin(), rOverrides.end(), [](const beans::StringPair& rPair)
-    {
-        return rPair.First.startsWith("/_xmlsignatures/sig");
-    }));
+    CPPUNIT_ASSERT(
+        std::none_of(rOverrides.begin(), rOverrides.end(), [](const beans::StringPair& rPair) {
+            return rPair.First.startsWith("/_xmlsignatures/sig");
+        }));
 }
 
 void SigningTest::testODFGood()
@@ -568,11 +598,9 @@ void SigningTest::testODFGood()
     // We expect NOTVALIDATED in case the root CA is not imported on the system, and OK otherwise, so accept both.
     SignatureState nActual = pObjectShell->GetDocumentSignatureState();
     CPPUNIT_ASSERT_MESSAGE(
-        (OString::number(
-             static_cast<std::underlying_type<SignatureState>::type>(nActual))
-         .getStr()),
-        (nActual == SignatureState::NOTVALIDATED
-         || nActual == SignatureState::OK));
+        (OString::number(static_cast<std::underlying_type<SignatureState>::type>(nActual))
+             .getStr()),
+        (nActual == SignatureState::NOTVALIDATED || nActual == SignatureState::OK));
 }
 
 void SigningTest::testODFBroken()
@@ -582,7 +610,8 @@ void SigningTest::testODFBroken()
     CPPUNIT_ASSERT(pBaseModel);
     SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell();
     CPPUNIT_ASSERT(pObjectShell);
-    CPPUNIT_ASSERT_EQUAL(static_cast<int>(SignatureState::BROKEN), static_cast<int>(pObjectShell->GetDocumentSignatureState()));
+    CPPUNIT_ASSERT_EQUAL(static_cast<int>(SignatureState::BROKEN),
+                         static_cast<int>(pObjectShell->GetDocumentSignatureState()));
 }
 
 void SigningTest::testODFNo()
@@ -592,7 +621,8 @@ void SigningTest::testODFNo()
     CPPUNIT_ASSERT(pBaseModel);
     SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell();
     CPPUNIT_ASSERT(pObjectShell);
-    CPPUNIT_ASSERT_EQUAL(static_cast<int>(SignatureState::NOSIGNATURES), static_cast<int>(pObjectShell->GetDocumentSignatureState()));
+    CPPUNIT_ASSERT_EQUAL(static_cast<int>(SignatureState::NOSIGNATURES),
+                         static_cast<int>(pObjectShell->GetDocumentSignatureState()));
 }
 
 void SigningTest::testOOXMLPartial()
@@ -606,11 +636,9 @@ void SigningTest::testOOXMLPartial()
     // We expect NOTVALIDATED in case the root CA is not imported on the system, and PARTIAL_OK otherwise, so accept both.
     SignatureState nActual = pObjectShell->GetDocumentSignatureState();
     CPPUNIT_ASSERT_MESSAGE(
-        (OString::number(
-             static_cast<std::underlying_type<SignatureState>::type>(nActual))
-         .getStr()),
-        (nActual == SignatureState::NOTVALIDATED
-         || nActual == SignatureState::PARTIAL_OK));
+        (OString::number(static_cast<std::underlying_type<SignatureState>::type>(nActual))
+             .getStr()),
+        (nActual == SignatureState::NOTVALIDATED || nActual == SignatureState::PARTIAL_OK));
 }
 
 void SigningTest::testOOXMLBroken()
@@ -621,7 +649,8 @@ void SigningTest::testOOXMLBroken()
     SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell();
     CPPUNIT_ASSERT(pObjectShell);
     // This was SignatureState::NOTVALIDATED/PARTIAL_OK as we did not validate manifest references.
-    CPPUNIT_ASSERT_EQUAL(static_cast<int>(SignatureState::BROKEN), static_cast<int>(pObjectShell->GetDocumentSignatureState()));
+    CPPUNIT_ASSERT_EQUAL(static_cast<int>(SignatureState::BROKEN),
+                         static_cast<int>(pObjectShell->GetDocumentSignatureState()));
 }
 
 #if HAVE_FEATURE_PDFIMPORT
@@ -636,11 +665,9 @@ void SigningTest::testPDFGood()
     // We expect NOTVALIDATED in case the root CA is not imported on the system, and OK otherwise, so accept both.
     SignatureState nActual = pObjectShell->GetDocumentSignatureState();
     CPPUNIT_ASSERT_MESSAGE(
-        (OString::number(
-             static_cast<std::underlying_type<SignatureState>::type>(nActual))
-         .getStr()),
-        (nActual == SignatureState::NOTVALIDATED
-         || nActual == SignatureState::OK));
+        (OString::number(static_cast<std::underlying_type<SignatureState>::type>(nActual))
+             .getStr()),
+        (nActual == SignatureState::NOTVALIDATED || nActual == SignatureState::OK));
 }
 
 void SigningTest::testPDFBad()
@@ -650,7 +677,8 @@ void SigningTest::testPDFBad()
     CPPUNIT_ASSERT(pBaseModel);
     SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell();
     CPPUNIT_ASSERT(pObjectShell);
-    CPPUNIT_ASSERT_EQUAL(static_cast<int>(SignatureState::BROKEN), static_cast<int>(pObjectShell->GetDocumentSignatureState()));
+    CPPUNIT_ASSERT_EQUAL(static_cast<int>(SignatureState::BROKEN),
+                         static_cast<int>(pObjectShell->GetDocumentSignatureState()));
 }
 
 void SigningTest::testPDFNo()
@@ -660,7 +688,8 @@ void SigningTest::testPDFNo()
     CPPUNIT_ASSERT(pBaseModel);
     SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell();
     CPPUNIT_ASSERT(pObjectShell);
-    CPPUNIT_ASSERT_EQUAL(static_cast<int>(SignatureState::NOSIGNATURES), static_cast<int>(pObjectShell->GetDocumentSignatureState()));
+    CPPUNIT_ASSERT_EQUAL(static_cast<int>(SignatureState::NOSIGNATURES),
+                         static_cast<int>(pObjectShell->GetDocumentSignatureState()));
 }
 
 #endif
@@ -676,24 +705,18 @@ void SigningTest::test96097Calc()
 
     SignatureState nActual = pObjectShell->GetScriptingSignatureState();
     CPPUNIT_ASSERT_MESSAGE(
-        (OString::number(
-             static_cast<std::underlying_type<SignatureState>::type>(nActual))
-         .getStr()),
-        (nActual == SignatureState::OK
-         || nActual == SignatureState::NOTVALIDATED
+        (OString::number(static_cast<std::underlying_type<SignatureState>::type>(nActual))
+             .getStr()),
+        (nActual == SignatureState::OK || nActual == SignatureState::NOTVALIDATED
          || nActual == SignatureState::INVALID));
 
-
     uno::Reference<frame::XStorable> xDocStorable(mxComponent, uno::UNO_QUERY_THROW);
 
     // Save a copy
     utl::TempFile aTempFileSaveCopy;
     aTempFileSaveCopy.EnableKillingFile();
     uno::Sequence<beans::PropertyValue> descSaveACopy(comphelper::InitPropertySequence(
-    {
-        { "SaveACopy", uno::Any(true) },
-        { "FilterName", uno::Any(OUString("calc8")) }
-    }));
+        { { "SaveACopy", uno::Any(true) }, { "FilterName", uno::Any(OUString("calc8")) } }));
     xDocStorable->storeToURL(aTempFileSaveCopy.GetURL(), descSaveACopy);
 
     try
@@ -701,10 +724,8 @@ void SigningTest::test96097Calc()
         // Save As
         utl::TempFile aTempFileSaveAs;
         aTempFileSaveAs.EnableKillingFile();
-        uno::Sequence<beans::PropertyValue> descSaveAs(comphelper::InitPropertySequence(
-        {
-            { "FilterName", uno::Any(OUString("calc8")) }
-        }));
+        uno::Sequence<beans::PropertyValue> descSaveAs(
+            comphelper::InitPropertySequence({ { "FilterName", uno::Any(OUString("calc8")) } }));
         xDocStorable->storeAsURL(aTempFileSaveAs.GetURL(), descSaveAs);
     }
     catch (...)
@@ -723,25 +744,18 @@ void SigningTest::test96097Doc()
 
     SignatureState nActual = pObjectShell->GetScriptingSignatureState();
     CPPUNIT_ASSERT_MESSAGE(
-        (OString::number(
-             static_cast<std::underlying_type<SignatureState>::type>(nActual))
-         .getStr()),
-        (nActual == SignatureState::OK
-         || nActual == SignatureState::NOTVALIDATED
+        (OString::number(static_cast<std::underlying_type<SignatureState>::type>(nActual))
+             .getStr()),
+        (nActual == SignatureState::OK || nActual == SignatureState::NOTVALIDATED
          || nActual == SignatureState::INVALID));
 
-
-
     uno::Reference<frame::XStorable> xDocStorable(mxComponent, uno::UNO_QUERY_THROW);
 
     // Save a copy
     utl::TempFile aTempFileSaveCopy;
     aTempFileSaveCopy.EnableKillingFile();
     uno::Sequence<beans::PropertyValue> descSaveACopy(comphelper::InitPropertySequence(
-    {
-        { "SaveACopy", uno::Any(true) },
-        { "FilterName", uno::Any(OUString("writer8")) }
-    }));
+        { { "SaveACopy", uno::Any(true) }, { "FilterName", uno::Any(OUString("writer8")) } }));
     xDocStorable->storeToURL(aTempFileSaveCopy.GetURL(), descSaveACopy);
 
     try
@@ -749,10 +763,8 @@ void SigningTest::test96097Doc()
         // Save As
         utl::TempFile aTempFileSaveAs;
         aTempFileSaveAs.EnableKillingFile();
-        uno::Sequence<beans::PropertyValue> descSaveAs(comphelper::InitPropertySequence(
-        {
-            { "FilterName", uno::Any(OUString("writer8")) }
-        }));
+        uno::Sequence<beans::PropertyValue> descSaveAs(
+            comphelper::InitPropertySequence({ { "FilterName", uno::Any(OUString("writer8")) } }));
         xDocStorable->storeAsURL(aTempFileSaveAs.GetURL(), descSaveAs);
     }
     catch (...)
@@ -775,17 +787,21 @@ void SigningTest::testXAdES()
 
     DocumentSignatureManager aManager(mxComponentContext, DocumentSignatureMode::Content);
     CPPUNIT_ASSERT(aManager.init());
-    uno::Reference <embed::XStorage> xStorage = comphelper::OStorageHelper::GetStorageOfFormatFromURL(ZIP_STORAGE_FORMAT_STRING, aTempFile.GetURL(), embed::ElementModes::READWRITE);
+    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");
 
     // Create a signature.
-    uno::Reference<security::XCertificate> xCertificate = getCertificate(aManager, svl::crypto::SignatureMethodAlgorithm::RSA);
+    uno::Reference<security::XCertificate> xCertificate
+        = getCertificate(aManager, svl::crypto::SignatureMethodAlgorithm::RSA);
     if (!xCertificate.is())
         return;
     sal_Int32 nSecurityId;
-    aManager.add(xCertificate, mxSecurityContext, /*rDescription=*/OUString(), nSecurityId, /*bAdESCompliant=*/true);
+    aManager.add(xCertificate, mxSecurityContext, /*rDescription=*/OUString(), nSecurityId,
+                 /*bAdESCompliant=*/true);
 
     // Write to storage.
     aManager.read(/*bUseTempStream=*/true);
@@ -794,20 +810,29 @@ void SigningTest::testXAdES()
     xTransactedObject->commit();
 
     // Parse the resulting XML.
-    uno::Reference<embed::XStorage> xMetaInf = xStorage->openStorageElement("META-INF", embed::ElementModes::READ);
-    uno::Reference<io::XInputStream> xInputStream(xMetaInf->openStreamElement("documentsignatures.xml", embed::ElementModes::READ), uno::UNO_QUERY);
+    uno::Reference<embed::XStorage> xMetaInf
+        = xStorage->openStorageElement("META-INF", embed::ElementModes::READ);
+    uno::Reference<io::XInputStream> xInputStream(
+        xMetaInf->openStreamElement("documentsignatures.xml", embed::ElementModes::READ),
+        uno::UNO_QUERY);
     std::shared_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(xInputStream, true));
     xmlDocPtr pXmlDoc = parseXmlStream(pStream.get());
 
     // Assert that the digest algorithm is SHA-256 in the bAdESCompliant case, not SHA-1.
-    assertXPath(pXmlDoc, "/odfds:document-signatures/dsig:Signature/dsig:SignedInfo/dsig:Reference[@URI='content.xml']/dsig:DigestMethod", "Algorithm", ALGO_XMLDSIGSHA256);
+    assertXPath(pXmlDoc,
+                "/odfds:document-signatures/dsig:Signature/dsig:SignedInfo/"
+                "dsig:Reference[@URI='content.xml']/dsig:DigestMethod",
+                "Algorithm", ALGO_XMLDSIGSHA256);
 
     // Assert that the digest of the signing certificate is included.
     assertXPath(pXmlDoc, "//xd:CertDigest", 1);
 
     // Assert that the Type attribute on the idSignedProperties reference is
     // not missing.
-    assertXPath(pXmlDoc, "/odfds:document-signatures/dsig:Signature/dsig:SignedInfo/dsig:Reference[@URI='#idSignedProperties']", "Type", "http://uri.etsi.org/01903#SignedProperties");
+    assertXPath(pXmlDoc,
+                "/odfds:document-signatures/dsig:Signature/dsig:SignedInfo/"
+                "dsig:Reference[@URI='#idSignedProperties']",
+                "Type", "http://uri.etsi.org/01903#SignedProperties");
 }
 
 void SigningTest::testXAdESGood()
@@ -820,31 +845,33 @@ void SigningTest::testXAdESGood()
     // We expect NOTVALIDATED in case the root CA is not imported on the system, and OK otherwise, so accept both.
     SignatureState nActual = pObjectShell->GetDocumentSignatureState();
     CPPUNIT_ASSERT_MESSAGE(
-        (OString::number(
-             static_cast<std::underlying_type<SignatureState>::type>(nActual))
-         .getStr()),
-        (nActual == SignatureState::NOTVALIDATED
-         || nActual == SignatureState::OK));
+        (OString::number(static_cast<std::underlying_type<SignatureState>::type>(nActual))
+             .getStr()),
+        (nActual == SignatureState::NOTVALIDATED || nActual == SignatureState::OK));
 }
 
 void SigningTest::testSignatureLineImages()
 {
     // Given: A document (docx) with a signature line and a valid signature
-    uno::Reference< security::XDocumentDigitalSignatures > xSignatures(
+    uno::Reference<security::XDocumentDigitalSignatures> xSignatures(
         security::DocumentDigitalSignatures::createWithVersion(
             comphelper::getProcessComponentContext(), "1.2"));
 
-    uno::Reference<embed::XStorage> xStorage = comphelper::OStorageHelper::GetStorageOfFormatFromURL(
-                ZIP_STORAGE_FORMAT_STRING, m_directories.getURLFromSrc(DATA_DIRECTORY) + "signatureline.docx",
-                embed::ElementModes::READ);
+    uno::Reference<embed::XStorage> xStorage
+        = comphelper::OStorageHelper::GetStorageOfFormatFromURL(
+            ZIP_STORAGE_FORMAT_STRING,
+            m_directories.getURLFromSrc(DATA_DIRECTORY) + "signatureline.docx",
+            embed::ElementModes::READ);
     CPPUNIT_ASSERT(xStorage.is());
 
-    uno::Sequence< security::DocumentSignatureInformation > xSignatureInfo =
-        xSignatures->verifyScriptingContentSignatures(xStorage, uno::Reference< io::XInputStream >());
+    uno::Sequence<security::DocumentSignatureInformation> xSignatureInfo
+        = xSignatures->verifyScriptingContentSignatures(xStorage,
+                                                        uno::Reference<io::XInputStream>());
 
     // The signature should have a valid signature, and signature line with two valid images
     CPPUNIT_ASSERT(xSignatureInfo[0].SignatureIsValid);
-    CPPUNIT_ASSERT_EQUAL(OUString("{DEE0514B-13E8-4674-A831-46E3CDB18BB4}"), xSignatureInfo[0].SignatureLineId);
+    CPPUNIT_ASSERT_EQUAL(OUString("{DEE0514B-13E8-4674-A831-46E3CDB18BB4}"),
+                         xSignatureInfo[0].SignatureLineId);
     CPPUNIT_ASSERT(xSignatureInfo[0].ValidSignatureLineImage.is());
     CPPUNIT_ASSERT(xSignatureInfo[0].InvalidSignatureLineImage.is());
 }
@@ -861,9 +888,8 @@ void SigningTest::testODFGoodGPG()
     // contrast to the X509 test we can fail on NOTVALIDATED here
     SignatureState nActual = pObjectShell->GetDocumentSignatureState();
     CPPUNIT_ASSERT_EQUAL_MESSAGE(
-        (OString::number(
-             static_cast<std::underlying_type<SignatureState>::type>(nActual))
-         .getStr()),
+        (OString::number(static_cast<std::underlying_type<SignatureState>::type>(nActual))
+             .getStr()),
         SignatureState::OK, nActual);
 }
 
@@ -879,9 +905,8 @@ void SigningTest::testODFUntrustedGoodGPG()
     // NOTVALIDATED here
     SignatureState nActual = pObjectShell->GetDocumentSignatureState();
     CPPUNIT_ASSERT_EQUAL_MESSAGE(
-        (OString::number(
-             static_cast<std::underlying_type<SignatureState>::type>(nActual))
-         .getStr()),
+        (OString::number(static_cast<std::underlying_type<SignatureState>::type>(nActual))
+             .getStr()),
         SignatureState::NOTVALIDATED, nActual);
 }
 
@@ -892,7 +917,8 @@ void SigningTest::testODFBrokenStreamGPG()
     CPPUNIT_ASSERT(pBaseModel);
     SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell();
     CPPUNIT_ASSERT(pObjectShell);
-    CPPUNIT_ASSERT_EQUAL(static_cast<int>(SignatureState::BROKEN), static_cast<int>(pObjectShell->GetDocumentSignatureState()));
+    CPPUNIT_ASSERT_EQUAL(static_cast<int>(SignatureState::BROKEN),
+                         static_cast<int>(pObjectShell->GetDocumentSignatureState()));
 }
 
 void SigningTest::testODFBrokenDsigGPG()
@@ -902,7 +928,8 @@ void SigningTest::testODFBrokenDsigGPG()
     CPPUNIT_ASSERT(pBaseModel);
     SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell();
     CPPUNIT_ASSERT(pObjectShell);
-    CPPUNIT_ASSERT_EQUAL(static_cast<int>(SignatureState::BROKEN), static_cast<int>(pObjectShell->GetDocumentSignatureState()));
+    CPPUNIT_ASSERT_EQUAL(static_cast<int>(SignatureState::BROKEN),
+                         static_cast<int>(pObjectShell->GetDocumentSignatureState()));
 }
 
 #if HAVE_GPGCONF_SOCKETDIR
@@ -930,8 +957,10 @@ void SigningTest::testODFEncryptedGPG()
 
 void SigningTest::registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx)
 {
-    xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("odfds"), BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:digitalsignature:1.0"));
-    xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("dsig"), BAD_CAST("http://www.w3.org/2000/09/xmldsig#"));
+    xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("odfds"),
+                       BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:digitalsignature:1.0"));
+    xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("dsig"),
+                       BAD_CAST("http://www.w3.org/2000/09/xmldsig#"));
     xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("xd"), BAD_CAST("http://uri.etsi.org/01903/v1.3.2#"));
 }
 


More information about the Libreoffice-commits mailing list