BIND 10 trac2427, updated. d0f80f2a66545a7247e97e7a17c26ae812349d26 [2427] Origin handling in $INCLUDE

BIND 10 source code commits bind10-changes at lists.isc.org
Fri Dec 14 13:30:19 UTC 2012


The branch, trac2427 has been updated
       via  d0f80f2a66545a7247e97e7a17c26ae812349d26 (commit)
       via  a651d9b90dc0bc9737e6f104d1fde7f4b7c2110e (commit)
       via  a8c08c6be23f58204300bb2c916fcda7aef7b4c1 (commit)
      from  e47b08e8a356c1bf498aa5a615fcce86958f1fe0 (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 d0f80f2a66545a7247e97e7a17c26ae812349d26
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Fri Dec 14 14:29:50 2012 +0100

    [2427] Origin handling in $INCLUDE

commit a651d9b90dc0bc9737e6f104d1fde7f4b7c2110e
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Fri Dec 14 14:22:49 2012 +0100

    [2427] Check handling of origin in $INCLUDE
    
    This is leftover from #2428, but it wasn't possible to handle then yet.

commit a8c08c6be23f58204300bb2c916fcda7aef7b4c1
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Fri Dec 14 14:10:26 2012 +0100

    [2427] More error handling tests for $ORIGIN
    
    They all pass now, as the framework to handle them was already in place.
    This is just to check it works well.

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

Summary of changes:
 src/lib/dns/master_loader.cc                |    7 +++-
 src/lib/dns/tests/master_loader_unittest.cc |   48 +++++++++++++++++++++++++--
 2 files changed, 52 insertions(+), 3 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/dns/master_loader.cc b/src/lib/dns/master_loader.cc
index d82f462..4644659 100644
--- a/src/lib/dns/master_loader.cc
+++ b/src/lib/dns/master_loader.cc
@@ -128,7 +128,12 @@ public:
 
         if (name_tok.getType() == MasterToken::QSTRING ||
             name_tok.getType() == MasterToken::STRING) {
-            // TODO: Handle the origin. Once we complete #2427.
+            // There's an optional name, meaning origin. Extract it
+            // and store.
+            const MasterToken::StringRegion&
+                name_string(name_tok.getStringRegion());
+            active_origin_ = Name(name_string.beg, name_string.len,
+                                  &active_origin_);
         } else {
             // We return the newline there. This is because after we pop
             // the source, we want to call eatUntilEOL and this would
diff --git a/src/lib/dns/tests/master_loader_unittest.cc b/src/lib/dns/tests/master_loader_unittest.cc
index f882def..2c9f8b1 100644
--- a/src/lib/dns/tests/master_loader_unittest.cc
+++ b/src/lib/dns/tests/master_loader_unittest.cc
@@ -331,8 +331,12 @@ struct ErrorCase {
     { "$INCLUDES " TEST_DATA_SRCDIR "/example.org", "Include too long" },
     { "$INCLUDE", "Missing include path" },
     { "$INCLUDE /file/not/found", "Include file not found" },
-    { "$INCLUDE /file/not/found and here goes bunch of garbage",
+    { "$INCLUDE /file/not/found example.org. and here goes bunch of garbage",
         "Include file not found and garbage at the end of line" },
+    { "$ORIGIN", "Missing origin name" },
+    { "$ORIGIN invalid...name", "Invalid name for origin" },
+    { "$ORIGI name.", "$ORIGIN too short" },
+    { "$ORIGINAL name.", "$ORIGIN too long" },
     { NULL, NULL }
 };
 
@@ -407,7 +411,7 @@ TEST_F(MasterLoaderTest, includeWithGarbage) {
     // Include an origin (example.org) because we expect it to be handled
     // soon and we don't want it to break here.
     const string include_str("$INCLUDE " TEST_DATA_SRCDIR
-                             "/example.org example.org bunch of other stuff\n"
+                             "/example.org example.org. bunch of other stuff\n"
                              "www 3600 IN AAAA 2001:db8::1\n");
     stringstream zone_stream(include_str);
     setLoader(zone_stream, Name("example.org."), RRClass::IN(),
@@ -423,6 +427,46 @@ TEST_F(MasterLoaderTest, includeWithGarbage) {
     checkRR("www.example.org", RRType::AAAA(), "2001:db8::1");
 }
 
+// Check we error about garbage at the end of $ORIGIN line (but the line works).
+TEST_F(MasterLoaderTest, originWithGarbage) {
+    const string origin_str = "$ORIGIN www More garbage here\n"
+        "@  1H  IN  A   192.0.2.1\n";
+    stringstream ss(origin_str);
+    setLoader(ss, Name("example.org."), RRClass::IN(),
+              MasterLoader::MANY_ERRORS);
+    EXPECT_NO_THROW(loader_->load());
+    EXPECT_FALSE(loader_->loadedSucessfully());
+    ASSERT_EQ(1, errors_.size());
+    // It says something about extra tokens at the end
+    EXPECT_NE(string::npos, errors_[0].find("Extra"));
+    EXPECT_TRUE(warnings_.empty());
+    checkARR("www.example.org");
+}
+
+// Test we can pass both file to include and the origin to switch
+TEST_F(MasterLoaderTest, includeAndOrigin) {
+    // First, switch origin to something else, so we can check it is
+    // switched back.
+    const string include_string = "$ORIGIN www\n"
+        "@  1H  IN  A   192.0.2.1\n"
+        // Then include the file with data and switch origin back
+        "$INCLUDE " TEST_DATA_SRCDIR "/example.org example.org.\n"
+        // Another RR to see the switch survives after we exit include
+        "www    1H  IN  A   192.0.2.1\n";
+    stringstream ss(include_string);
+    setLoader(ss, Name("example.org"), RRClass::IN(),
+              MasterLoader::MANY_ERRORS);
+    // Successfully load the data
+    loader_->load();
+    EXPECT_TRUE(loader_->loadedSucessfully());
+    EXPECT_TRUE(errors_.empty());
+    EXPECT_TRUE(warnings_.empty());
+    // And check it's the correct data
+    checkARR("www.example.org");
+    checkBasicRRs();
+    checkARR("www.example.org");
+}
+
 // Test the constructor rejects empty add callback.
 TEST_F(MasterLoaderTest, emptyCallback) {
     EXPECT_THROW(MasterLoader(TEST_DATA_SRCDIR "/example.org",



More information about the bind10-changes mailing list