Browse Source

[2390] Update std::string NS constructor to use the MasterLexer

Also adjust tests.
Mukund Sivaraman 12 years ago
parent
commit
b8e8e7ed5f

+ 1 - 1
src/bin/ddns/tests/ddns_test.py

@@ -1129,7 +1129,7 @@ class TestDDNSSession(unittest.TestCase):
         # them as separate RRs.
         dummy_record = RRset(TEST_ZONE_NAME, TEST_RRCLASS, RRType.NS(),
                              RRTTL(0))
-        dummy_record.add_rdata(Rdata(RRType.NS(), TEST_RRCLASS, "ns.example"))
+        dummy_record.add_rdata(Rdata(RRType.NS(), TEST_RRCLASS, "ns.example."))
         self.server.handle_request((self.__sock, TEST_SERVER6, TEST_CLIENT6,
                                     create_msg(prereq=[dummy_record,
                                                        dummy_record])))

+ 2 - 2
src/bin/xfrin/tests/xfrin_test.py

@@ -361,7 +361,7 @@ class TestXfrinState(unittest.TestCase):
         self.ns_rrset = RRset(TEST_ZONE_NAME, TEST_RRCLASS, RRType.NS(),
                               RRTTL(3600))
         self.ns_rrset.add_rdata(Rdata(RRType.NS(), TEST_RRCLASS,
-                                      'ns.example.com'))
+                                      'ns.example.com.'))
         self.a_rrset = RRset(TEST_ZONE_NAME, TEST_RRCLASS, RRType.A(),
                              RRTTL(3600))
         self.a_rrset.add_rdata(Rdata(RRType.A(), TEST_RRCLASS, '192.0.2.1'))
@@ -1168,7 +1168,7 @@ class TestAXFR(TestXfrinConnection):
     def test_soacheck_referral_response(self):
         self.conn.response_generator = self._create_soa_response_data
         self.soa_response_params['answers'] = []
-        self.soa_response_params['authorities'] = [create_ns('ns.example.com')]
+        self.soa_response_params['authorities'] = [create_ns('ns.example.com.')]
         self.assertRaises(XfrinProtocolError, self.conn._check_soa_serial)
 
     def test_soacheck_nodata_response(self):

+ 1 - 1
src/bin/xfrout/tests/xfrout_test.py.in

@@ -1144,7 +1144,7 @@ class TestXfroutSessionWithSQLite3(TestXfroutSessionBase):
         self.xfrsess._request_data = self.mdata
         self.xfrsess._server.get_db_file = lambda : TESTDATA_SRCDIR + \
             'test.sqlite3'
-        self.ns_name = 'a.dns.example.com'
+        self.ns_name = 'a.dns.example.com.'
 
     def check_axfr_stream(self, response):
         '''Common checks for AXFR(-style) response for the test zone.

+ 2 - 2
src/lib/datasrc/tests/database_unittest.cc

@@ -2466,7 +2466,7 @@ TYPED_TEST(DatabaseClientTest, findDelegation) {
     // It should normally just result in DELEGATION; if GLUE_OK is specified,
     // the other RR should be visible.
     this->expected_rdatas_.clear();
-    this->expected_rdatas_.push_back("ns.example.com");
+    this->expected_rdatas_.push_back("ns.example.com.");
     doFindTest(*finder, Name("brokenns1.example.org"), this->qtype_,
                RRType::NS(), this->rrttl_, ZoneFinder::DELEGATION,
                this->expected_rdatas_, this->empty_rdatas_,
@@ -2515,7 +2515,7 @@ TYPED_TEST(DatabaseClientTest, findDS) {
     // Some insane case: DS under a zone cut.  It's included in the DB, but
     // shouldn't be visible via finder.
     this->expected_rdatas_.clear();
-    this->expected_rdatas_.push_back("ns.example.com");
+    this->expected_rdatas_.push_back("ns.example.com.");
     doFindTest(*finder, Name("child.insecdelegation.example.org"),
                RRType::DS(), RRType::NS(), this->rrttl_,
                ZoneFinder::DELEGATION, this->expected_rdatas_,

+ 1 - 1
src/lib/datasrc/tests/memory/rdata_serialization_unittest.cc

@@ -767,7 +767,7 @@ TEST_F(RdataSerializationTest, badAddRdata) {
 
     // Likewise.  Inconsistent name compression policy.
     const ConstRdataPtr ns_rdata =
-        createRdata(RRType::NS(), RRClass::IN(), "ns.example");
+        createRdata(RRType::NS(), RRClass::IN(), "ns.example.");
     encoder_.start(RRClass::IN(), RRType::DNAME());
     EXPECT_THROW(encoder_.addRdata(*ns_rdata), isc::BadValue);
 

+ 1 - 1
src/lib/datasrc/tests/memory/zone_finder_unittest.cc

@@ -123,7 +123,7 @@ public:
             {"example.org. 300 IN A 192.0.2.1", &rr_a_},
             {"ns.example.org. 300 IN A 192.0.2.2", &rr_ns_a_},
             // This one will place rr_ns_a_ at a zone cut, making it a glue:
-            {"ns.example.org. 300 IN NS 192.0.2.2", &rr_ns_ns_},
+            {"ns.example.org. 300 IN NS 192.0.2.2.", &rr_ns_ns_},
             {"ns.example.org. 300 IN AAAA 2001:db8::2", &rr_ns_aaaa_},
             {"cname.example.org. 300 IN CNAME canonical.example.org",
              &rr_cname_},

+ 1 - 1
src/lib/dns/python/tests/rrset_python_test.py

@@ -78,7 +78,7 @@ class TestModuleSpec(unittest.TestCase):
     def test_add_rdata(self):
         # no iterator to read out yet (TODO: add addition test once implemented)
 
-        self.assertRaises(TypeError, self.rrset_a.add_rdata, Rdata(RRType("NS"), RRClass("IN"), "test.name"))
+        self.assertRaises(TypeError, self.rrset_a.add_rdata, Rdata(RRType("NS"), RRClass("IN"), "test.name."))
         pass
 
     def test_to_text(self):

+ 1 - 1
src/lib/dns/python/tests/zone_checker_python_test.py

@@ -142,7 +142,7 @@ class ZoneCheckerTest(unittest.TestCase):
                     ns = RRset(Name('example'), RRClass.IN(), rrtype,
                                RRTTL(0))
                     ns.add_rdata(Rdata(RRType.NS(), RRClass.IN(),
-                                       'example.org'))
+                                       'example.org.'))
                     return ns
                 return None
 

+ 19 - 2
src/lib/dns/rdata/generic/ns_2.cc

@@ -31,8 +31,25 @@ using namespace isc::util;
 // BEGIN_RDATA_NAMESPACE
 
 NS::NS(const std::string& namestr) :
-    nsname_(namestr)
-{}
+    // Fill in dummy name and replace them soon below.
+    nsname_(Name::ROOT_NAME())
+{
+    try {
+        std::istringstream ss(namestr);
+        MasterLexer lexer;
+        lexer.pushSource(ss);
+
+        nsname_ = createNameFromLexer(lexer, NULL);
+
+        if (lexer.getNextToken().getType() != MasterToken::END_OF_FILE) {
+            isc_throw(InvalidRdataText, "extra input text for NS: "
+                      << namestr);
+        }
+    } catch (const MasterLexer::LexerError& ex) {
+        isc_throw(InvalidRdataText, "Failed to construct NS from '" <<
+                  namestr << "': " << ex.what());
+    }
+}
 
 NS::NS(InputBuffer& buffer, size_t) :
     nsname_(buffer)

+ 9 - 9
src/lib/dns/tests/rdata_ns_unittest.cc

@@ -36,8 +36,8 @@ class Rdata_NS_Test : public RdataTest {
     // there's nothing to specialize
 };
 
-const generic::NS rdata_ns("ns.example.com");
-const generic::NS rdata_ns2("ns2.example.com");
+const generic::NS rdata_ns("ns.example.com.");
+const generic::NS rdata_ns2("ns2.example.com.");
 const uint8_t wiredata_ns[] = {
     0x02, 0x6e, 0x73, 0x07, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x03,
     0x63, 0x6f, 0x6d, 0x00 };
@@ -50,15 +50,15 @@ const uint8_t wiredata_ns2[] = {
     0x03, 0x6e, 0x73, 0x32, 0xc0, 0x03 };
 
 TEST_F(Rdata_NS_Test, createFromText) {
-    EXPECT_EQ(0, rdata_ns.compare(generic::NS("ns.example.com")));
+    EXPECT_EQ(0, rdata_ns.compare(generic::NS("ns.example.com.")));
     // explicitly add a trailing dot.  should be the same RDATA.
     EXPECT_EQ(0, rdata_ns.compare(generic::NS("ns.example.com.")));
     // should be case sensitive.
-    EXPECT_EQ(0, rdata_ns.compare(generic::NS("NS.EXAMPLE.COM")));
+    EXPECT_EQ(0, rdata_ns.compare(generic::NS("NS.EXAMPLE.COM.")));
     // RDATA of a class-independent type should be recognized for any
     // "unknown" class.
     EXPECT_EQ(0, rdata_ns.compare(*createRdata(RRType("NS"), RRClass(65000),
-                                               "ns.example.com")));
+                                               "ns.example.com.")));
 }
 
 TEST_F(Rdata_NS_Test, createFromWire) {
@@ -78,7 +78,7 @@ TEST_F(Rdata_NS_Test, createFromWire) {
                                       "rdata_ns_fromWire", 71),
                  DNSMessageFORMERR);
 
-    EXPECT_EQ(0, generic::NS("ns2.example.com").compare(
+    EXPECT_EQ(0, generic::NS("ns2.example.com.").compare(
                   *rdataFactoryFromFile(RRType("NS"), RRClass("IN"),
                                         "rdata_ns_fromWire", 55)));
     EXPECT_THROW(*rdataFactoryFromFile(RRType("NS"), RRClass("IN"),
@@ -119,13 +119,13 @@ TEST_F(Rdata_NS_Test, toText) {
 }
 
 TEST_F(Rdata_NS_Test, compare) {
-    generic::NS small("a.example");
-    generic::NS large("example");
+    generic::NS small("a.example.");
+    generic::NS large("example.");
     EXPECT_TRUE(Name("a.example") > Name("example"));
     EXPECT_GT(0, small.compare(large));
 }
 
 TEST_F(Rdata_NS_Test, getNSName) {
-    EXPECT_EQ(Name("ns.example.com"), rdata_ns.getNSName());
+    EXPECT_EQ(Name("ns.example.com."), rdata_ns.getNSName());
 }
 }

+ 1 - 1
src/lib/dns/tests/rrset_unittest.cc

@@ -168,7 +168,7 @@ TEST_F(RRsetTest, addRdataPtr) {
     // Pointer version of addRdata() doesn't type check and does allow to
     //add a different type of Rdata as a result.
     rrset_a_empty.addRdata(createRdata(RRType::NS(), RRClass::IN(),
-                                       "ns.example.com"));
+                                       "ns.example.com."));
     EXPECT_EQ(3, rrset_a_empty.getRdataCount());
 }
 

+ 6 - 6
src/lib/dns/tests/zone_checker_unittest.cc

@@ -160,7 +160,7 @@ TEST_F(ZoneCheckerTest, checkSOA) {
     // Likewise, if the SOA RRset contains non SOA Rdata, it should be a bug.
     rrsets_->removeRRset(zname_, zclass_, RRType::SOA());
     soa_.reset(new RRset(zname_, zclass_, RRType::SOA(), RRTTL(60)));
-    soa_->addRdata(createRdata(RRType::NS(), zclass_, "ns.example.com"));
+    soa_->addRdata(createRdata(RRType::NS(), zclass_, "ns.example.com."));
     rrsets_->addRRset(soa_);
     EXPECT_THROW(checkZone(zname_, zclass_, *rrsets_, callbacks_), Unexpected);
     checkIssues();              // no error/warning should be reported
@@ -245,7 +245,7 @@ TEST_F(ZoneCheckerTest, checkNSData) {
     rrsets_->removeRRset(ns_name, zclass_, RRType::CNAME());
     rrsets_->removeRRset(zname_, zclass_, RRType::NS());
     ns_.reset(new RRset(zname_, zclass_, RRType::NS(), RRTTL(60)));
-    ns_->addRdata(generic::NS("ns.example.org"));
+    ns_->addRdata(generic::NS("ns.example.org."));
     rrsets_->addRRset(ns_);
     EXPECT_TRUE(checkZone(zname_, zclass_, *rrsets_, callbacks_));
     checkIssues();
@@ -274,7 +274,7 @@ TEST_F(ZoneCheckerTest, checkNSWithDelegation) {
     rrsets_->addRRset(ns_);
     RRsetPtr child_ns(new RRset(Name("child.example.com"), zclass_,
                                 RRType::NS(), RRTTL(60)));
-    child_ns->addRdata(generic::NS("ns.example.org"));
+    child_ns->addRdata(generic::NS("ns.example.org."));
     rrsets_->addRRset(child_ns);
     EXPECT_TRUE(checkZone(zname_, zclass_, *rrsets_, callbacks_));
     checkIssues();
@@ -282,7 +282,7 @@ TEST_F(ZoneCheckerTest, checkNSWithDelegation) {
     // Zone cut at the NS name.  Same result.
     rrsets_->removeRRset(child_ns->getName(), zclass_, RRType::NS());
     child_ns.reset(new RRset(ns_name, zclass_, RRType::NS(), RRTTL(60)));
-    child_ns->addRdata(generic::NS("ns.example.org"));
+    child_ns->addRdata(generic::NS("ns.example.org."));
     rrsets_->addRRset(child_ns);
     EXPECT_TRUE(checkZone(zname_, zclass_, *rrsets_, callbacks_));
     checkIssues();
@@ -291,7 +291,7 @@ TEST_F(ZoneCheckerTest, checkNSWithDelegation) {
     rrsets_->removeRRset(child_ns->getName(), zclass_, RRType::NS());
     child_ns.reset(new RRset(Name("another.ns.child.example.com"), zclass_,
                              RRType::NS(), RRTTL(60)));
-    child_ns->addRdata(generic::NS("ns.example.org"));
+    child_ns->addRdata(generic::NS("ns.example.org."));
     rrsets_->addRRset(child_ns);
     EXPECT_TRUE(checkZone(zname_, zclass_, *rrsets_, callbacks_));
     expected_warns_.push_back("zone example.com/IN: NS has no address");
@@ -332,7 +332,7 @@ TEST_F(ZoneCheckerTest, checkNSWithDNAME) {
     // this implementation prefers the NS and skips further checks.
     ns_.reset(new RRset(Name("child.example.com"), zclass_, RRType::NS(),
                         RRTTL(60)));
-    ns_->addRdata(generic::NS("ns.example.org"));
+    ns_->addRdata(generic::NS("ns.example.org."));
     rrsets_->addRRset(ns_);
     EXPECT_TRUE(checkZone(zname_, zclass_, *rrsets_, callbacks_));
     checkIssues();

+ 1 - 1
src/lib/nsas/tests/nameserver_address_store_unittest.cc

@@ -386,7 +386,7 @@ TEST_F(NameserverAddressStoreTest, CombinedTest) {
 
     // But we do not answer it right away. We create a new zone and
     // let this nameserver entry get out.
-    rrns_->addRdata(rdata::generic::NS("example.cz"));
+    rrns_->addRdata(rdata::generic::NS("example.cz."));
     nsas.lookupAndAnswer(EXAMPLE_CO_UK, RRClass::IN(), rrns_, getCallback());
 
     // It really should ask something, one of the nameservers

+ 2 - 2
src/lib/nsas/tests/nsas_test.h

@@ -264,8 +264,8 @@ protected:
         rrch_->addRdata(ConstRdataPtr(new RdataTest<A>("1324")));
 
         // NS records take a single name
-        rrns_->addRdata(rdata::generic::NS("example.fr"));
-        rrns_->addRdata(rdata::generic::NS("example.de"));
+        rrns_->addRdata(rdata::generic::NS("example.fr."));
+        rrns_->addRdata(rdata::generic::NS("example.de."));
 
         // Single NS record with 0 TTL
         rr_single_->addRdata(rdata::generic::NS(ns_name_));