From: Michal 'vorner' Vaner Date: Wed, 8 Feb 2012 12:55:28 +0000 (+0100) Subject: [1581] Test for exception on missing NSEC3 X-Git-Tag: trac2351_base~97^2~33^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=871e4c22effffd79ff1d0a44d06a102b27b24ac7;p=thirdparty%2Fkea.git [1581] Test for exception on missing NSEC3 --- diff --git a/src/bin/auth/tests/query_unittest.cc b/src/bin/auth/tests/query_unittest.cc index 75941c7158..612cd40776 100644 --- a/src/bin/auth/tests/query_unittest.cc +++ b/src/bin/auth/tests/query_unittest.cc @@ -220,7 +220,8 @@ public: rrclass_(RRClass::IN()), include_rrsig_anyway_(false), use_nsec3_(false), - nsec_name_(origin_) + nsec_name_(origin_), + nsec3_fake_(NULL) { stringstream zone_stream; zone_stream << soa_txt << zone_ns_txt << ns_addrs_txt << @@ -295,6 +296,14 @@ public: nsec_result_.reset(new ZoneFinder::FindResult(code, rrset)); } + // Once called, the findNSEC3 will return the provided result for the next + // query. After that, it'll return to operate normally. + // NULL disables. Does not take ownership of the pointer (it is generally + // expected to be a local variable in the test function). + void setNSEC3Result(const FindNSEC3Result* result) { + nsec3_fake_ = result; + } + // If true is passed return an empty NSEC3 RRset for some negative // answers when DNSSEC is required. void setNSEC3Flag(bool on) { use_nsec3_ = on; } @@ -385,6 +394,9 @@ private: // The following two will be used for faked NSEC cases Name nsec_name_; boost::scoped_ptr nsec_result_; + // The following two are for faking bad NSEC3 responses + // Enabled when not NULL + const FindNSEC3Result* nsec3_fake_; public: // Public, to allow tests looking up the right names for something map hash_map_; @@ -431,6 +443,14 @@ MockZoneFinder::findAll(const Name& name, std::vector& target, ZoneFinder::FindNSEC3Result MockZoneFinder::findNSEC3(const Name& name, bool recursive) { + // Do we have a fake result set? If so, use it. + if (nsec3_fake_ != NULL) { + const FindNSEC3Result* result(nsec3_fake_); + // Disable the fake for the next call + nsec3_fake_ = NULL; + return (*result); + } + ConstRRsetPtr covering_proof; const int labels = name.getLabelCount(); @@ -1646,8 +1666,20 @@ TEST_F(QueryTest, nxrrsetWithNSEC3) { ".example.com. 3600 IN RRSIG " + getCommonRRSIGText("NSEC3") + "\n").c_str(), NULL, mock_finder->getOrigin()); - // TODO: Does the mock finder generate signatures by itself, or one - // needs to be added explicitly? +} + +// Check the exception is correctly raised when the NSEC3 thing isn't in the +// zone +TEST_F(QueryTest, nxrrsetMissingNSEC3) { + mock_finder->setNSEC3Flag(true); + // We just need it to return false for "matched". This indicates + // there's no exact match for NSEC3 on www.example.com. + ZoneFinder::FindNSEC3Result nsec3(false, 0, ConstRRsetPtr(), + ConstRRsetPtr()); + mock_finder->setNSEC3Result(&nsec3); + + EXPECT_THROW(Query(memory_client, Name("www.example.com"), RRType::TXT(), + response, true).process(), Query::BadNSEC3); } // The following are tentative tests until we really add tests for the