[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [flashproxy/master] Add tests for parse_addr_spec.



commit 8201762b9ca27ec232270c2d3c7256a3775cabaf
Author: David Fifield <david@xxxxxxxxxxxxxxx>
Date:   Tue Sep 11 08:42:37 2012 -0700

    Add tests for parse_addr_spec.
---
 facilitator/fac.py           |    6 +++++-
 facilitator/facilitator-test |   27 +++++++++++++++++++++++++++
 2 files changed, 32 insertions(+), 1 deletions(-)

diff --git a/facilitator/fac.py b/facilitator/fac.py
index b9ad435..2382d2b 100644
--- a/facilitator/fac.py
+++ b/facilitator/fac.py
@@ -12,11 +12,15 @@ def parse_addr_spec(spec, defhost = None, defport = None, resolve = False):
     >>> parse_addr_spec("192.168.0.2:8888", defhost="192.168.0.1", defport=9999)
     ('192.168.0.2', 8888)
     >>> parse_addr_spec(":8888", defhost="192.168.0.1", defport=9999)
-    ('192.168.0.1', 9999)
+    ('192.168.0.1', 8888)
+    >>> parse_addr_spec("192.168.0.2", defhost="192.168.0.1", defport=9999)
+    ('192.168.0.2', 9999)
     >>> parse_addr_spec("192.168.0.2:", defhost="192.168.0.1", defport=9999)
     ('192.168.0.2', 9999)
     >>> parse_addr_spec(":", defhost="192.168.0.1", defport=9999)
     ('192.168.0.1', 9999)
+    >>> parse_addr_spec("", defhost="192.168.0.1", defport=9999)
+    ('192.168.0.1', 9999)
 
     If resolve is true, then the host in the specification or the defhost may be
     a domain name, which will be resolved. If resolve is false, then the host
diff --git a/facilitator/facilitator-test b/facilitator/facilitator-test
index b06f5d7..c8946e6 100755
--- a/facilitator/facilitator-test
+++ b/facilitator/facilitator-test
@@ -86,6 +86,33 @@ class FacilitatorTest(unittest.TestCase):
 #         """Test that the facilitator rejects hostnames."""
 #         self.fail()
 
+class ParseAddrSpecTest(unittest.TestCase):
+    def test_ipv4(self):
+        self.assertEqual(fac.parse_addr_spec("192.168.0.1:9999"), ("192.168.0.1", 9999))
+
+    def test_ipv6(self):
+        self.assertEqual(fac.parse_addr_spec("[12::34]:9999"), ("12::34", 9999))
+
+    def test_defhost_defport_ipv4(self):
+        self.assertEqual(fac.parse_addr_spec("192.168.0.2:8888", defhost="192.168.0.1", defport=9999), ("192.168.0.2", 8888))
+        self.assertEqual(fac.parse_addr_spec("192.168.0.2:", defhost="192.168.0.1", defport=9999), ("192.168.0.2", 9999))
+        self.assertEqual(fac.parse_addr_spec("192.168.0.2", defhost="192.168.0.1", defport=9999), ("192.168.0.2", 9999))
+        self.assertEqual(fac.parse_addr_spec(":8888", defhost="192.168.0.1", defport=9999), ("192.168.0.1", 8888))
+        self.assertEqual(fac.parse_addr_spec(":", defhost="192.168.0.1", defport=9999), ("192.168.0.1", 9999))
+        self.assertEqual(fac.parse_addr_spec("", defhost="192.168.0.1", defport=9999), ("192.168.0.1", 9999))
+
+    def test_defhost_defport_ipv6(self):
+        self.assertEqual(fac.parse_addr_spec("[1234::2]:8888", defhost="1234::1", defport=9999), ("1234::2", 8888))
+        self.assertEqual(fac.parse_addr_spec("[1234::2]:", defhost="1234::1", defport=9999), ("1234::2", 9999))
+        self.assertEqual(fac.parse_addr_spec("[1234::2]", defhost="1234::1", defport=9999), ("1234::2", 9999))
+        self.assertEqual(fac.parse_addr_spec(":8888", defhost="1234::1", defport=9999), ("1234::1", 8888))
+        self.assertEqual(fac.parse_addr_spec(":", defhost="1234::1", defport=9999), ("1234::1", 9999))
+        self.assertEqual(fac.parse_addr_spec("", defhost="1234::1", defport=9999), ("1234::1", 9999))
+
+    def test_noresolve(self):
+        """Test that parse_addr_spec does not do DNS resolution by default."""
+        self.assertRaises(ValueError, fac.parse_addr_spec, "example.com")
+
 class ParseTransactionTest(unittest.TestCase):
     def test_empty_string(self):
         self.assertRaises(ValueError, fac.parse_transaction, "")



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits