Merge pull request #61 from yeraydiazdiaz/test-config
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Test config
authored by Tom Christie · committed by GitHub · parents 8f4abe0, 8d53257 · Browse files · 3 files·+53 added−12 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+53 added−12 removed
- tests:+52 added−11 removed
- other:+1 added−1 removed
Provenance
- Commit
abec2e8- Tree
7c206e2- Author
Tom Christie <tom@tomchristie.com>- Committer
GitHub <noreply@github.com>- Parent 1
8f4abe0- Parent 2
8d53257
3 files changed+53 added−12 removed
modified:scripts/test+1 added-1 removed
7 unmodified lines8 9 set -x10 11 PYTHONPATH=. ${PREFIX}pytest --ignore venv --cov tests --cov ${PACKAGE} --cov-report= ${@}12-${PREFIX}coverage report12+${PREFIX}coverage report -mmodified:tests/conftest.py+13 added-11 removed
50 unmodified lines51 await send({"type": "http.response.body", "body": b"Hello, world!"})52 53 54 @pytest.fixture55+def cert_and_key_paths():56+ ca = trustme.CA()57+ ca.issue_cert("example.org")58+ with ca.cert_pem.tempfile() as cert_temp_path, ca.private_key_pem.tempfile() as key_temp_path:59+ yield cert_temp_path, key_temp_path60+61+62+@pytest.fixture63 async def server():64 config = Config(app=app, lifespan="off")65 server = Server(config=config)66 task = asyncio.ensure_future(server.serve())6 unmodified lines73 await task74 75 76 @pytest.fixture69-async def https_server():70- ca = trustme.CA()71- server_cert = ca.issue_cert("example.org")72- with ca.cert_pem.tempfile() as cert_temp_path, ca.private_key_pem.tempfile() as key_temp_path:73- config = Config(74- app=app,75- lifespan="off",76- ssl_certfile=cert_temp_path,77- ssl_keyfile=key_temp_path,78- port=8001,79- )77+async def https_server(cert_and_key_paths):78+ cert_path, key_path = cert_and_key_paths79+ config = Config(80+ app=app, lifespan="off", ssl_certfile=cert_path, ssl_keyfile=key_path, port=800181+ )82 server = Server(config=config)83 task = asyncio.ensure_future(server.serve())84 try:85 while not server.started:5 unmodified linesmodified:tests/test_config.py+39 added
1+import os2 import ssl3 4 import pytest5 7 unmodified lines13 assert context.verify_mode == ssl.VerifyMode.CERT_REQUIRED14 15 16 @pytest.mark.asyncio17+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.asyncio24+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_REQUIRED28+29+30+@pytest.mark.asyncio31+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_REQUIRED36+37+38+@pytest.mark.asyncio39+async def test_load_ssl_config_cert_and_key(cert_and_key_paths):40+ cert_path, key_path = cert_and_key_paths41+ 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_REQUIRED44+45+46+@pytest.mark.asyncio47+async def test_load_ssl_config_cert_without_key_raises(cert_and_key_paths):48+ cert_path, _ = cert_and_key_paths49+ ssl_config = httpcore.SSLConfig(cert=cert_path)50+ with pytest.raises(ssl.SSLError):51+ await ssl_config.load_ssl_context()52+53+54+@pytest.mark.asyncio55 async def test_load_ssl_config_no_verify(verify=False):56 ssl_config = httpcore.SSLConfig(verify=False)57 context = await ssl_config.load_ssl_context()58 assert context.verify_mode == ssl.VerifyMode.CERT_NONE38 unmodified lines