def test_tunnel_init(self): proxy_host = '127.0.0.49' server = OpenSSHServer(listen_ip=proxy_host, port=self.port) server.start_server() in_q, out_q = deque(), deque() try: tunnel = Tunnel(proxy_host, in_q, out_q, port=self.port, pkey=self.user_key, num_retries=1) tunnel._init_tunnel_client() consume_let = spawn(tunnel._consume_q) in_q.append((self.host, self.port)) while not tunnel.tunnel_open.is_set(): sleep(.1) if not tunnel.is_alive(): raise ProxyError self.assertTrue(tunnel.tunnel_open.is_set()) self.assertIsNotNone(tunnel.client) tunnel.cleanup() for _sock in tunnel._sockets: self.assertTrue(_sock.closed) finally: server.stop()
def test_tunnel_channel_failure(self): remote_host = '127.0.0.8' remote_server = OpenSSHServer(listen_ip=remote_host, port=self.port) remote_server.start_server() in_q, out_q = deque(), deque() try: tunnel = Tunnel(self.proxy_host, in_q, out_q, port=self.port, pkey=self.user_key, num_retries=1) tunnel.daemon = True tunnel.start() in_q.append((remote_host, self.port)) while not tunnel.tunnel_open.is_set(): sleep(.1) if not tunnel.is_alive(): raise ProxyError self.assertTrue(tunnel.tunnel_open.is_set()) self.assertIsNotNone(tunnel.client) while True: try: _port = out_q.pop() except IndexError: sleep(.5) else: break proxy_client = SSHClient( '127.0.0.1', pkey=self.user_key, port=_port, num_retries=1, _auth_thread_pool=False) tunnel.cleanup() spawn(proxy_client.execute, 'echo me') proxy_client.disconnect() self.assertTrue(proxy_client.sock.closed) finally: remote_server.stop()
def test_tunnel_server_failure(self): proxy_host = '127.0.0.9' remote_host = '127.0.0.8' server = OpenSSHServer(listen_ip=proxy_host, port=self.port) remote_server = OpenSSHServer(listen_ip=remote_host, port=self.port) for _server in (server, remote_server): _server.start_server() in_q, out_q = deque(), deque() try: tunnel = Tunnel(proxy_host, in_q, out_q, port=self.port, pkey=self.user_key, num_retries=1) tunnel._init_tunnel_client() consume_let = spawn(tunnel._consume_q) in_q.append((remote_host, self.port)) while not tunnel.tunnel_open.is_set(): sleep(.1) if not tunnel.is_alive(): raise ProxyError self.assertTrue(tunnel.tunnel_open.is_set()) self.assertIsNotNone(tunnel.client) while True: try: _port = out_q.pop() except IndexError: sleep(.5) else: break proxy_client = spawn(SSHClient, '127.0.0.1', pkey=self.user_key, port=_port, num_retries=1, _auth_thread_pool=False) remote_server.stop() tunnel.cleanup() self.assertRaises(ConnectionErrorException, proxy_client.get) finally: for _server in (server, remote_server): _server.stop()
def test_tunnel_channel_failure(self): remote_host = '127.0.0.8' remote_server = OpenSSHServer(listen_ip=remote_host, port=self.port) remote_server.start_server() in_q, out_q = deque(), deque() try: tunnel = Tunnel(self.proxy_host, in_q, out_q, port=self.port, pkey=self.user_key, num_retries=1) tunnel.daemon = True tunnel.start() in_q.append((remote_host, self.port)) while not tunnel.tunnel_open.is_set(): sleep(.1) if not tunnel.is_alive(): raise ProxyError self.assertTrue(tunnel.tunnel_open.is_set()) self.assertIsNotNone(tunnel.client) while True: try: _port = out_q.pop() except IndexError: sleep(.5) else: break proxy_client = SSHClient('127.0.0.1', pkey=self.user_key, port=_port, num_retries=1, _auth_thread_pool=False) sleep(1) cmd = spawn(proxy_client.execute, 'echo me') proxy_client.disconnect() joinall([cmd]) self.assertEqual(proxy_client.sock, None) finally: remote_server.stop()
def test_tunnel_init(self): proxy_host = '127.0.0.49' server = OpenSSHServer(listen_ip=proxy_host, port=self.port) server.start_server() in_q, out_q = deque(), deque() try: tunnel = Tunnel(proxy_host, in_q, out_q, port=self.port, pkey=self.user_key, num_retries=1) tunnel._init_tunnel_client() consume_let = spawn(tunnel._consume_q) in_q.append((self.host, self.port)) while not tunnel.tunnel_open.is_set(): sleep(.1) if not tunnel.is_alive(): raise ProxyError self.assertTrue(tunnel.tunnel_open.is_set()) self.assertIsNotNone(tunnel.client) tunnel.cleanup() for _sock in tunnel._sockets: self.assertTrue(_sock.closed) finally: server.stop()
def test_tunnel_server_failure(self): proxy_host = '127.0.0.9' remote_host = '127.0.0.8' server = OpenSSHServer(listen_ip=proxy_host, port=self.port) remote_server = OpenSSHServer(listen_ip=remote_host, port=self.port) for _server in (server, remote_server): _server.start_server() in_q, out_q = deque(), deque() try: tunnel = Tunnel(proxy_host, in_q, out_q, port=self.port, pkey=self.user_key, num_retries=1) tunnel._init_tunnel_client() consume_let = spawn(tunnel._consume_q) in_q.append((remote_host, self.port)) while not tunnel.tunnel_open.is_set(): sleep(.1) if not tunnel.is_alive(): raise ProxyError self.assertTrue(tunnel.tunnel_open.is_set()) self.assertIsNotNone(tunnel.client) while True: try: _port = out_q.pop() except IndexError: sleep(.5) else: break proxy_client = spawn( SSHClient, '127.0.0.1', pkey=self.user_key, port=_port, num_retries=1, _auth_thread_pool=False) remote_server.stop() tunnel.cleanup() self.assertRaises(ConnectionErrorException, proxy_client.get) finally: for _server in (server, remote_server): _server.stop()