Browse Source

[2429] some other cases with $TTL, including more than one $TTL w/ change val.

JINMEI Tatuya 12 years ago
parent
commit
1f1d62190f
2 changed files with 17 additions and 4 deletions
  1. 7 1
      src/lib/dns/master_loader.cc
  2. 10 3
      src/lib/dns/tests/master_loader_unittest.cc

+ 7 - 1
src/lib/dns/master_loader.cc

@@ -142,8 +142,9 @@ public:
     void setDefaultTTL(const string& ttl_txt) {
         if (!default_ttl_) {
             default_ttl_.reset(new RRTTL(ttl_txt));
+        } else {
+            *default_ttl_ = RRTTL(ttl_txt);
         }
-        //setCurrentTTL(*default_ttl_);
         eatUntilEOL(true);
     }
 
@@ -288,9 +289,12 @@ MasterLoader::MasterLoaderImpl::loadIncremental(size_t count_limit) {
 
             // The parameters
             MasterToken rrparam_token = lexer_.getNextToken();
+
+            bool explicit_ttl = false;
             if (rrparam_token.getType() == MasterToken::STRING) {
                 // Try TTL
                 if (setCurrentTTL(rrparam_token.getString())) {
+                    explicit_ttl = true;
                     rrparam_token = lexer_.getNextToken();
                 }
             }
@@ -303,6 +307,8 @@ MasterLoader::MasterLoaderImpl::loadIncremental(size_t count_limit) {
                 if (default_ttl_) {
                     setCurrentTTL(*default_ttl_);
                 } // TBD: else: try SOA min TTL for default, then error
+            } else if (!explicit_ttl && default_ttl_) {
+                setCurrentTTL(*default_ttl_);
             }
 
             // TODO: Some more validation?

+ 10 - 3
src/lib/dns/tests/master_loader_unittest.cc

@@ -389,15 +389,22 @@ TEST_F(MasterLoaderTest, includeWithGarbage) {
 
 // Test for "$TTL"
 TEST_F(MasterLoaderTest, ttlDirective) {
+    stringstream zone_stream;
+
     // Set the default TTL with $TTL followed by an RR omitting the TTL
-    const string input("$TTL 1800\n"
-                       "example.org. IN A 192.0.2.1\n");
-    stringstream zone_stream(input);
+    zone_stream << "$TTL 1800\nexample.org. IN A 192.0.2.1\n";
+    // $TTL can be quoted.  Also testing the case of $TTL being changed.
+    zone_stream << "\"$TTL\" 100\na1.example.org. IN A 192.0.2.2\n";
+    // Extended TTL form is accepted.
+    zone_stream << "$TTL 1H\na2.example.org. IN A 192.0.2.3\n";
+
     setLoader(zone_stream, Name("example.org."), RRClass::IN(),
               MasterLoader::DEFAULT);
     loader_->load();
     EXPECT_TRUE(loader_->loadedSucessfully());
     checkRR("example.org", RRType::A(), "192.0.2.1", RRTTL(1800));
+    checkRR("a1.example.org", RRType::A(), "192.0.2.2", RRTTL(100));
+    checkRR("a2.example.org", RRType::A(), "192.0.2.3", RRTTL(3600));
 }
 
 // Test the constructor rejects empty add callback.