Mercurial > p > roundup > code
changeset 8381:31f86326bee8
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.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sat, 12 Jul 2025 10:49:52 -0400 |
| parents | 76050d59e41f |
| children | 109c1112c329 |
| files | test/test_xmlrpc.py |
| diffstat | 1 files changed, 17 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/test/test_xmlrpc.py Fri Jul 11 23:18:42 2025 -0400 +++ b/test/test_xmlrpc.py Sat Jul 12 10:49:52 2025 -0400 @@ -7,6 +7,8 @@ from __future__ import print_function import unittest, os, shutil, errno, pytest, sys, difflib, re +from contextlib import contextmanager + from roundup.anypy import xmlrpc_ MultiCall = xmlrpc_.client.MultiCall from roundup.cgi.exceptions import * @@ -26,14 +28,9 @@ if client.defusedxml: skip_defusedxml = lambda func, *args, **kwargs: func - - skip_defusedxml_used = mark_class(pytest.mark.skip( - reason='Skipping non-defusedxml tests: defusedxml library in use')) else: skip_defusedxml = mark_class(pytest.mark.skip( reason='Skipping defusedxml tests: defusedxml library not available')) - - skip_defusedxml_used = lambda func, *args, **kwargs: func if sys.version_info[0] > 2: skip_python2 = lambda func, *args, **kwargs: func @@ -41,6 +38,19 @@ skip_python2 = mark_class(pytest.mark.skip( reason='Skipping test under python 2')) +@contextmanager +def disable_defusedxml(): + # if defusedxml not loaded, do nothing + if 'defusedxml' not in sys.modules: + yield + return + + sys.modules['defusedxml'].xmlrpc.unmonkey_patch() + try: + yield + finally: + # restore normal defused xmlrpc functions + sys.modules['defusedxml'].xmlrpc.monkey_patch() class XmlrpcTest(object): @@ -340,9 +350,9 @@ self.XmlBomb(expectIn=b"defusedxml.common.EntitiesForbidden") @skip_python2 - @skip_defusedxml_used def testNonDefusedXmlBomb(self): - self.XmlBomb(expectIn=b"1234567890"*511) + with disable_defusedxml(): + self.XmlBomb(expectIn=b"1234567890"*511) def XmlBomb(self, expectIn=None):
