Robert Brewer avatar Robert Brewer committed 7487fb8

Basic SSL test.

Comments (0)

Files changed (5)


     You must have the corresponding SSL driver library installed."""
     def __init__(self, bind_addr, gateway, minthreads=10, maxthreads=-1,
-                 server_name=None, protocol='HTTP/1.1'):
+                 server_name=None, protocol='HTTP/1.1', ssl_adapter=None):
         self.bind_addr = bind_addr
         self.gateway = gateway
             server_name = socket.gethostname()
         self.server_name = server_name
         self.protocol = protocol
+        self.ssl_adapter = ssl_adapter
     def clear_stats(self):


 import sys
+from cheroot._compat import basestring, py3k
     'pyopenssl': 'cheroot.ssllib.ssl_pyopenssl.pyOpenSSLAdapter',
-def get_ssl_adapter_class(name='pyopenssl'):
+def get_ssl_adapter_class(name=None):
     """Return an SSL adapter class for the given name."""
+    if name is None:
+        if py3k:
+            name = 'builtin'
+        else:
+            name = 'pyopenssl'
     adapter = ssl_adapters[name.lower()]
     if isinstance(adapter, basestring):
         last_dot = adapter.rfind(".")


 import sys
-from cheroot import ssllib
+from cheroot import server, ssllib
 class BuiltinSSLAdapter(ssllib.SSLAdapter):


 import cheroot
 from cheroot._compat import basestring, format_exc, HTTPConnection, HTTPSConnection, ntob
-from cheroot import server, wsgi
+from cheroot import server, ssllib, wsgi
 from cheroot.test import webtest
 import nose
             cls.HOST, cls.PORT = cls.httpserver.bind_addr
             if cls.httpserver.ssl_adapter is None:
-                ssl = ""
+                cls.HTTP_CONN = HTTPConnection
                 cls.scheme = 'http'
-                ssl = " (ssl)"
                 cls.HTTP_CONN = HTTPSConnection
                 cls.scheme = 'https'
             if traceback:
                 traceback = format_exc()
             cls.log.append((msg, level, traceback))
+            #print(msg, level, traceback)
         cls.log = []
         cls.httpserver.error_log = logsink
+def get_default_ssl_adapter():
+    """Return an instance of a cheroot.ssllib.SSLAdapter."""
+    # Use the default ('pyopenssl' for Python 2 and 'builtin' for 3):
+    ssl_adapter_class = ssllib.get_ssl_adapter_class()
+    serverpem = os.path.join(thisdir, 'test.pem')
+    return ssl_adapter_class(certificate=serverpem, private_key=serverpem)


+class SSLTest(helper.CherootWebCase):
+    config = {"ssl_adapter": helper.get_default_ssl_adapter()}
+    def setup_server(cls):
+        class Root(helper.Controller):
+            def hello(self, req, resp):
+                return "hello"
+        cls.httpserver.wsgi_app = Root()
+    setup_server = classmethod(setup_server)
+    def test_normal(self):
+        self.getPage("/hello")
+        self.assertBody('hello')
+        self.assertStatus(200)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.