def test_https_process(self): valid_cfg = { 'proxy_ip': '127.0.0.1', 'proxy_port': 43434, 'tls_socket_fds': [sock.fileno() for sock in self.https_socks], 'debug': False, } db_cfg = yield wrap_db_tx(load_tls_dict) valid_cfg.update(db_cfg) tmp = tempfile.TemporaryFile() tmp.write(json.dumps(valid_cfg)) tmp.seek(0, 0) tmp_fd = tmp.fileno() self.http_process = HTTPSProcess(fd=tmp_fd) # Connect to service ensure that it responds with a 502 yield threads.deferToThread(self.fetch_resource_with_fail) # Start the HTTP server proxy requests will be forwarded to. self.pp = helpers.SimpleServerPP() reactor.spawnProcess( self.pp, 'python', args=['python', '-m', 'SimpleHTTPServer', '43434'], usePTY=True) yield self.pp.start_defer # Check that requests are routed successfully yield threads.deferToThread(self.fetch_resource) yield threads.deferToThread(self.fetch_resource_with_gzip)
def test_https_process(self): valid_cfg = { 'proxy_ip': '127.0.0.1', 'proxy_port': 43434, 'tls_socket_fds': [sock.fileno() for sock in self.https_socks], 'debug': False, } valid_cfg['site_cfgs'] = yield tw(load_tls_dict_list) tmp = tempfile.TemporaryFile(mode='w') tmp.write(json.dumps(valid_cfg)) tmp.seek(0, 0) tmp_fd = tmp.fileno() self.http_process = HTTPSProcess(fd=tmp_fd) # Connect to service ensure that it responds with a 502 yield threads.deferToThread(self.fetch_resource_with_fail) # Start the HTTP server proxy requests will be forwarded to. self.pp = helpers.SimpleServerPP() reactor.spawnProcess(self.pp, 'python', args=['python', '-m', 'SimpleHTTPServer', '43434'], usePTY=True) yield self.pp.start_defer # Check that requests are routed successfully yield threads.deferToThread(self.fetch_resource)
class TestSubprocessRun(helpers.TestGL): @inlineCallbacks def setUp(self): super(TestSubprocessRun, self).setUp() with open('hello.txt', 'w') as f: f.write('Hello, world!\n') https_sock, _ = reserve_port_for_ip('127.0.0.1', 9443) self.https_socks = [https_sock] ssl._https_verify_certificates(enable=False) yield test_tls.commit_valid_config() @inlineCallbacks def test_https_process(self): valid_cfg = { 'proxy_ip': '127.0.0.1', 'proxy_port': 43434, 'tls_socket_fds': [sock.fileno() for sock in self.https_socks], 'debug': False, } db_cfg = yield wrap_db_tx(load_tls_dict) valid_cfg.update(db_cfg) tmp = tempfile.TemporaryFile() tmp.write(json.dumps(valid_cfg)) tmp.seek(0, 0) tmp_fd = tmp.fileno() self.http_process = HTTPSProcess(fd=tmp_fd) # Connect to service ensure that it responds with a 502 yield threads.deferToThread(self.fetch_resource_with_fail) # Start the HTTP server proxy requests will be forwarded to. self.pp = helpers.SimpleServerPP() reactor.spawnProcess( self.pp, 'python', args=['python', '-m', 'SimpleHTTPServer', '43434'], usePTY=True) yield self.pp.start_defer # Check that requests are routed successfully yield threads.deferToThread(self.fetch_resource) yield threads.deferToThread(self.fetch_resource_with_gzip) def fetch_resource_with_fail(self): try: response = urllib2.urlopen('https://127.0.0.1:9443') self.fail('Request had to throw a 502') except urllib2.HTTPError as e: # Ensure the connection always has an HSTS header self.assertEqual(e.headers.get('Strict-Transport-Security'), 'max-age=31536000') self.assertEqual(e.code, 502) return def fetch_resource(self): response = urllib2.urlopen('https://127.0.0.1:9443/') hdrs = response.info() self.assertEqual(hdrs.get('Strict-Transport-Security'), 'max-age=31536000') def fetch_resource_with_gzip(self): request = urllib2.Request('https://127.0.0.1:9443/hello.txt') request.add_header('Accept-encoding', 'gzip') response = urllib2.urlopen(request) hdrs = response.info() # Ensure the connection uses gzip self.assertEqual(hdrs.get('Content-Encoding'), 'gzip') s = response.read() buf = StringIO(s) f = gzip.GzipFile(fileobj=buf) data = f.read() self.assertEqual(data, 'Hello, world!\n') def tearDown(self): for sock in self.https_socks: sock.close() if hasattr(self, 'http_process'): self.http_process.shutdown() if hasattr(self, 'pp'): self.pp.transport.loseConnection() self.pp.transport.signalProcess('KILL') helpers.TestGL.tearDown(self)
class TestSubprocessRun(helpers.TestGL): @inlineCallbacks def setUp(self): super(TestSubprocessRun, self).setUp() with open('hello.txt', 'w') as f: f.write('Hello, world!\n') https_sock, _ = reserve_port_for_ip('127.0.0.1', 9443) self.https_socks = [https_sock] ssl._create_default_https_context = ssl._create_unverified_context yield test_tls.commit_valid_config() @inlineCallbacks def test_https_process(self): valid_cfg = { 'proxy_ip': '127.0.0.1', 'proxy_port': 43434, 'tls_socket_fds': [sock.fileno() for sock in self.https_socks], 'debug': False, } valid_cfg['site_cfgs'] = yield wrap_db_tx(load_tls_dict_list) tmp = tempfile.TemporaryFile(mode='w') tmp.write(json.dumps(valid_cfg)) tmp.seek(0, 0) tmp_fd = tmp.fileno() self.http_process = HTTPSProcess(fd=tmp_fd) # Connect to service ensure that it responds with a 502 yield threads.deferToThread(self.fetch_resource_with_fail) # Start the HTTP server proxy requests will be forwarded to. self.pp = helpers.SimpleServerPP() reactor.spawnProcess( self.pp, 'python', args=['python', '-m', 'SimpleHTTPServer', '43434'], usePTY=True) yield self.pp.start_defer # Check that requests are routed successfully yield threads.deferToThread(self.fetch_resource) def fetch_resource_with_fail(self): try: urllib.request.urlopen('https://127.0.0.1:9443') self.fail('Request had to throw a 502') except urllib.error.HTTPError as e: # Ensure the connection always has an HSTS header self.assertEqual(e.headers.get('Strict-Transport-Security'), 'max-age=31536000') self.assertEqual(e.code, 502) return def fetch_resource(self): response = urllib.request.urlopen('https://127.0.0.1:9443/hello.txt') hdrs = response.info() self.assertEqual(hdrs.get('Strict-Transport-Security'), 'max-age=31536000') self.assertEqual(response.read(), b'Hello, world!\n') def tearDown(self): if hasattr(self, 'http_process'): self.http_process.shutdown() if hasattr(self, 'pp'): self.pp.transport.loseConnection() helpers.TestGL.tearDown(self)
class TestSubprocessRun(helpers.TestGL): @inlineCallbacks def setUp(self): super(TestSubprocessRun, self).setUp() with open('hello.txt', 'w') as f: f.write('Hello, world!\n') https_sock, _ = reserve_port_for_ip('127.0.0.1', 9443) self.https_socks = [https_sock] ssl._create_default_https_context = ssl._create_unverified_context yield test_tls.commit_valid_config() @inlineCallbacks def test_https_process(self): valid_cfg = { 'proxy_ip': '127.0.0.1', 'proxy_port': 43434, 'tls_socket_fds': [sock.fileno() for sock in self.https_socks], 'debug': False, } valid_cfg['site_cfgs'] = yield tw(load_tls_dict_list) tmp = tempfile.TemporaryFile(mode='w') tmp.write(json.dumps(valid_cfg)) tmp.seek(0, 0) tmp_fd = tmp.fileno() self.http_process = HTTPSProcess(fd=tmp_fd) # Connect to service ensure that it responds with a 502 yield threads.deferToThread(self.fetch_resource_with_fail) # Start the HTTP server proxy requests will be forwarded to. self.pp = helpers.SimpleServerPP() reactor.spawnProcess(self.pp, 'python', args=['python', '-m', 'SimpleHTTPServer', '43434'], usePTY=True) yield self.pp.start_defer # Check that requests are routed successfully yield threads.deferToThread(self.fetch_resource) def fetch_resource_with_fail(self): try: urllib.request.urlopen('https://127.0.0.1:9443') self.fail('Request had to throw a 502') except urllib.error.HTTPError as e: # Ensure the connection always has an HSTS header self.assertEqual(e.headers.get('Strict-Transport-Security'), 'max-age=31536000') self.assertEqual(e.code, 502) return def fetch_resource(self): response = urllib.request.urlopen('https://127.0.0.1:9443/hello.txt') hdrs = response.info() self.assertEqual(hdrs.get('Strict-Transport-Security'), 'max-age=31536000') self.assertEqual(response.read(), b'Hello, world!\n') def tearDown(self): if hasattr(self, 'http_process'): self.http_process.shutdown() if hasattr(self, 'pp'): self.pp.transport.loseConnection() helpers.TestGL.tearDown(self)