import asyncio
+import os
import pytest
+import trustme
from uvicorn.config import Config
from uvicorn.main import Server
finally:
server.should_exit = True
await task
+
+
+@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,
+ )
+ server = Server(config=config)
+ task = asyncio.ensure_future(server.serve())
+ try:
+ while not server.started:
+ await asyncio.sleep(0.0001)
+ yield server
+ finally:
+ server.should_exit = True
+ await task
import pytest
-from httpcore import HTTPConnection, Request
+from httpcore import HTTPConnection, Request, SSLConfig
@pytest.mark.asyncio
assert response.content == b"Hello, world!"
+@pytest.mark.asyncio
+async def test_https_get(https_server):
+ http = HTTPConnection(origin="https://127.0.0.1:8001/", ssl=SSLConfig(verify=False))
+ response = await http.request("GET", "https://127.0.0.1:8001/")
+ assert response.status_code == 200
+ assert response.content == b"Hello, world!"
+
+
@pytest.mark.asyncio
async def test_post(server):
conn = HTTPConnection(origin="http://127.0.0.1:8000/")