1+ import os
12import ssl
23
34import pytest
@@ -12,6 +13,44 @@ async def test_load_ssl_config():
1213 assert context .verify_mode == ssl .VerifyMode .CERT_REQUIRED
1314
1415
16+ @pytest .mark .asyncio
17+ async def test_load_ssl_config_verify_non_existing_path ():
18+ ssl_config = httpcore .SSLConfig (verify = "/path/to/nowhere" )
19+ with pytest .raises (IOError ):
20+ await ssl_config .load_ssl_context ()
21+
22+
23+ @pytest .mark .asyncio
24+ async def test_load_ssl_config_verify_existing_file ():
25+ ssl_config = httpcore .SSLConfig (verify = httpcore .config .DEFAULT_CA_BUNDLE_PATH )
26+ context = await ssl_config .load_ssl_context ()
27+ assert context .verify_mode == ssl .VerifyMode .CERT_REQUIRED
28+
29+
30+ @pytest .mark .asyncio
31+ async def test_load_ssl_config_verify_directory ():
32+ path = os .path .dirname (httpcore .config .DEFAULT_CA_BUNDLE_PATH )
33+ ssl_config = httpcore .SSLConfig (verify = path )
34+ context = await ssl_config .load_ssl_context ()
35+ assert context .verify_mode == ssl .VerifyMode .CERT_REQUIRED
36+
37+
38+ @pytest .mark .asyncio
39+ async def test_load_ssl_config_cert_and_key (cert_and_key_paths ):
40+ cert_path , key_path = cert_and_key_paths
41+ ssl_config = httpcore .SSLConfig (cert = (cert_path , key_path ))
42+ context = await ssl_config .load_ssl_context ()
43+ assert context .verify_mode == ssl .VerifyMode .CERT_REQUIRED
44+
45+
46+ @pytest .mark .asyncio
47+ async def test_load_ssl_config_cert_without_key_raises (cert_and_key_paths ):
48+ cert_path , _ = cert_and_key_paths
49+ ssl_config = httpcore .SSLConfig (cert = cert_path )
50+ with pytest .raises (ssl .SSLError ):
51+ await ssl_config .load_ssl_context ()
52+
53+
1554@pytest .mark .asyncio
1655async def test_load_ssl_config_no_verify (verify = False ):
1756 ssl_config = httpcore .SSLConfig (verify = False )
0 commit comments