Browse Source

[1414] address some more comments

Jelte Jansen 13 years ago
parent
commit
23350205fb
2 changed files with 25 additions and 9 deletions
  1. 14 6
      src/bin/zonemgr/tests/zonemgr_test.py
  2. 11 3
      src/bin/zonemgr/zonemgr.py.in

+ 14 - 6
src/bin/zonemgr/tests/zonemgr_test.py

@@ -551,19 +551,16 @@ class TestZonemgrRefresh(unittest.TestCase):
         self.zone_refresh.update_config_data(config, self.cc_session)
         self.assertEqual(self.zone_refresh._zonemgr_refresh_info, {})
         # Put something in
-        #config.set_zone_list_from_name_classes([ZONE_NAME_CLASS1_IN])
         config['secondary_zones'] = \
             zone_list_from_name_classes([ZONE_NAME_CLASS1_IN])
         self.zone_refresh.update_config_data(config, self.cc_session)
         self.assertTrue(("example.net.", "IN") in
                         self.zone_refresh._zonemgr_refresh_info)
-        # This one does not exist
+        # Reset the data, set to use a different class, and make sure
+        # it does not get set to IN
         config['secondary_zones'] = \
-            zone_list_from_name_classes(["example.net", "CH"])
+            zone_list_from_name_classes([ZONE_NAME_CLASS1_CH])
         self.zone_refresh.update_config_data(config, self.cc_session)
-        self.assertFalse(("example.net.", "CH") in
-                         self.zone_refresh._zonemgr_refresh_info)
-        # Simply skip loading soa for the zone, the other configs should be updated successful
         self.assertFalse(("example.net.", "IN") in
                          self.zone_refresh._zonemgr_refresh_info)
         # Make sure it works even when we "accidentally" forget the final dot
@@ -572,6 +569,17 @@ class TestZonemgrRefresh(unittest.TestCase):
         self.zone_refresh.update_config_data(config, self.cc_session)
         self.assertTrue(("example.net.", "IN") in
                         self.zone_refresh._zonemgr_refresh_info)
+        # Try some bad names
+        config['secondary_zones'] = \
+            zone_list_from_name_classes([("example..net", "IN")])
+        self.assertRaises(ZonemgrException,
+                          self.zone_refresh.update_config_data,
+                          config, self.cc_session)
+        config['secondary_zones'] = \
+            zone_list_from_name_classes([("", "IN")])
+        self.assertRaises(ZonemgrException,
+                          self.zone_refresh.update_config_data,
+                          config, self.cc_session)
 
     def tearDown(self):
         sys.stderr= self.stderr_backup

+ 11 - 3
src/bin/zonemgr/zonemgr.py.in

@@ -28,6 +28,7 @@ import os
 import time
 import signal
 import isc
+import isc.dns
 import random
 import threading
 import select
@@ -461,9 +462,16 @@ class ZonemgrRefresh:
                         raise ZonemgrException("Secondary zone specified "
                                                "without a name")
                     name = secondary_zone['name']
-                    # Be tolerant to sclerotic users who forget the final dot
-                    if name[-1] != '.':
-                        name = name + '.'
+
+                    # Convert to Name and back (both to check and to normalize)
+                    try:
+                        name = isc.dns.Name(name, True).to_text()
+                    # Name() can raise a number of different exceptions, just
+                    # catch 'em all.
+                    except Exception as isce:
+                        raise ZonemgrException("Bad zone name '" + name +
+                                               "': " + str(isce))
+
                     # Currently we use an explicit get_default_value call
                     # in case the class hasn't been set. Alternatively, we
                     # could use