Skip to content
Myr

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 file

Take it

The walk stopped after 200 commits: lines older than 8a227c1 point at it.

Fix docstringsTom Christiebefore adoption8a227c1

line 1why, one step back
1import ssl

Add support for SSLKEYLOGFILE (#301)Tomás Faríasbefore adoptiondb7f2d0

line 2why, one step back
2import sys

Fix docstringsTom Christiebefore adoption8a227c1

lines 3–5why, one step back
3
4import pytest5

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 6why, one step back
6import httpx

Fix docstringsTom Christiebefore adoption8a227c1

lines 7–8why, one step back
7
8

Run SSLConfig cert loading in threadpool (#209)Can Sarıgölbefore adoptionc5248e6

line 9why, one step back
9def test_load_ssl_config():

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 10why, one step back
10 ssl_config = httpx.SSLConfig()

Run SSLConfig cert loading in threadpool (#209)Can Sarıgölbefore adoptionc5248e6

line 11why, one step back
11 context = ssl_config.load_ssl_context()

Fix docstringsTom Christiebefore adoption8a227c1

line 12why, one step back
12 assert context.verify_mode == ssl.VerifyMode.CERT_REQUIRED

Support client cert passwords, new TLS options (#118)Seth Michael Larsonbefore adoptionba83e29

line 13why, one step back
13 assert context.check_hostname is True

Merge pull request #61 from yeraydiazdiaz/test-configTom Christiebefore adoptionabec2e8

lines 14–15why, one step back
14
15

Run SSLConfig cert loading in threadpool (#209)Can Sarıgölbefore adoptionc5248e6

line 16why, one step back
16def test_load_ssl_config_verify_non_existing_path():

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 17why, one step back
17 ssl_config = httpx.SSLConfig(verify="/path/to/nowhere")

Merge pull request #61 from yeraydiazdiaz/test-configTom Christiebefore adoptionabec2e8

line 18why, one step back
18 with pytest.raises(IOError):

Run SSLConfig cert loading in threadpool (#209)Can Sarıgölbefore adoptionc5248e6

line 19why, one step back
19 ssl_config.load_ssl_context()

Merge pull request #61 from yeraydiazdiaz/test-configTom Christiebefore adoptionabec2e8

lines 20–21why, one step back
20
21

Run SSLConfig cert loading in threadpool (#209)Can Sarıgölbefore adoptionc5248e6

line 22why, one step back
22def test_load_ssl_config_verify_existing_file():

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 23why, one step back
23 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 back
24 context = ssl_config.load_ssl_context()

Merge pull request #61 from yeraydiazdiaz/test-configTom Christiebefore adoptionabec2e8

line 25why, one step back
25 assert context.verify_mode == ssl.VerifyMode.CERT_REQUIRED

Support client cert passwords, new TLS options (#118)Seth Michael Larsonbefore adoptionba83e29

line 26why, one step back
26 assert context.check_hostname is True

Merge pull request #61 from yeraydiazdiaz/test-configTom Christiebefore adoptionabec2e8

lines 27–28why, one step back
27
28

Run SSLConfig cert loading in threadpool (#209)Can Sarıgölbefore adoptionc5248e6

line 29why, one step back
29def test_load_ssl_config_verify_directory():

Use pathlib.Path instead of os.path functions (#188)Stephen Brown IIbefore adoptionfde30b8

line 30why, one step back
30 path = httpx.config.DEFAULT_CA_BUNDLE_PATH.parent

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 31why, one step back
31 ssl_config = httpx.SSLConfig(verify=path)

Run SSLConfig cert loading in threadpool (#209)Can Sarıgölbefore adoptionc5248e6

line 32why, one step back
32 context = ssl_config.load_ssl_context()

Merge pull request #61 from yeraydiazdiaz/test-configTom Christiebefore adoptionabec2e8

line 33why, one step back
33 assert context.verify_mode == ssl.VerifyMode.CERT_REQUIRED

Support client cert passwords, new TLS options (#118)Seth Michael Larsonbefore adoptionba83e29

line 34why, one step back
34 assert context.check_hostname is True

Merge pull request #61 from yeraydiazdiaz/test-configTom Christiebefore adoptionabec2e8

lines 35–36why, one step back
35
36

Run SSLConfig cert loading in threadpool (#209)Can Sarıgölbefore adoptionc5248e6

line 37why, one step back
37def test_load_ssl_config_cert_and_key(cert_pem_file, cert_private_key_file):

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 38why, one step back
38 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 back
39 context = ssl_config.load_ssl_context()

Merge pull request #61 from yeraydiazdiaz/test-configTom Christiebefore adoptionabec2e8

line 40why, one step back
40 assert context.verify_mode == ssl.VerifyMode.CERT_REQUIRED

Support client cert passwords, new TLS options (#118)Seth Michael Larsonbefore adoptionba83e29

line 41why, one step back
41 assert context.check_hostname is True

Merge pull request #61 from yeraydiazdiaz/test-configTom Christiebefore adoptionabec2e8

lines 42–43why, one step back
42
43

Support client cert passwords, new TLS options (#118)Seth Michael Larsonbefore adoptionba83e29

line 44why, one step back
44@pytest.mark.parametrize("password", [b"password", "password"])

Run SSLConfig cert loading in threadpool (#209)Can Sarıgölbefore adoptionc5248e6

line 45why, one step back
45def 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 back
46 cert_pem_file, cert_encrypted_private_key_file, password
47):

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 48why, one step back
48 ssl_config = httpx.SSLConfig(

Support client cert passwords, new TLS options (#118)Seth Michael Larsonbefore adoptionba83e29

lines 49–50why, one step back
49 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 back
51 context = ssl_config.load_ssl_context()

Support client cert passwords, new TLS options (#118)Seth Michael Larsonbefore adoptionba83e29

lines 52–55why, one step back
52 assert context.verify_mode == ssl.VerifyMode.CERT_REQUIRED
53 assert context.check_hostname is True5455

Run SSLConfig cert loading in threadpool (#209)Can Sarıgölbefore adoptionc5248e6

line 56why, one step back
56def 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 back
57 cert_pem_file, cert_encrypted_private_key_file
58):

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 59why, one step back
59 ssl_config = httpx.SSLConfig(

Support client cert passwords, new TLS options (#118)Seth Michael Larsonbefore adoptionba83e29

lines 60–62why, one step back
60 cert=(cert_pem_file, cert_encrypted_private_key_file, "password1")
61 )62

Merge pull request #61 from yeraydiazdiaz/test-configTom Christiebefore adoptionabec2e8

line 63why, one step back
63 with pytest.raises(ssl.SSLError):

Run SSLConfig cert loading in threadpool (#209)Can Sarıgölbefore adoptionc5248e6

line 64why, one step back
64 ssl_config.load_ssl_context()

Fix docstringsTom Christiebefore adoption8a227c1

lines 65–66why, one step back
65
66

Run SSLConfig cert loading in threadpool (#209)Can Sarıgölbefore adoptionc5248e6

line 67why, one step back
67def test_load_ssl_config_cert_without_key_raises(cert_pem_file):

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 68why, one step back
68 ssl_config = httpx.SSLConfig(cert=cert_pem_file)

Support client cert passwords, new TLS options (#118)Seth Michael Larsonbefore adoptionba83e29

line 69why, one step back
69 with pytest.raises(ssl.SSLError):

Run SSLConfig cert loading in threadpool (#209)Can Sarıgölbefore adoptionc5248e6

line 70why, one step back
70 ssl_config.load_ssl_context()

Support client cert passwords, new TLS options (#118)Seth Michael Larsonbefore adoptionba83e29

lines 71–72why, one step back
71
72

Run SSLConfig cert loading in threadpool (#209)Can Sarıgölbefore adoptionc5248e6

line 73why, one step back
73def test_load_ssl_config_no_verify():

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 74why, one step back
74 ssl_config = httpx.SSLConfig(verify=False)

Run SSLConfig cert loading in threadpool (#209)Can Sarıgölbefore adoptionc5248e6

line 75why, one step back
75 context = ssl_config.load_ssl_context()

Fix docstringsTom Christiebefore adoption8a227c1

line 76why, one step back
76 assert context.verify_mode == ssl.VerifyMode.CERT_NONE

Support client cert passwords, new TLS options (#118)Seth Michael Larsonbefore adoptionba83e29

line 77why, one step back
77 assert context.check_hostname is False

Fix docstringsTom Christiebefore adoption8a227c1

lines 78–79why, one step back
78
79

Accept SSLContext into SSLConfig(verify=...) (#215)Seth Michael Larsonbefore adoptiondf8874b

lines 80–88why, one step back
80def 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)"8788

Fix docstringsTom Christiebefore adoption8a227c1

line 89why, one step back
89def test_ssl_repr():

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 90why, one step back
90 ssl = httpx.SSLConfig(verify=False)

Fix docstringsTom Christiebefore adoption8a227c1

lines 91–93why, one step back
91 assert repr(ssl) == "SSLConfig(cert=None, verify=False)"
9293

Merge pull request #241 from encode/protocol-supportTom Christiebefore adoptione0b523d

lines 94–118why, one step back
94def 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")117118

Raise TypeError if invalid parameter for HTTPVersionConfig (#253)Can Sarıgölbefore adoption4ea4af6

lines 119–128why, one step back
119def 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])127128

Merge pull request #241 from encode/protocol-supportTom Christiebefore adoptione0b523d

lines 129–133why, one step back
129def test_empty_http_version():
130 with pytest.raises(ValueError):131 httpx.HTTPVersionConfig([])132133

Fix docstringsTom Christiebefore adoption8a227c1

line 134why, one step back
134def test_timeout_repr():

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 135why, one step back
135 timeout = httpx.TimeoutConfig(timeout=5.0)

Fix docstringsTom Christiebefore adoption8a227c1

lines 136–137why, one step back
136 assert repr(timeout) == "TimeoutConfig(timeout=5.0)"
137

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 138why, one step back
138 timeout = httpx.TimeoutConfig(read_timeout=5.0)

Fix docstringsTom Christiebefore adoption8a227c1

lines 139–145why, one step back
139 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 back
146 limits = httpx.PoolLimits(hard_limit=100)

Fix docstringsTom Christiebefore adoption8a227c1

lines 147–152why, one step back
147 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 back
153 ssl = httpx.SSLConfig(verify=False)
154 assert ssl == httpx.SSLConfig(verify=False)

Fix docstringsTom Christiebefore adoption8a227c1

lines 155–157why, one step back
155
156157def test_timeout_eq():

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

lines 158–159why, one step back
158 timeout = httpx.TimeoutConfig(timeout=5.0)
159 assert timeout == httpx.TimeoutConfig(timeout=5.0)

Fix docstringsTom Christiebefore adoption8a227c1

lines 160–162why, one step back
160
161162def test_limits_eq():

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

lines 163–164why, one step back
163 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 back
165
166167def test_timeout_from_tuple():

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

lines 168–169why, one step back
168 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 back
170
171172def test_timeout_from_config_instance():

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

lines 173–174why, one step back
173 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 back
175
176177@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