test_config.py
This file
Path
tests/test_config.py
204 lines · 6.0 KiB · Python
Last changed by
Add support for SSLKEYLOGFILE (#301)Tomás Faríasbefore adoptiondb7f2d0
History of this fileTake it
The walk stopped after 200 commits: lines older than 8a227c1 point at it.
Fix docstringsTom Christiebefore adoption8a227c1
line 1why, one step back1import sslAdd support for SSLKEYLOGFILE (#301)Tomás Faríasbefore adoptiondb7f2d0
line 2why, one step back2import sysFix docstringsTom Christiebefore adoption8a227c1
lines 3–5why, one step back34import pytest5Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 6why, one step back6import httpxFix docstringsTom Christiebefore adoption8a227c1
lines 7–8why, one step back78Run SSLConfig cert loading in threadpool (#209)Can Sarıgölbefore adoptionc5248e6
line 9why, one step back9def test_load_ssl_config():Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 10why, one step back10 ssl_config = httpx.SSLConfig()Run SSLConfig cert loading in threadpool (#209)Can Sarıgölbefore adoptionc5248e6
line 11why, one step back11 context = ssl_config.load_ssl_context()Fix docstringsTom Christiebefore adoption8a227c1
line 12why, one step back12 assert context.verify_mode == ssl.VerifyMode.CERT_REQUIREDSupport client cert passwords, new TLS options (#118)Seth Michael Larsonbefore adoptionba83e29
line 13why, one step back13 assert context.check_hostname is TrueMerge pull request #61 from yeraydiazdiaz/test-configTom Christiebefore adoptionabec2e8
lines 14–15why, one step back1415Run SSLConfig cert loading in threadpool (#209)Can Sarıgölbefore adoptionc5248e6
line 16why, one step back16def test_load_ssl_config_verify_non_existing_path():Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 17why, one step back17 ssl_config = httpx.SSLConfig(verify="/path/to/nowhere")Merge pull request #61 from yeraydiazdiaz/test-configTom Christiebefore adoptionabec2e8
line 18why, one step back18 with pytest.raises(IOError):Run SSLConfig cert loading in threadpool (#209)Can Sarıgölbefore adoptionc5248e6
line 19why, one step back19 ssl_config.load_ssl_context()Merge pull request #61 from yeraydiazdiaz/test-configTom Christiebefore adoptionabec2e8
lines 20–21why, one step back2021Run SSLConfig cert loading in threadpool (#209)Can Sarıgölbefore adoptionc5248e6
line 22why, one step back22def test_load_ssl_config_verify_existing_file():Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 23why, one step back23 ssl_config = httpx.SSLConfig(verify=httpx.config.DEFAULT_CA_BUNDLE_PATH)Run SSLConfig cert loading in threadpool (#209)Can Sarıgölbefore adoptionc5248e6
line 24why, one step back24 context = ssl_config.load_ssl_context()Merge pull request #61 from yeraydiazdiaz/test-configTom Christiebefore adoptionabec2e8
line 25why, one step back25 assert context.verify_mode == ssl.VerifyMode.CERT_REQUIREDSupport client cert passwords, new TLS options (#118)Seth Michael Larsonbefore adoptionba83e29
line 26why, one step back26 assert context.check_hostname is TrueMerge pull request #61 from yeraydiazdiaz/test-configTom Christiebefore adoptionabec2e8
lines 27–28why, one step back2728Run SSLConfig cert loading in threadpool (#209)Can Sarıgölbefore adoptionc5248e6
line 29why, one step back29def test_load_ssl_config_verify_directory():Use pathlib.Path instead of os.path functions (#188)Stephen Brown IIbefore adoptionfde30b8
line 30why, one step back30 path = httpx.config.DEFAULT_CA_BUNDLE_PATH.parentRenaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 31why, one step back31 ssl_config = httpx.SSLConfig(verify=path)Run SSLConfig cert loading in threadpool (#209)Can Sarıgölbefore adoptionc5248e6
line 32why, one step back32 context = ssl_config.load_ssl_context()Merge pull request #61 from yeraydiazdiaz/test-configTom Christiebefore adoptionabec2e8
line 33why, one step back33 assert context.verify_mode == ssl.VerifyMode.CERT_REQUIREDSupport client cert passwords, new TLS options (#118)Seth Michael Larsonbefore adoptionba83e29
line 34why, one step back34 assert context.check_hostname is TrueMerge pull request #61 from yeraydiazdiaz/test-configTom Christiebefore adoptionabec2e8
lines 35–36why, one step back3536Run SSLConfig cert loading in threadpool (#209)Can Sarıgölbefore adoptionc5248e6
line 37why, one step back37def test_load_ssl_config_cert_and_key(cert_pem_file, cert_private_key_file):Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 38why, one step back38 ssl_config = httpx.SSLConfig(cert=(cert_pem_file, cert_private_key_file))Run SSLConfig cert loading in threadpool (#209)Can Sarıgölbefore adoptionc5248e6
line 39why, one step back39 context = ssl_config.load_ssl_context()Merge pull request #61 from yeraydiazdiaz/test-configTom Christiebefore adoptionabec2e8
line 40why, one step back40 assert context.verify_mode == ssl.VerifyMode.CERT_REQUIREDSupport client cert passwords, new TLS options (#118)Seth Michael Larsonbefore adoptionba83e29
line 41why, one step back41 assert context.check_hostname is TrueMerge pull request #61 from yeraydiazdiaz/test-configTom Christiebefore adoptionabec2e8
lines 42–43why, one step back4243Support client cert passwords, new TLS options (#118)Seth Michael Larsonbefore adoptionba83e29
line 44why, one step back44@pytest.mark.parametrize("password", [b"password", "password"])Run SSLConfig cert loading in threadpool (#209)Can Sarıgölbefore adoptionc5248e6
line 45why, one step back45def test_load_ssl_config_cert_and_encrypted_key(Support client cert passwords, new TLS options (#118)Seth Michael Larsonbefore adoptionba83e29
lines 46–47why, one step back46 cert_pem_file, cert_encrypted_private_key_file, password47):Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 48why, one step back48 ssl_config = httpx.SSLConfig(Support client cert passwords, new TLS options (#118)Seth Michael Larsonbefore adoptionba83e29
lines 49–50why, one step back49 cert=(cert_pem_file, cert_encrypted_private_key_file, password)50 )Run SSLConfig cert loading in threadpool (#209)Can Sarıgölbefore adoptionc5248e6
line 51why, one step back51 context = ssl_config.load_ssl_context()Support client cert passwords, new TLS options (#118)Seth Michael Larsonbefore adoptionba83e29
lines 52–55why, one step back52 assert context.verify_mode == ssl.VerifyMode.CERT_REQUIRED53 assert context.check_hostname is True5455Run SSLConfig cert loading in threadpool (#209)Can Sarıgölbefore adoptionc5248e6
line 56why, one step back56def test_load_ssl_config_cert_and_key_invalid_password(Support client cert passwords, new TLS options (#118)Seth Michael Larsonbefore adoptionba83e29
lines 57–58why, one step back57 cert_pem_file, cert_encrypted_private_key_file58):Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 59why, one step back59 ssl_config = httpx.SSLConfig(Support client cert passwords, new TLS options (#118)Seth Michael Larsonbefore adoptionba83e29
lines 60–62why, one step back60 cert=(cert_pem_file, cert_encrypted_private_key_file, "password1")61 )62Merge pull request #61 from yeraydiazdiaz/test-configTom Christiebefore adoptionabec2e8
line 63why, one step back63 with pytest.raises(ssl.SSLError):Run SSLConfig cert loading in threadpool (#209)Can Sarıgölbefore adoptionc5248e6
line 64why, one step back64 ssl_config.load_ssl_context()Fix docstringsTom Christiebefore adoption8a227c1
lines 65–66why, one step back6566Run SSLConfig cert loading in threadpool (#209)Can Sarıgölbefore adoptionc5248e6
line 67why, one step back67def test_load_ssl_config_cert_without_key_raises(cert_pem_file):Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 68why, one step back68 ssl_config = httpx.SSLConfig(cert=cert_pem_file)Support client cert passwords, new TLS options (#118)Seth Michael Larsonbefore adoptionba83e29
line 69why, one step back69 with pytest.raises(ssl.SSLError):Run SSLConfig cert loading in threadpool (#209)Can Sarıgölbefore adoptionc5248e6
line 70why, one step back70 ssl_config.load_ssl_context()Support client cert passwords, new TLS options (#118)Seth Michael Larsonbefore adoptionba83e29
lines 71–72why, one step back7172Run SSLConfig cert loading in threadpool (#209)Can Sarıgölbefore adoptionc5248e6
line 73why, one step back73def test_load_ssl_config_no_verify():Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 74why, one step back74 ssl_config = httpx.SSLConfig(verify=False)Run SSLConfig cert loading in threadpool (#209)Can Sarıgölbefore adoptionc5248e6
line 75why, one step back75 context = ssl_config.load_ssl_context()Fix docstringsTom Christiebefore adoption8a227c1
line 76why, one step back76 assert context.verify_mode == ssl.VerifyMode.CERT_NONESupport client cert passwords, new TLS options (#118)Seth Michael Larsonbefore adoptionba83e29
line 77why, one step back77 assert context.check_hostname is FalseFix docstringsTom Christiebefore adoption8a227c1
lines 78–79why, one step back7879Accept SSLContext into SSLConfig(verify=...) (#215)Seth Michael Larsonbefore adoptiondf8874b
lines 80–88why, one step back80def test_load_ssl_context():81 ssl_context = ssl.create_default_context()82 ssl_config = httpx.SSLConfig(verify=ssl_context)8384 assert ssl_config.verify is True85 assert ssl_config.ssl_context is ssl_context86 assert repr(ssl_config) == "SSLConfig(cert=None, verify=True)"8788Fix docstringsTom Christiebefore adoption8a227c1
line 89why, one step back89def test_ssl_repr():Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 90why, one step back90 ssl = httpx.SSLConfig(verify=False)Fix docstringsTom Christiebefore adoption8a227c1
lines 91–93why, one step back91 assert repr(ssl) == "SSLConfig(cert=None, verify=False)"9293Merge pull request #241 from encode/protocol-supportTom Christiebefore adoptione0b523d
lines 94–118why, one step back94def test_http_versions_repr():95 http_versions = httpx.HTTPVersionConfig()96 assert repr(http_versions) == "HTTPVersionConfig(['HTTP/1.1', 'HTTP/2'])"979899def test_http_versions_from_string():100 http_versions = httpx.HTTPVersionConfig("HTTP/1.1")101 assert repr(http_versions) == "HTTPVersionConfig(['HTTP/1.1'])"102103104def test_http_versions_from_list():105 http_versions = httpx.HTTPVersionConfig(["http/1.1"])106 assert repr(http_versions) == "HTTPVersionConfig(['HTTP/1.1'])"107108109def test_http_versions_from_config():110 http_versions = httpx.HTTPVersionConfig(httpx.HTTPVersionConfig("HTTP/1.1"))111 assert repr(http_versions) == "HTTPVersionConfig(['HTTP/1.1'])"112113114def test_invalid_http_version():115 with pytest.raises(ValueError):116 httpx.HTTPVersionConfig("HTTP/9")117118Raise TypeError if invalid parameter for HTTPVersionConfig (#253)Can Sarıgölbefore adoption4ea4af6
lines 119–128why, one step back119def test_invalid_http_version_type():120 with pytest.raises(TypeError):121 httpx.HTTPVersionConfig(123)122123124def test_invalid_http_version_list_type():125 with pytest.raises(ValueError):126 httpx.HTTPVersionConfig([123])127128Merge pull request #241 from encode/protocol-supportTom Christiebefore adoptione0b523d
lines 129–133why, one step back129def test_empty_http_version():130 with pytest.raises(ValueError):131 httpx.HTTPVersionConfig([])132133Fix docstringsTom Christiebefore adoption8a227c1
line 134why, one step back134def test_timeout_repr():Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 135why, one step back135 timeout = httpx.TimeoutConfig(timeout=5.0)Fix docstringsTom Christiebefore adoption8a227c1
lines 136–137why, one step back136 assert repr(timeout) == "TimeoutConfig(timeout=5.0)"137Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 138why, one step back138 timeout = httpx.TimeoutConfig(read_timeout=5.0)Fix docstringsTom Christiebefore adoption8a227c1
lines 139–145why, one step back139 assert (140 repr(timeout)141 == "TimeoutConfig(connect_timeout=None, read_timeout=5.0, write_timeout=None)"142 )143144145def test_limits_repr():Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 146why, one step back146 limits = httpx.PoolLimits(hard_limit=100)Fix docstringsTom Christiebefore adoption8a227c1
lines 147–152why, one step back147 assert (148 repr(limits) == "PoolLimits(soft_limit=None, hard_limit=100, pool_timeout=None)"149 )150151152def test_ssl_eq():Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
lines 153–154why, one step back153 ssl = httpx.SSLConfig(verify=False)154 assert ssl == httpx.SSLConfig(verify=False)Fix docstringsTom Christiebefore adoption8a227c1
lines 155–157why, one step back155156157def test_timeout_eq():Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
lines 158–159why, one step back158 timeout = httpx.TimeoutConfig(timeout=5.0)159 assert timeout == httpx.TimeoutConfig(timeout=5.0)Fix docstringsTom Christiebefore adoption8a227c1
lines 160–162why, one step back160161162def test_limits_eq():Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
lines 163–164why, one step back163 limits = httpx.PoolLimits(hard_limit=100)164 assert limits == httpx.PoolLimits(hard_limit=100)Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041
lines 165–167why, one step back165166167def test_timeout_from_tuple():Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
lines 168–169why, one step back168 timeout = httpx.TimeoutConfig(timeout=(5.0, 5.0, 5.0))169 assert timeout == httpx.TimeoutConfig(timeout=5.0)Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041
lines 170–172why, one step back170171172def test_timeout_from_config_instance():Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
lines 173–174why, one step back173 timeout = httpx.TimeoutConfig(timeout=5.0)174 assert httpx.TimeoutConfig(timeout) == httpx.TimeoutConfig(timeout=5.0)Add support for SSLKEYLOGFILE (#301)Tomás Faríasbefore adoptiondb7f2d0
lines 175–204why, one step back175176177@pytest.mark.skipif(178 not hasattr(ssl.SSLContext, "keylog_filename"),179 reason="requires OpenSSL 1.1.1 or higher",180)181@pytest.mark.skipif(sys.version_info < (3, 8), reason="requires python3.8 or higher")182def test_ssl_config_support_for_keylog_file(tmpdir, monkeypatch):183 with monkeypatch.context() as m:184 m.delenv("SSLKEYLOGFILE", raising=False)185186 ssl_config = httpx.SSLConfig(trust_env=True)187 ssl_config.load_ssl_context()188189 assert ssl_config.ssl_context.keylog_filename is None190191 filename = str(tmpdir.join("test.log"))192193 with monkeypatch.context() as m:194 m.setenv("SSLKEYLOGFILE", filename)195196 ssl_config = httpx.SSLConfig(trust_env=True)197 ssl_config.load_ssl_context()198199 assert ssl_config.ssl_context.keylog_filename == filename200201 ssl_config = httpx.SSLConfig(trust_env=False)202 ssl_config.load_ssl_context()203204 assert ssl_config.ssl_context.keylog_filename is None