diff --git a/README.rst b/README.rst index c83022d..2040f18 100644 --- a/README.rst +++ b/README.rst @@ -74,6 +74,16 @@ If you're using a wrapper around your WSGI application such as dj_static or Whit static files. Otherwise, you may see 404s when requesting static files. You can disable the default behavior by using the ``--nostatic`` option. +Testing Tools +============= + +Django SSL Server adds SSL-enabled versions of +`LiveServerTestCase `_ and +`StaticLiveServerTestCase `_, called . +``SecureLiveServerTestCase`` and ``SecureStaticLiveServerTestCase`` respectively. + +You can use these classes to write tests that involve running the code under test and consuming it with testing tools through HTTPS (e.g. Selenium, PhantomJS, etc.), for cases in which a secure connection is needed (e.g., `WebAuthn `). + Getting Involved ================ diff --git a/sslserver/__init__.py b/sslserver/__init__.py index 2390dc1..3fe695d 100644 --- a/sslserver/__init__.py +++ b/sslserver/__init__.py @@ -1 +1 @@ -__version__ = "0.20" +__version__ = "0.23" diff --git a/sslserver/testcases.py b/sslserver/testcases.py new file mode 100644 index 0000000..0bdd168 --- /dev/null +++ b/sslserver/testcases.py @@ -0,0 +1,33 @@ +import os + +from django.contrib.staticfiles.testing import StaticLiveServerTestCase +from django.test.testcases import LiveServerTestCase, LiveServerThread, QuietWSGIRequestHandler + +from sslserver.management.commands.runsslserver import ( + SecureHTTPServer, WSGIRequestHandler, default_ssl_files_dir, +) + + +class SecureQuietWSGIRequestHandler(WSGIRequestHandler, QuietWSGIRequestHandler): + pass + + +class SecureLiveServerThread(LiveServerThread): + def _create_server(self): + cert_file = os.path.join(default_ssl_files_dir(), "development.crt") + key_file = os.path.join(default_ssl_files_dir(), "development.key") + + return SecureHTTPServer( + (self.host, self.port), + SecureQuietWSGIRequestHandler, + cert_file, + key_file, + ) + + +class SecureLiveServerTestCase(LiveServerTestCase): + server_thread_class = SecureLiveServerThread + + +class SecureStaticLiveServerTestCase(StaticLiveServerTestCase): + server_thread_class = SecureLiveServerThread