From 648e3d0da766ce50422af51232880fca1c01361f Mon Sep 17 00:00:00 2001 From: John Rouillard Date: Sun, 29 Dec 2024 19:48:42 -0500 Subject: [PATCH] issue2551116 - difusedxml support - python2 fixups. Make sure python2 code path sets client.defusedxml so the code can still run. Bomb tests fail under python2. So disable test under python 2. In the past it was due to string/byte type difference. Not worth fixing the tests since python 2 support dropped. --- roundup/anypy/xmlrpc_.py | 7 ++++--- test/test_xmlrpc.py | 9 +++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/roundup/anypy/xmlrpc_.py b/roundup/anypy/xmlrpc_.py index 9d39e2e0..d77d2341 100644 --- a/roundup/anypy/xmlrpc_.py +++ b/roundup/anypy/xmlrpc_.py @@ -3,18 +3,19 @@ from xmlrpc import client, server # If client.defusedxml == False, client.py will warn that # xmlrpc is insecure and defusedxml should be installed. - client.defusedxml=False + client.defusedxml = False try: from defusedxml import xmlrpc xmlrpc.monkey_patch() # figure out how to allow user to set xmlrpc.MAX_DATA = bytes - client.defusedxml=True + client.defusedxml = True except ImportError: # use regular xmlrpc with warnings pass - server.SimpleXMLRPCDispatcher + server.SimpleXMLRPCDispatcher # noqa: B018 except (ImportError, AttributeError): # Python 2. import SimpleXMLRPCServer as server import xmlrpclib as client # noqa: F401 + client.defusedxml = False diff --git a/test/test_xmlrpc.py b/test/test_xmlrpc.py index ae134689..c3709bf8 100644 --- a/test/test_xmlrpc.py +++ b/test/test_xmlrpc.py @@ -35,6 +35,13 @@ skip_defusedxml_used = lambda func, *args, **kwargs: func +if sys.version_info[0] > 2: + skip_python2 = lambda func, *args, **kwargs: func +else: + skip_python2 = mark_class(pytest.mark.skip( + reason='Skipping test under python 2')) + + class XmlrpcTest(object): backend = None @@ -327,10 +334,12 @@ class S: for n, r in enumerate(result): self.assertEqual(r, results[n]) + @skip_python2 @skip_defusedxml def testDefusedXmlBomb(self): self.XmlBomb(expectIn=b"defusedxml.common.EntitiesForbidden") + @skip_python2 @skip_defusedxml_used def testNonDefusedXmlBomb(self): self.XmlBomb(expectIn=b"1234567890"*511)