PR review fixes:
Before adoption: this commit came in with the history the project adopted, so no landing records it.
- used httpbin_secure for tests - updated docstring related to `verify` param" - used TLS acronym instead of SSL
authored by Bastien Gérard · committed by Bastien Gérard · parent 42ec8b0 · Browse files · 4 files·+26 added−18 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+26 added−18 removed
- tests:+8 added−8 removed
- other:+18 added−10 removed
Provenance
- Commit
4207867- Tree
bd4b09f- Author
Bastien Gérard <bastien.gerard@cluepoints.com>- Committer
Bastien Gérard <bastien.gerard@cluepoints.com>- Parent
42ec8b0
4 files changed+26 added−18 removed
modified:requests/adapters.py+12 added-7 removed
62 unmodified lines63 :param timeout: (optional) How long to wait for the server to send64 data before giving up, as a float, or a :ref:`(connect timeout,65 read timeout) <timeouts>` tuple.66 :type timeout: float or tuple67- :param verify: (optional) Whether to verify SSL certificates.67+ :param verify: (optional) Either a boolean, in which case it controls whether we verify68+ the server's TLS certificate, or a string, in which case it must be a path69+ to a CA bundle to use70 :param cert: (optional) Any user-provided SSL certificate to be trusted.71 :param proxies: (optional) The proxies dictionary to apply to the request.72 """73 raise NotImplementedError129 unmodified lines203 :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.204 205 :param conn: The urllib3 connection object associated with the cert.206 :param url: The requested URL.205- :param verify: Whether we should actually verify the certificate206- or it could be a path to a ca bundle207+ :param verify: Either a boolean, in which case it controls whether we verify208+ 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:213 6 unmodified lines220 if not cert_loc:221 cert_loc = DEFAULT_CA_BUNDLE_PATH222 223 if not cert_loc or not os.path.exists(cert_loc):221- raise IOError("Could not find a suitable SSL CA certificate bundle, "224+ raise IOError("Could not find a suitable TLS CA certificate bundle, "225 "invalid path: {0}".format(cert_loc))226 227 conn.cert_reqs = 'CERT_REQUIRED'228 12 unmodified lines241 conn.key_file = cert[1]242 else:243 conn.cert_file = cert244 if conn.cert_file and not os.path.exists(conn.cert_file):242- raise IOError("Could not find the SSL certificate 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):245- raise IOError("Could not find the SSL key file, "248+ raise IOError("Could not find the TLS key file, "249 "invalid path: {0}".format(conn.key_file))250 251 def build_response(self, req, resp):252 """Builds a :class:`Response <requests.Response>` object from a urllib3138 unmodified lines391 :param timeout: (optional) How long to wait for the server to send392 data before giving up, as a float, or a :ref:`(connect timeout,393 read timeout) <timeouts>` tuple.394 :type timeout: float or tuple392- :param verify: (optional) Whether to verify SSL certificates.395+ :param verify: (optional) Either a boolean, in which case it controls whether396+ we verify the server's TLS certificate, or a string, in which case it397+ must be a path to a CA bundle to use398 :param cert: (optional) Any user-provided SSL certificate to be trusted.399 :param proxies: (optional) The proxies dictionary to apply to the request.400 :rtype: requests.Response401 """115 unmodified linesmodified:requests/api.py+3 added-1 removed
34 unmodified lines35 :type timeout: float or tuple36 :param allow_redirects: (optional) Boolean. Enable/disable GET/OPTIONS/POST/PUT/PATCH/DELETE/HEAD redirection. Defaults to ``True``.37 :type allow_redirects: bool38 :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.39- :param verify: (optional) whether the SSL cert will be verified. A CA_BUNDLE path can also be provided. Defaults to ``True``.39+ :param verify: (optional) Either a boolean, in which case it controls whether we verify40+ the server's TLS certificate, or a string, in which case it must be a path41+ to a CA bundle to use. Defaults to ``True``.42 :param stream: (optional) if ``False``, the response content will be immediately downloaded.43 :param cert: (optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair.44 :return: :class:`Response <Response>` object45 :rtype: requests.Response107 unmodified linesmodified:requests/sessions.py+3 added-2 removed
458 unmodified lines459 :param proxies: (optional) Dictionary mapping protocol or protocol and460 hostname to the URL of the proxy.461 :param stream: (optional) whether to immediately download the response462 content. Defaults to ``False``.463- :param verify: (optional) whether the SSL cert will be verified.464- A CA_BUNDLE path can also be provided. Defaults to ``True``.463+ :param verify: (optional) Either a boolean, in which case it controls whether we verify464+ the server's TLS certificate, or a string, in which case it must be a path465+ to a CA bundle to use. Defaults to ``True``.466 :param cert: (optional) if String, path to ssl client cert file (.pem).467 If Tuple, ('cert', 'key') pair.468 :rtype: requests.Response469 """266 unmodified linesmodified:tests/test_requests.py+8 added-8 removed
767 unmodified lines768 769 def test_pyopenssl_redirect(self, httpbin_secure, httpbin_ca_bundle):770 requests.get(httpbin_secure('status', '301'), verify=httpbin_ca_bundle)771 772- def test_invalid_ca_certificate_path(self):772+ def test_invalid_ca_certificate_path(self, httpbin_secure):773 INVALID_PATH = '/garbage'774 with pytest.raises(IOError) as e:775- requests.get('http://github.com', verify=INVALID_PATH)776- assert str(e.value) == 'Could not find a suitable SSL CA certificate bundle, invalid path: {0}'.format(INVALID_PATH)775+ requests.get(httpbin_secure(), verify=INVALID_PATH)776+ assert str(e.value) == 'Could not find a suitable TLS CA certificate bundle, invalid path: {0}'.format(INVALID_PATH)777 778- def test_invalid_ssl_certificate_files(self):778+ def test_invalid_ssl_certificate_files(self, httpbin_secure):779 INVALID_PATH = '/garbage'780 with pytest.raises(IOError) as e:781- requests.get('http://github.com', cert=INVALID_PATH)782- assert str(e.value) == 'Could not find the SSL certificate file, invalid path: {0}'.format(INVALID_PATH)781+ requests.get(httpbin_secure(), cert=INVALID_PATH)782+ assert str(e.value) == 'Could not find the TLS certificate file, invalid path: {0}'.format(INVALID_PATH)783 784 with pytest.raises(IOError) as e:785- requests.get('http://github.com', cert=('.', INVALID_PATH))786- assert str(e.value) == 'Could not find the SSL key file, invalid path: {0}'.format(INVALID_PATH)785+ requests.get(httpbin_secure(), cert=('.', INVALID_PATH))786+ assert str(e.value) == 'Could not find the TLS key file, invalid path: {0}'.format(INVALID_PATH)787 788 def test_https_warnings(self, httpbin_secure, httpbin_ca_bundle):789 """warnings are emitted with requests.get"""790 if HAS_MODERN_SSL or HAS_PYOPENSSL:1564 unmodified lines