8000 Fix up test coverage · python-telegram-bot/urllib3@248f038 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on May 21, 2023. It is now read-only.

Commit 248f038

Browse files
author
Ian Cordasco
committed
Fix up test coverage
1 parent 0ba9a1f commit 248f038

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

test/test_util.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import ssl
55
from itertools import chain
66

7-
from mock import patch
7+
from mock import patch, Mock
88

99
from urllib3 import add_stderr_logger, disable_warnings
1010
from urllib3.util.request import make_headers
@@ -15,7 +15,7 @@
1515
split_first,
1616
Url,
1717
)
18-
from urllib3.util.ssl_ import resolve_cert_reqs
18+
from urllib3.util.ssl_ import resolve_cert_reqs, ssl_wrap_socket
1919
from urllib3.exceptions import (
2020
LocationParseError,
2121
TimeoutStateError,
@@ -372,3 +372,20 @@ class NotReallyAFile(object):
372372
pass
373373

374374
self.assertRaises(ValueError, is_fp_closed, NotReallyAFile())
375+
376+
def test_ssl_wrap_socket_loads_the_cert_chain(self):
377+
socket = object()
378+
mock_context = Mock()
379+
ssl_wrap_socket(ssl_context=mock_context, sock=socket,
380+
certfile='/path/to/certfile')
381+
382+
mock_context.load_cert_chain.assert_called_once_with(
383+
'/path/to/certfile', None)
384+
385+
def test_ssl_wrap_socket_loads_verify_locations(self):
386+
socket = object()
387+
mock_context = Mock()
388+
ssl_wrap_socket(ssl_context=mock_context, ca_certs='/path/to/pem',
389+
sock=socket)
390+
mock_context.load_verify_locations.assert_called_once_with(
391+
'/path/to/pem')

urllib3/util/ssl_.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def create_urllib3_context(ssl_version=None, cert_reqs=ssl.CERT_REQUIRED,
176176
"""
177177
try:
178178
context = SSLContext(ssl_version or ssl.PROTOCOL_SSLv23)
179-
except (NameError, TypeError):
179+
except (NameError, TypeError): # Platform-specific: Python 3.1, 2.7 or 2.6
180180
context = FakeSSLContext(ssl_version or ssl.PROTOCOL_SSLv23)
181181
if options is None:
182182
options = 0

0 commit comments

Comments
 (0)
0