from tornado.httputil import HTTPHeaders
from tornado.iostream import IOStream
from tornado.simple_httpclient import SimpleAsyncHTTPClient
-from tornado.testing import AsyncHTTPTestCase, AsyncSSLTestCase, AsyncTestCase, LogTrapTestCase
+from tornado.testing import AsyncHTTPTestCase, AsyncHTTPSTestCase, AsyncTestCase, LogTrapTestCase
from tornado.util import b, bytes_type
from tornado.web import Application, RequestHandler
import os
self.finish("Got %d bytes in POST" % len(self.request.body))
-class BaseSSLTest(AsyncSSLTestCase, LogTrapTestCase):
+class BaseSSLTest(AsyncHTTPSTestCase, LogTrapTestCase):
def get_app(self):
return Application([('/', HelloWorldRequestHandler,
dict(protocol="https"))])
class SSLTestMixin(object):
+ def get_ssl_options(self):
+ return dict(ssl_version = self.get_ssl_version(),
+ **AsyncHTTPSTestCase.get_ssl_options())
+
+ def get_ssl_version(self):
+ raise NotImplementedError()
+
def test_ssl(self):
response = self.fetch('/')
self.assertEqual(response.body, b("Hello world"))
class SSLv2Test(BaseSSLTest):
- def get_ssl_version(self):
- return ssl.PROTOCOL_SSLv2
+ def get_ssl_options(self):
+ return dict(ssl_version=ssl.PROTOCOL_SSLv2,
+ **AsyncHTTPSTestCase.get_ssl_options(self))
def test_sslv2_fail(self):
# This is really more of a client test, but run it here since
super(AsyncHTTPTestCase, self).tearDown()
-class AsyncSSLTestCase(AsyncHTTPTestCase):
- def get_ssl_version(self):
- raise NotImplementedError()
+class AsyncHTTPSTestCase(AsyncHTTPTestCase):
+ """A test case that starts an HTTPS server.
+ Interface is generally the same as `AsyncHTTPTestCase`.
+ """
def get_http_client(self):
# Some versions of libcurl have deadlock bugs with ssl,
# so always run these tests with SimpleAsyncHTTPClient.
return dict(ssl_options=self.get_ssl_options())
def get_ssl_options(self):
+ """May be overridden by subclasses to select SSL options.
+
+ By default includes a self-signed testing certificate.
+ """
# Testing keys were generated with:
# openssl req -new -keyout tornado/test/test.key -out tornado/test/test.crt -nodes -days 3650 -x509
module_dir = os.path.dirname(__file__)
return dict(
certfile=os.path.join(module_dir, 'test', 'test.crt'),
- keyfile=os.path.join(module_dir, 'test', 'test.key'),
- ssl_version=self.get_ssl_version())
+ keyfile=os.path.join(module_dir, 'test', 'test.key'))
def get_protocol(self):
return 'https'