Skip to content
Myr

Merge pull request #6074 from nateprewitt/curl_ca_bundle

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

Fix environment CA Bundle resolution

authored by Ian Stapleton Cordasco · committed by GitHub · parents 5e74954, 79c4a01 · Browse files · 2 files+49 added−6 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+49 added−6 removed

  • tests:+36 added−0 removed
  • other:+13 added−6 removed

2 files+49 added−6 removed

modified:requests/sessions.py+13 added-6 removed
700 unmodified lines
701 env_proxies = get_environ_proxies(url, no_proxy=no_proxy)702 for (k, v) in env_proxies.items():703 proxies.setdefault(k, v)704705 # Look for requests environment configuration and be compatible706 # with cURL.705 # Look for requests environment configuration706 # and be compatible with cURL.707 if verify is True or verify is None:708 verify = (os.environ.get('REQUESTS_CA_BUNDLE') or709 os.environ.get('CURL_CA_BUNDLE'))708 verify = (709 os.environ.get('REQUESTS_CA_BUNDLE')710 or os.environ.get('CURL_CA_BUNDLE')711 or verify712 )713714 # Merge all the kwargs.715 proxies = merge_setting(proxies, self.proxies)716 stream = merge_setting(stream, self.stream)717 verify = merge_setting(verify, self.verify)718 cert = merge_setting(cert, self.cert)719717 return {'verify': verify, 'proxies': proxies, 'stream': stream,718 'cert': cert}720 return {721 'proxies': proxies,722 'stream': stream,723 'verify': verify,724 'cert': cert725 }726727 def get_adapter(self, url):728 """729 Returns the appropriate connection adapter for the given URL.
49 unmodified lines
modified:tests/test_requests.py+36 added
896 unmodified lines
897 with pytest.raises(IOError) as e:898 requests.get(httpbin_secure(), cert=('.', INVALID_PATH))899 assert str(e.value) == 'Could not find the TLS key file, invalid path: {}'.format(INVALID_PATH)900901 @pytest.mark.parametrize(902 'env, expected', (903 ({}, True),904 ({'REQUESTS_CA_BUNDLE': '/some/path'}, '/some/path'),905 ({'REQUESTS_CA_BUNDLE': ''}, True),906 ({'CURL_CA_BUNDLE': '/some/path'}, '/some/path'),907 ({'CURL_CA_BUNDLE': ''}, True),908 ({'REQUESTS_CA_BUNDLE': '', 'CURL_CA_BUNDLE': ''}, True),909 (910 {911 'REQUESTS_CA_BUNDLE': '/some/path',912 'CURL_CA_BUNDLE': '/curl/path',913 },914 '/some/path',915 ),916 (917 {918 'REQUESTS_CA_BUNDLE': '',919 'CURL_CA_BUNDLE': '/curl/path',920 },921 '/curl/path',922 ),923 )924 )925 def test_env_cert_bundles(self, httpbin, mocker, env, expected):926 s = requests.Session()927 mocker.patch('os.environ', env)928 settings = s.merge_environment_settings(929 url=httpbin('get'),930 proxies={},931 stream=False,932 verify=True,933 cert=None934 )935 assert settings['verify'] == expected936937 def test_http_with_certificate(self, httpbin):938 r = requests.get(httpbin(), cert='.')939 assert r.status_code == 200940
1732 unmodified lines