From: Mukund Sivaraman Date: Fri, 18 Jan 2013 10:53:49 +0000 (+0530) Subject: [2499] Re-enable testcase where invalid data is copied from another data source X-Git-Tag: bind10-1.0.0-rc-release~76^2~25 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=dc2aa27ea58ec3be03e742f2f4dd123a2c044200;p=thirdparty%2Fkea.git [2499] Re-enable testcase where invalid data is copied from another data source --- diff --git a/src/lib/datasrc/tests/zone_loader_unittest.cc b/src/lib/datasrc/tests/zone_loader_unittest.cc index 3de290e16c..2ca4cf5fe4 100644 --- a/src/lib/datasrc/tests/zone_loader_unittest.cc +++ b/src/lib/datasrc/tests/zone_loader_unittest.cc @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -32,15 +33,11 @@ #include #include -using isc::dns::RRClass; -using isc::dns::Name; -using isc::dns::RRType; -using isc::dns::ConstRRsetPtr; -using isc::dns::RRsetPtr; +using namespace isc::dns; +using namespace isc::datasrc; +using boost::shared_ptr; using std::string; using std::vector; -using boost::shared_ptr; -using namespace isc::datasrc; namespace { @@ -51,8 +48,97 @@ public: missing_zone_(false), rrclass_(RRClass::IN()) {} - virtual FindResult findZone(const Name&) const { - isc_throw(isc::NotImplemented, "Method not used in tests"); + class Finder : public ZoneFinder { + public: + Finder(const Name& origin) : + origin_(origin) + {} + Name getOrigin() const { + return (origin_); + } + RRClass getClass() const { + return (RRClass::IN()); + } + // The rest is not to be called, so they throw. + shared_ptr find(const Name&, const RRType&, + const FindOptions) + { + isc_throw(isc::NotImplemented, "Not implemented"); + } + shared_ptr findAll(const Name&, + vector&, + const FindOptions) + { + isc_throw(isc::NotImplemented, "Not implemented"); + } + FindNSEC3Result findNSEC3(const Name&, bool) { + isc_throw(isc::NotImplemented, "Not implemented"); + } + private: + Name origin_; + }; + class Iterator : public ZoneIterator { + public: + Iterator() : + origin_("example.org"), + soa_(new RRset(origin_, RRClass::IN(), RRType::SOA(), + RRTTL(3600))) + { + // The RData here is bogus, but it is not used to anything. There + // just needs to be some. + soa_->addRdata(rdata::generic::SOA(Name::ROOT_NAME(), + Name::ROOT_NAME(), + 0, 0, 0, 0, 0)); + rrsets_.push_back(soa_); + + // There is no NS record on purpose here. + + // Dummy A rrset. This is used for checking zone data after + // reload. + RRsetPtr rrset(new RRset(Name("tstzonedata").concatenate(origin_), + RRClass::IN(), RRType::A(), + RRTTL(3600))); + rrset->addRdata(rdata::in::A("192.0.2.1")); + rrsets_.push_back(rrset); + + rrsets_.push_back(ConstRRsetPtr()); + + it_ = rrsets_.begin(); + } + virtual isc::dns::ConstRRsetPtr getNextRRset() { + ConstRRsetPtr result = *it_; + ++it_; + return (result); + } + virtual isc::dns::ConstRRsetPtr getSOA() const { + return (soa_); + } + private: + const Name origin_; + const RRsetPtr soa_; + std::vector rrsets_; + std::vector::const_iterator it_; + }; + virtual ZoneIteratorPtr getIterator(const isc::dns::Name& name, + bool) const + { + if (name != Name("example.org")) { + isc_throw(DataSourceError, "No such zone"); + } + return (ZoneIteratorPtr(new Iterator())); + } + virtual FindResult findZone(const Name& name) const { + const Name origin("example.org"); + const ZoneFinderPtr finder(new Finder(origin)); + NameComparisonResult compar(origin.compare(name)); + switch (compar.getRelation()) { + case NameComparisonResult::EQUAL: + return (FindResult(result::SUCCESS, finder)); + case NameComparisonResult::SUPERDOMAIN: + return (FindResult(result::PARTIALMATCH, finder)); + default: + return (FindResult(result::NOTFOUND, ZoneFinderPtr())); + } }; virtual std::pair getJournalReader(const Name&, uint32_t, uint32_t) const @@ -214,13 +300,6 @@ protected: source_client_(ztable_segment_, rrclass_) {} void prepareSource(const Name& zone, const char* filename) { - // TODO: - // Currently, source_client_ is of InMemoryClient and its load() - // uses a different code than the ZoneLoader (so we can cross-check - // the implementations). Currently, the load() doesn't perform any - // post-load checks. It will change in #2499, at which point the - // loading may start failing depending on details of the test data. We - // should prepare the data by some different method then. source_client_.load(zone, string(TEST_DATA_DIR) + "/" + filename); } private: @@ -461,18 +540,6 @@ TEST_F(ZoneLoaderTest, loadCheck) { EXPECT_FALSE(destination_client_.commit_called_); } -// The same test, but for copying from other data source -// Disabled by #2499. See the comment in prepareSource(). -TEST_F(ZoneLoaderTest, DISABLED_copyCheck) { - prepareSource(Name("example.org"), "novalidate.zone"); - ZoneLoader loader(destination_client_, Name("example.org"), - source_client_); - - EXPECT_THROW(loader.loadIncremental(10), ZoneContentError); - // The messages go to the log. We don't have an easy way to examine them. - EXPECT_FALSE(destination_client_.commit_called_); -} - // Check a warning doesn't disrupt the loading of the zone TEST_F(ZoneLoaderTest, loadCheckWarn) { ZoneLoader loader(destination_client_, Name("example.org"), @@ -496,4 +563,20 @@ TEST_F(ZoneLoaderTest, copyCheckWarn) { } +// Test there's validation of the data in the zone loader when copying +// from another data source. Currently, this test doesn't require +// creating a fixture as it uses almost nothing in existing fixtures. +TEST(ZoneLoaderMockSourceTest, copyCheck) { + // In this test, source_client provides a zone that does not + // validate (no NS). + MockClient source_client; + MockClient destination_client; + ZoneLoader loader(destination_client, Name("example.org"), + source_client); + + EXPECT_THROW(loader.loadIncremental(10), ZoneContentError); + // The messages go to the log. We don't have an easy way to examine them. + EXPECT_FALSE(destination_client.commit_called_); +} + }