Parcourir la source

[1790] Add more testcases for missing keys

Strictly, this is not necessary as the spec file schema would check for
it.
Mukund Sivaraman il y a 13 ans
Parent
commit
d872878ef5
2 fichiers modifiés avec 67 ajouts et 4 suppressions
  1. 61 4
      src/bin/xfrin/tests/xfrin_test.py
  2. 6 0
      src/bin/xfrin/xfrin.py.in

+ 61 - 4
src/bin/xfrin/tests/xfrin_test.py

@@ -2931,7 +2931,7 @@ class TestXfrinProcess(unittest.TestCase):
         self.assertTrue(self._send_cc_session.recv_called)
         self.assertTrue(self._send_cc_session.recv_called)
         self.assertTrue(self._send_cc_session.recv_called_correctly)
         self.assertTrue(self._send_cc_session.recv_called_correctly)
 
 
-    def test_inmem_not_memory(self):
+    def test_inmem_datasource_type_not_memory(self):
         """
         """
         Inmem configuration where the datasource type is not memory. In
         Inmem configuration where the datasource type is not memory. In
         this case, loadzone should not be sent to b10-auth.
         this case, loadzone should not be sent to b10-auth.
@@ -2945,7 +2945,21 @@ class TestXfrinProcess(unittest.TestCase):
         self.assertFalse(self._send_cc_session.recv_called)
         self.assertFalse(self._send_cc_session.recv_called)
         self.assertFalse(self._send_cc_session.recv_called_correctly)
         self.assertFalse(self._send_cc_session.recv_called_correctly)
 
 
-    def test_inmem_not_sqlite3(self):
+    def test_inmem_datasource_type_is_missing(self):
+        """
+        Inmem configuration where the datasource type is missing. In
+        this case, loadzone should not be sent to b10-auth.
+        """
+        self._module_cc.config = [{'zones': [{'origin': 'example.org', 'filetype': 'sqlite3',
+                                              'file': 'data/inmem-xfrin.sqlite3'}],
+                                   'class': 'IN'}]
+        self.__do_test([XFRIN_OK], [RRType.IXFR()], RRType.IXFR())
+        self.assertFalse(self._send_cc_session.send_called)
+        self.assertFalse(self._send_cc_session.send_called_correctly)
+        self.assertFalse(self._send_cc_session.recv_called)
+        self.assertFalse(self._send_cc_session.recv_called_correctly)
+
+    def test_inmem_backend_type_not_sqlite3(self):
         """
         """
         Inmem configuration where the datasource backing file is not of
         Inmem configuration where the datasource backing file is not of
         type sqlite3. In this case, loadzone should not be sent to
         type sqlite3. In this case, loadzone should not be sent to
@@ -2960,7 +2974,21 @@ class TestXfrinProcess(unittest.TestCase):
         self.assertFalse(self._send_cc_session.recv_called)
         self.assertFalse(self._send_cc_session.recv_called)
         self.assertFalse(self._send_cc_session.recv_called_correctly)
         self.assertFalse(self._send_cc_session.recv_called_correctly)
 
 
-    def test_inmem_not_of_same_class(self):
+    def test_inmem_backend_type_is_missing(self):
+        """
+        Inmem configuration where the datasource backing file type is
+        not set. In this case, loadzone should not be sent to b10-auth.
+        """
+        self._module_cc.config = [{'zones': [{'origin': 'example.org',
+                                              'file': 'data/inmem-xfrin.sqlite3'}],
+                                   'type': 'memory', 'class': 'IN'}]
+        self.__do_test([XFRIN_OK], [RRType.IXFR()], RRType.IXFR())
+        self.assertFalse(self._send_cc_session.send_called)
+        self.assertFalse(self._send_cc_session.send_called_correctly)
+        self.assertFalse(self._send_cc_session.recv_called)
+        self.assertFalse(self._send_cc_session.recv_called_correctly)
+
+    def test_inmem_class_is_different(self):
         """
         """
         Inmem configuration where the datasource class does not match
         Inmem configuration where the datasource class does not match
         the received class. In this case, loadzone should not be sent to
         the received class. In this case, loadzone should not be sent to
@@ -2975,7 +3003,22 @@ class TestXfrinProcess(unittest.TestCase):
         self.assertFalse(self._send_cc_session.recv_called)
         self.assertFalse(self._send_cc_session.recv_called)
         self.assertFalse(self._send_cc_session.recv_called_correctly)
         self.assertFalse(self._send_cc_session.recv_called_correctly)
 
 
-    def test_inmem_not_present(self):
+    def test_inmem_class_is_missing(self):
+        """
+        Inmem configuration where the datasource class is missing. In
+        this case, we assume the IN class and loadzone may be sent to
+        b10-auth if everything else matches.
+        """
+        self._module_cc.config = [{'zones': [{'origin': 'example.org', 'filetype': 'sqlite3',
+                                              'file': 'data/inmem-xfrin.sqlite3'}],
+                                   'type': 'memory'}]
+        self.__do_test([XFRIN_OK], [RRType.IXFR()], RRType.IXFR())
+        self.assertTrue(self._send_cc_session.send_called)
+        self.assertTrue(self._send_cc_session.send_called_correctly)
+        self.assertTrue(self._send_cc_session.recv_called)
+        self.assertTrue(self._send_cc_session.recv_called_correctly)
+
+    def test_inmem_name_doesnt_match(self):
         """
         """
         Inmem configuration where the origin does not match the received
         Inmem configuration where the origin does not match the received
         name. In this case, loadzone should not be sent to b10-auth.
         name. In this case, loadzone should not be sent to b10-auth.
@@ -2989,6 +3032,20 @@ class TestXfrinProcess(unittest.TestCase):
         self.assertFalse(self._send_cc_session.recv_called)
         self.assertFalse(self._send_cc_session.recv_called)
         self.assertFalse(self._send_cc_session.recv_called_correctly)
         self.assertFalse(self._send_cc_session.recv_called_correctly)
 
 
+    def test_inmem_name_is_missing(self):
+        """
+        Inmem configuration where the origin is missing. In this case,
+        loadzone should not be sent to b10-auth.
+        """
+        self._module_cc.config = [{'zones': [{'filetype': 'sqlite3',
+                                              'file': 'data/inmem-xfrin.sqlite3'}],
+                                   'type': 'memory', 'class': 'IN'}]
+        self.__do_test([XFRIN_OK], [RRType.IXFR()], RRType.IXFR())
+        self.assertFalse(self._send_cc_session.send_called)
+        self.assertFalse(self._send_cc_session.send_called_correctly)
+        self.assertFalse(self._send_cc_session.recv_called)
+        self.assertFalse(self._send_cc_session.recv_called_correctly)
+
 class TestFormatting(unittest.TestCase):
 class TestFormatting(unittest.TestCase):
     # If the formatting functions are moved to a more general library
     # If the formatting functions are moved to a more general library
     # (ticket #1379), these tests should be moved with them.
     # (ticket #1379), these tests should be moved with them.

+ 6 - 0
src/bin/xfrin/xfrin.py.in

@@ -1256,6 +1256,8 @@ def _do_auth_loadzone(server, zone_name, zone_class):
     if is_default:
     if is_default:
         return
         return
     for d in datasources:
     for d in datasources:
+        if "type" not in d:
+            continue
         try:
         try:
             if "class" in d:
             if "class" in d:
                 dclass = RRClass(d["class"])
                 dclass = RRClass(d["class"])
@@ -1269,6 +1271,10 @@ def _do_auth_loadzone(server, zone_name, zone_class):
             for zone in d["zones"]:
             for zone in d["zones"]:
                 if "filetype" not in zone:
                 if "filetype" not in zone:
                     continue
                     continue
+                if "origin" not in zone:
+                    continue
+                if "filetype" not in zone:
+                    continue
                 try:
                 try:
                     name = Name(zone["origin"])
                     name = Name(zone["origin"])
                 except (EmptyLabel, TooLongLabel, BadLabelType, BadEscape, TooLongName, IncompleteName):
                 except (EmptyLabel, TooLongLabel, BadLabelType, BadEscape, TooLongName, IncompleteName):