From: Michal 'vorner' Vaner Date: Mon, 3 Oct 2011 09:19:11 +0000 (+0200) Subject: [1259] Check the class X-Git-Tag: perftcpdns_before_epoll~37^2~30^2^2~7 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d36eda71276b43e4281ae53fd558155725f4d4eb;p=thirdparty%2Fkea.git [1259] Check the class If it corresponds to the updater. This would be a bug, but we better detect it sooner. --- diff --git a/src/lib/python/isc/xfrin/diff.py b/src/lib/python/isc/xfrin/diff.py index 9a286e80fe..082bdb38a4 100644 --- a/src/lib/python/isc/xfrin/diff.py +++ b/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') diff --git a/src/lib/python/isc/xfrin/tests/diff_tests.py b/src/lib/python/isc/xfrin/tests/diff_tests.py index 963b16d008..dc1aca966e 100644 --- a/src/lib/python/isc/xfrin/tests/diff_tests.py +++ b/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()