Exemplo n.º 1
0
 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()
Exemplo n.º 2
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.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 = spawn(SSHClient,
                              '127.0.0.1',
                              pkey=self.user_key,
                              port=_port,
                              num_retries=1,
                              _auth_thread_pool=False)
         stop_cmd = spawn(remote_server.stop)
         joinall([proxy_client, stop_cmd])
         sleep(1)
     finally:
         for _server in (server, remote_server):
             _server.stop()
Exemplo n.º 3
0
 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()