summaryrefslogtreecommitdiff
path: root/test/test_response.py
diff options
context:
space:
mode:
authorSeth Michael Larson <sethmichaellarson@gmail.com>2020-08-31 10:35:21 -0500
committerGitHub <noreply@github.com>2020-08-31 10:35:21 -0500
commitbb862a23587cdbab9483cd096ab3cf96042d2756 (patch)
treeaacc92ae417ff99bef65878709ef6969a9e28b8e /test/test_response.py
parent24e540fb1ee8e127d7d3a354c6fa50c22e61ed11 (diff)
downloadurllib3-bb862a23587cdbab9483cd096ab3cf96042d2756.tar.gz
Wrap BaseSSLError into SSLError during response reads
Diffstat (limited to 'test/test_response.py')
-rw-r--r--test/test_response.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/test/test_response.py b/test/test_response.py
index a476f23b..b838622f 100644
--- a/test/test_response.py
+++ b/test/test_response.py
@@ -1,7 +1,9 @@
# -*- coding: utf-8 -*-
+import contextlib
import re
import socket
+import ssl
import zlib
from io import BytesIO, BufferedReader, TextIOWrapper
@@ -19,6 +21,7 @@ from urllib3.exceptions import (
httplib_IncompleteRead,
IncompleteRead,
InvalidChunkLength,
+ SSLError,
)
from urllib3.packages.six.moves import http_client as httplib
from urllib3.util.retry import Retry, RequestHistory
@@ -936,6 +939,30 @@ class TestResponse(object):
assert b"foo\nbar" == data
+ def test_non_timeout_ssl_error_on_read(self):
+ mac_error = ssl.SSLError(
+ "SSL routines", "ssl3_get_record", "decryption failed or bad record mac"
+ )
+
+ @contextlib.contextmanager
+ def make_bad_mac_fp():
+ fp = BytesIO(b"")
+ with mock.patch.object(fp, "read") as fp_read:
+ # mac/decryption error
+ fp_read.side_effect = mac_error
+ yield fp
+
+ with make_bad_mac_fp() as fp:
+ with pytest.raises(SSLError) as e:
+ HTTPResponse(fp)
+ assert e.value.args[0] == mac_error
+
+ with make_bad_mac_fp() as fp:
+ resp = HTTPResponse(fp, preload_content=False)
+ with pytest.raises(SSLError) as e:
+ resp.read()
+ assert e.value.args[0] == mac_error
+
class MockChunkedEncodingResponse(object):
def __init__(self, content):