diff options
author | Marcus Huewe <suse-tux@gmx.de> | 2018-03-12 17:59:20 +0100 |
---|---|---|
committer | Marcus Huewe <suse-tux@gmx.de> | 2018-03-13 21:24:20 +0100 |
commit | a5d58f9ceabe8eb35294db942134b5f4928375a1 (patch) | |
tree | 7e0ef28cbc1d9f6c940ed9c0f2ed5a9433088263 /tests | |
parent | 460189f9d50576095be0bcd924d990285a8d5834 (diff) | |
download | m2crypto-a5d58f9ceabe8eb35294db942134b5f4928375a1.tar.gz |
Do not by-pass a potential transfer decoding in m2urllib2
For instance, without this patch no chunk decoding is performed, even
if the HTTP response includes a "Transfer-Encoding: chunked" header
(only affects the python3 code path). To fix this, "recv_into" has to
call http.client.HTTPResponse.readinto, which does the corresponding
transfer decoding.
Thanks to Marco Strigl <mstrigl@suse.com> for reporting and helping
to debug this issue.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/te_chunked_response.txt | 11 | ||||
-rw-r--r-- | tests/test_ssl.py | 22 |
2 files changed, 33 insertions, 0 deletions
diff --git a/tests/te_chunked_response.txt b/tests/te_chunked_response.txt new file mode 100644 index 0000000..f7eaadd --- /dev/null +++ b/tests/te_chunked_response.txt @@ -0,0 +1,11 @@ +HTTP/1.1 200 ok
+Content-Type: text/plain
+Transfer-Encoding: chunked
+
+4
+foo +
+7
+foobar +
+0
diff --git a/tests/test_ssl.py b/tests/test_ssl.py index 3140b33..459531a 100644 --- a/tests/test_ssl.py +++ b/tests/test_ssl.py @@ -1004,6 +1004,27 @@ class Urllib2SSLClientTestCase(BaseSSLClientTestCase): self.stop_server(pid) +class Urllib2TEChunkedSSLClientTestCase(BaseSSLClientTestCase): + """Test a response with "Transfer-Encoding: chunked".""" + + def setUp(self): + super(Urllib2TEChunkedSSLClientTestCase, self).setUp() + self.args = ['s_server', '-quiet', '-HTTP', + '-accept', str(self.srv_port)] + + def test_transfer_encoding_chunked(self): + pid = self.start_server(self.args) + try: + url = 'https://%s:%s/te_chunked_response.txt' % (srv_host, + self.srv_port) + o = m2urllib2.build_opener() + u = o.open(url) + data = u.read() + self.assertEqual(b'foo\nfoobar\n', data) + finally: + self.stop_server(pid) + + @unittest.skipUnless(util.py27plus, "Twisted doesn't test well with Python 2.6") class TwistedSSLClientTestCase(BaseSSLClientTestCase): @@ -1166,6 +1187,7 @@ def suite(): suite.addTest(unittest.makeSuite(HttpslibSSLSNIClientTestCase)) suite.addTest(unittest.makeSuite(UrllibSSLClientTestCase)) suite.addTest(unittest.makeSuite(Urllib2SSLClientTestCase)) + suite.addTest(unittest.makeSuite(Urllib2TEChunkedSSLClientTestCase)) suite.addTest(unittest.makeSuite(MiscSSLClientTestCase)) suite.addTest(unittest.makeSuite(FtpslibTestCase)) try: |