using result::SUCCESS;
using result::EXIST;
-// Proxy accessor for faked NSEC3 mapping for tests. map isn't a trivial
-// type, so it's safer to get access to it via a proxy to avoid initialization
-// fiasco.
-NSEC3HashMap&
-getNSEC3HashMap() {
- static NSEC3HashMap nsec3_hash_map;
- return (nsec3_hash_map);
-}
-
-// A faked NSEC3 hash calculator for convenience. Tests that need to use
-// the faked hashed values should call setFakeNSEC3Calculate() on the
-// MyZoneFinder object at the beginning of the test (at least before
-// adding any NSEC3/NSEC3PARAM RR).
-std::string
-fakeNSEC3Calculate(const Name& name,
- const uint16_t,
- const uint8_t*,
- size_t)
-{
- const NSEC3HashMap::const_iterator found = getNSEC3HashMap().find(name);
- if (found != getNSEC3HashMap().end()) {
- return (found->second);
- }
-
- isc_throw(isc::Unexpected,
- "unexpected name for NSEC3 test: " << name);
-}
-
-class MyZoneFinder : public memory::InMemoryZoneFinder {
-public:
- MyZoneFinder(const ZoneData& zone_data,
- const isc::dns::RRClass& rrclass) :
- memory::InMemoryZoneFinder(zone_data, rrclass)
- {
- buildFakeNSEC3Map(getNSEC3HashMap());
- }
-
- void setFakeNSEC3Calculate() {
- nsec3_calculate_ = fakeNSEC3Calculate;
- }
-};
-
/// \brief expensive rrset converter
///
/// converts any specialized rrset (which may not have implemented some
// The zone finder to torture by tests
MemorySegmentTest mem_sgmt_;
memory::ZoneData* zone_data_;
- MyZoneFinder zone_finder_;
+ memory::InMemoryZoneFinder zone_finder_;
isc::datasrc::memory::RdataEncoder encoder_;
// Placeholder for storing RRsets to be checked with rrsetsCheck()
TEST_F(InMemoryZoneFinderTest, findNSEC3ForBadZone) {
// Set up the faked hash calculator.
- zone_finder_.setFakeNSEC3Calculate();
+ const TestNSEC3HashCreator creator;
+ setNSEC3HashCreator(&creator);
// If the zone has nothing about NSEC3 (neither NSEC3 or NSEC3PARAM),
// findNSEC3() should be rejected.
public:
InMemoryZoneFinderNSEC3Test() {
// Set up the faked hash calculator.
- zone_finder_.setFakeNSEC3Calculate();
+ setNSEC3HashCreator(&creator_);
// Add a few NSEC3 records:
// apex (example.org.): hash=0P..
string(nsec3_common);
addZoneData(textToRRset(zzz_nsec3_text));
}
+
+private:
+ const TestNSEC3HashCreator creator_;
};
TEST_F(InMemoryZoneFinderNSEC3Test, findNSEC3) {
#include <dns/name.h>
#include <dns/rrset.h>
#include <dns/rrtype.h>
+#include <dns/nsec3hash.h>
#include <datasrc/logger.h>
// the deepest label one by one, until we find a name that has a matching
// NSEC3 hash.
for (unsigned int labels = qlabels; labels >= olabels; --labels) {
+ const std::vector<uint8_t> salt(nsec3_data->getSaltData(),
+ (nsec3_data->getSaltData() +
+ nsec3_data->getSaltLen()));
+ const std::auto_ptr<NSEC3Hash> hash
+ (NSEC3Hash::create(nsec3_data->hashalg,
+ nsec3_data->iterations,
+ salt));
const Name& hname = (labels == qlabels ?
name : name.split(qlabels - labels, labels));
- const std::string hlabel =
- (nsec3_calculate_) (hname,
- nsec3_data->iterations,
- nsec3_data->getSaltData(),
- nsec3_data->getSaltLen());
+ const std::string hlabel = hash->calculate(hname);
LOG_DEBUG(logger, DBG_TRACE_BASIC, DATASRC_MEM_FINDNSEC3_TRYHASH).
arg(name).arg(labels).arg(hlabel);
#include <dns/name.h>
#include <dns/rrset.h>
#include <dns/rrtype.h>
-#include <dns/nsec3hash.h>
#include <string>
const ZoneNode* const found_node;
};
-std::string
-InMemoryZoneFinderNSEC3Calculate(const isc::dns::Name& name,
- const uint16_t iterations,
- const uint8_t* salt,
- size_t salt_len);
-
/// A derived zone finder class intended to be used with the memory data
/// source, using ZoneData for its contents.
class InMemoryZoneFinder : boost::noncopyable, public ZoneFinder {
InMemoryZoneFinder(const ZoneData& zone_data,
const isc::dns::RRClass& rrclass) :
zone_data_(zone_data),
- rrclass_(rrclass),
- nsec3_calculate_(isc::dns::NSEC3Hash::calculate)
+ rrclass_(rrclass)
{}
/// \brief Find an RRset in the datasource
const ZoneData& zone_data_;
const isc::dns::RRClass& rrclass_;
-
-protected:
- typedef std::string (NSEC3CalculateFn) (const isc::dns::Name& name,
- const uint16_t iterations,
- const uint8_t* salt,
- size_t salt_len);
- NSEC3CalculateFn* nsec3_calculate_;
};
} // namespace memory
NSEC3HashMap map_;
public:
TestNSEC3Hash() {
- buildFakeNSEC3Map(map_);
+ // Build pre-defined hash
+ map_[Name("example.org")] = apex_hash;
+ map_[Name("www.example.org")] = "2S9MHAVEQVM6T7VBL5LOP2U3T2RP3TOM";
+ map_[Name("xxx.example.org")] = "Q09MHAVEQVM6T7VBL5LOP2U3T2RP3TOM";
+ map_[Name("yyy.example.org")] = "0A9MHAVEQVM6T7VBL5LOP2U3T2RP3TOM";
+ map_[Name("x.y.w.example.org")] =
+ "2VPTU5TIMAMQTTGL4LUU9KG21E0AOR3S";
+ map_[Name("y.w.example.org")] = "K8UDEMVP1J2F7EG6JEBPS17VP3N8I58H";
+ map_[Name("w.example.org")] = w_hash;
+ map_[Name("zzz.example.org")] = zzz_hash;
+ map_[Name("smallest.example.org")] =
+ "00000000000000000000000000000000";
+ map_[Name("largest.example.org")] =
+ "UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU";
+
+ // These are used by the findNSEC3Walk test.
+ map_[Name("n0.example.org")] = "00000000000000000000000000000000";
+ map_[Name("n1.example.org")] = "01UDEMVP1J2F7EG6JEBPS17VP3N8I58H";
+ map_[Name("n2.example.org")] = "02UDEMVP1J2F7EG6JEBPS17VP3N8I58H";
+ map_[Name("n3.example.org")] = "0P9MHAVEQVM6T7VBL5LOP2U3T2RP3TOM";
+ map_[Name("n4.example.org")] = "11111111111111111111111111111111";
+ map_[Name("n5.example.org")] = "2T7B4G4VSA5SMI47K61MV5BV1A22BOJR";
+ map_[Name("n6.example.org")] = "44444444444444444444444444444444";
+ map_[Name("n7.example.org")] = "R53BQ7CC2UVMUBFU5OCMM6PERS9TK9EN";
+ map_[Name("n8.example.org")] = "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ";
}
virtual string calculate(const Name& name) const {
const NSEC3HashMap::const_iterator found = map_.find(name);
return (new TestNSEC3Hash);
}
-void
-buildFakeNSEC3Map(NSEC3HashMap& fmap)
-{
- // Build pre-defined hash
- fmap.clear();
- fmap[Name("example.org")] = apex_hash;
- fmap[Name("www.example.org")] = "2S9MHAVEQVM6T7VBL5LOP2U3T2RP3TOM";
- fmap[Name("xxx.example.org")] = "Q09MHAVEQVM6T7VBL5LOP2U3T2RP3TOM";
- fmap[Name("yyy.example.org")] = "0A9MHAVEQVM6T7VBL5LOP2U3T2RP3TOM";
- fmap[Name("x.y.w.example.org")] =
- "2VPTU5TIMAMQTTGL4LUU9KG21E0AOR3S";
- fmap[Name("y.w.example.org")] = "K8UDEMVP1J2F7EG6JEBPS17VP3N8I58H";
- fmap[Name("w.example.org")] = w_hash;
- fmap[Name("zzz.example.org")] = zzz_hash;
- fmap[Name("smallest.example.org")] =
- "00000000000000000000000000000000";
- fmap[Name("largest.example.org")] =
- "UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU";
-
- // These are used by the findNSEC3Walk test.
- fmap[Name("n0.example.org")] = "00000000000000000000000000000000";
- fmap[Name("n1.example.org")] = "01UDEMVP1J2F7EG6JEBPS17VP3N8I58H";
- fmap[Name("n2.example.org")] = "02UDEMVP1J2F7EG6JEBPS17VP3N8I58H";
- fmap[Name("n3.example.org")] = "0P9MHAVEQVM6T7VBL5LOP2U3T2RP3TOM";
- fmap[Name("n4.example.org")] = "11111111111111111111111111111111";
- fmap[Name("n5.example.org")] = "2T7B4G4VSA5SMI47K61MV5BV1A22BOJR";
- fmap[Name("n6.example.org")] = "44444444444444444444444444444444";
- fmap[Name("n7.example.org")] = "R53BQ7CC2UVMUBFU5OCMM6PERS9TK9EN";
- fmap[Name("n8.example.org")] = "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ";
+NSEC3Hash*
+TestNSEC3HashCreator::create(uint8_t, uint16_t,
+ const vector<uint8_t>&) const {
+ return (new TestNSEC3Hash);
}
void
#include <datasrc/zone.h>
#include <dns/nsec3hash.h>
-#include <dns/name.h>
#include <stdint.h>
#include <string>
-#include <map>
namespace isc {
namespace datasrc {
const;
virtual isc::dns::NSEC3Hash* create(const isc::dns::rdata::generic::NSEC3&)
const;
+ virtual isc::dns::NSEC3Hash* create(uint8_t algorithm, uint16_t iterations,
+ const std::vector<uint8_t>& salt)
+ const;
};
-typedef std::map<isc::dns::Name, std::string> NSEC3HashMap;
-typedef NSEC3HashMap::value_type NSEC3HashPair;
-
-// Build the test map with the fake NSEC3 hashes.
-void
-buildFakeNSEC3Map(NSEC3HashMap& fmap);
-
// Check the result against expected values. It directly calls EXPECT_ macros
void
findNSEC3Check(bool expected_matched, uint8_t expected_labels,
virtual NSEC3Hash* create(const generic::NSEC3&) const {
return (new TestNSEC3Hash);
}
+ virtual NSEC3Hash* create(uint8_t, uint16_t,
+ const vector<uint8_t>&) const {
+ return (new TestNSEC3Hash);
+}
+
};
/// \brief Test fixture for the InMemoryZoneFinder class