BIND 10 trac2431, updated. 7400eee5cb287236717e78c8956cc09efb424813 [2431] Check exception message in tests

BIND 10 source code commits bind10-changes at lists.isc.org
Mon Dec 17 05:33:59 UTC 2012


The branch, trac2431 has been updated
       via  7400eee5cb287236717e78c8956cc09efb424813 (commit)
       via  88dd03a0064c14a1608b6be9e4cff5d5cee7643f (commit)
       via  8a49f520e191d8ff14d8118ec80ab5c83701995d (commit)
       via  c41a723a55a2d5665ee28716b32983ea17a38d97 (commit)
       via  1a7c1e3d9a33115839c64869a28f3c7daf63efc0 (commit)
       via  78688fbf0ddeb0f2e47a4988246b8ad29fe14ba4 (commit)
      from  7450f285f169e7ab894c5b85e303d1065795529e (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 7400eee5cb287236717e78c8956cc09efb424813
Author: Mukund Sivaraman <muks at isc.org>
Date:   Mon Dec 17 10:58:39 2012 +0530

    [2431] Check exception message in tests

commit 88dd03a0064c14a1608b6be9e4cff5d5cee7643f
Author: Mukund Sivaraman <muks at isc.org>
Date:   Mon Dec 17 09:33:11 2012 +0530

    [2431] Remove always-true operand

commit 8a49f520e191d8ff14d8118ec80ab5c83701995d
Author: Mukund Sivaraman <muks at isc.org>
Date:   Mon Dec 17 09:30:56 2012 +0530

    [2431] Rename test

commit c41a723a55a2d5665ee28716b32983ea17a38d97
Author: Mukund Sivaraman <muks at isc.org>
Date:   Mon Dec 17 09:30:19 2012 +0530

    [2431] Update test comment (to refer to implementation)

commit 1a7c1e3d9a33115839c64869a28f3c7daf63efc0
Author: Mukund Sivaraman <muks at isc.org>
Date:   Mon Dec 17 09:24:47 2012 +0530

    [2431] Add comments

commit 78688fbf0ddeb0f2e47a4988246b8ad29fe14ba4
Author: JINMEI Tatuya <jinmei at isc.org>
Date:   Mon Dec 17 09:18:57 2012 +0530

    [2431] Move TTL, class and type parsing into a helper method

-----------------------------------------------------------------------

Summary of changes:
 src/lib/dns/master_loader.cc                |  109 +++++++++++++--------------
 src/lib/dns/tests/master_loader_unittest.cc |   30 ++++----
 2 files changed, 68 insertions(+), 71 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/dns/master_loader.cc b/src/lib/dns/master_loader.cc
index fd8ec82..30930ed 100644
--- a/src/lib/dns/master_loader.cc
+++ b/src/lib/dns/master_loader.cc
@@ -143,6 +143,53 @@ private:
         pushSource(filename);
     }
 
+    RRType parseRRParams(bool& explicit_ttl) {
+        // Find TTL, class and type.  Both TTL and class are
+        // optional and may occur in any order if they exist. TTL
+        // and class come before type which must exist.
+        //
+        // [<TTL>] [<class>] <type> <RDATA>
+        // [<class>] [<TTL>] <type> <RDATA>
+        MasterToken rrparam_token = lexer_.getNextToken(MasterToken::STRING);
+
+        // named-signzone outputs TTL first, so try parsing it in order
+        // first.
+        if (setCurrentTTL(rrparam_token.getString())) {
+            explicit_ttl = true;
+            rrparam_token = lexer_.getNextToken(MasterToken::STRING);
+        } else {
+            // If it's not a TTL here, continue and try again
+            // after the RR class below.
+        }
+
+        boost::scoped_ptr<RRClass> rrclass;
+        try {
+            rrclass.reset(new RRClass(rrparam_token.getString()));
+            rrparam_token = lexer_.getNextToken(MasterToken::STRING);
+        } catch (const InvalidRRClass&) {
+            // If it's not an rrclass here, use the zone's class.
+            rrclass.reset(new RRClass(zone_class_));
+        }
+
+        // If we couldn't parse TTL earlier in the stream (above), try
+        // again at current location.
+        if (!explicit_ttl &&
+            setCurrentTTL(rrparam_token.getString())) {
+            explicit_ttl = true;
+            rrparam_token = lexer_.getNextToken(MasterToken::STRING);
+        }
+
+        if (*rrclass != zone_class_) {
+            // It doesn't really matter much what type of exception
+            // we throw, we catch it just below.
+            isc_throw(isc::BadValue, "Class mismatch: " << *rrclass <<
+                      "vs. " << zone_class_);
+        }
+
+        // Return the current string token's value as the RRType.
+        return (RRType(rrparam_token.getString()));
+    }
+
     // Upper limit check when recognizing a specific TTL value from the
     // zone file ($TTL, the RR's TTL field, or the SOA minimum).  RFC2181
     // Section 8 limits the range of TTL values to unsigned 32-bit integers,
@@ -380,72 +427,22 @@ MasterLoader::MasterLoaderImpl::loadIncremental(size_t count_limit) {
                 continue;
             }
 
-            const Name name(name_string.beg, name_string.len,
-                            &zone_origin_);
-
-            // Find TTL, class and type.  Both TTL and class are
-            // optional and may occur in any order if they exist. TTL
-            // and class come before type which must exist.
-            //
-            // [<TTL>] [<class>] <type> <RDATA>
-            // [<class>] [<TTL>] <type> <RDATA>
+            const Name name(name_string.beg, name_string.len, &zone_origin_);
 
             // The parameters
-            MasterToken rrparam_token = lexer_.getNextToken();
-
-            boost::scoped_ptr<RRClass> rrclass;
-            try {
-                rrclass.reset(new RRClass(rrparam_token.getString()));
-                rrparam_token = lexer_.getNextToken();
-            } catch (const InvalidRRClass&) {
-                // If it's not an rrclass here, continue and try again
-                // after the TTL below.
-            }
-
             bool explicit_ttl = false;
-            if (rrparam_token.getType() == MasterToken::STRING) {
-                // Try TTL
-                if (setCurrentTTL(rrparam_token.getString())) {
-                    explicit_ttl = true;
-                    rrparam_token = lexer_.getNextToken();
-                }
-            }
-
-            if (!rrclass) {
-                try {
-                    rrclass.reset(new RRClass(rrparam_token.getString()));
-                    rrparam_token = lexer_.getNextToken();
-                } catch (const InvalidRRClass&) {
-                    // If it's not an rrclass here, use the zone's class.
-                    rrclass.reset(new RRClass(zone_class_));
-                }
-            }
-
-            // Return the last token
-            lexer_.ungetToken();
-
-            const RRType rrtype(getString());
-
-            // TODO: Some more validation?
-            if (*rrclass != zone_class_) {
-                // It doesn't really matter much what type of exception
-                // we throw, we catch it just below.
-                isc_throw(isc::BadValue, "Class mismatch: " << *rrclass <<
-                          "vs. " << zone_class_);
-            }
+            const RRType rrtype = parseRRParams(explicit_ttl);
             // TODO: Check if it is SOA, it should be at the origin.
 
-            const rdata::RdataPtr rdata(rdata::createRdata(rrtype, *rrclass,
-                                                           lexer_,
-                                                           &zone_origin_,
-                                                           options_,
-                                                           callbacks_));
+            const rdata::RdataPtr rdata =
+                rdata::createRdata(rrtype, zone_class_, lexer_, &zone_origin_,
+                                   options_, callbacks_);
             // In case we get NULL, it means there was error creating
             // the Rdata. The errors should have been reported by
             // callbacks_ already. We need to decide if we want to continue
             // or not.
             if (rdata) {
-                add_callback_(name, *rrclass, rrtype,
+                add_callback_(name, zone_class_, rrtype,
                               getCurrentTTL(explicit_ttl, rrtype, rdata),
                               rdata);
 
diff --git a/src/lib/dns/tests/master_loader_unittest.cc b/src/lib/dns/tests/master_loader_unittest.cc
index 7ddc392..544dae5 100644
--- a/src/lib/dns/tests/master_loader_unittest.cc
+++ b/src/lib/dns/tests/master_loader_unittest.cc
@@ -280,14 +280,18 @@ struct ErrorCase {
     { "www      FORTNIGHT   IN  A   192.0.2.1", NULL, "Invalid TTL" },
     { "www      3600    XX  A   192.0.2.1", NULL, "Invalid class" },
     { "www      3600    IN  A   bad_ip", NULL, "Invalid Rdata" },
-    { "www      IN      A   3600 192.168.2.7", NULL,
-      "Invalid Rdata (incorrect order of class, TTL and type)" },
-    { "www      A       IN  3600 192.168.2.8", NULL,
-      "Invalid Rdata (incorrect order of class, TTL and type)" },
-    { "www      3600    A   IN   192.168.2.7", NULL,
-      "Invalid Rdata (incorrect order of class, TTL and type)" },
-    { "www      A       3600 IN  192.168.2.8", NULL,
-      "Invalid Rdata (incorrect order of class, TTL and type)" },
+    { "www      IN      A   3600 192.168.2.7",
+      "createRdata from text failed: IN/A RDATA construction from text failed",
+      "Incorrect order of class, TTL and type" },
+    { "www      A       IN  3600 192.168.2.8",
+      "createRdata from text failed: IN/A RDATA construction from text failed",
+      "Incorrect order of class, TTL and type" },
+    { "www      3600    A   IN   192.168.2.7",
+      "createRdata from text failed: IN/A RDATA construction from text failed",
+      "Incorrect order of class, TTL and type" },
+    { "www      A       3600 IN  192.168.2.8",
+      "createRdata from text failed: IN/A RDATA construction from text failed",
+      "Incorrect order of class, TTL and type" },
     { "www      3600    IN", NULL, "Unexpected EOLN" },
     { "www      3600    CH  TXT nothing", NULL, "Class mismatch" },
     { "www      \"3600\"  IN  A   192.0.2.1", NULL, "Quoted TTL" },
@@ -479,13 +483,9 @@ TEST_F(MasterLoaderTest, ttlFromPrevious) {
     checkCallbackMessage(warnings_.at(0), "using RFC1035 TTL semantics", 2);
 }
 
-TEST_F(MasterLoaderTest, ttlClassTypeOrder) {
-    // We test the order and lack of TTL, class and type.  Both TTL and
-    // class are optional and may occur in any order if they exist. TTL
-    // and class come before type which must exist.
-    //
-    // [<TTL>] [<class>] <type> <RDATA>
-    // [<class>] [<TTL>] <type> <RDATA>
+TEST_F(MasterLoaderTest, RRParamsOrdering) {
+    // We test the order and existence of TTL, class and type. See
+    // MasterLoader::MasterLoaderImpl::parseRRParams() for ordering.
 
     stringstream zone_stream;
     // <TTL> <class> <type> <RDATA>



More information about the bind10-changes mailing list