def setUp(self): super(SSLTest, self).setUp() # Replace the client defined in the parent class. # Some versions of libcurl have deadlock bugs with ssl, # so always run these tests with SimpleAsyncHTTPClient. self.http_client = SimpleAsyncHTTPClient(io_loop=self.io_loop, force_instance=True)
def test_connection_limit(self): client = SimpleAsyncHTTPClient(self.io_loop, max_clients=2, force_instance=True) self.assertEqual(client.max_clients, 2) seen = [] # Send 4 requests. Two can be sent immediately, while the others # will be queued for i in range(4): client.fetch(self.get_url("/trigger"), lambda response, i=i: (seen.append(i), self.stop())) self.wait(condition=lambda: len(self.triggers) == 2) self.assertEqual(len(client.queue), 2) # Finish the first two requests and let the next two through self.triggers.popleft()() self.triggers.popleft()() self.wait(condition=lambda: (len(self.triggers) == 2 and len(seen) == 2)) self.assertEqual(set(seen), set([0, 1])) self.assertEqual(len(client.queue), 0) # Finish all the pending requests self.triggers.popleft()() self.triggers.popleft()() self.wait(condition=lambda: len(seen) == 4) self.assertEqual(set(seen), set([0, 1, 2, 3])) self.assertEqual(len(self.triggers), 0)
def test_redirect_connection_limit(self): # following redirects should not consume additional connections client = SimpleAsyncHTTPClient(self.io_loop, max_clients=1, force_instance=True) client.fetch(self.get_url('/countdown/3'), self.stop, max_redirects=3) response = self.wait() response.rethrow()
class SSLTest(AsyncHTTPTestCase, LogTrapTestCase): def setUp(self): super(SSLTest, self).setUp() # Replace the client defined in the parent class. # Some versions of libcurl have deadlock bugs with ssl, # so always run these tests with SimpleAsyncHTTPClient. self.http_client = SimpleAsyncHTTPClient(io_loop=self.io_loop, force_instance=True) def get_app(self): return Application([('/', HelloWorldRequestHandler, dict(protocol="https"))]) def get_httpserver_options(self): # Testing keys were generated with: # openssl req -new -keyout anzu/test/test.key -out anzu/test/test.crt -nodes -days 3650 -x509 test_dir = os.path.dirname(__file__) return dict(ssl_options=dict( certfile=os.path.join(test_dir, 'test.crt'), keyfile=os.path.join(test_dir, 'test.key'))) def fetch(self, path, **kwargs): self.http_client.fetch(self.get_url(path).replace('http', 'https'), self.stop, validate_cert=False, **kwargs) return self.wait() def test_ssl(self): response = self.fetch('/') self.assertEqual(response.body, b("Hello world")) def test_large_post(self): response = self.fetch('/', method='POST', body='A'*5000) self.assertEqual(response.body, b("Got 5000 bytes in POST")) def test_non_ssl_request(self): # Make sure the server closes the connection when it gets a non-ssl # connection, rather than waiting for a timeout or otherwise # misbehaving. self.http_client.fetch(self.get_url("/"), self.stop, request_timeout=3600, connect_timeout=3600) response = self.wait() self.assertEqual(response.code, 599)
class SSLTest(AsyncHTTPTestCase, LogTrapTestCase): def setUp(self): super(SSLTest, self).setUp() # Replace the client defined in the parent class. # Some versions of libcurl have deadlock bugs with ssl, # so always run these tests with SimpleAsyncHTTPClient. self.http_client = SimpleAsyncHTTPClient(io_loop=self.io_loop, force_instance=True) def get_app(self): return Application([('/', HelloWorldRequestHandler, dict(protocol="https"))]) def get_httpserver_options(self): # Testing keys were generated with: # openssl req -new -keyout anzu/test/test.key -out anzu/test/test.crt -nodes -days 3650 -x509 test_dir = os.path.dirname(__file__) return dict( ssl_options=dict(certfile=os.path.join(test_dir, 'test.crt'), keyfile=os.path.join(test_dir, 'test.key'))) def fetch(self, path, **kwargs): self.http_client.fetch(self.get_url(path).replace('http', 'https'), self.stop, validate_cert=False, **kwargs) return self.wait() def test_ssl(self): response = self.fetch('/') self.assertEqual(response.body, b("Hello world")) def test_large_post(self): response = self.fetch('/', method='POST', body='A' * 5000) self.assertEqual(response.body, b("Got 5000 bytes in POST")) def test_non_ssl_request(self): # Make sure the server closes the connection when it gets a non-ssl # connection, rather than waiting for a timeout or otherwise # misbehaving. self.http_client.fetch(self.get_url("/"), self.stop, request_timeout=3600, connect_timeout=3600) response = self.wait() self.assertEqual(response.code, 599)