Skip to content

Commit

Permalink
issue2551116 - difusedxml support - python2 fixups.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rouilj committed Dec 30, 2024
1 parent 13b7396 commit 648e3d0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 4 additions & 3 deletions roundup/anypy/xmlrpc_.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions test/test_xmlrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 648e3d0

Please sign in to comment.