Exemplo n.º 1
0
    def test_no_server_service(self):
        """
        Tests the server tunnel endpoint behaviour when there's no service to connect
        """
        srv_tun = WSTunnelServer(
            0, proxies={"/test": ("127.0.0.1", random_free_port())})
        srv_tun.start()
        clt_tun = WSTunnelClient()
        clt_tun.add_proxy(
            "test",
            WebSocketProxy(port=0,
                           ws_url="ws://localhost:{0}/test".format(
                               srv_tun.port)))

        clt_tun.start()

        message = "Hello World!"
        client = EchoClient(clt_tun.address_list[0])
        client.send_message(message, self.no_response)
        with self.assertRaises(Exception):
            try:
                self.wait(timeout=ASYNC_TIMEOUT)
            except Exception as e:
                #print(e)
                #self.assertEqual(str(e),)
                raise e
Exemplo n.º 2
0
 def test_no_client_ws_options(self):
     """
     Tests the client tunnel endpoint behaviour when there's no server counterpart
     """
     clt_tun = WSTunnelClient(family=socket.AF_INET,
                              io_loop=self.io_loop)
     clt_tun.add_proxy("test", WebSocketProxy(port=0, ws_url="ws://localhost:{0}/test".format(random_free_port())))
     clt_tun.start()
     self.assertEqual(clt_tun.ws_options, {})
Exemplo n.º 3
0
 def test_add_get_remove_client_proxy(self):
     """
     Tests adding/remove/get operations on client proxies
     """
     ws_proxy = WebSocketProxy(port=0, ws_url="ws://localhost:9000/test_add_remove")
     self.assertFalse(ws_proxy.serving)
     self.clt_tun.add_proxy("test_add_remove", ws_proxy)
     self.assertEqual(ws_proxy, self.clt_tun.get_proxy("test_add_remove"))
     self.assertTrue(ws_proxy.serving)
     self.clt_tun.remove_proxy("test_add_remove")
     self.assertFalse(ws_proxy.serving)
Exemplo n.º 4
0
def create_ws_client_endpoint(config):
    """
    Create a client endpoint parsing the configuration file options
    """
    ws_url = config["ws_url"]
    srv = WSTunnelClient(ws_options=config.get("ws_options", {}))
    proxies = config["proxies"]
    for resource, settings in proxies.items():
        filters = [load_filter(clazz) for clazz in config.get("filters", [])]

        srv.add_proxy(
            key=settings["port"],
            ws_proxy=WebSocketProxy(  #address=settings.get("address", ''),
                port=int(settings.get("port", 0)),
                ws_url=join_url(ws_url, resource),
                filters=filters,
                ws_options=config.get("ws_options", {})))
    return srv
Exemplo n.º 5
0
 def test_no_ws_endpoint(self):
     """
     Tests the client tunnel endpoint behaviour when there's no server counterpart
     """
     clt_tun = WSTunnelClient(family=socket.AF_INET,
                              io_loop=self.io_loop)
     clt_tun.add_proxy("test", WebSocketProxy(port=0, ws_url="ws://localhost:{0}/test".format(random_free_port())))
     clt_tun.start()
     message = "Hello World!"
     client = EchoClient(clt_tun.address_list[0])
     client.send_message(message, self.no_response)
     #self.wait(timeout=ASYNC_TIMEOUT)
     with self.assertRaises(Exception):
         try:
             self.wait(timeout=ASYNC_TIMEOUT)
         except Exception as e:
             self.assertEqual(str(e),
                              "The server endpoint is not available, caused by HTTPError('HTTP 599: [Errno 61] Connection refused',))")
             raise e