Fix environment CA Bundle resolution
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Nate Prewitt · committed by Nate Prewitt · parent 5e74954 · 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
Provenance
- Commit
79c4a01- Tree
462843f- Author
Nate Prewitt <nate.prewitt@gmail.com>- Committer
Nate Prewitt <nate.prewitt@gmail.com>- Parent
5e74954
2 files changed+49 added−6 removed
modified:requests/sessions.py+13 added-6 removed
700 unmodified lines701 env_proxies = get_environ_proxies(url, no_proxy=no_proxy)702 for (k, v) in env_proxies.items():703 proxies.setdefault(k, v)704 705- # 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+ )713 714 # 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)719 717- return {'verify': verify, 'proxies': proxies, 'stream': stream,718- 'cert': cert}720+ return {721+ 'proxies': proxies,722+ 'stream': stream,723+ 'verify': verify,724+ 'cert': cert725+ }726 727 def get_adapter(self, url):728 """729 Returns the appropriate connection adapter for the given URL.49 unmodified linesmodified:tests/test_requests.py+36 added
896 unmodified lines897 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)900 901+ @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'] == expected936+937 def test_http_with_certificate(self, httpbin):938 r = requests.get(httpbin(), cert='.')939 assert r.status_code == 200940 1732 unmodified lines