]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2432] Throw during addRRset() if an rrset with the given class, type and name alread...
authorMukund Sivaraman <muks@isc.org>
Wed, 26 Dec 2012 05:17:16 +0000 (10:47 +0530)
committerMukund Sivaraman <muks@isc.org>
Wed, 26 Dec 2012 05:17:16 +0000 (10:47 +0530)
src/lib/dns/rrset_collection.cc
src/lib/dns/rrset_collection.h
src/lib/dns/tests/rrset_collection_unittest.cc

index 6cf280902db7294405696e49f5e69a72f8bfca95..69e1cf4b9c6ddedf40f1724b6f7e1f6354767845 100644 (file)
 #include <dns/master_loader_callbacks.h>
 #include <dns/master_loader.h>
 
+#include <exceptions/exceptions.h>
+
 #include <boost/bind.hpp>
 
+using namespace isc;
+
 namespace isc {
 namespace dns {
 
@@ -41,6 +45,13 @@ void
 RRsetCollection::addRRset(RRsetPtr rrset) {
     const CollectionKey key(rrset->getClass(), rrset->getType(),
                             rrset->getName());
+    CollectionMap::const_iterator it = rrsets_.find(key);
+    if (it != rrsets_.end()) {
+        isc_throw(InvalidParameter,
+                  "RRset for " << rrset->getName() << "/" << rrset->getClass()
+                  << " with type " << rrset->getType() << " already exists");
+    }
+
     rrsets_.insert(std::pair<CollectionKey, RRsetPtr>(key, rrset));
 }
 
index 37db6cca4f8d7e6ea144c12ff6b0527f65afcb11..b1998ae4d80e48d8cf4b3b70db61ff0f7b3f2332 100644 (file)
@@ -50,7 +50,9 @@ public:
     /// \brief Add an RRset to the collection.
     ///
     /// Does not do any validation whether \c rrset belongs to a
-    /// particular zone or not.
+    /// particular zone or not. It throws an \c isc::InvalidParameter
+    /// exception if an rrset with the same class, type and name already
+    /// exists.
     void addRRset(isc::dns::RRsetPtr rrset);
 
     /// \brief Remove an RRset from the collection.
index b222c45b82440dfe561428bfc937db84dcbdc120..29853e12bcb72ad1030d5013beed4f7598e8a33e 100644 (file)
@@ -129,6 +129,11 @@ doAddAndRemove(RRsetCollection& collection, const RRClass& rrclass) {
     // The collection must not be empty.
     EXPECT_NE(collection.end(), collection.begin());
 
+    // Adding a duplicate RRset must throw.
+    EXPECT_THROW({
+        collection.addRRset(rrset);
+    }, isc::InvalidParameter);
+
     // Remove foo.example.org/A
     collection.removeRRset(Name("foo.example.org"), rrclass, RRType::A());