Skip to content
Myr

Fix #4025

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Jonas Laursen · committed by Cory Benfield · parent a8bfa82 · Browse files · 2 files+35 added−31 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+35 added−31 removed

  • tests:+4 added−0 removed
  • other:+31 added−31 removed

2 files+35 added−31 removed

modified:requests/adapters.py+31 added-31 removed
207 unmodified lines
208 the server's TLS certificate, or a string, in which case it must be a path209 to a CA bundle to use210 :param cert: The SSL certificate to verify.211 """212 if url.lower().startswith('https') and verify:212 if url.lower().startswith('https'):213 if verify:214 cert_loc = None215216 # Allow self-specified cert location.217 if verify is not True:214 cert_loc = None218 cert_loc = verify219216 # Allow self-specified cert location.217 if verify is not True:218 cert_loc = verify220 if not cert_loc:221 cert_loc = DEFAULT_CA_BUNDLE_PATH222220 if not cert_loc:221 cert_loc = DEFAULT_CA_BUNDLE_PATH223 if not cert_loc or not os.path.exists(cert_loc):224 raise IOError("Could not find a suitable TLS CA certificate bundle, "225 "invalid path: {0}".format(cert_loc))226223 if not cert_loc or not os.path.exists(cert_loc):224 raise IOError("Could not find a suitable TLS CA certificate bundle, "225 "invalid path: {0}".format(cert_loc))227 conn.cert_reqs = 'CERT_REQUIRED'228227 conn.cert_reqs = 'CERT_REQUIRED'228229 if not os.path.isdir(cert_loc):230 conn.ca_certs = cert_loc229 if not os.path.isdir(cert_loc):230 conn.ca_certs = cert_loc231 else:232 conn.ca_cert_dir = cert_loc233 else:232 conn.ca_cert_dir = cert_loc233 else:234 conn.cert_reqs = 'CERT_NONE'235 conn.ca_certs = None236 conn.ca_cert_dir = None234 conn.cert_reqs = 'CERT_NONE'235 conn.ca_certs = None236 conn.ca_cert_dir = None237238 if cert:239 if not isinstance(cert, basestring):240 conn.cert_file = cert[0]241 conn.key_file = cert[1]242 else:243 conn.cert_file = cert244 if conn.cert_file and not os.path.exists(conn.cert_file):245 raise IOError("Could not find the TLS certificate file, "246 "invalid path: {0}".format(conn.cert_file))247 if conn.key_file and not os.path.exists(conn.key_file):248 raise IOError("Could not find the TLS key file, "249 "invalid path: {0}".format(conn.key_file))238 if cert:239 if not isinstance(cert, basestring):240 conn.cert_file = cert[0]241 conn.key_file = cert[1]242 else:243 conn.cert_file = cert244 if conn.cert_file and not os.path.exists(conn.cert_file):245 raise IOError("Could not find the TLS certificate file, "246 "invalid path: {0}".format(conn.cert_file))247 if conn.key_file and not os.path.exists(conn.key_file):248 raise IOError("Could not find the TLS key file, "249 "invalid path: {0}".format(conn.key_file))250251 def build_response(self, req, resp):252 """Builds a :class:`Response <requests.Response>` object from a urllib3253 response. This should not be called from user code, and is only exposed
265 unmodified lines
modified:tests/test_requests.py+4 added
784 unmodified lines
785 with pytest.raises(IOError) as e:786 requests.get(httpbin_secure(), cert=('.', INVALID_PATH))787 assert str(e.value) == 'Could not find the TLS key file, invalid path: {0}'.format(INVALID_PATH)788789 def test_http_with_certificate(self, httpbin):790 r = requests.get(httpbin(), cert='.')791 assert r.status_code == 200792793 def test_https_warnings(self, httpbin_secure, httpbin_ca_bundle):794 """warnings are emitted with requests.get"""795 if HAS_MODERN_SSL or HAS_PYOPENSSL:796 warnings_expected = ('SubjectAltNameWarning', )
1583 unmodified lines