summaryrefslogtreecommitdiff
path: root/xmlsecurity/qa
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2016-11-30 11:01:29 +0100
committerMiklos Vajna <vmiklos@collabora.co.uk>2016-11-30 14:13:09 +0000
commitdeaa4701e609f698999c3e05ce79b15f4cb94670 (patch)
tree19603baf28c216d18b32ae68b69ccf9309896de7 /xmlsecurity/qa
parentbf7b5ee0c8a552625b80a7a57c32fe05ee756f7a (diff)
CppunitTest_xmlsecurity_signing: add 2 more ODF / XAdES tests
1) Make sure we handle the case when the document has a signature stream, but it's empty. 2) Make sure we find a given XAdES-enabled ODF document valid. Previously this was tested only dynamically, i.e. breaking both the import and the export at the same time went unnoticed. Change-Id: Icaa29cfa1f5b817459239ee8dbdc3bf023a2a1a7 Reviewed-on: https://gerrit.libreoffice.org/31413 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Diffstat (limited to 'xmlsecurity/qa')
-rw-r--r--xmlsecurity/qa/unit/signing/data/good-xades.odtbin0 -> 13918 bytes
-rw-r--r--xmlsecurity/qa/unit/signing/data/no.odtbin0 -> 8345 bytes
-rw-r--r--xmlsecurity/qa/unit/signing/signing.cxx33
3 files changed, 33 insertions, 0 deletions
diff --git a/xmlsecurity/qa/unit/signing/data/good-xades.odt b/xmlsecurity/qa/unit/signing/data/good-xades.odt
new file mode 100644
index 000000000000..4f96d4bd89c0
--- /dev/null
+++ b/xmlsecurity/qa/unit/signing/data/good-xades.odt
Binary files differ
diff --git a/xmlsecurity/qa/unit/signing/data/no.odt b/xmlsecurity/qa/unit/signing/data/no.odt
new file mode 100644
index 000000000000..22cf7683a0c7
--- /dev/null
+++ b/xmlsecurity/qa/unit/signing/data/no.odt
Binary files differ
diff --git a/xmlsecurity/qa/unit/signing/signing.cxx b/xmlsecurity/qa/unit/signing/signing.cxx
index 5bcf0c26f441..8ddc39b06220 100644
--- a/xmlsecurity/qa/unit/signing/signing.cxx
+++ b/xmlsecurity/qa/unit/signing/signing.cxx
@@ -69,6 +69,8 @@ public:
void testODFGood();
/// Test a typical broken ODF signature where one stream is corrupted.
void testODFBroken();
+ /// Document has a signature stream, but no actual signatures.
+ void testODFNo();
/// Test a typical OOXML where a number of (but not all) streams are signed.
void testOOXMLPartial();
/// Test a typical broken OOXML signature where one stream is corrupted.
@@ -90,12 +92,16 @@ public:
#endif
void test96097Calc();
void test96097Doc();
+ /// Creates a XAdES signature from scratch.
void testXAdES();
+ /// Works with an existing good XAdES signature.
+ void testXAdESGood();
CPPUNIT_TEST_SUITE(SigningTest);
CPPUNIT_TEST(testDescription);
CPPUNIT_TEST(testODFGood);
CPPUNIT_TEST(testODFBroken);
+ CPPUNIT_TEST(testODFNo);
CPPUNIT_TEST(testODFBroken);
CPPUNIT_TEST(testOOXMLPartial);
CPPUNIT_TEST(testOOXMLBroken);
@@ -111,6 +117,7 @@ public:
CPPUNIT_TEST(test96097Calc);
CPPUNIT_TEST(test96097Doc);
CPPUNIT_TEST(testXAdES);
+ CPPUNIT_TEST(testXAdESGood);
CPPUNIT_TEST_SUITE_END();
private:
@@ -380,6 +387,16 @@ void SigningTest::testODFBroken()
CPPUNIT_ASSERT_EQUAL(static_cast<int>(SignatureState::BROKEN), static_cast<int>(pObjectShell->GetDocumentSignatureState()));
}
+void SigningTest::testODFNo()
+{
+ createDoc(m_directories.getURLFromSrc(DATA_DIRECTORY) + "no.odt");
+ SfxBaseModel* pBaseModel = dynamic_cast<SfxBaseModel*>(mxComponent.get());
+ CPPUNIT_ASSERT(pBaseModel);
+ SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell();
+ CPPUNIT_ASSERT(pObjectShell);
+ CPPUNIT_ASSERT_EQUAL(static_cast<int>(SignatureState::NOSIGNATURES), static_cast<int>(pObjectShell->GetDocumentSignatureState()));
+}
+
void SigningTest::testOOXMLPartial()
{
createDoc(m_directories.getURLFromSrc(DATA_DIRECTORY) + "partial.docx");
@@ -591,6 +608,22 @@ void SigningTest::testXAdES()
assertXPath(pXmlDoc, "//xd:CertDigest", 1);
}
+void SigningTest::testXAdESGood()
+{
+ createDoc(m_directories.getURLFromSrc(DATA_DIRECTORY) + "good-xades.odt");
+ SfxBaseModel* pBaseModel = dynamic_cast<SfxBaseModel*>(mxComponent.get());
+ CPPUNIT_ASSERT(pBaseModel);
+ SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell();
+ CPPUNIT_ASSERT(pObjectShell);
+ // 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));
+}
void SigningTest::registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx)
{
xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("odfds"), BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:digitalsignature:1.0"));