Example #1
0
 def test_tuple_to_address_invalid_arg(self):
     """
     Tests the tuple to address conversion when a wrong argument is passed
     """
     with self.assertRaises(ValueError):
         try:
             tuple_to_address("WRONG")
         except ValueError as e:
             self.assertTrue(str(e).startswith("too many values to unpack"))
             raise e
Example #2
0
 def test_tuple_to_address_invalid_arg(self):
     """
     Tests the tuple to address conversion when a wrong argument is passed
     """
     with self.assertRaises(ValueError):
         try:
             tuple_to_address("WRONG")
         except ValueError as e:
             self.assertTrue(str(e).startswith("too many values to unpack"))
             raise e
Example #3
0
 def test_tuple_to_address_empty_tuple(self):
     """
     Tests the tuple to address conversion when a tuple with empty values is passed
     """
     with self.assertRaises(ValueError):
         try:
             tuple_to_address((None, None))
         except ValueError as e:
             self.assertEqual("invalid argument passed: (None, None)", str(e))
             raise e
Example #4
0
 def handle_stream(self, stream, address):
     """
     Handle a new client connection with a proxy over websocket
     """
     logger.info("Got connection from %s on %s" % (tuple_to_address(stream.socket.getpeername()),
                                                   tuple_to_address(stream.socket.getsockname())))
     self.ws_conn = WebSocketProxyConnection(self.ws_url, stream, address,
                                             filters=self.filters,
                                             ws_options=self.ws_options)
     self.ws_conn.connect()
Example #5
0
 def test_tuple_to_address_empty_tuple(self):
     """
     Tests the tuple to address conversion when a tuple with empty values is passed
     """
     with self.assertRaises(ValueError):
         try:
             tuple_to_address((None, None))
         except ValueError as e:
             self.assertEqual("invalid argument passed: (None, None)",
                              str(e))
             raise e
Example #6
0
 def handle_stream(self, stream, address):
     """
     Handle a new client connection with a proxy over websocket
     """
     logger.info("Got connection from %s on %s" %
                 (tuple_to_address(stream.socket.getpeername()),
                  tuple_to_address(stream.socket.getsockname())))
     self.ws_conn = WebSocketProxyConnection(self.ws_url,
                                             stream,
                                             address,
                                             filters=self.filters,
                                             ws_options=self.ws_options)
     self.ws_conn.connect()
Example #7
0
 def open(self):
     """
     Open the connection to the service when the WebSocket connection has been established
     """
     logger.info("Forwarding connection to server %s" %
                 tuple_to_address(self.remote_address))
     self.io_stream.connect(self.remote_address, self.on_connect)
Example #8
0
 def test_address_to_tuple(self):
     """
     Tests the address to tuple conversions
     """
     addr = "127.0.0.1:443"
     t = address_to_tuple(addr)
     self.assertEqual(t, ("127.0.0.1", 443))
     self.assertEqual(addr, tuple_to_address(t))
Example #9
0
 def test_address_to_tuple(self):
     """
     Tests the address to tuple conversions
     """
     addr = "127.0.0.1:443"
     t = address_to_tuple(addr)
     self.assertEqual(t, ("127.0.0.1", 443))
     self.assertEqual(addr, tuple_to_address(t))
Example #10
0
 def test_address_to_tuple_missing_port(self):
     """
     Tests the address to tuple conversions when port is missing
     """
     addr = "127.0.0.1"
     t = address_to_tuple(addr)
     self.assertEqual(t, ("127.0.0.1", None))
     self.assertEqual(addr, tuple_to_address(t))
Example #11
0
 def test_address_to_tuple_missing_host(self):
     """
     Tests the address to tuple conversions when host is missing
     """
     addr = 443
     t = address_to_tuple(addr)
     self.assertEqual(t, (None, 443))
     self.assertEqual(addr, tuple_to_address(t))
Example #12
0
 def test_address_to_tuple_missing_port(self):
     """
     Tests the address to tuple conversions when port is missing
     """
     addr = "127.0.0.1"
     t = address_to_tuple(addr)
     self.assertEqual(t, ("127.0.0.1", None))
     self.assertEqual(addr, tuple_to_address(t))
Example #13
0
 def test_address_to_tuple_missing_host(self):
     """
     Tests the address to tuple conversions when host is missing
     """
     addr = 443
     t = address_to_tuple(addr)
     self.assertEqual(t, (None, 443))
     self.assertEqual(addr, tuple_to_address(t))
Example #14
0
 def on_connect(self):
     """
     Callback invoked on connection with mapped service
     """
     logger.info("Connection established with peer at %s" %
                 tuple_to_address(self.remote_address))
     for k in range(len(self.filters)):
         self.filters[k] = copy.deepcopy(self.filters[k])
         self.filters[k].startup()
     self.io_stream.read_until_close(self.on_close, self.on_peer_message)
Example #15
0
 def on_close(self, *args, **kwargs):
     """
     When web socket gets closed, close the connection to the service too
     """
     logger.info("Closing connection with peer at %s" % tuple_to_address(self.remote_address))
     logger.debug("Received args %s and %s", args, kwargs)
     #if not self.io_stream._closed:
     for message in args:
         self.on_peer_message(message)
     if not self.io_stream.closed():
         self.io_stream.close()
     self.close()
Example #16
0
 def on_connect(self):
     """
     Callback invoked on connection with mapped service
     """
     logger.info("Connection established with peer at %s" % tuple_to_address(self.remote_address))
     self.io_stream.read_until_close(self.on_close, self.on_peer_message)
Example #17
0
 def open(self):
     """
     Open the connection to the service when the WebSocket connection has been established
     """
     logger.info("Forwarding connection to server %s" % tuple_to_address(self.remote_address))
     self.io_stream.connect(self.remote_address, self.on_connect)