From 3124a381237f0fdacda93b43a863e2c1aa04ed95 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Mon, 9 Dec 2019 10:59:55 +0000 Subject: [PATCH] Minor config cleanup (#621) --- httpx/config.py | 6 +++--- tests/test_config.py | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/httpx/config.py b/httpx/config.py index 34c3ad04..294c1ab7 100644 --- a/httpx/config.py +++ b/httpx/config.py @@ -50,6 +50,8 @@ class SSLConfig: SSL Configuration. """ + DEFAULT_CA_BUNDLE_PATH = Path(certifi.where()) + def __init__( self, *, @@ -129,7 +131,7 @@ class SSLConfig: self.verify = ca_bundle # type: ignore if isinstance(self.verify, bool): - ca_bundle_path = DEFAULT_CA_BUNDLE_PATH + ca_bundle_path = self.DEFAULT_CA_BUNDLE_PATH elif Path(self.verify).exists(): ca_bundle_path = Path(self.verify) else: @@ -321,8 +323,6 @@ class PoolLimits: TimeoutConfig = Timeout # Synonym for backwards compat -DEFAULT_SSL_CONFIG = SSLConfig(cert=None, verify=True) DEFAULT_TIMEOUT_CONFIG = Timeout(timeout=5.0) DEFAULT_POOL_LIMITS = PoolLimits(soft_limit=10, hard_limit=100) -DEFAULT_CA_BUNDLE_PATH = Path(certifi.where()) DEFAULT_MAX_REDIRECTS = 20 diff --git a/tests/test_config.py b/tests/test_config.py index f97680c4..c2701c08 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -4,6 +4,7 @@ import ssl import sys from pathlib import Path +import certifi import pytest import httpx @@ -24,7 +25,7 @@ def test_load_ssl_config_verify_non_existing_path(): def test_load_ssl_config_verify_existing_file(): - ssl_config = SSLConfig(verify=httpx.config.DEFAULT_CA_BUNDLE_PATH) + ssl_config = SSLConfig(verify=certifi.where()) context = ssl_config.load_ssl_context() assert context.verify_mode == ssl.VerifyMode.CERT_REQUIRED assert context.check_hostname is True @@ -55,7 +56,7 @@ def test_load_ssl_config_verify_env_file(https_server, ca_cert_pem_file, config) def test_load_ssl_config_verify_directory(): - path = httpx.config.DEFAULT_CA_BUNDLE_PATH.parent + path = Path(certifi.where()).parent ssl_config = SSLConfig(verify=path) context = ssl_config.load_ssl_context() assert context.verify_mode == ssl.VerifyMode.CERT_REQUIRED -- 2.47.3