Skip to content

Commit 226f2a6

Browse files
Hugo Osvaldo Barreracsernazs
authored andcommitted
Add a howto entry on how to create an HTTPS server
I had to implement this for `vdirsyncer`'s test suite, and this might save the next person needing it some headaches.
1 parent e226a46 commit 226f2a6

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

doc/howto.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,3 +455,32 @@ given amount of time.
455455
456456
There's one drawback though: the test takes 2 seconds to run as it waits the
457457
handler thread to be completed.
458+
459+
460+
Running and HTTPS server
461+
------------------------
462+
463+
To run an https server, `trustme` can be used to do the heavy lifting:
464+
465+
.. code-block:: python
466+
467+
@pytest.fixture(scope="session")
468+
def ca():
469+
return trustme.CA()
470+
471+
472+
@pytest.fixture(scope="session")
473+
def localhost_cert(ca):
474+
return ca.issue_cert("localhost")
475+
476+
477+
@pytest.fixture(scope="session")
478+
def httpserver_ssl_context(localhost_cert):
479+
context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
480+
481+
crt = localhost_cert.cert_chain_pems[0]
482+
key = localhost_cert.private_key_pem
483+
with crt.tempfile() as crt_file, key.tempfile() as key_file:
484+
context.load_cert_chain(crt_file, key_file)
485+
486+
return context

0 commit comments

Comments
 (0)