From 2a1bf30e6d09f3a9d89304261bb27d11440e468f Mon Sep 17 00:00:00 2001 From: Tomas Divis Date: Wed, 22 Mar 2023 20:36:45 +0100 Subject: [PATCH] Fix #244 - Fix failing test with libxmlsec-1.2.36, also make libxmlsec version available from Python. --- src/main.c | 13 +++++ tests/data/sign5-out-xmlsec_lt_1_2_36.xml | 67 +++++++++++++++++++++++ tests/data/sign5-out.xml | 4 +- tests/test_ds.py | 6 +- 4 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 tests/data/sign5-out-xmlsec_lt_1_2_36.xml diff --git a/src/main.c b/src/main.c index ffcae14f..5773db3b 100644 --- a/src/main.c +++ b/src/main.c @@ -119,6 +119,13 @@ static PyObject* PyXmlSec_PyShutdown(PyObject* self) { Py_RETURN_NONE; } +static char PyXmlSec_GetLibXmlSecVersion__doc__[] = \ + "get_libxmlsec_version() -> tuple\n" + "Returns Version tuple of wrapped libxml library."; +static PyObject* PyXmlSec_GetLibXmlSecVersion() { + return Py_BuildValue("(iii)", XMLSEC_VERSION_MAJOR, XMLSEC_VERSION_MINOR, XMLSEC_VERSION_SUBMINOR); +} + static char PyXmlSec_PyEnableDebugOutput__doc__[] = \ "enable_debug_trace(enabled) -> None\n" "Enables or disables calling LibXML2 callback from the default errors callback.\n\n" @@ -386,6 +393,12 @@ static PyMethodDef PyXmlSec_MainMethods[] = { METH_NOARGS, PyXmlSec_PyShutdown__doc__ }, + { + "get_libxmlsec_version", + (PyCFunction)PyXmlSec_GetLibXmlSecVersion, + METH_NOARGS, + PyXmlSec_GetLibXmlSecVersion__doc__ + }, { "enable_debug_trace", (PyCFunction)PyXmlSec_PyEnableDebugOutput, diff --git a/tests/data/sign5-out-xmlsec_lt_1_2_36.xml b/tests/data/sign5-out-xmlsec_lt_1_2_36.xml new file mode 100644 index 00000000..4d8d28be --- /dev/null +++ b/tests/data/sign5-out-xmlsec_lt_1_2_36.xml @@ -0,0 +1,67 @@ + + + + + Hello, World! + + + + + + + + + + +HjY8ilZAIEM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certificate,O=XML Security Library (http://www.aleksey.com/xmlsec),ST=California,C=US +JIQs8tRZIGKLLlyGkKOqMLonGpw= + + + diff --git a/tests/data/sign5-out.xml b/tests/data/sign5-out.xml index 4d8d28be..f359b138 100644 --- a/tests/data/sign5-out.xml +++ b/tests/data/sign5-out.xml @@ -60,8 +60,8 @@ MA0GCSqGSIb3DQEBBAUAA4GBALU/mzIxSv8vhDuomxFcplzwdlLZbvSQrfoNkMGY 1UoS3YJrN+jZLWKSyWE3mIaPpElqXiXQGGkwD5iPQ1iJMbI7BeLvx6ZxX/f+c8Wn ss0uc1NxfahMaBoyG15IL4+beqO182fosaKJTrJNG3mc//ANGU9OsQM9mfBEt4oL NJ2D -emailAddress=xmlsec@aleksey.com,CN=Aleksey Sanin,OU=Examples RSA Certificate,O=XML Security Library (http://www.aleksey.com/xmlsec),ST=California,C=US -JIQs8tRZIGKLLlyGkKOqMLonGpw= + + diff --git a/tests/test_ds.py b/tests/test_ds.py index 694ad431..459545f4 100644 --- a/tests/test_ds.py +++ b/tests/test_ds.py @@ -182,7 +182,11 @@ def test_sign_case5(self): self.assertEqual("rsakey.pem", ctx.key.name) ctx.sign(sign) - self.assertEqual(self.load_xml("sign5-out.xml"), root) + if xmlsec.get_libxmlsec_version() >= (1, 2, 36): + expected_xml_file = 'sign5-out.xml' + else: + expected_xml_file = 'sign5-out-xmlsec_lt_1_2_36.xml' + self.assertEqual(self.load_xml(expected_xml_file), root) def test_sign_binary_bad_args(self): ctx = xmlsec.SignatureContext()