From fb8f0ef26d57986bd27c6c5088939c32453e6b06 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Fri, 19 Jun 2020 17:21:58 +0200 Subject: sd signature line: add testcase Fails with commit 9b7a890fd59744459692d7f66402c6bdd25acec4 (sd signature line: include shape in the appearance widget, 2020-06-19) reverted. Change-Id: Ib237774374553af5d37c9deaffdea6fae65a28f4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96737 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- xmlsecurity/CppunitTest_xmlsecurity_signing.mk | 3 + .../qa/unit/signing/data/add-visible-signature.pdf | Bin 0 -> 2235 bytes xmlsecurity/qa/unit/signing/signing.cxx | 76 +++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 xmlsecurity/qa/unit/signing/data/add-visible-signature.pdf (limited to 'xmlsecurity') diff --git a/xmlsecurity/CppunitTest_xmlsecurity_signing.mk b/xmlsecurity/CppunitTest_xmlsecurity_signing.mk index c748c644aecb..11a00d0482b4 100644 --- a/xmlsecurity/CppunitTest_xmlsecurity_signing.mk +++ b/xmlsecurity/CppunitTest_xmlsecurity_signing.mk @@ -22,16 +22,19 @@ $(eval $(call gb_CppunitTest_use_libraries,xmlsecurity_signing, \ sal \ sax \ sfx \ + svx \ test \ tl \ unotest \ utl \ + vcl \ xmlsecurity \ )) $(eval $(call gb_CppunitTest_use_externals,xmlsecurity_signing,\ boost_headers \ libxml2 \ + $(if $(filter PDFIUM,$(BUILD_TYPE)),pdfium) \ )) $(eval $(call gb_CppunitTest_set_include,xmlsecurity_signing,\ diff --git a/xmlsecurity/qa/unit/signing/data/add-visible-signature.pdf b/xmlsecurity/qa/unit/signing/data/add-visible-signature.pdf new file mode 100644 index 000000000000..8dedb6998b23 Binary files /dev/null and b/xmlsecurity/qa/unit/signing/data/add-visible-signature.pdf differ diff --git a/xmlsecurity/qa/unit/signing/signing.cxx b/xmlsecurity/qa/unit/signing/signing.cxx index 637e5057bd05..4373a5a5bb26 100644 --- a/xmlsecurity/qa/unit/signing/signing.cxx +++ b/xmlsecurity/qa/unit/signing/signing.cxx @@ -26,6 +26,8 @@ #include #include #include +#include +#include #include #include @@ -50,6 +52,16 @@ #include #include #include +#include +#include +#include +#include + +#if HAVE_FEATURE_PDFIUM +#include +#include +#include +#endif using namespace com::sun::star; @@ -623,6 +635,70 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testPDFNo) static_cast(pObjectShell->GetDocumentSignatureState())); } +#if HAVE_FEATURE_PDFIUM +CPPUNIT_TEST_FIXTURE(SigningTest, testPDFAddVisibleSignature) +{ + // Given: copy the test document to a temporary file, as it'll be modified. + utl::TempFile aTempFile; + aTempFile.EnableKillingFile(); + OUString aSourceURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "add-visible-signature.pdf"; + OUString aURL = aTempFile.GetURL(); + osl::File::RC eRet = osl::File::copy(aSourceURL, aURL); + CPPUNIT_ASSERT_EQUAL(osl::File::RC::E_None, eRet); + + // Open it. + uno::Sequence aArgs = { comphelper::makePropertyValue("ReadOnly", true) }; + mxComponent = loadFromDesktop(aURL, "com.sun.star.drawing.DrawingDocument", aArgs); + SfxBaseModel* pBaseModel = dynamic_cast(mxComponent.get()); + CPPUNIT_ASSERT(pBaseModel); + SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell(); + CPPUNIT_ASSERT(pObjectShell); + + // Add a signature line. + uno::Reference xFactory(mxComponent, uno::UNO_QUERY); + uno::Reference xShape( + xFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"), uno::UNO_QUERY); + xShape->setPosition(awt::Point(1000, 15000)); + xShape->setSize(awt::Size(10000, 10000)); + uno::Reference xSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xDrawPages = xSupplier->getDrawPages(); + uno::Reference xDrawPage(xDrawPages->getByIndex(0), uno::UNO_QUERY); + xDrawPage->add(xShape); + + // Select it and assign a certificate. + uno::Reference xSelectionSupplier(pBaseModel->getCurrentController(), + uno::UNO_QUERY); + xSelectionSupplier->select(uno::makeAny(xShape)); + uno::Sequence> aCertificates + = mxSecurityContext->getSecurityEnvironment()->getPersonalCertificates(); + if (!aCertificates.hasElements()) + { + return; + } + SdrView* pView = SfxViewShell::Current()->GetDrawView(); + svx::SignatureLineHelper::setShapeCertificate(pView, aCertificates[0]); + + // When: do the actual signing. + pObjectShell->SignDocumentContentUsingCertificate(aCertificates[0]); + + // Then: count the # of shapes on the signature widget/annotation. + std::shared_ptr pPDFium = vcl::pdf::PDFiumLibrary::get(); + SvFileStream aFile(aTempFile.GetURL(), StreamMode::READ); + SvMemoryStream aMemory; + aMemory.WriteStream(aFile); + ScopedFPDFDocument pPdfDocument( + FPDF_LoadMemDocument(aMemory.GetData(), aMemory.GetSize(), /*password=*/nullptr)); + ScopedFPDFPage pPdfPage(FPDF_LoadPage(pPdfDocument.get(), /*page_index=*/0)); + CPPUNIT_ASSERT_EQUAL(1, FPDFPage_GetAnnotCount(pPdfPage.get())); + ScopedFPDFAnnotation pAnnot(FPDFPage_GetAnnot(pPdfPage.get(), 0)); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 4 + // - Actual : 0 + // i.e. the signature was there, but it was empty / not visible. + CPPUNIT_ASSERT_EQUAL(4, FPDFAnnot_GetObjectCount(pAnnot.get())); +} +#endif + #endif CPPUNIT_TEST_FIXTURE(SigningTest, test96097Calc) -- cgit