Exemplo n.º 1
0
 def test_tunnel_channel_exc(self):
     remote_host = '127.0.0.69'
     server = OpenSSHServer(listen_ip=remote_host, port=self.port)
     server.start_server()
     in_q, out_q = deque(), deque()
     try:
         tunnel = Tunnel(remote_host,
                         in_q,
                         out_q,
                         port=self.port,
                         pkey=self.user_key,
                         num_retries=1)
         tunnel._init_tunnel_client()
         tunnel_accept = spawn(tunnel._start_tunnel, '127.0.0.255',
                               self.port)
         while len(out_q) == 0:
             sleep(1)
         listen_port = out_q.pop()
         client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         client_socket.connect(('127.0.0.1', listen_port))
         client = spawn(self._connect_client, client_socket)
         sleep(1)
         client.kill()
         tunnel_accept.kill()
         for _sock in tunnel._sockets:
             self.assertTrue(_sock.closed)
     finally:
         server.stop()
Exemplo n.º 2
0
 def test_tunnel_channel_eof(self):
     remote_host = '127.0.0.59'
     server = OpenSSHServer(listen_ip=remote_host, port=self.port)
     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._init_tunnel_client()
         channel = tunnel._open_channel_retries(self.proxy_host, self.port,
                                                2150)
         self.assertFalse(channel.eof())
         channel.close()
         listen_socket, listen_port = tunnel._init_tunnel_sock()
         client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         client_socket.connect(('127.0.0.1', listen_port))
         client = spawn(self._connect_client, client_socket)
         tunnel._read_channel(client_socket, channel)
         tunnel._read_forward_sock(client_socket, channel)
         self.assertTrue(channel.eof())
         client.kill()
     finally:
         server.stop()
Exemplo n.º 3
0
 def test_tunnel_sock_failure(self):
     remote_host = '127.0.0.59'
     server = OpenSSHServer(listen_ip=remote_host, port=self.port)
     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._init_tunnel_client()
         channel = tunnel._open_channel_retries(self.proxy_host, self.port,
                                                2150)
         self.assertFalse(channel.eof())
         listen_socket, listen_port = tunnel._init_tunnel_sock()
         client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         client_socket.connect(('127.0.0.1', listen_port))
         client_socket.send(b'blah\n')
         client_socket.close()
         gl1 = spawn(tunnel._read_channel, client_socket, channel)
         gl2 = spawn(tunnel._read_forward_sock, client_socket, channel)
         sleep(1)
         gl1.kill()
         gl2.kill()
         tunnel._sockets.append(None)
         tunnel.cleanup()
     finally:
         server.stop()
Exemplo n.º 4
0
 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()
Exemplo n.º 5
0
 def test_tunnel_sock_failure(self):
     remote_host = '127.0.0.59'
     server = OpenSSHServer(listen_ip=remote_host, port=self.port)
     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._init_tunnel_client()
         channel = tunnel._open_channel_retries(self.proxy_host, self.port, 2150)
         self.assertFalse(channel.eof())
         listen_socket, listen_port = tunnel._init_tunnel_sock()
         client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         client_socket.connect(('127.0.0.1', listen_port))
         client_socket.send(b'blah\n')
         client_socket.close()
         gl1 = spawn(tunnel._read_channel, client_socket, channel)
         gl2 = spawn(tunnel._read_forward_sock, client_socket, channel)
         sleep(1)
         gl1.kill()
         gl2.kill()
         tunnel._sockets.append(None)
         tunnel.cleanup()
     finally:
         server.stop()
Exemplo n.º 6
0
 def test_tunnel_retries(self):
     local_port = 3050
     fw_host, fw_port = '127.0.0.1', 2100
     t = Tunnel(self.proxy_host,
                deque(),
                deque(),
                port=self.port,
                pkey=self.user_key,
                num_retries=2)
     t._init_tunnel_client()
     self.assertRaises(ChannelFailure, t._open_channel_retries, fw_host,
                       fw_port, local_port)
Exemplo n.º 7
0
 def test_tunnel_retries(self):
     local_port = 3050
     fw_host, fw_port = '127.0.0.1', 2100
     t = Tunnel(self.proxy_host, deque(), deque(), port=self.port,
                pkey=self.user_key, num_retries=2)
     t._init_tunnel_client()
     try:
         t._open_channel_retries(fw_host, fw_port, local_port)
     except (ChannelFailure, SocketSendError) as ex:
         pass
     else:
         raise AssertionError(ex)
Exemplo n.º 8
0
 def test_tunnel_retries(self):
     local_port = 3050
     fw_host, fw_port = '127.0.0.1', 2100
     t = Tunnel(self.proxy_host,
                deque(),
                deque(),
                port=self.port,
                pkey=self.user_key,
                num_retries=2)
     t._init_tunnel_client()
     try:
         t._open_channel_retries(fw_host, fw_port, local_port)
     except (ChannelFailure, SocketSendError) as ex:
         pass
     else:
         raise AssertionError(ex)
Exemplo n.º 9
0
 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()
Exemplo n.º 10
0
 def test_tunnel_channel_eof(self):
     remote_host = '127.0.0.59'
     server = OpenSSHServer(listen_ip=remote_host, port=self.port)
     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._init_tunnel_client()
         channel = tunnel._open_channel_retries(self.proxy_host, self.port, 2150)
         self.assertFalse(channel.eof())
         channel.close()
         listen_socket, listen_port = tunnel._init_tunnel_sock()
         client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         client_socket.connect(('127.0.0.1', listen_port))
         client = spawn(self._connect_client, client_socket)
         tunnel._read_channel(client_socket, channel)
         tunnel._read_forward_sock(client_socket, channel)
         self.assertTrue(channel.eof())
         client.kill()
     finally:
         server.stop()
Exemplo n.º 11
0
 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()
Exemplo n.º 12
0
 def test_tunnel_channel_exc(self):
     remote_host = '127.0.0.69'
     server = OpenSSHServer(listen_ip=remote_host, port=self.port)
     server.start_server()
     in_q, out_q = deque(), deque()
     try:
         tunnel = Tunnel(remote_host, in_q, out_q, port=self.port,
                         pkey=self.user_key, num_retries=1)
         tunnel._init_tunnel_client()
         tunnel_accept = spawn(tunnel._start_tunnel, '127.0.0.255', self.port)
         while len(out_q) == 0:
             sleep(1)
         listen_port = out_q.pop()
         client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         client_socket.connect(('127.0.0.1', listen_port))
         client = spawn(self._connect_client, client_socket)
         sleep(1)
         client.kill()
         tunnel_accept.kill()
         for _sock in tunnel._sockets:
             self.assertTrue(_sock.closed)
     finally:
         server.stop()
Exemplo n.º 13
0
 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()