Browse Source

[1259] Check the class

If it corresponds to the updater. This would be a bug, but we better
detect it sooner.
Michal 'vorner' Vaner 13 years ago
parent
commit
d36eda7127
2 changed files with 28 additions and 0 deletions
  1. 10 0
      src/lib/python/isc/xfrin/diff.py
  2. 18 0
      src/lib/python/isc/xfrin/tests/diff_tests.py

+ 10 - 0
src/lib/python/isc/xfrin/diff.py

@@ -91,6 +91,10 @@ class Diff:
         if rr.get_rdata_count() != 1:
             raise ValueError('The rrset must contain exactly 1 Rdata, but ' +
                              'it holds ' + str(rr.get_rdata_count()))
+        if rr.get_class() != self.__updater.get_class():
+            raise ValueError("The rrset's class " + str(rr.get_class()) +
+                             " does not match updater's " +
+                             str(self.__updater.get_class()))
         self.__buffer.append((operation, rr))
         if len(self.__buffer) >= DIFF_APPLY_TRESHOLD:
             # Time to auto-apply, so the data don't accumulate too much
@@ -103,6 +107,9 @@ class Diff:
         The rr is of isc.dns.RRset type and it must contain only one RR.
         If this is not the case or if the diff was already commited, this
         raises the ValueError exception.
+
+        The rr class must match the one of the datasource client. If
+        it does not, ValueError is raised.
         """
         self.__data_common(rr, 'add')
 
@@ -113,6 +120,9 @@ class Diff:
         The rr is of isc.dns.RRset type and it must contain only one RR.
         If this is not the case or if the diff was already commited, this
         raises the ValueError exception.
+
+        The rr class must match the one of the datasource client. If
+        it does not, ValueError is raised.
         """
         self.__data_common(rr, 'remove')
 

+ 18 - 0
src/lib/python/isc/xfrin/tests/diff_tests.py

@@ -94,6 +94,13 @@ class DiffTest(unittest.TestCase):
         """
         self.__data_operations.append(('remove', rrset))
 
+    def get_class(self):
+        """
+        This one is part of pretending to be a zone updater. It returns
+        the IN class.
+        """
+        return self.__rrclass
+
     def get_updater(self, zone_name, replace):
         """
         This one pretends this is the data source client and serves
@@ -322,6 +329,17 @@ class DiffTest(unittest.TestCase):
         diff.compact()
         check()
 
+    def test_wrong_class(self):
+        """
+        Test a wrong class of rrset is rejected.
+        """
+        diff = Diff(self, Name('example.org.'))
+        rrset = RRset(Name('a.example.org.'), RRClass.CH(), RRType.NS(),
+                      self.__ttl)
+        rrset.add_rdata(Rdata(RRType.NS(), RRClass.CH(), 'ns.example.org.'))
+        self.assertRaises(ValueError, diff.add_data, rrset)
+        self.assertRaises(ValueError, diff.remove_data, rrset)
+
 if __name__ == "__main__":
     isc.log.init("bind10")
     unittest.main()