diff options
author | Benjamin Peterson <benjamin@python.org> | 2014-12-06 01:15:15 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2014-12-06 01:15:15 (GMT) |
commit | 4e9cefaf86035f8014e09049328d197b6506532f (patch) | |
tree | ddbd8877138fec984a96531571b870f996ed37d0 /Lib/test | |
parent | 258f3f0dc23c7721c7a9314d9aa47fa3504b3c52 (diff) | |
download | cpython-4e9cefaf86035f8014e09049328d197b6506532f.zip cpython-4e9cefaf86035f8014e09049328d197b6506532f.tar.gz cpython-4e9cefaf86035f8014e09049328d197b6506532f.tar.bz2 |
add a default limit for the amount of data xmlrpclib.gzip_decode will return (closes #16043)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_xmlrpc.py | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/Lib/test/test_xmlrpc.py b/Lib/test/test_xmlrpc.py index 3814191..718cc17 100644 --- a/Lib/test/test_xmlrpc.py +++ b/Lib/test/test_xmlrpc.py @@ -776,7 +776,7 @@ class GzipServerTestCase(BaseServerTestCase): p.pow(6, 8) p("close")() - def test_gsip_response(self): + def test_gzip_response(self): t = self.Transport() p = xmlrpclib.ServerProxy(URL, transport=t) old = self.requestHandler.encode_threshold @@ -790,6 +790,26 @@ class GzipServerTestCase(BaseServerTestCase): self.requestHandler.encode_threshold = old self.assertTrue(a>b) + +class GzipUtilTestCase(unittest.TestCase): + + def test_gzip_decode_limit(self): + max_gzip_decode = 20 * 1024 * 1024 + data = b'\0' * max_gzip_decode + encoded = xmlrpclib.gzip_encode(data) + decoded = xmlrpclib.gzip_decode(encoded) + self.assertEqual(len(decoded), max_gzip_decode) + + data = b'\0' * (max_gzip_decode + 1) + encoded = xmlrpclib.gzip_encode(data) + + with self.assertRaisesRegexp(ValueError, + "max gzipped payload length exceeded"): + xmlrpclib.gzip_decode(encoded) + + xmlrpclib.gzip_decode(encoded, max_decode=-1) + + #Test special attributes of the ServerProxy object class ServerProxyTestCase(unittest.TestCase): def setUp(self): @@ -990,6 +1010,7 @@ def test_main(): try: import gzip xmlrpc_tests.append(GzipServerTestCase) + xmlrpc_tests.append(GzipUtilTestCase) except ImportError: pass #gzip not supported in this build xmlrpc_tests.append(MultiPathServerTestCase) |