From: JINMEI Tatuya Date: Thu, 9 Feb 2012 22:20:51 +0000 (-0800) Subject: [1641] added more tests for NSEC(3)::toText(). fixed one crash bug in NSEC3 X-Git-Tag: trac2351_base~97^2~37^2~17 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c41cda65e06b6776c7111e65b04c72d5bc84c54f;p=thirdparty%2Fkea.git [1641] added more tests for NSEC(3)::toText(). fixed one crash bug in NSEC3 due to an incorrect assert() condition. --- diff --git a/src/lib/dns/rdata/generic/nsec3_50.cc b/src/lib/dns/rdata/generic/nsec3_50.cc index 092695c082..7b08c3cea3 100644 --- a/src/lib/dns/rdata/generic/nsec3_50.cc +++ b/src/lib/dns/rdata/generic/nsec3_50.cc @@ -225,7 +225,7 @@ NSEC3::toText() const { assert(i + 2 <= impl_->typebits_.size()); int window = impl_->typebits_[i]; len = impl_->typebits_[i + 1]; - assert(len >= 0 && len < 32); + assert(len > 0 && len <= 32); i += 2; for (int j = 0; j < len; j++) { if (impl_->typebits_[i + j] == 0) { diff --git a/src/lib/dns/tests/rdata_nsecbitmap_unittest.cc b/src/lib/dns/tests/rdata_nsecbitmap_unittest.cc index 7c46f86473..068c643b5a 100644 --- a/src/lib/dns/tests/rdata_nsecbitmap_unittest.cc +++ b/src/lib/dns/tests/rdata_nsecbitmap_unittest.cc @@ -22,9 +22,12 @@ #include +#include + #include using namespace std; +using boost::lexical_cast; using namespace isc::dns; using namespace isc::dns::rdata; @@ -34,10 +37,15 @@ namespace { template class NSECBitmapTest : public RdataTest { protected: + RDATA_TYPE fromText(const string& rdata_text) { + return (RDATA_TYPE(rdata_text)); + } + // These depend on the specific RR type. We use specialized methods // for them. static RRType getType(); // return either RRType::NSEC() or NSEC3() static string getWireFilePrefix(); + static string getCommonText(); // commonly used part of textual form }; typedef ::testing::Types TestRdataTypes; @@ -67,9 +75,17 @@ NSECBitmapTest::getType() { return (RRType::NSEC3()); } -class Rdata_NSECBITMAP_Test : public RdataTest { - // there's nothing to specialize -}; +template <> +string +NSECBitmapTest::getCommonText() { + return ("next. "); +} + +template <> +string +NSECBitmapTest::getCommonText() { + return ("1 1 12 AABBCCDD 2T7B4G4VSA5SMI47K61MV5BV1A22BOJR "); +} // Tests against various types of bogus NSEC/NSEC3 type bitmaps. // The syntax and semantics are common for both RR types, and our @@ -126,4 +142,36 @@ TYPED_TEST(NSECBitmapTest, createFromWire) { "fromWire10.wire").c_str()), DNSMessageFORMERR); } + +// This tests the result of toText() with various kinds of NSEC/NSEC3 bitmaps. +// It also tests the "from text" constructor as a result. +TYPED_TEST(NSECBitmapTest, toText) { + // A simple case (some commonly seen RR types in NSEC(3) bitmaps) + string rdata_text = this->getCommonText() + "NS SOA RRSIG DNSKEY"; + EXPECT_EQ(rdata_text, this->fromText(rdata_text).toText()); + + // Similar to above, but involves more than one bitmap window blocks. + rdata_text = this->getCommonText() + "NS DLV"; + EXPECT_EQ(rdata_text, this->fromText(rdata_text).toText()); + + // Make sure all possible bits in a one-octet bitmap field correctly. + // We use the range around 1024 (reasonably higher number) so it's + // unlikely that they have predefined mnemonic and can be safely converted + // to TYPEnnnn by toText(). + for (unsigned int i = 1024; i < 1032; ++i) { + rdata_text = this->getCommonText() + "TYPE" + lexical_cast(i); + EXPECT_EQ(rdata_text, this->fromText(rdata_text).toText()); + } + + // Make sure all possible 32 octets in a longest possible block are + // handled correctly. + for (unsigned int i = 1024; i < 1024 + 256; i += 8) { + rdata_text = this->getCommonText() + "TYPE" + lexical_cast(i); + EXPECT_EQ(rdata_text, this->fromText(rdata_text).toText()); + } + + // Check for the highest window block. + rdata_text = this->getCommonText() + "TYPE65535"; + EXPECT_EQ(rdata_text, this->fromText(rdata_text).toText()); +} }