From: Mukund Sivaraman Date: Wed, 9 Jan 2013 05:34:40 +0000 (+0530) Subject: [2435] Handle find() with RRClass that may not be found X-Git-Tag: bind10-1.0.0-rc-release~123 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c16bfe0dc892c2bd34e88daa12120202bcf9e3eb;p=thirdparty%2Fkea.git [2435] Handle find() with RRClass that may not be found --- diff --git a/src/lib/datasrc/rrset_collection.cc b/src/lib/datasrc/rrset_collection.cc index 51fa97c5a7..e4cfd88015 100644 --- a/src/lib/datasrc/rrset_collection.cc +++ b/src/lib/datasrc/rrset_collection.cc @@ -23,11 +23,16 @@ namespace datasrc { ConstRRsetPtr RRsetCollection::find(const isc::dns::Name& name, - const isc::dns::RRClass&, + const isc::dns::RRClass& rrclass, const isc::dns::RRType& rrtype) const { - // TODO: RRClass needs to be checked here to see if it is as - // expected. + if (rrclass != rrclass_) { + // We could throw an exception here, but RRsetCollection is + // expected to support an arbitrary collection of RRsets, and it + // can be queried just as arbitrarily. So we just return nothing + // here. + return (ConstRRsetPtr()); + } ZoneFinder& finder = updater_->getFinder(); ZoneFinderContextPtr result = diff --git a/src/lib/datasrc/rrset_collection.h b/src/lib/datasrc/rrset_collection.h index 6ad494a36d..afe11992db 100644 --- a/src/lib/datasrc/rrset_collection.h +++ b/src/lib/datasrc/rrset_collection.h @@ -33,8 +33,10 @@ public: /// destroyed by the client. /// /// \param updater The ZoneUpdater to wrap around. - RRsetCollection(ZoneUpdaterPtr updater) : - updater_(updater) + /// \param rrclass The RRClass of the records in the zone. + RRsetCollection(ZoneUpdaterPtr updater, const isc::dns::RRClass& rrclass) : + updater_(updater), + rrclass_(rrclass) {} /// \brief Destructor @@ -56,6 +58,7 @@ public: private: ZoneUpdaterPtr updater_; + isc::dns::RRClass rrclass_; protected: // TODO: RRsetCollectionBase::Iter is not implemented and the diff --git a/src/lib/datasrc/tests/database_unittest.cc b/src/lib/datasrc/tests/database_unittest.cc index 3df02cf60a..39729f8d27 100644 --- a/src/lib/datasrc/tests/database_unittest.cc +++ b/src/lib/datasrc/tests/database_unittest.cc @@ -4162,7 +4162,8 @@ class RRsetCollectionTest : public DatabaseClientTest { public: RRsetCollectionTest() : DatabaseClientTest(), - collection(this->client_->getUpdater(this->zname_, false)) + collection(this->client_->getUpdater(this->zname_, false), + this->qclass_) {} RRsetCollection collection; @@ -4192,6 +4193,11 @@ TYPED_TEST(RRsetCollectionTest, find) { rrset = this->collection.find(Name("www.example.org"), this->qclass_, RRType::AAAA()); EXPECT_TRUE(rrset); + + // www.example.org with AAAA does not exist in RRClass::CH() + rrset = this->collection.find(Name("www.example.org"), RRClass::CH(), + RRType::AAAA()); + EXPECT_FALSE(rrset); } TYPED_TEST(RRsetCollectionTest, iteratorTest) {