Пример #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
Пример #2
0
 def test_add_get_remove_server_proxy(self):
     """
     Tests adding/remove/get operations on server proxies
     """
     ws_proxies = {"/test": ("127.0.0.1", random_free_port())}
     for key, address in ws_proxies.items():
         self.srv_tun.add_proxy(key, address)
         self.assertEqual(address, self.srv_tun.get_proxy(key))
         self.assertEqual(1, len(self.srv_tun.proxies))
         self.srv_tun.remove_proxy(key)
         self.assertEqual(0, len(self.srv_tun.proxies))
Пример #3
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)
     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, {})
Пример #4
0
        def setUp(self):
            super(WSTunnelSSLClientDaemonTestCase, self).setUp()

            with open(os.path.join(fixture, "wstuncltd.yml")) as f:
                self.tun_conf = yaml.load(f.read())
            self.tun_conf["logging"]["handlers"]["file_handler"]["filename"] = self.log_file
            self.tun_conf["pid_file"] = self.pid_file
            self.tun_conf["proxies"]["/test"]["port"] = random_free_port()
            self.tun_conf["ws_url"] = "wss://localhost:9000/"

            IOLoop.instance().start = lambda: 0
            IOLoop.instance().stop = lambda: 0

            self.daemon = WSTunnelClientDaemon(self.tun_conf)
            self.daemon.hush = lambda **kwargs: 0
Пример #5
0
        def setUp(self):
            # super(WSTunnelServerDaemonTestCase, self).setUp()
            self.log_file, self.pid_file = setup_logging()

            with open(os.path.join(fixture, "wstunsrvd.yml")) as f:
                self.tun_conf = yaml.load(f.read())
            self.tun_conf["logging"]["handlers"]["file_handler"]["filename"] = self.log_file
            self.tun_conf["pid_file"] = self.pid_file
            self.tun_conf["listen"] = random_free_port()

            IOLoop.instance().start = lambda: 0
            IOLoop.instance().stop = lambda: 0

            self.daemon = WSTunnelServerDaemon(self.tun_conf)
            self.daemon.hush = lambda **kwargs: 0
Пример #6
0
        def setUp(self):
            super(WSTunnelSSLClientDaemonTestCase, self).setUp()

            with open(os.path.join(fixture, "wstuncltd.yml")) as f:
                self.tun_conf = yaml.load(f.read())
            self.tun_conf["logging"]["handlers"]["file_handler"][
                "filename"] = self.log_file
            self.tun_conf["pid_file"] = self.pid_file
            self.tun_conf["proxies"]["/test"]["port"] = random_free_port()
            self.tun_conf["ws_url"] = "wss://localhost:9000/"

            IOLoop.instance().start = lambda: 0
            IOLoop.instance().stop = lambda: 0

            self.daemon = WSTunnelClientDaemon(self.tun_conf)
            self.daemon.hush = lambda **kwargs: 0
Пример #7
0
        def setUp(self):
            # super(WSTunnelServerDaemonTestCase, self).setUp()
            self.log_file, self.pid_file = setup_logging()

            with open(os.path.join(fixture, "wstunsrvd.yml")) as f:
                self.tun_conf = yaml.load(f.read())
            self.tun_conf["logging"]["handlers"]["file_handler"][
                "filename"] = self.log_file
            self.tun_conf["pid_file"] = self.pid_file
            self.tun_conf["listen"] = random_free_port()

            IOLoop.instance().start = lambda: 0
            IOLoop.instance().stop = lambda: 0

            self.daemon = WSTunnelServerDaemon(self.tun_conf)
            self.daemon.hush = lambda **kwargs: 0
Пример #8
0
        def setUp(self):
            super(WSTunnelSSLServerDaemonTestCase, self).setUp()

            with open(os.path.join(fixture, "wstunsrvd.yml")) as f:
                self.tun_conf = yaml.load(f.read())
            self.tun_conf["logging"]["handlers"]["file_handler"]["filename"] = self.log_file
            self.tun_conf["pid_file"] = self.pid_file
            self.tun_conf["listen"] = random_free_port()
            self.tun_conf["ssl"] = True
            self.tun_conf["ssl_options"].update({"certfile": os.path.join(fixture, "localhost.pem"),
                                                 "keyfile": os.path.join(fixture, "localhost.key")})

            IOLoop.instance().start = lambda: 0
            IOLoop.instance().stop = lambda: 0

            self.daemon = WSTunnelServerDaemon(self.tun_conf)
            self.daemon.hush = lambda **kwargs: 0
Пример #9
0
        def setUp(self):
            super(WSTunnelSSLServerDaemonTestCase, self).setUp()

            with open(os.path.join(fixture, "wstunsrvd.yml")) as f:
                self.tun_conf = yaml.load(f.read())
            self.tun_conf["logging"]["handlers"]["file_handler"][
                "filename"] = self.log_file
            self.tun_conf["pid_file"] = self.pid_file
            self.tun_conf["listen"] = random_free_port()
            self.tun_conf["ssl"] = True
            self.tun_conf["ssl_options"].update({
                "certfile":
                os.path.join(fixture, "localhost.pem"),
                "keyfile":
                os.path.join(fixture, "localhost.key")
            })

            IOLoop.instance().start = lambda: 0
            IOLoop.instance().stop = lambda: 0

            self.daemon = WSTunnelServerDaemon(self.tun_conf)
            self.daemon.hush = lambda **kwargs: 0
Пример #10
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)
     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
Пример #11
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, {})
Пример #12
0
    def test_no_server_service(self):
        """
        Tests the server tunnel endpoint behaviour when there's no service to connect
        """
        srv_tun = WSTunnelServer(0, io_loop=self.io_loop, proxies={"/test": ("127.0.0.1", random_free_port())})
        srv_tun.start()
        clt_tun = WSTunnelClient(io_loop=self.io_loop)
        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
Пример #13
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
Пример #14
0
 def port(self, value):
     self._port = value if value else random_free_port()
Пример #15
0
 def _test_random_free_port(self, address, family, type):
     port = random_free_port(family=family, type=type)
     sock = socket.socket(family=family, type=type)
     self.assertRaises(socket.error, sock.connect, (address, port))
Пример #16
0
 def _test_random_free_port(self, address, family, type):
     port = random_free_port(family=family, type=type)
     sock = socket.socket(family=family, type=type)
     self.assertRaises(socket.error, sock.connect, (address, port))