Skip to content

Commit 6fdbeae

Browse files
committed
test: test regular xmlrpc codepath even when defusedxml installed
This was a leftover from the defusedxml support addition. When defusedxml was installed, the bomb test for regular xmlrpc was skipped. Now if defusedxml is installed, a context manager unpatches the xmlrpc and runs the test for the regular xmlrpc which should result in a long string.
1 parent a7760c5 commit 6fdbeae

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

test/test_xmlrpc.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
from __future__ import print_function
88
import unittest, os, shutil, errno, pytest, sys, difflib, re
99

10+
from contextlib import contextmanager
11+
1012
from roundup.anypy import xmlrpc_
1113
MultiCall = xmlrpc_.client.MultiCall
1214
from roundup.cgi.exceptions import *
@@ -26,21 +28,29 @@
2628

2729
if client.defusedxml:
2830
skip_defusedxml = lambda func, *args, **kwargs: func
29-
30-
skip_defusedxml_used = mark_class(pytest.mark.skip(
31-
reason='Skipping non-defusedxml tests: defusedxml library in use'))
3231
else:
3332
skip_defusedxml = mark_class(pytest.mark.skip(
3433
reason='Skipping defusedxml tests: defusedxml library not available'))
35-
36-
skip_defusedxml_used = lambda func, *args, **kwargs: func
3734

3835
if sys.version_info[0] > 2:
3936
skip_python2 = lambda func, *args, **kwargs: func
4037
else:
4138
skip_python2 = mark_class(pytest.mark.skip(
4239
reason='Skipping test under python 2'))
4340

41+
@contextmanager
42+
def disable_defusedxml():
43+
# if defusedxml not loaded, do nothing
44+
if 'defusedxml' not in sys.modules:
45+
yield
46+
return
47+
48+
sys.modules['defusedxml'].xmlrpc.unmonkey_patch()
49+
try:
50+
yield
51+
finally:
52+
# restore normal defused xmlrpc functions
53+
sys.modules['defusedxml'].xmlrpc.monkey_patch()
4454

4555
class XmlrpcTest(object):
4656

@@ -340,9 +350,9 @@ def testDefusedXmlBomb(self):
340350
self.XmlBomb(expectIn=b"defusedxml.common.EntitiesForbidden")
341351

342352
@skip_python2
343-
@skip_defusedxml_used
344353
def testNonDefusedXmlBomb(self):
345-
self.XmlBomb(expectIn=b"1234567890"*511)
354+
with disable_defusedxml():
355+
self.XmlBomb(expectIn=b"1234567890"*511)
346356

347357
def XmlBomb(self, expectIn=None):
348358

0 commit comments

Comments
 (0)