Ticket #6124: ticket_6124.patch

File ticket_6124.patch, 22.0 KB (added by jct, 6 years ago)

A candidate patch in order to resolve the ticket.

  • facilitator/fac.py

    From 691628db78ccc4f6bc9df50e366cdfc6b006b749 Mon Sep 17 00:00:00 2001
    From: Jorge Couchet <jorge.couchet@gmail.com>
    Date: Thu, 6 Dec 2012 12:44:45 +0100
    Subject: [PATCH] Patch for the ticket 6124
    
    ---
     facilitator/fac.py              |  134 +++++++++++++--------
     facilitator/facilitator         |   38 +++++-
     facilitator/ticket-6124-test.py |  250 +++++++++++++++++++++++++++++++++++++++
     3 files changed, 368 insertions(+), 54 deletions(-)
     create mode 100755 facilitator/ticket-6124-test.py
    
    diff --git a/facilitator/fac.py b/facilitator/fac.py
    index 9d77b95..7d47ae3 100644
    a b  
    11import re
    22import socket
    33
     4def ip_ver(spec, defhost=None, defport=None, resolve=False, onlyhost=False):
     5
     6    if resolve:
     7        flags = 0
     8    else:
     9        # The flag 'AI_NUMERICHOST' is disabling domain name resolution, so the address must be numeric.
     10        flags = socket.AI_NUMERICHOST
     11
     12    if onlyhost:
     13        port = None
     14    else:
     15        port = defport
     16
     17    # IPv6 syntax (with square brackets).
     18    m = re.match(ur'^\[(.+)\]:(\d*)$', spec)
     19    if m:
     20        host, port = m.groups()
     21        if onlyhost:
     22            port = None
     23        elif port == '':
     24            port = defport
     25        af = socket.AF_INET6
     26    else:
     27        # Still IPv6 syntax but without port.
     28        m = re.match(ur'^\[(.+)\]$', spec)
     29        if m:
     30            host, = m.groups()
     31            af = socket.AF_INET6
     32        else:
     33            # It could be an IPv6 host without brackets
     34            if "::" in spec:
     35                host = spec
     36                af = socket.AF_INET6
     37            else:
     38                res = spec.split(":")
     39                # It still could be an IPv6 host without brackets.
     40                if len(res) > 2:
     41                    host = spec
     42                    af = socket.AF_INET6
     43
     44                # It could be IPv4 or not numeric IPv4/IPv6.
     45                else:
     46                    host = res[0]
     47                    if len(res) == 2:
     48                        port = res[1]
     49                    else:
     50                        port = ''
     51
     52                    if host == '':
     53                        if defhost is not None:
     54                            host = defhost
     55                        else:
     56                            return None
     57
     58                    if onlyhost:
     59                        port = None
     60                    else:
     61                        if len(res) == 2:
     62                            port = res[1]
     63                        else:
     64                            port = ''
     65                        if port == '':
     66                            port = defport
     67
     68                    if re.match(ur'^[\d.]+$', str(host)):
     69                        af = socket.AF_INET
     70                    else:
     71                        af = 0
     72    if not onlyhost:
     73        if (host is None or port is None):
     74            return None
     75        if port is not None and not (0 < int(port) <= 65535):
     76            return None
     77    try:
     78        addrs = socket.getaddrinfo(host, port, af, socket.SOCK_STREAM, socket.IPPROTO_TCP, flags)
     79        host, port = socket.getnameinfo(addrs[0][4], socket.NI_NUMERICHOST | socket.NI_NUMERICSERV)
     80        return (host,int(port),addrs[0][0])
     81    except:
     82        return None
     83
     84
    485def parse_addr_spec(spec, defhost = None, defport = None, resolve = False):
    586    """Parse a host:port specification and return a 2-tuple ("host", port) as
    687    understood by the Python socket functions.
    def parse_addr_spec(spec, defhost = None, defport = None, resolve = False): 
    27108    must be a numeric IPv4 or IPv6 address.
    28109
    29110    IPv6 addresses must be enclosed in square brackets."""
    30     host = None
    31     port = None
    32     af = 0
    33     m = None
    34     # IPv6 syntax.
    35     if not m:
    36         m = re.match(ur'^\[(.+)\]:(\d*)$', spec)
    37         if m:
    38             host, port = m.groups()
    39             af = socket.AF_INET6
    40     if not m:
    41         m = re.match(ur'^\[(.+)\]$', spec)
    42         if m:
    43             host, = m.groups()
    44             af = socket.AF_INET6
    45     # IPv4/hostname/port-only syntax.
    46     if not m:
    47         try:
    48             host, port = spec.split(":", 1)
    49         except ValueError:
    50             host = spec
    51         if re.match(ur'^[\d.]+$', host):
    52             af = socket.AF_INET
    53         else:
    54             af = 0
    55     host = host or defhost
    56     port = port or defport
    57     if host is None or port is None:
    58         raise ValueError("Bad address specification \"%s\"" % spec)
    59 
    60     # Now we have split around the colon and have a guess at the address family.
    61     # Forward-resolve the name into an addrinfo struct. Real DNS resolution is
    62     # done only if resolve is true; otherwise the address must be numeric.
    63     if resolve:
    64         flags = 0
     111    res = ip_ver(spec,defhost,defport,resolve)
     112    if res is not None:
     113        return (res[0], res[1])
    65114    else:
    66         flags = socket.AI_NUMERICHOST
    67     try:
    68         addrs = socket.getaddrinfo(host, port, af, socket.SOCK_STREAM, socket.IPPROTO_TCP, flags)
    69     except socket.gaierror, e:
    70         raise ValueError("Bad host or port: \"%s\" \"%s\": %s" % (host, port, str(e)))
    71     if not addrs:
    72         raise ValueError("Bad host or port: \"%s\" \"%s\"" % (host, port))
    73 
    74     # Convert the result of socket.getaddrinfo (which is a 2-tuple for IPv4 and
    75     # a 4-tuple for IPv6) into a (host, port) 2-tuple.
    76     host, port = socket.getnameinfo(addrs[0][4], socket.NI_NUMERICHOST | socket.NI_NUMERICSERV)
    77     port = int(port)
    78     return host, port
     115        raise ValueError("Bad address specification \"%s\"" % spec)   
     116
    79117
    80118def format_addr(addr):
    81119    host, port = addr
  • facilitator/facilitator

    diff --git a/facilitator/facilitator b/facilitator/facilitator
    index 26e449d..3ea223d 100755
    a b class Handler(SocketServer.StreamRequestHandler): 
    225225        print >> self.wfile, "ERROR"
    226226
    227227    def do_GET(self, params):
    228         reg = REGS.fetch()
     228        proxy_spec = fac.param_first("FROM", params)
     229        res = fac.ip_ver(proxy_spec, onlyhost=True)
     230        if res is not None:
     231            proxy_ip_ver = res[2]
     232            if proxy_ip_ver == socket.AF_INET:
     233                reg = REGS_v4.fetch()
     234                REGS = REGS_v4
     235            else:
     236                reg = REGS_v6.fetch()
     237                REGS = REGS_v6
     238                # If there isn't an available IPv6 address, then it tries to give a IPv4 address
     239                # (It is assuming that a IPv6 proxy understand IPv4)
     240                if reg is None:
     241                    reg = REGS_v4.fetch()
     242                    REGS = REGS_v4
     243        else:
     244            reg = None
    229245        if reg:
    230246            log(u"proxy gets %s, relay %s (now %d)" %
    231247                (safe_str(unicode(reg)), options.relay_spec, len(REGS)))
    class Handler(SocketServer.StreamRequestHandler): 
    250266            log(u"syntax error in %s: %s" % (safe_str(repr(client_spec)), safe_str(repr(str(e)))))
    251267            self.send_error()
    252268            return False
    253 
    254         if REGS.add(reg):
    255             log(u"client %s (now %d)" % (safe_str(unicode(reg)), len(REGS)))
     269     
     270        res = fac.ip_ver(reg.host, onlyhost=True)
     271        if res is not None:
     272            client_ip_ver = res[2]
     273            if client_ip_ver == socket.AF_INET:
     274                REGS = REGS_v4
     275            else:
     276                REGS = REGS_v6
     277            if REGS.add(reg):
     278                log(u"client %s (now %d)" % (safe_str(unicode(reg)), len(REGS)))
     279            else:
     280                log(u"client %s (already present, now %d)" % (safe_str(unicode(reg)), len(REGS)))
    256281        else:
    257             log(u"client %s (already present, now %d)" % (safe_str(unicode(reg)), len(REGS)))
     282            log(u"client address %s (is incorrect)" % (safe_str(unicode(reg.host))))
    258283
    259284        self.send_ok()
    260285        return True
    class Handler(SocketServer.StreamRequestHandler): 
    264289class Server(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
    265290    allow_reuse_address = True
    266291
    267 REGS = RegSet()
     292REGS_v4 = RegSet()
     293REGS_v6 = RegSet()
    268294
    269295def main():
    270296    opts, args = getopt.gnu_getopt(sys.argv[1:], "dhl:p:r:",
  • new file facilitator/ticket-6124-test.py

    diff --git a/facilitator/ticket-6124-test.py b/facilitator/ticket-6124-test.py
    new file mode 100755
    index 0000000..879af84
    - +  
     1#!/usr/bin/env python
     2
     3import subprocess
     4import time
     5import unittest
     6
     7import fac
     8
     9
     10FACILITATOR_PORT = 9002
     11FACILITATOR_ADDR = ("127.0.0.1", FACILITATOR_PORT)
     12
     13
     14class IpVerTest(unittest.TestCase):
     15    def test_ipv4(self):
     16        self.assertEqual(fac.ip_ver("192.168.0.1:9999"), ("192.168.0.1", 9999, 2))
     17
     18    def test_dns_ipv4(self):
     19        self.assertEqual(len(fac.ip_ver("google.com:80", resolve=True)), 3)
     20        self.assertEqual(fac.ip_ver("google.com:80", resolve=True)[1], 80)   
     21
     22    def test_ipv6(self):
     23        self.assertEqual(fac.ip_ver("[12::34]:9999"), ("12::34", 9999, 10))
     24
     25    def test_dns_ipv6(self):
     26        self.assertEqual(len(fac.ip_ver("[google.com]:80", resolve=True)), 3)
     27        self.assertEqual(fac.ip_ver("[google.com]:80", resolve=True)[1], 80)
     28        self.assertEqual(fac.ip_ver("[google.com]:80", resolve=True)[2], 10)
     29
     30    def test_onlyhost_ipv4(self):
     31       self.assertEqual(fac.ip_ver("192.168.0.1:9999", onlyhost=True), ("192.168.0.1", 0, 2))
     32       self.assertEqual(fac.ip_ver("192.168.0.1:", defport=80, onlyhost=True), ("192.168.0.1", 0, 2))
     33       self.assertEqual(fac.ip_ver("192.168.0.1:", onlyhost=True), ("192.168.0.1", 0, 2))
     34       self.assertEqual(fac.ip_ver("192.168.0.1", defport=80, onlyhost=True), ("192.168.0.1", 0, 2))
     35       self.assertEqual(fac.ip_ver("192.168.0.1", onlyhost=True), ("192.168.0.1", 0, 2))
     36       self.assertEqual(fac.ip_ver("192.168.0.1", defport=9999,onlyhost=True), ("192.168.0.1", 0, 2))
     37       self.assertEqual(fac.ip_ver("192.168.0.1:", defport=9999,onlyhost=True), ("192.168.0.1", 0, 2))
     38       self.assertEqual(fac.ip_ver("192.168.0.1:80", defport=9999,onlyhost=True), ("192.168.0.1", 0, 2))
     39       self.assertEqual(fac.ip_ver("192.168.0.1", defhost="10.1.1.1", defport=80, onlyhost=True), ("192.168.0.1", 0, 2))
     40       self.assertEqual(fac.ip_ver("", defhost="192.168.0.1", defport=9999, onlyhost=True), ("192.168.0.1", 0, 2))
     41       self.assertEqual(fac.ip_ver("", defhost="192.168.0.1", onlyhost=True), ("192.168.0.1", 0, 2))
     42
     43    def test_dns_onlyhost_ipv4(self):
     44       self.assertEqual(len(fac.ip_ver("google.com", resolve=True, onlyhost=True)), 3)
     45       self.assertEqual(len(fac.ip_ver("google.com:", resolve=True, onlyhost=True)), 3)
     46       self.assertEqual(fac.ip_ver("google.com", resolve=True, onlyhost=True)[1], 0)
     47       self.assertEqual(fac.ip_ver("google.com:", resolve=True, onlyhost=True)[1], 0)
     48       self.assertEqual(fac.ip_ver("google.com:80", resolve=True, onlyhost=True)[1], 0)
     49
     50    def test_defhost_defport_ipv4(self):
     51        self.assertEqual(fac.ip_ver("192.168.0.2:8888", defhost="192.168.0.1", defport=9999), ("192.168.0.2", 8888, 2))
     52        self.assertEqual(fac.ip_ver("192.168.0.2:", defhost="192.168.0.1", defport=9999), ("192.168.0.2", 9999, 2))
     53        self.assertEqual(fac.ip_ver("192.168.0.2", defhost="192.168.0.1", defport=9999), ("192.168.0.2", 9999, 2))
     54        self.assertEqual(fac.ip_ver(":8888", defhost="192.168.0.1", defport=9999), ("192.168.0.1", 8888, 2))
     55        self.assertEqual(fac.ip_ver(":", defhost="192.168.0.1", defport=9999), ("192.168.0.1", 9999, 2))
     56        self.assertEqual(fac.ip_ver("", defhost="192.168.0.1", defport=9999), ("192.168.0.1", 9999, 2))
     57
     58    def test_dns_defhost_defport_ipv4(self):
     59        self.assertEqual(len(fac.ip_ver("google.com", defport=80, resolve=True)), 3)
     60        self.assertEqual(fac.ip_ver("google.com", defport=80, resolve=True)[1], 80)
     61        self.assertEqual(fac.ip_ver("google.com", defport=80, resolve=True)[1], 80)
     62
     63    def test_onlyhost_ipv6(self):
     64        self.assertEqual(fac.ip_ver("[12::34]:9999", onlyhost=True), ("12::34", 0, 10))
     65        self.assertEqual(fac.ip_ver("[12::34]:", defport=80, onlyhost=True), ("12::34", 0, 10))
     66        self.assertEqual(fac.ip_ver("[12::34]:", onlyhost=True), ("12::34", 0, 10))
     67        self.assertEqual(fac.ip_ver("[12::34]", defport=80, onlyhost=True), ("12::34", 0, 10))
     68        self.assertEqual(fac.ip_ver("[12::34]", onlyhost=True), ("12::34", 0, 10))
     69        self.assertEqual(fac.ip_ver("[1234::2]", defhost="1234::1", defport=9999, onlyhost=True), ("1234::2", 0, 10))
     70        self.assertEqual(fac.ip_ver("[1234::2]:", defhost="1234::1", defport=9999, onlyhost=True), ("1234::2", 0, 10))
     71        self.assertEqual(fac.ip_ver("[1234::2]:80", defhost="1234::1", defport=9999, onlyhost=True), ("1234::2", 0, 10))
     72        self.assertEqual(fac.ip_ver("", defhost="1234::1", defport=9999, onlyhost=True), ("1234::1", 0, 10))
     73        self.assertEqual(fac.ip_ver("12::34", onlyhost=True), ("12::34", 0, 10))
     74        self.assertEqual(fac.ip_ver("12::34", defport=80, onlyhost=True), ("12::34", 0, 10))
     75        self.assertEqual(fac.ip_ver("", defhost="12::34", defport=80, onlyhost=True), ("12::34", 0, 10))
     76        self.assertEqual(fac.ip_ver(":", defhost="12::34", defport=80, onlyhost=True), ("12::34", 0, 10))
     77
     78    def test_dns_onlyhost_ipv6(self):
     79        self.assertEqual(len(fac.ip_ver("[google.com]", resolve=True, onlyhost=True)), 3)
     80        self.assertEqual(len(fac.ip_ver("[google.com]:", resolve=True, onlyhost=True)), 3)
     81        self.assertEqual(fac.ip_ver("[google.com]", resolve=True, onlyhost=True)[1], 0)
     82        self.assertEqual(fac.ip_ver("[google.com]:", resolve=True, onlyhost=True)[1], 0)
     83        self.assertEqual(fac.ip_ver("[google.com]:80", resolve=True, onlyhost=True)[1], 0)
     84        self.assertEqual(fac.ip_ver("[google.com]", resolve=True, onlyhost=True)[2], 10)
     85
     86    def test_defhost_defport_ipv6(self):
     87        self.assertEqual(fac.ip_ver("[1234::2]:8888", defhost="1234::1", defport=9999), ("1234::2", 8888, 10))
     88        self.assertEqual(fac.ip_ver("[1234::2]:", defhost="1234::1", defport=9999), ("1234::2", 9999, 10))
     89        self.assertEqual(fac.ip_ver("[1234::2]", defhost="1234::1", defport=9999), ("1234::2", 9999, 10))
     90        self.assertEqual(fac.ip_ver(":8888", defhost="1234::1", defport=9999), ("1234::1", 8888, 10))
     91        self.assertEqual(fac.ip_ver(":", defhost="1234::1", defport=9999), ("1234::1", 9999, 10))
     92        self.assertEqual(fac.ip_ver("", defhost="1234::1", defport=9999), ("1234::1", 9999, 10))
     93
     94    def test_dns_defhost_defport_ipv6(self):
     95        self.assertEqual(len(fac.ip_ver("[google.com]", defport=80, resolve=True)), 3)
     96        self.assertEqual(fac.ip_ver("[google.com]", defport=80, resolve=True)[1], 80)
     97        self.assertEqual(fac.ip_ver("[google.com]", defport=80, resolve=True)[2], 10)
     98
     99    def test_bad_port_ipv4(self):
     100        self.assertEqual(fac.ip_ver("127.0.0.1:65536"), None)
     101        self.assertEqual(fac.ip_ver("127.0.0.1", defport=65536), None)
     102        self.assertEqual(fac.ip_ver("127.0.0.1:65536", onlyhost=True), ("127.0.0.1", 0, 2))
     103
     104    def test_bad_port_ipv6(self):
     105        self.assertEqual(fac.ip_ver("[12::1]:65536"), None)
     106        self.assertEqual(fac.ip_ver("[12::1]", defport=65536), None)
     107        self.assertEqual(fac.ip_ver("[12::1]:65536", onlyhost=True), ("12::1", 0, 10))
     108
     109    def test_incomplete_address_ipv4(self):
     110        """Test that when in ip_ver the flag 'onlyhost' is not set, it must have 'host' and 'port' """
     111        self.assertEqual(fac.ip_ver("127.0.0.1"), None)
     112
     113    def test_incomplete_address_ipv6(self):
     114        """Test that when in ip_ver the flag 'onlyhost' is not set, it must have 'host' and 'port'"""
     115        self.assertEqual(fac.ip_ver("[1::4]:"), None)
     116
     117    def test_invalid_address1_ipv6(self):
     118        """Test ip_ver with an invalid IPv6 address"""
     119        self.assertEqual(fac.ip_ver("1:1:3", defport = 9999), None)
     120
     121    def test_invalid_address2_ipv6(self):
     122        """Test ip_ver with an invalid IPv6 address"""
     123        self.assertEqual(fac.ip_ver("[1.1]:9999"), None)
     124
     125    def test_noresolve_ipv4(self):
     126        """ Test that ip_ver does not do DNS resolution by default. """
     127        self.assertEqual(fac.ip_ver("google.com:80"), None)
     128
     129    def test_noresolve_ipv6(self):
     130        """ Test that ip_ver does not do DNS resolution by default. """
     131        self.assertEqual(fac.ip_ver("[google.com]:80"), None)
     132
     133
     134
     135class ParseAddrSpecTest(unittest.TestCase):
     136    def test_ipv4(self):
     137        self.assertEqual(fac.parse_addr_spec("192.168.0.1:9999"), ("192.168.0.1", 9999))
     138
     139    def test_dns_ipv4(self):
     140        self.assertEqual(len(fac.parse_addr_spec("google.com:80", resolve=True)), 2)
     141        self.assertEqual(fac.parse_addr_spec("google.com:80", resolve=True)[1], 80)
     142
     143    def test_ipv6(self):
     144        self.assertEqual(fac.parse_addr_spec("[12::34]:9999"), ("12::34", 9999))
     145
     146    def test_dns_ipv6(self):
     147        self.assertEqual(len(fac.parse_addr_spec("[google.com]:80", resolve=True)), 2)
     148        self.assertEqual(fac.parse_addr_spec("[google.com]:80", resolve=True)[1], 80)
     149
     150    def test_defhost_defport_ipv4(self):
     151        self.assertEqual(fac.parse_addr_spec("192.168.0.2:8888", defhost="192.168.0.1", defport=9999), ("192.168.0.2", 8888))
     152        self.assertEqual(fac.parse_addr_spec("192.168.0.2:", defhost="192.168.0.1", defport=9999), ("192.168.0.2", 9999))
     153        self.assertEqual(fac.parse_addr_spec("192.168.0.2", defhost="192.168.0.1", defport=9999), ("192.168.0.2", 9999))
     154        self.assertEqual(fac.parse_addr_spec(":8888", defhost="192.168.0.1", defport=9999), ("192.168.0.1", 8888))
     155        self.assertEqual(fac.parse_addr_spec(":", defhost="192.168.0.1", defport=9999), ("192.168.0.1", 9999))
     156        self.assertEqual(fac.parse_addr_spec("", defhost="192.168.0.1", defport=9999), ("192.168.0.1", 9999))
     157
     158    def test_dns_defhost_defport_ipv4(self):
     159        self.assertEqual(len(fac.parse_addr_spec("google.com", defport=80, resolve=True)), 2)
     160        self.assertEqual(fac.parse_addr_spec("google.com", defport=80, resolve=True)[1], 80)
     161
     162    def test_defhost_defport_ipv6(self):
     163        self.assertEqual(fac.parse_addr_spec("[1234::2]:8888", defhost="1234::1", defport=9999), ("1234::2", 8888))
     164        self.assertEqual(fac.parse_addr_spec("[1234::2]:", defhost="1234::1", defport=9999), ("1234::2", 9999))
     165        self.assertEqual(fac.parse_addr_spec("[1234::2]", defhost="1234::1", defport=9999), ("1234::2", 9999))
     166        self.assertEqual(fac.parse_addr_spec(":8888", defhost="1234::1", defport=9999), ("1234::1", 8888))
     167        self.assertEqual(fac.parse_addr_spec(":", defhost="1234::1", defport=9999), ("1234::1", 9999))
     168        self.assertEqual(fac.parse_addr_spec("", defhost="1234::1", defport=9999), ("1234::1", 9999))
     169
     170    def test_dns_defhost_defport_ipv6(self):
     171        self.assertEqual(len(fac.parse_addr_spec("[google.com]", defport=80, resolve=True)), 2)
     172        self.assertEqual(fac.parse_addr_spec("[google.com]", defport=80, resolve=True)[1], 80)
     173
     174    def test_noresolve(self):
     175        """Test that parse_addr_spec does not do DNS resolution by default."""
     176        self.assertRaises(ValueError, fac.parse_addr_spec, "example.com")
     177
     178
     179class FacilitatorTest(unittest.TestCase):
     180
     181    def setUp(self):
     182        self.process = subprocess.Popen(["./facilitator", "-d", "-p", str(FACILITATOR_PORT), "-r", "0.0.1.0:1", "-l", "/dev/null"])
     183        time.sleep(0.1)
     184
     185    def tearDown(self):
     186        self.process.terminate()
     187
     188    def test_t1(self):
     189        """IPv6 client and IPv4 proxy"""
     190        proxy_addr = ("145.89.56.7", None)
     191        client_spec = "[234:1::1:2]:455"
     192        client_addr = fac.parse_addr_spec(client_spec, defhost=proxy_addr[0])
     193        fac.put_reg(FACILITATOR_ADDR, client_addr, proxy_addr)
     194        reg = fac.get_reg(FACILITATOR_ADDR, proxy_addr)
     195        self.assertEqual(reg['client'], "")
     196
     197    def test_t2(self):
     198        """IPv6 client and IPv6 proxy"""
     199        proxy_addr = ("[145::2]", None)
     200        client_spec = "[234:1::1:2]:455"
     201        client_addr = fac.parse_addr_spec(client_spec, defhost=proxy_addr[0])
     202        fac.put_reg(FACILITATOR_ADDR, client_addr, proxy_addr)
     203        reg = fac.get_reg(FACILITATOR_ADDR, proxy_addr)
     204        self.assertEqual(reg['client'], "[234:1::1:2]:455")
     205
     206    def test_t3(self):
     207        """IPv4 client and IPv6 proxy"""
     208        proxy_addr = ("[145::1]", None)
     209        client_spec = "234.12.1.1:455"
     210        client_addr = fac.parse_addr_spec(client_spec, defhost=proxy_addr[0])
     211        fac.put_reg(FACILITATOR_ADDR, client_addr, proxy_addr)
     212        reg = fac.get_reg(FACILITATOR_ADDR, proxy_addr)
     213        self.assertEqual(reg['client'], "234.12.1.1:455")
     214
     215    def test_t4(self):
     216        """IPv4 client and IPv4 proxy"""
     217        proxy_addr = ("156.45.89.70", None)
     218        client_spec = "234.12.1.1:455"
     219        client_addr = fac.parse_addr_spec(client_spec, defhost=proxy_addr[0])
     220        fac.put_reg(FACILITATOR_ADDR, client_addr, proxy_addr)
     221        reg = fac.get_reg(FACILITATOR_ADDR, proxy_addr)
     222        self.assertEqual(reg['client'], "234.12.1.1:455")
     223
     224    def test_t5(self):
     225        """IPv6 client, IPv4 client and IPv4 proxy"""
     226        proxy_addr = ("156.45.89.70", None)
     227        client_spec = "[234:1::1:2]:455"
     228        client_addr = fac.parse_addr_spec(client_spec, defhost=proxy_addr[0])
     229        fac.put_reg(FACILITATOR_ADDR, client_addr, proxy_addr)
     230        client_spec = "234.12.1.1:455"
     231        client_addr = fac.parse_addr_spec(client_spec, defhost=proxy_addr[0])
     232        fac.put_reg(FACILITATOR_ADDR, client_addr, proxy_addr)
     233        reg = fac.get_reg(FACILITATOR_ADDR, proxy_addr)
     234        self.assertEqual(reg['client'], "234.12.1.1:455")
     235
     236    def test_t6(self):
     237        """IPv6 client, IPv4 client and IPv6 proxy"""
     238        proxy_addr = ("[156::10]", None)
     239        client_spec = "23.4.5.12:455"
     240        client_addr = fac.parse_addr_spec(client_spec, defhost=proxy_addr[0])
     241        fac.put_reg(FACILITATOR_ADDR, client_addr, proxy_addr)
     242        client_spec = "[234::1]:455"
     243        client_addr = fac.parse_addr_spec(client_spec, defhost=proxy_addr[0])
     244        fac.put_reg(FACILITATOR_ADDR, client_addr, proxy_addr)
     245        reg = fac.get_reg(FACILITATOR_ADDR, proxy_addr)
     246        self.assertEqual(reg['client'], "[234::1]:455")
     247
     248
     249if __name__ == "__main__":
     250    unittest.main()