commit f644c0e11362b122bee5e3df6a229057b03e5fb0 Author: Ximin Luo infinity0@gmx.com Date: Mon Oct 7 12:33:04 2013 +0100
fix a bug in get_reg and fix tests to be able to expose that bug --- facilitator/fac.py | 10 ++++++---- facilitator/facilitator-test | 25 +++++++++++++------------ 2 files changed, 19 insertions(+), 16 deletions(-)
diff --git a/facilitator/fac.py b/facilitator/fac.py index 5e1737a..74ce27d 100644 --- a/facilitator/fac.py +++ b/facilitator/fac.py @@ -253,6 +253,8 @@ def transact(f, command, *params): def put_reg(facilitator_addr, client_addr, transport_chain, registrant_addr=None): """Send a registration to the facilitator using a one-time socket. Returns true iff the command was successful.""" + # TODO(infinity0): replace "transport_chain" with better terminology, e.g. + # transport_pair f = fac_socket(facilitator_addr) params = [("CLIENT", format_addr(client_addr))] params.append(("TRANSPORT_CHAIN", transport_chain)) @@ -275,18 +277,18 @@ def get_reg(facilitator_addr, proxy_addr, transport_list): "relay-<transport>" if successful, or a dict with the key "client" mapped to the value "" if there are no registrations available for proxy_addr. Raises an exception otherwise.""" + # TODO(infinity0): replace "transport_list" with better terminology, e.g. + # transport_suffix_list f = fac_socket(facilitator_addr)
# Form a list (in transact() format) with the transports that we # should send to the facilitator. Then pass that list to the # transact() function. # For example, TRANSPORT=obfs2 TRANSPORT=obfs3. - transports = [] - for transport in transport_list: - transports += ("TRANSPORT", transport) + transports = [("TRANSPORT", transport) for transport in transport_list]
try: - command, params = transact(f, "GET", ("FROM", format_addr(proxy_addr)), transports) + command, params = transact(f, "GET", ("FROM", format_addr(proxy_addr)), *transports) finally: f.close() response = {} diff --git a/facilitator/facilitator-test b/facilitator/facilitator-test index bd4894e..6b3b0f1 100755 --- a/facilitator/facilitator-test +++ b/facilitator/facilitator-test @@ -13,7 +13,8 @@ import fac FACILITATOR_HOST = "127.0.0.1" FACILITATOR_PORT = 39002 # diff port to not conflict with production service FACILITATOR_ADDR = (FACILITATOR_HOST, FACILITATOR_PORT) -WS_TRANSPORT = ("websocket",) +CLIENT_TP = "websocket" +PROXY_TPS = ["websocket", "webrtc"]
def gimme_socket(host, port): addrinfo = socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM, socket.IPPROTO_TCP)[0] @@ -81,34 +82,34 @@ class FacilitatorProcTest(unittest.TestCase):
def test_af_v4_v4(self): """Test that IPv4 proxies can get IPv4 clients.""" - fac.put_reg(FACILITATOR_ADDR, self.IPV4_CLIENT_ADDR, WS_TRANSPORT) - fac.put_reg(FACILITATOR_ADDR, self.IPV6_CLIENT_ADDR, WS_TRANSPORT) - reg = fac.get_reg(FACILITATOR_ADDR, self.IPV4_PROXY_ADDR, WS_TRANSPORT) + fac.put_reg(FACILITATOR_ADDR, self.IPV4_CLIENT_ADDR, CLIENT_TP) + fac.put_reg(FACILITATOR_ADDR, self.IPV6_CLIENT_ADDR, CLIENT_TP) + reg = fac.get_reg(FACILITATOR_ADDR, self.IPV4_PROXY_ADDR, PROXY_TPS) self.assertEqual(reg["client"], fac.format_addr(self.IPV4_CLIENT_ADDR))
def test_af_v4_v6(self): """Test that IPv4 proxies do not get IPv6 clients.""" - fac.put_reg(FACILITATOR_ADDR, self.IPV6_CLIENT_ADDR, WS_TRANSPORT) - reg = fac.get_reg(FACILITATOR_ADDR, self.IPV4_PROXY_ADDR, WS_TRANSPORT) + fac.put_reg(FACILITATOR_ADDR, self.IPV6_CLIENT_ADDR, CLIENT_TP) + reg = fac.get_reg(FACILITATOR_ADDR, self.IPV4_PROXY_ADDR, PROXY_TPS) self.assertEqual(reg["client"], "")
def test_af_v6_v4(self): """Test that IPv6 proxies do not get IPv4 clients.""" - fac.put_reg(FACILITATOR_ADDR, self.IPV4_CLIENT_ADDR, WS_TRANSPORT) - reg = fac.get_reg(FACILITATOR_ADDR, self.IPV6_PROXY_ADDR, WS_TRANSPORT) + fac.put_reg(FACILITATOR_ADDR, self.IPV4_CLIENT_ADDR, CLIENT_TP) + reg = fac.get_reg(FACILITATOR_ADDR, self.IPV6_PROXY_ADDR, PROXY_TPS) self.assertEqual(reg["client"], "")
def test_af_v6_v6(self): """Test that IPv6 proxies can get IPv6 clients.""" - fac.put_reg(FACILITATOR_ADDR, self.IPV4_CLIENT_ADDR, WS_TRANSPORT) - fac.put_reg(FACILITATOR_ADDR, self.IPV6_CLIENT_ADDR, WS_TRANSPORT) - reg = fac.get_reg(FACILITATOR_ADDR, self.IPV6_PROXY_ADDR, WS_TRANSPORT) + fac.put_reg(FACILITATOR_ADDR, self.IPV4_CLIENT_ADDR, CLIENT_TP) + fac.put_reg(FACILITATOR_ADDR, self.IPV6_CLIENT_ADDR, CLIENT_TP) + reg = fac.get_reg(FACILITATOR_ADDR, self.IPV6_PROXY_ADDR, PROXY_TPS) self.assertEqual(reg["client"], fac.format_addr(self.IPV6_CLIENT_ADDR))
def test_check_back_in(self): """Test that facilitator responses contain a CHECK-BACK-IN key with a numeric value.""" - reg = fac.get_reg(FACILITATOR_ADDR, self.IPV6_PROXY_ADDR, WS_TRANSPORT) + reg = fac.get_reg(FACILITATOR_ADDR, self.IPV6_PROXY_ADDR, PROXY_TPS) self.assertGreater(int(reg["check-back-in"]), 0)
# def test_same_proxy(self):