Skip to content

Commit

Permalink
Add testcase for SSLError on read()
Browse files Browse the repository at this point in the history
  • Loading branch information
sethmlarson committed Aug 31, 2020
1 parent cb80f84 commit dda3f13
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions test/test_response.py
Expand Up @@ -2,6 +2,7 @@

import re
import socket
import ssl
import zlib

from io import BytesIO, BufferedReader, TextIOWrapper
Expand All @@ -19,6 +20,7 @@
httplib_IncompleteRead,
IncompleteRead,
InvalidChunkLength,
SSLError,
)
from urllib3.packages.six.moves import http_client as httplib
from urllib3.util.retry import Retry, RequestHistory
Expand Down Expand Up @@ -936,6 +938,24 @@ def stream():

assert b"foo\nbar" == data

def test_non_timeout_ssl_error_on_read(self):
fp = BytesIO(b"")
with mock.patch.object(fp, "read") as fp_read:
# mac/decryption error
mac_error = ssl.SSLError(
"SSL routines", "ssl3_get_record", "decryption failed or bad record mac"
)
fp_read.side_effect = mac_error

with pytest.raises(SSLError) as e:
HTTPResponse(fp)
assert e.value.args[0] == mac_error

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):
Expand Down

0 comments on commit dda3f13

Please sign in to comment.