Skip to content
Myr

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

3 files+53 added−12 removed

modified:scripts/test+1 added-1 removed
7 unmodified lines
89set -x1011PYTHONPATH=. ${PREFIX}pytest --ignore venv --cov tests --cov ${PACKAGE} --cov-report= ${@}12${PREFIX}coverage report12${PREFIX}coverage report -m
modified:tests/conftest.py+13 added-11 removed
50 unmodified lines
51 await send({"type": "http.response.body", "body": b"Hello, world!"})525354@pytest.fixture55def 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_path606162@pytest.fixture63async def server():64 config = Config(app=app, lifespan="off")65 server = Server(config=config)66 task = asyncio.ensure_future(server.serve())
6 unmodified lines
73 await task747576@pytest.fixture69async 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 )77async 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 lines
modified:tests/test_config.py+39 added
1import os2import ssl34import pytest5
7 unmodified lines
13 assert context.verify_mode == ssl.VerifyMode.CERT_REQUIRED141516@pytest.mark.asyncio17async 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()212223@pytest.mark.asyncio24async 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_REQUIRED282930@pytest.mark.asyncio31async 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_REQUIRED363738@pytest.mark.asyncio39async 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_REQUIRED444546@pytest.mark.asyncio47async 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()525354@pytest.mark.asyncio55async 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_NONE
38 unmodified lines