def get(self): if self.request.protocol != self.expected_protocol: raise Exception("unexpected protocol") self.finish("Hello world") def post(self): self.finish("Got %d bytes in POST" % len(self.request.body)) # In pre-1.0 versions of openssl, SSLv23 clients always send SSLv2 # ClientHello messages, which are rejected by SSLv3 and TLSv1 # servers. Note that while the OPENSSL_VERSION_INFO was formally # introduced in python3.2, it was present but undocumented in # python 2.7 skipIfOldSSL = unittest.skipIf( getattr(ssl, 'OPENSSL_VERSION_INFO', (0, 0)) < (1, 0), "old version of ssl module and/or openssl") class BaseSSLTest(AsyncHTTPSTestCase): 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):
import weakref from webalchemy.tornado.concurrent import return_future from webalchemy.tornado.escape import url_escape from webalchemy.tornado.httpclient import AsyncHTTPClient from webalchemy.tornado.ioloop import IOLoop from webalchemy.tornado.log import app_log from webalchemy.tornado import stack_context from webalchemy.tornado.testing import AsyncHTTPTestCase, AsyncTestCase, ExpectLog, gen_test from webalchemy.tornado.test.util import unittest, skipOnTravis from webalchemy.tornado.web import Application, RequestHandler, asynchronous, HTTPError from webalchemy.tornado import gen skipBefore33 = unittest.skipIf(sys.version_info < (3, 3), 'PEP 380 not available') skipNotCPython = unittest.skipIf(platform.python_implementation() != 'CPython', 'Not CPython implementation') class GenEngineTest(AsyncTestCase): def setUp(self): super(GenEngineTest, self).setUp() self.named_contexts = [] def named_context(self, name): @contextlib.contextmanager def context(): self.named_contexts.append(name) try: yield