BIND 10 trac1512, updated. e2706e3bf587ca97983e0115e998904d9d0cc674 [1512] test different name hash values for a known pair.

BIND 10 source code commits bind10-changes at lists.isc.org
Tue May 22 00:24:14 UTC 2012


The branch, trac1512 has been updated
       via  e2706e3bf587ca97983e0115e998904d9d0cc674 (commit)
       via  d50547b048f15666f637e47df6ae5854c01102c7 (commit)
      from  dd418d92a81da33ab22b97d3316205ed5e1ad7ec (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit e2706e3bf587ca97983e0115e998904d9d0cc674
Author: JINMEI Tatuya <jinmei at isc.org>
Date:   Mon May 21 17:21:26 2012 -0700

    [1512] test different name hash values for a known pair.
    
    added comments about the underlying assumption and what we should do
    if that isn't held.

commit d50547b048f15666f637e47df6ae5854c01102c7
Author: JINMEI Tatuya <jinmei at isc.org>
Date:   Mon May 21 17:12:00 2012 -0700

    [1512] added some specific ZoneConfig tests.
    
    mainly covering some unusual setups.  no need to update the tested code.

-----------------------------------------------------------------------

Summary of changes:
 src/lib/dns/python/tests/name_python_test.py       |   15 ++-
 src/lib/python/isc/ddns/tests/Makefile.am          |    2 +-
 src/lib/python/isc/ddns/tests/zone_config_tests.py |  117 ++++++++++++++++++++
 3 files changed, 131 insertions(+), 3 deletions(-)
 create mode 100644 src/lib/python/isc/ddns/tests/zone_config_tests.py

-----------------------------------------------------------------------
diff --git a/src/lib/dns/python/tests/name_python_test.py b/src/lib/dns/python/tests/name_python_test.py
index b3b6e6a..8ea2e35 100644
--- a/src/lib/dns/python/tests/name_python_test.py
+++ b/src/lib/dns/python/tests/name_python_test.py
@@ -223,8 +223,19 @@ class NameTest(unittest.TestCase):
         self.assertEqual(hash(Name('example.com')), hash(Name('example.com')))
         # Hash is case insensitive.
         self.assertEqual(hash(Name('example.com')), hash(Name('EXAMPLE.COM')))
-        # We cannot reliably test the case for different hash values, but
-        # we can at least confirm inequality is case insensitive.
+
+        # These pairs happen to be known to have different hashes.
+        # It may be naive to assume the hash value is always the same (we use
+        # an external library and it depends on its internal details).  If
+        # it turns out that this assumption isn't always held, we should
+        # disable this test.
+        self.assertNotEqual(hash(Name('example.com')),
+                            hash(Name('example.org')))
+
+        # Check insensitiveness for the case of inequality.
+        # Based on the assumption above, this 'if' should be true and
+        # we'll always test the case inside it.  We'll still keep the if in
+        # case we end up disabling the above test.
         if hash(Name('example.com')) != hash(Name('example.org')):
             self.assertNotEqual(hash(Name('example.com')),
                                 hash(Name('EXAMPLE.ORG')))
diff --git a/src/lib/python/isc/ddns/tests/Makefile.am b/src/lib/python/isc/ddns/tests/Makefile.am
index 87de762..f8e05b8 100644
--- a/src/lib/python/isc/ddns/tests/Makefile.am
+++ b/src/lib/python/isc/ddns/tests/Makefile.am
@@ -1,5 +1,5 @@
 PYCOVERAGE_RUN = @PYCOVERAGE_RUN@
-PYTESTS = session_tests.py
+PYTESTS = session_tests.py zone_config_tests.py
 EXTRA_DIST = $(PYTESTS)
 CLEANFILES = $(builddir)/rwtest.sqlite3.copied
 
diff --git a/src/lib/python/isc/ddns/tests/zone_config_tests.py b/src/lib/python/isc/ddns/tests/zone_config_tests.py
new file mode 100644
index 0000000..7d4bc76
--- /dev/null
+++ b/src/lib/python/isc/ddns/tests/zone_config_tests.py
@@ -0,0 +1,117 @@
+# Copyright (C) 2012  Internet Systems Consortium.
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM
+# DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
+# INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
+# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+import isc.log
+import unittest
+from isc.dns import *
+from isc.datasrc import DataSourceClient
+from isc.ddns.zone_config import *
+
+# Some common test parameters
+TEST_ZONE_NAME = Name('example.org')
+TEST_SECONDARY_ZONE_NAME = Name('example.com')
+TEST_RRCLASS = RRClass.IN()
+
+class FakeDataSourceClient:
+    '''Faked data source client used in the ZoneConfigTest.
+
+    It emulates isc.datasrc.DataSourceClient, but only has to provide
+    the find_zone() interface (and only the first element of the return
+    value matters).  By default it returns 'SUCCESS' (exact match) for
+    any input.  It can be dynamically customized via the set_find_result()
+    method.
+
+    '''
+    def __init__(self):
+        self.__find_result = DataSourceClient.SUCCESS
+
+    def find_zone(self, zname):
+        return (self.__find_result, None)
+
+    def set_find_result(self, result):
+        self.__find_result = result
+
+class ZoneConfigTest(unittest.TestCase):
+    '''Some basic tests for the ZoneConfig class.'''
+    def setUp(self):
+        self.__datasrc_client = FakeDataSourceClient()
+        self.zconfig = ZoneConfig([(TEST_SECONDARY_ZONE_NAME, TEST_RRCLASS)],
+                                  TEST_RRCLASS, self.__datasrc_client)
+
+    def test_find_zone(self):
+        # Primay zone case: zone is in the data source, and not in secondaries
+        self.assertEqual((ZONE_PRIMARY, self.__datasrc_client),
+                         (self.zconfig.find_zone(TEST_ZONE_NAME, TEST_RRCLASS)))
+
+        # Secondary zone case: zone is in the data source and in secondaries.
+        self.assertEqual((ZONE_SECONDARY, None),
+                         (self.zconfig.find_zone(TEST_SECONDARY_ZONE_NAME,
+                                                 TEST_RRCLASS)))
+
+        # 'not found' case: zone not in the data source.
+        self.__datasrc_client.set_find_result(DataSourceClient.NOTFOUND)
+        self.assertEqual((ZONE_NOTFOUND, None),
+                         (self.zconfig.find_zone(Name('example'),
+                                                 TEST_RRCLASS)))
+        # same for the partial match
+        self.__datasrc_client.set_find_result(DataSourceClient.PARTIALMATCH)
+        self.assertEqual((ZONE_NOTFOUND, None),
+                         (self.zconfig.find_zone(Name('example'),
+                                                 TEST_RRCLASS)))
+        # a bit unusual case: zone not in the data source, but in secondaries.
+        # this is probably a configuration error, but ZoneConfig doesn't do
+        # this level check.
+        self.__datasrc_client.set_find_result(DataSourceClient.NOTFOUND)
+        self.assertEqual((ZONE_NOTFOUND, None),
+                         (self.zconfig.find_zone(TEST_ZONE_NAME,
+                                                 TEST_RRCLASS)))
+        # zone class doesn't match (but zone name matches)
+        self.__datasrc_client.set_find_result(DataSourceClient.SUCCESS)
+        zconfig = ZoneConfig([(TEST_SECONDARY_ZONE_NAME, TEST_RRCLASS)],
+                             RRClass.CH(), self.__datasrc_client)
+        self.assertEqual((ZONE_NOTFOUND, None),
+                         (zconfig.find_zone(TEST_ZONE_NAME, TEST_RRCLASS)))
+        # similar to the previous case, but also in the secondary list
+        zconfig = ZoneConfig([(TEST_ZONE_NAME, TEST_RRCLASS)],
+                             RRClass.CH(), self.__datasrc_client)
+        self.assertEqual((ZONE_NOTFOUND, None),
+                         (zconfig.find_zone(TEST_ZONE_NAME, TEST_RRCLASS)))
+
+        # check some basic tests varying the secondary list.
+        # empty secondary list doesn't cause any disruption.
+        zconfig = ZoneConfig([], TEST_RRCLASS, self.__datasrc_client)
+        self.assertEqual((ZONE_PRIMARY, self.__datasrc_client),
+                         (self.zconfig.find_zone(TEST_ZONE_NAME, TEST_RRCLASS)))
+        # adding some mulitle tuples, including subdomainof the test zone name,
+        # and the same zone name but a different class
+        zconfig = ZoneConfig([(TEST_SECONDARY_ZONE_NAME, TEST_RRCLASS),
+                              (Name('example'), TEST_RRCLASS),
+                              (Name('sub.example.org'), TEST_RRCLASS),
+                              (TEST_ZONE_NAME, RRClass.CH())],
+                             TEST_RRCLASS, self.__datasrc_client)
+        self.assertEqual((ZONE_PRIMARY, self.__datasrc_client),
+                         (self.zconfig.find_zone(TEST_ZONE_NAME, TEST_RRCLASS)))
+        # secondary zone list has a duplicate entry, which is just
+        # (effecitivey) ignored
+        zconfig = ZoneConfig([(TEST_SECONDARY_ZONE_NAME, TEST_RRCLASS),
+                              (TEST_SECONDARY_ZONE_NAME, TEST_RRCLASS)],
+                             TEST_RRCLASS, self.__datasrc_client)
+        self.assertEqual((ZONE_PRIMARY, self.__datasrc_client),
+                         (self.zconfig.find_zone(TEST_ZONE_NAME, TEST_RRCLASS)))
+
+if __name__ == "__main__":
+    isc.log.init("bind10")
+    isc.log.resetUnitTestRootLogger()
+    unittest.main()



More information about the bind10-changes mailing list