commit
abec2e85e9
@ -9,4 +9,4 @@ fi
|
||||
set -x
|
||||
|
||||
PYTHONPATH=. ${PREFIX}pytest --ignore venv --cov tests --cov ${PACKAGE} --cov-report= ${@}
|
||||
${PREFIX}coverage report
|
||||
${PREFIX}coverage report -m
|
||||
|
||||
@ -51,6 +51,14 @@ async def status_code(scope, receive, send):
|
||||
await send({"type": "http.response.body", "body": b"Hello, world!"})
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def cert_and_key_paths():
|
||||
ca = trustme.CA()
|
||||
ca.issue_cert("example.org")
|
||||
with ca.cert_pem.tempfile() as cert_temp_path, ca.private_key_pem.tempfile() as key_temp_path:
|
||||
yield cert_temp_path, key_temp_path
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def server():
|
||||
config = Config(app=app, lifespan="off")
|
||||
@ -66,17 +74,11 @@ async def server():
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def https_server():
|
||||
ca = trustme.CA()
|
||||
server_cert = ca.issue_cert("example.org")
|
||||
with ca.cert_pem.tempfile() as cert_temp_path, ca.private_key_pem.tempfile() as key_temp_path:
|
||||
config = Config(
|
||||
app=app,
|
||||
lifespan="off",
|
||||
ssl_certfile=cert_temp_path,
|
||||
ssl_keyfile=key_temp_path,
|
||||
port=8001,
|
||||
)
|
||||
async def https_server(cert_and_key_paths):
|
||||
cert_path, key_path = cert_and_key_paths
|
||||
config = Config(
|
||||
app=app, lifespan="off", ssl_certfile=cert_path, ssl_keyfile=key_path, port=8001
|
||||
)
|
||||
server = Server(config=config)
|
||||
task = asyncio.ensure_future(server.serve())
|
||||
try:
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import os
|
||||
import ssl
|
||||
|
||||
import pytest
|
||||
@ -12,6 +13,44 @@ async def test_load_ssl_config():
|
||||
assert context.verify_mode == ssl.VerifyMode.CERT_REQUIRED
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_load_ssl_config_verify_non_existing_path():
|
||||
ssl_config = httpcore.SSLConfig(verify="/path/to/nowhere")
|
||||
with pytest.raises(IOError):
|
||||
await ssl_config.load_ssl_context()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_load_ssl_config_verify_existing_file():
|
||||
ssl_config = httpcore.SSLConfig(verify=httpcore.config.DEFAULT_CA_BUNDLE_PATH)
|
||||
context = await ssl_config.load_ssl_context()
|
||||
assert context.verify_mode == ssl.VerifyMode.CERT_REQUIRED
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_load_ssl_config_verify_directory():
|
||||
path = os.path.dirname(httpcore.config.DEFAULT_CA_BUNDLE_PATH)
|
||||
ssl_config = httpcore.SSLConfig(verify=path)
|
||||
context = await ssl_config.load_ssl_context()
|
||||
assert context.verify_mode == ssl.VerifyMode.CERT_REQUIRED
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_load_ssl_config_cert_and_key(cert_and_key_paths):
|
||||
cert_path, key_path = cert_and_key_paths
|
||||
ssl_config = httpcore.SSLConfig(cert=(cert_path, key_path))
|
||||
context = await ssl_config.load_ssl_context()
|
||||
assert context.verify_mode == ssl.VerifyMode.CERT_REQUIRED
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_load_ssl_config_cert_without_key_raises(cert_and_key_paths):
|
||||
cert_path, _ = cert_and_key_paths
|
||||
ssl_config = httpcore.SSLConfig(cert=cert_path)
|
||||
with pytest.raises(ssl.SSLError):
|
||||
await ssl_config.load_ssl_context()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_load_ssl_config_no_verify(verify=False):
|
||||
ssl_config = httpcore.SSLConfig(verify=False)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user