Commit c5efaec3 authored by Mukund Sivaraman's avatar Mukund Sivaraman
Browse files

[2656] Update std::string DNAME constructor to use the MasterLexer

Also adjust tests.
parent ae25fcc7
......@@ -773,7 +773,7 @@ TEST_F(RdataSerializationTest, badAddRdata) {
// Same as the previous one, opposite inconsistency.
const ConstRdataPtr dname_rdata =
createRdata(RRType::DNAME(), RRClass::IN(), "dname.example");
createRdata(RRType::DNAME(), RRClass::IN(), "dname.example.");
encoder_.start(RRClass::IN(), RRType::NS());
EXPECT_THROW(encoder_.addRdata(*dname_rdata), isc::BadValue);
......
......@@ -32,8 +32,25 @@ using isc::dns::rdata::generic::detail::createNameFromLexer;
// BEGIN_RDATA_NAMESPACE
DNAME::DNAME(const std::string& namestr) :
dname_(namestr)
{}
// Fill in dummy name and replace it soon below.
dname_(Name::ROOT_NAME())
{
try {
std::istringstream ss(namestr);
MasterLexer lexer;
lexer.pushSource(ss);
dname_ = createNameFromLexer(lexer, NULL);
if (lexer.getNextToken().getType() != MasterToken::END_OF_FILE) {
isc_throw(InvalidRdataText, "extra input text for DNAME: "
<< namestr);
}
} catch (const MasterLexer::LexerError& ex) {
isc_throw(InvalidRdataText, "Failed to construct DNAME from '" <<
namestr << "': " << ex.what());
}
}
DNAME::DNAME(InputBuffer& buffer, size_t) :
dname_(buffer)
......
......@@ -36,8 +36,8 @@ class Rdata_DNAME_Test : public RdataTest {
// there's nothing to specialize
};
const generic::DNAME rdata_dname("dn.example.com");
const generic::DNAME rdata_dname2("dn2.example.com");
const generic::DNAME rdata_dname("dn.example.com.");
const generic::DNAME rdata_dname2("dn2.example.com.");
const uint8_t wiredata_dname[] = {
0x02, 0x64, 0x6e, 0x07, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x03,
0x63, 0x6f, 0x6d, 0x00 };
......@@ -52,16 +52,16 @@ const uint8_t wiredata_dname2[] = {
0x63, 0x6f, 0x6d, 0x00 };
TEST_F(Rdata_DNAME_Test, createFromText) {
EXPECT_EQ(0, rdata_dname.compare(generic::DNAME("dn.example.com")));
EXPECT_EQ(0, rdata_dname.compare(generic::DNAME("dn.example.com.")));
// explicitly add a trailing dot. should be the same RDATA.
EXPECT_EQ(0, rdata_dname.compare(generic::DNAME("dn.example.com.")));
// should be case sensitive.
EXPECT_EQ(0, rdata_dname.compare(generic::DNAME("DN.EXAMPLE.COM")));
EXPECT_EQ(0, rdata_dname.compare(generic::DNAME("DN.EXAMPLE.COM.")));
// RDATA of a class-independent type should be recognized for any
// "unknown" class.
EXPECT_EQ(0, rdata_dname.compare(*createRdata(RRType("DNAME"),
RRClass(65000),
"dn.example.com")));
"dn.example.com.")));
}
TEST_F(Rdata_DNAME_Test, createFromWire) {
......@@ -81,7 +81,7 @@ TEST_F(Rdata_DNAME_Test, createFromWire) {
"rdata_dname_fromWire", 71),
DNSMessageFORMERR);
EXPECT_EQ(0, generic::DNAME("dn2.example.com").compare(
EXPECT_EQ(0, generic::DNAME("dn2.example.com.").compare(
*rdataFactoryFromFile(RRType("DNAME"), RRClass("IN"),
"rdata_dname_fromWire", 55)));
EXPECT_THROW(*rdataFactoryFromFile(RRType("DNAME"), RRClass("IN"),
......
......@@ -309,7 +309,7 @@ TEST_F(ZoneCheckerTest, checkNSWithDNAME) {
ns_->addRdata(generic::NS(ns_name));
rrsets_->addRRset(ns_);
RRsetPtr dname(new RRset(zname_, zclass_, RRType::DNAME(), RRTTL(60)));
dname->addRdata(generic::DNAME("example.org"));
dname->addRdata(generic::DNAME("example.org."));
rrsets_->addRRset(dname);
EXPECT_FALSE(checkZone(zname_, zclass_, *rrsets_, callbacks_));
expected_errors_.push_back("zone example.com/IN: NS 'ns.child.example.com'"
......@@ -320,7 +320,7 @@ TEST_F(ZoneCheckerTest, checkNSWithDNAME) {
rrsets_->removeRRset(zname_, zclass_, RRType::DNAME());
dname.reset(new RRset(Name("child.example.com"), zclass_, RRType::DNAME(),
RRTTL(60)));
dname->addRdata(generic::DNAME("example.org"));
dname->addRdata(generic::DNAME("example.org."));
rrsets_->addRRset(dname);
EXPECT_FALSE(checkZone(zname_, zclass_, *rrsets_, callbacks_));
expected_errors_.push_back("zone example.com/IN: NS 'ns.child.example.com'"
......@@ -342,7 +342,7 @@ TEST_F(ZoneCheckerTest, checkNSWithDNAME) {
rrsets_->removeRRset(dname->getName(), zclass_, RRType::DNAME());
rrsets_->removeRRset(ns_->getName(), zclass_, RRType::NS());
dname.reset(new RRset(ns_name, zclass_, RRType::DNAME(), RRTTL(60)));
dname->addRdata(generic::DNAME("example.org"));
dname->addRdata(generic::DNAME("example.org."));
rrsets_->addRRset(dname);
EXPECT_TRUE(checkZone(zname_, zclass_, *rrsets_, callbacks_));
expected_warns_.push_back("zone example.com/IN: NS has no address");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment