]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2390] Update std::string NS constructor to use the MasterLexer
authorMukund Sivaraman <muks@isc.org>
Mon, 28 Jan 2013 08:51:47 +0000 (14:21 +0530)
committerMukund Sivaraman <muks@isc.org>
Tue, 29 Jan 2013 04:59:00 +0000 (10:29 +0530)
Also adjust tests.

14 files changed:
src/bin/ddns/tests/ddns_test.py
src/bin/xfrin/tests/xfrin_test.py
src/bin/xfrout/tests/xfrout_test.py.in
src/lib/datasrc/tests/database_unittest.cc
src/lib/datasrc/tests/memory/rdata_serialization_unittest.cc
src/lib/datasrc/tests/memory/zone_finder_unittest.cc
src/lib/dns/python/tests/rrset_python_test.py
src/lib/dns/python/tests/zone_checker_python_test.py
src/lib/dns/rdata/generic/ns_2.cc
src/lib/dns/tests/rdata_ns_unittest.cc
src/lib/dns/tests/rrset_unittest.cc
src/lib/dns/tests/zone_checker_unittest.cc
src/lib/nsas/tests/nameserver_address_store_unittest.cc
src/lib/nsas/tests/nsas_test.h

index 0f5ca9b7f096f15da926d681694d5d52e8847d1d..9119a89f4558d29ea81d360d9cb31ca70d767d3c 100755 (executable)
@@ -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])))
index 99c5e1e1a5e932cee6c1612eeb7fb508f55a2ea1..08dbbd5df5cfc0c503da92ad4064a29e3b1f0a91 100644 (file)
@@ -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):
index 774187f484a1ead67e31f95d4c0a8a5fdd62a626..7bc395e7a61606a46dd66ac19a34f61b74a19ff6 100644 (file)
@@ -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.
index e52d9e9d7e85dd78a936e7a1e06f319df45585e0..cb8ed41ad9dae4d53963fccf31a3a17021c46d4d 100644 (file)
@@ -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_,
index a45c2bd3e610d6731166f1d11e4e27cc3c2b08f9..2734bea0051fddf12ab69ebbd841b0f1afccd076 100644 (file)
@@ -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);
 
index 42667da8e873cb2ca7cfa71b26c6538cb5bded86..e05cde69f6321e50416c39ffd315a0a0408e9b94 100644 (file)
@@ -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_},
index 0544872d34f0cdd803470cc014629f1a3d1d63d5..f100a4b699a78eea351212bcb748474b60d610e3 100644 (file)
@@ -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):
index 66b6c47abeb29d4a5b92330176383bd8f5360fbf..ec3a3b062daef795aaadcc61585283d3f7f4911a 100644 (file)
@@ -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
 
index 96d5704330c0e8d07775dea04e637fadc756d676..4842fd24b32f44b3368e7b3228fafdc472bd9fa8 100644 (file)
@@ -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)
index 8ec2a2bd5ca0f0389327dc73baeea39db104c2ba..087d345458bc7675e87429ceaaccb5f5bfe22e7f 100644 (file)
@@ -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());
 }
 }
index 725eea799da91fd8dc16cbf65cabc431b078e6d6..1b4abfd096cb5933a45cca5c6a3f11861c6b2ccb 100644 (file)
@@ -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());
 }
 
index dbe204d026f58a8db7e0b981eb3aca8c6340e6a4..115587f7dd34d42c00f61a5994ae9e578c6b9262 100644 (file)
@@ -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();
index 6ddae72b696dc1c6663063a11512d8c53cac80b2..ceb5775166fedd1ba5b1576d35b679e3d10ae11f 100644 (file)
@@ -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
index d6b4d924f8f714f4a4207662b9f415d50c7a2687..9f92149891bc2cfeca70f2ab2dd7e32ab5e3ed50 100644 (file)
@@ -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_));