From: JINMEI Tatuya Date: Wed, 8 Feb 2012 02:33:05 +0000 (-0800) Subject: [1576] cleanup: replaced findNSEC3Tmp with the complete findNSEC3. X-Git-Tag: trac2351_base~97^2~35^2~7 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4f23a482e885f3fe3dd104fa43638352f9ff3e7b;p=thirdparty%2Fkea.git [1576] cleanup: replaced findNSEC3Tmp with the complete findNSEC3. The tmp version was removed. --- diff --git a/src/lib/datasrc/memory_datasrc.cc b/src/lib/datasrc/memory_datasrc.cc index 9a3ec316df..e368b5354b 100644 --- a/src/lib/datasrc/memory_datasrc.cc +++ b/src/lib/datasrc/memory_datasrc.cc @@ -946,54 +946,6 @@ InMemoryZoneFinder::findNSEC3(const Name& name, bool recursive) { << impl_->zone_class_); } -ZoneFinder::FindNSEC3Result -InMemoryZoneFinder::findNSEC3Tmp(const Name& name, bool recursive) { - if (!impl_->zone_data_->nsec3_data_) { - isc_throw(Unexpected, "findNSEC3 is called for non NSEC3 zone"); - } - if (recursive) { - isc_throw(Unexpected, "recursive mode isn't expected in tests"); - } - - // A temporary workaround for testing: convert the original name to - // NSEC3-hashed name using hardcoded mapping. - string hname_text; - if (name == Name("example.org")) { - hname_text = "0P9MHAVEQVM6T7VBL5LOP2U3T2RP3TOM"; - } else if (name == Name("www.example.org")) { - hname_text = "2S9MHAVEQVM6T7VBL5LOP2U3T2RP3TOM"; - } else if (name == Name("xxx.example.org")) { - hname_text = "Q09MHAVEQVM6T7VBL5LOP2U3T2RP3TOM"; - } else if (name == Name("yyy.example.org")) { - hname_text = "0A9MHAVEQVM6T7VBL5LOP2U3T2RP3TOM"; - } else { - isc_throw(Unexpected, "unexpected name for NSEC3 test: " << name); - } - - // Below we assume the map is not empty for simplicity. - NSEC3Map::const_iterator found = - impl_->zone_data_->nsec3_data_->map_.lower_bound(hname_text); - if (found != impl_->zone_data_->nsec3_data_->map_.end() && - found->first == hname_text) { - // exact match - return (FindNSEC3Result(true, 2, found->second, ConstRRsetPtr())); - } else if (found == impl_->zone_data_->nsec3_data_->map_.end() || - found == impl_->zone_data_->nsec3_data_->map_.begin()) { - // the search key is "smaller" than the smallest or "larger" than - // largest. In either case "previous" is the largest one. - return (FindNSEC3Result(false, 2, - impl_->zone_data_->nsec3_data_->map_. - rbegin()->second, ConstRRsetPtr())); - } else { - // Otherwise, H(found_domain-1) < given_hash < H(found_domain) - // The covering proof is the first one. - return (FindNSEC3Result(false, 2, (--found)->second, ConstRRsetPtr())); - } - - // We should have covered all cases. - isc_throw(Unexpected, "Impossible NSEC3 search result for " << name); -} - result::Result InMemoryZoneFinder::add(const ConstRRsetPtr& rrset) { return (impl_->add(rrset, *impl_->zone_data_)); diff --git a/src/lib/datasrc/memory_datasrc.h b/src/lib/datasrc/memory_datasrc.h index 85fa5cfedc..b960ab9096 100644 --- a/src/lib/datasrc/memory_datasrc.h +++ b/src/lib/datasrc/memory_datasrc.h @@ -89,16 +89,6 @@ public: virtual FindNSEC3Result findNSEC3(const isc::dns::Name& name, bool recursive); - // A temporary fake version of findNSEC3 for tests - // - // This method intentionally has the same interface as findNSEC3 but - // uses internally hardcoded hash values and offers a limited set - // of functionality for the convenience of tests. This is a temporary - // workaround until #1577 is completed. At that point this method - // should be removed. - FindNSEC3Result - findNSEC3Tmp(const isc::dns::Name& name, bool recursive); - /// \brief Imelementation of the ZoneFinder::findPreviousName method /// /// This one throws NotImplemented exception, as InMemory doesn't diff --git a/src/lib/datasrc/tests/memory_datasrc_unittest.cc b/src/lib/datasrc/tests/memory_datasrc_unittest.cc index 3078b8d9e3..7de6645e04 100644 --- a/src/lib/datasrc/tests/memory_datasrc_unittest.cc +++ b/src/lib/datasrc/tests/memory_datasrc_unittest.cc @@ -1613,13 +1613,10 @@ nsec3Check(bool expected_matched, const string& expected_rrsets_txt, actual_rrsets.end()); } -// In the following tests we use a temporary faked version of findNSEC3 -// as the real version isn't implemented yet (it's a task for #1577). -// When #1577 is done the tests should be updated using the real version. -// If we can use fake hash calculator (see #1575), we should be able to -// just replace findNSEC3Tmp with findNSEC3. - TEST_F(InMemoryZoneFinderTest, addNSEC3) { + // Set up the faked hash calculator. + setNSEC3HashCreator(&nsec3_hash_creator_); + const string nsec3_text = string(apex_hash) + ".example.org." + string(nsec3_common); // This name shouldn't be found in the normal domain tree. @@ -1629,7 +1626,7 @@ TEST_F(InMemoryZoneFinderTest, addNSEC3) { RRType::NSEC3()).code); // Dedicated NSEC3 find should be able to find it. nsec3Check(true, nsec3_text, - zone_finder_.findNSEC3Tmp(Name("example.org"), false)); + zone_finder_.findNSEC3(Name("example.org"), false)); // This implementation rejects duplicate/update add of the same hash name EXPECT_EQ(result::EXIST, @@ -1638,7 +1635,7 @@ TEST_F(InMemoryZoneFinderTest, addNSEC3) { string(nsec3_common) + " AAAA"))); // The original NSEC3 should be intact nsec3Check(true, nsec3_text, - zone_finder_.findNSEC3Tmp(Name("example.org"), false)); + zone_finder_.findNSEC3(Name("example.org"), false)); // NSEC3-like name but of ordinary RR type should go to normal tree. const string nonsec3_text = string(apex_hash) + ".example.org. " + @@ -1650,15 +1647,21 @@ TEST_F(InMemoryZoneFinderTest, addNSEC3) { } TEST_F(InMemoryZoneFinderTest, addNSEC3Lower) { + // Set up the faked hash calculator. + setNSEC3HashCreator(&nsec3_hash_creator_); + // Similar to the previous case, but NSEC3 owner name is lower-cased. const string nsec3_text = string(apex_hash_lower) + ".example.org." + string(nsec3_common); EXPECT_EQ(result::SUCCESS, zone_finder_.add(textToRRset(nsec3_text))); nsec3Check(true, nsec3_text, - zone_finder_.findNSEC3Tmp(Name("example.org"), false)); + zone_finder_.findNSEC3(Name("example.org"), false)); } TEST_F(InMemoryZoneFinderTest, addNSEC3Ordering) { + // Set up the faked hash calculator. + setNSEC3HashCreator(&nsec3_hash_creator_); + // Check that the internal storage ensures comparison based on the NSEC3 // semantics, regardless of the add order or the letter-case of hash. @@ -1676,14 +1679,14 @@ TEST_F(InMemoryZoneFinderTest, addNSEC3Ordering) { // Then look for NSEC3 that covers a name whose hash is "2S.." // The covering NSEC3 should be "0P.." nsec3Check(false, smallest, - zone_finder_.findNSEC3Tmp(Name("www.example.org"), false)); + zone_finder_.findNSEC3(Name("www.example.org"), false)); // Look for NSEC3 that covers names whose hash are "Q0.." and "0A.." // The covering NSEC3 should be "2v.." in both cases nsec3Check(false, largest, - zone_finder_.findNSEC3Tmp(Name("xxx.example.org"), false)); + zone_finder_.findNSEC3(Name("xxx.example.org"), false)); nsec3Check(false, largest, - zone_finder_.findNSEC3Tmp(Name("yyy.example.org"), false)); + zone_finder_.findNSEC3(Name("yyy.example.org"), false)); } TEST_F(InMemoryZoneFinderTest, badNSEC3Name) { @@ -1711,6 +1714,9 @@ TEST_F(InMemoryZoneFinderTest, addMultiNSEC3) { } TEST_F(InMemoryZoneFinderTest, addNSEC3WithRRSIG) { + // Set up the faked hash calculator. + setNSEC3HashCreator(&nsec3_hash_creator_); + // Adding NSEC3 and its RRSIG const string nsec3_text = string(apex_hash) + ".example.org." + string(nsec3_common); @@ -1721,7 +1727,7 @@ TEST_F(InMemoryZoneFinderTest, addNSEC3WithRRSIG) { // Then look for it. The NSEC3 should have the RRSIG that was just added. nsec3Check(true, nsec3_text + "\n" + nsec3_rrsig_text, - zone_finder_.findNSEC3Tmp(Name("example.org"), false), true); + zone_finder_.findNSEC3(Name("example.org"), false), true); // Duplicate add of RRSIG for the same NSEC3 is prohibited. EXPECT_THROW(zone_finder_.add(textToRRset(nsec3_rrsig_text)), @@ -1932,6 +1938,9 @@ TEST_F(InMemoryZoneFinderTest, findNSEC3) { } TEST_F(InMemoryZoneFinderTest, findNSEC3ForWithoutNSEC3) { + // Set up the faked hash calculator. + setNSEC3HashCreator(&nsec3_hash_creator_); + // If the zone has nothing about NSEC3 (neither NSEC3 or NSEC3PARAM), // findNSEC3() should be rejected. EXPECT_THROW(zone_finder_.findNSEC3(Name("www.example.org"), true),