From: Michal 'vorner' Vaner Date: Thu, 29 Nov 2012 14:21:40 +0000 (+0100) Subject: [2378] Detect class mismatch with copy mode X-Git-Tag: bind10-1.0.0-beta-release~28^2~2^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c1ba429f5eb098d7b1a9498fe11b354bca8283bd;p=thirdparty%2Fkea.git [2378] Detect class mismatch with copy mode --- diff --git a/src/lib/datasrc/tests/zone_loader_unittest.cc b/src/lib/datasrc/tests/zone_loader_unittest.cc index 39108943d4..8f03bfc55c 100644 --- a/src/lib/datasrc/tests/zone_loader_unittest.cc +++ b/src/lib/datasrc/tests/zone_loader_unittest.cc @@ -42,7 +42,8 @@ class MockClient : public DataSourceClient { public: MockClient() : commit_called_(false), - missing_zone_(false) + missing_zone_(false), + rrclass_(RRClass::IN()) {} virtual FindResult findZone(const Name&) const { isc_throw(isc::NotImplemented, "Method not used in tests"); @@ -67,6 +68,8 @@ public: bool commit_called_; // If set to true, getUpdater returns NULL bool missing_zone_; + // The pretended class of the client. Usualy IN, but can be overriden. + RRClass rrclass_; }; // The updater isn't really correct according to the API. For example, @@ -77,10 +80,11 @@ public: class Updater : public ZoneUpdater { public: Updater(MockClient* client) : - client_(client) + client_(client), + finder_(client_->rrclass_) {} virtual ZoneFinder& getFinder() { - isc_throw(isc::NotImplemented, "Method not used in tests"); + return (finder_); } virtual void addRRset(const isc::dns::AbstractRRset& rrset) { if (client_->commit_called_) { @@ -96,6 +100,34 @@ public: } private: MockClient* client_; + class Finder : public ZoneFinder { + public: + Finder(const RRClass& rrclass) : + class_(rrclass) + {} + virtual RRClass getClass() const { + return (class_); + } + virtual Name getOrigin() const { + isc_throw(isc::NotImplemented, "Method not used in tests"); + } + virtual shared_ptr find(const Name&, const RRType&, + const FindOptions) + { + isc_throw(isc::NotImplemented, "Method not used in tests"); + } + virtual shared_ptr findAll(const Name&, + vector&, + const FindOptions) + { + isc_throw(isc::NotImplemented, "Method not used in tests"); + } + virtual FindNSEC3Result findNSEC3(const Name&, bool) { + isc_throw(isc::NotImplemented, "Method not used in tests"); + } + private: + const RRClass class_; + } finder_; }; ZoneUpdaterPtr @@ -242,6 +274,14 @@ TEST_F(ZoneLoaderTest, copyMissingSource) { source_client_), DataSourceError); } +// The class of the source and destination are different +TEST_F(ZoneLoaderTest, classMismatch) { + destination_client_.rrclass_ = RRClass::CH(); + prepareSource(Name::ROOT_NAME(), "root.zone"); + EXPECT_THROW(ZoneLoader(destination_client_, Name::ROOT_NAME(), + source_client_), isc::InvalidParameter); +} + // Load an unsigned zone, all at once TEST_F(ZoneLoaderTest, loadUnsigned) { ZoneLoader loader(destination_client_, Name::ROOT_NAME(), diff --git a/src/lib/datasrc/zone_loader.cc b/src/lib/datasrc/zone_loader.cc index 5fc03fa568..ce3e11240f 100644 --- a/src/lib/datasrc/zone_loader.cc +++ b/src/lib/datasrc/zone_loader.cc @@ -43,6 +43,17 @@ ZoneLoader::ZoneLoader(DataSourceClient& destination, const Name& zone_name, isc_throw(DataSourceError, "Zone " << zone_name << " not found in " "destination data source, can't fill it with data"); } + // The dereference of zone_finder is safe, if we can get iterator, we can + // get a finder. + // + // TODO: We probably need a getClass on the data source itself. + if (source.findZone(zone_name).zone_finder->getClass() != + updater_->getFinder().getClass()) { + isc_throw(isc::InvalidParameter, + "Source and destination class mismatch"); + } +} + } namespace {