|
@@ -17,11 +17,14 @@
|
|
|
#include <dns/rrtype.h>
|
|
|
#include <dns/rrset.h>
|
|
|
#include <dns/rrclass.h>
|
|
|
+#include <dns/rrttl.h>
|
|
|
#include <dns/name.h>
|
|
|
#include <dns/rdata.h>
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
+
|
|
|
#include <boost/bind.hpp>
|
|
|
+#include <boost/lexical_cast.hpp>
|
|
|
#include <boost/scoped_ptr.hpp>
|
|
|
|
|
|
#include <string>
|
|
@@ -35,6 +38,7 @@ using std::string;
|
|
|
using std::list;
|
|
|
using std::stringstream;
|
|
|
using std::endl;
|
|
|
+using boost::lexical_cast;
|
|
|
|
|
|
namespace {
|
|
|
class MasterLoaderTest : public ::testing::Test {
|
|
@@ -102,7 +106,8 @@ public:
|
|
|
|
|
|
// Check the next RR in the ones produced by the loader
|
|
|
// Other than passed arguments are checked to be the default for the tests
|
|
|
- void checkRR(const string& name, const RRType& type, const string& data) {
|
|
|
+ void checkRR(const string& name, const RRType& type, const string& data,
|
|
|
+ const RRTTL& rrttl = RRTTL(3600)) {
|
|
|
ASSERT_FALSE(rrsets_.empty());
|
|
|
RRsetPtr current = rrsets_.front();
|
|
|
rrsets_.pop_front();
|
|
@@ -110,6 +115,7 @@ public:
|
|
|
EXPECT_EQ(Name(name), current->getName());
|
|
|
EXPECT_EQ(type, current->getType());
|
|
|
EXPECT_EQ(RRClass::IN(), current->getClass());
|
|
|
+ EXPECT_EQ(rrttl, current->getTTL());
|
|
|
ASSERT_EQ(1, current->getRdataCount());
|
|
|
EXPECT_EQ(0, isc::dns::rdata::createRdata(type, RRClass::IN(), data)->
|
|
|
compare(current->getRdataIterator()->getCurrent()));
|
|
@@ -267,31 +273,53 @@ TEST_F(MasterLoaderTest, invalidFile) {
|
|
|
|
|
|
struct ErrorCase {
|
|
|
const char* const line; // The broken line in master file
|
|
|
+ const char* const reason; // If non NULL, the reason string
|
|
|
const char* const problem; // Description of the problem for SCOPED_TRACE
|
|
|
} const error_cases[] = {
|
|
|
- { "www... 3600 IN A 192.0.2.1", "Invalid name" },
|
|
|
- { "www FORTNIGHT IN A 192.0.2.1", "Invalid TTL" },
|
|
|
- { "www 3600 XX A 192.0.2.1", "Invalid class" },
|
|
|
- { "www 3600 IN A bad_ip", "Invalid Rdata" },
|
|
|
- { "www 3600 IN", "Unexpected EOLN" },
|
|
|
- { "www 3600 CH TXT nothing", "Class mismatch" },
|
|
|
- { "www \"3600\" IN A 192.0.2.1", "Quoted TTL" },
|
|
|
- { "www 3600 \"IN\" A 192.0.2.1", "Quoted class" },
|
|
|
- { "www 3600 IN \"A\" 192.0.2.1", "Quoted type" },
|
|
|
- { "unbalanced)paren 3600 IN A 192.0.2.1", "Token error 1" },
|
|
|
- { "www 3600 unbalanced)paren A 192.0.2.1", "Token error 2" },
|
|
|
+ { "www... 3600 IN A 192.0.2.1", NULL, "Invalid name" },
|
|
|
+ { "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 3600 IN", NULL, "Unexpected EOLN" },
|
|
|
+ { "www 3600 CH TXT nothing", NULL, "Class mismatch" },
|
|
|
+ { "www \"3600\" IN A 192.0.2.1", NULL, "Quoted TTL" },
|
|
|
+ { "www 3600 \"IN\" A 192.0.2.1", NULL, "Quoted class" },
|
|
|
+ { "www 3600 IN \"A\" 192.0.2.1", NULL, "Quoted type" },
|
|
|
+ { "unbalanced)paren 3600 IN A 192.0.2.1", NULL, "Token error 1" },
|
|
|
+ { "www 3600 unbalanced)paren A 192.0.2.1", NULL,
|
|
|
+ "Token error 2" },
|
|
|
// Check the unknown directive. The rest looks like ordinary RR,
|
|
|
// so we see the $ is actually special.
|
|
|
- { "$UNKNOWN 3600 IN A 192.0.2.1", "Unknown $ directive" },
|
|
|
- { "$INCLUD " TEST_DATA_SRCDIR "/example.org", "Include too short" },
|
|
|
- { "$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",
|
|
|
+ { "$UNKNOWN 3600 IN A 192.0.2.1", NULL, "Unknown $ directive" },
|
|
|
+ { "$INCLUD " TEST_DATA_SRCDIR "/example.org", NULL, "Include too short" },
|
|
|
+ { "$INCLUDES " TEST_DATA_SRCDIR "/example.org", NULL, "Include too long" },
|
|
|
+ { "$INCLUDE", NULL, "Missing include path" },
|
|
|
+ { "$INCLUDE /file/not/found", NULL, "Include file not found" },
|
|
|
+ { "$INCLUDE /file/not/found and here goes bunch of garbage", NULL,
|
|
|
"Include file not found and garbage at the end of line" },
|
|
|
- { NULL, NULL }
|
|
|
+ { "$TTL 100 extra-garbage", "Extra tokens at the end of line",
|
|
|
+ "$TTL with extra token" },
|
|
|
+ { "$TTL", "unexpected end of input", "missing TTL" },
|
|
|
+ { "$TTL No-ttl", "Unknown unit used: N in: No-ttl", "bad TTL" },
|
|
|
+ { "$TTL \"100\"", "invalid TTL: \"100\"", "bad TTL, quoted" },
|
|
|
+ { "$TT 100", "Unknown directive 'TT'", "bad directive, too short" },
|
|
|
+ { "$TTLLIKE 100", "Unknown directive 'TTLLIKE'", "bad directive, extra" },
|
|
|
+ { NULL, NULL, NULL }
|
|
|
};
|
|
|
|
|
|
+// A commonly used helper to check callback message.
|
|
|
+void
|
|
|
+checkCallbackMessage(const string& actual_msg, const string& expected_msg,
|
|
|
+ size_t expected_line) {
|
|
|
+ // The actual message should begin with the expected message.
|
|
|
+ EXPECT_EQ(0, actual_msg.find(expected_msg)) << "actual message: "
|
|
|
+ << actual_msg;
|
|
|
+
|
|
|
+ // and it should end with "...:<line_num>]"
|
|
|
+ const string line_desc = ":" + lexical_cast<string>(expected_line) + "]";
|
|
|
+ EXPECT_EQ(actual_msg.size() - line_desc.size(), actual_msg.find(line_desc));
|
|
|
+}
|
|
|
+
|
|
|
// Test a broken zone is handled properly. We test several problems,
|
|
|
// both in strict and lenient mode.
|
|
|
TEST_F(MasterLoaderTest, brokenZone) {
|
|
@@ -309,6 +337,9 @@ TEST_F(MasterLoaderTest, brokenZone) {
|
|
|
EXPECT_THROW(loader_->load(), MasterLoaderError);
|
|
|
EXPECT_FALSE(loader_->loadedSucessfully());
|
|
|
EXPECT_EQ(1, errors_.size());
|
|
|
+ if (ec->reason != NULL) {
|
|
|
+ checkCallbackMessage(errors_.at(0), ec->reason, 2);
|
|
|
+ }
|
|
|
EXPECT_TRUE(warnings_.empty());
|
|
|
|
|
|
checkRR("example.org", RRType::SOA(), "ns1.example.org. "
|
|
@@ -379,6 +410,158 @@ TEST_F(MasterLoaderTest, includeWithGarbage) {
|
|
|
checkRR("www.example.org", RRType::AAAA(), "2001:db8::1");
|
|
|
}
|
|
|
|
|
|
+// Test for "$TTL"
|
|
|
+TEST_F(MasterLoaderTest, ttlDirective) {
|
|
|
+ stringstream zone_stream;
|
|
|
+
|
|
|
+ // Set the default TTL with $TTL followed by an RR omitting the TTL
|
|
|
+ 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\na.example.org. IN A 192.0.2.2\n";
|
|
|
+ // Extended TTL form is accepted.
|
|
|
+ zone_stream << "$TTL 1H\nb.example.org. IN A 192.0.2.3\n";
|
|
|
+ // Matching is case insensitive.
|
|
|
+ zone_stream << "$tTl 360\nc.example.org. IN A 192.0.2.4\n";
|
|
|
+ // Maximum allowable TTL
|
|
|
+ zone_stream << "$TTL 2147483647\nd.example.org. IN A 192.0.2.5\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("a.example.org", RRType::A(), "192.0.2.2", RRTTL(100));
|
|
|
+ checkRR("b.example.org", RRType::A(), "192.0.2.3", RRTTL(3600));
|
|
|
+ checkRR("c.example.org", RRType::A(), "192.0.2.4", RRTTL(360));
|
|
|
+ checkRR("d.example.org", RRType::A(), "192.0.2.5", RRTTL(2147483647));
|
|
|
+}
|
|
|
+
|
|
|
+TEST_F(MasterLoaderTest, ttlFromSOA) {
|
|
|
+ // No $TTL, and the SOA doesn't have an explicit TTL field. Its minimum
|
|
|
+ // TTL field will be used as the RR's TTL, and it'll be used as the
|
|
|
+ // default TTL for others.
|
|
|
+ stringstream zone_stream("example.org. IN SOA . . 0 0 0 0 1800\n"
|
|
|
+ "a.example.org. IN A 192.0.2.1\n");
|
|
|
+ setLoader(zone_stream, Name("example.org."), RRClass::IN(),
|
|
|
+ MasterLoader::DEFAULT);
|
|
|
+ loader_->load();
|
|
|
+ EXPECT_TRUE(loader_->loadedSucessfully());
|
|
|
+ checkRR("example.org", RRType::SOA(), ". . 0 0 0 0 1800", RRTTL(1800));
|
|
|
+ checkRR("a.example.org", RRType::A(), "192.0.2.1", RRTTL(1800));
|
|
|
+
|
|
|
+ // The use of SOA minimum TTL should have caused a warning.
|
|
|
+ EXPECT_EQ(1, warnings_.size());
|
|
|
+ checkCallbackMessage(warnings_.at(0),
|
|
|
+ "no TTL specified; using SOA MINTTL instead", 1);
|
|
|
+}
|
|
|
+
|
|
|
+TEST_F(MasterLoaderTest, ttlFromPrevious) {
|
|
|
+ // No available default TTL. 2nd and 3rd RR will use the TTL of the
|
|
|
+ // 1st RR. This will result in a warning, but only for the first time.
|
|
|
+ stringstream zone_stream("a.example.org. 1800 IN A 192.0.2.1\n"
|
|
|
+ "b.example.org. IN A 192.0.2.2\n"
|
|
|
+ "c.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("a.example.org", RRType::A(), "192.0.2.1", RRTTL(1800));
|
|
|
+ checkRR("b.example.org", RRType::A(), "192.0.2.2", RRTTL(1800));
|
|
|
+ checkRR("c.example.org", RRType::A(), "192.0.2.3", RRTTL(1800));
|
|
|
+
|
|
|
+ EXPECT_EQ(1, warnings_.size());
|
|
|
+ checkCallbackMessage(warnings_.at(0), "using RFC1035 TTL semantics", 2);
|
|
|
+}
|
|
|
+
|
|
|
+TEST_F(MasterLoaderTest, ttlFromPreviousSOA) {
|
|
|
+ // Mixture of the previous two cases: SOA has explicit TTL, followed by
|
|
|
+ // an RR without an explicit TTL. In this case the minimum TTL won't be
|
|
|
+ // recognized as the "default TTL".
|
|
|
+ stringstream zone_stream("example.org. 100 IN SOA . . 0 0 0 0 1800\n"
|
|
|
+ "a.example.org. IN A 192.0.2.1\n");
|
|
|
+ setLoader(zone_stream, Name("example.org."), RRClass::IN(),
|
|
|
+ MasterLoader::DEFAULT);
|
|
|
+ loader_->load();
|
|
|
+ EXPECT_TRUE(loader_->loadedSucessfully());
|
|
|
+
|
|
|
+ checkRR("example.org", RRType::SOA(), ". . 0 0 0 0 1800", RRTTL(100));
|
|
|
+ checkRR("a.example.org", RRType::A(), "192.0.2.1", RRTTL(100));
|
|
|
+
|
|
|
+ EXPECT_EQ(1, warnings_.size());
|
|
|
+ checkCallbackMessage(warnings_.at(0), "using RFC1035 TTL semantics", 2);
|
|
|
+}
|
|
|
+
|
|
|
+TEST_F(MasterLoaderTest, ttlUnknown) {
|
|
|
+ // No available TTL is known for the first RR.
|
|
|
+ stringstream zone_stream("a.example.org. IN A 192.0.2.1\n");
|
|
|
+ setLoader(zone_stream, Name("example.org."), RRClass::IN(),
|
|
|
+ MasterLoader::DEFAULT);
|
|
|
+ EXPECT_THROW(loader_->load(), MasterLoaderError);
|
|
|
+}
|
|
|
+
|
|
|
+TEST_F(MasterLoaderTest, ttlUnknownAndContinue) {
|
|
|
+ stringstream zone_stream("a.example.org. IN A 192.0.2.1\n"
|
|
|
+ "b.example.org. 1800 IN A 192.0.2.2\n");
|
|
|
+ setLoader(zone_stream, Name("example.org."), RRClass::IN(),
|
|
|
+ MasterLoader::MANY_ERRORS);
|
|
|
+ loader_->load();
|
|
|
+ EXPECT_FALSE(loader_->loadedSucessfully());
|
|
|
+ checkRR("b.example.org", RRType::A(), "192.0.2.2", RRTTL(1800));
|
|
|
+
|
|
|
+ EXPECT_TRUE(warnings_.empty());
|
|
|
+ EXPECT_EQ(1, errors_.size());
|
|
|
+ checkCallbackMessage(errors_.at(0), "no TTL specified; load rejected", 1);
|
|
|
+}
|
|
|
+
|
|
|
+TEST_F(MasterLoaderTest, ttlUnknownAndEOF) {
|
|
|
+ // Similar to the previous case, but the input will be abruptly terminated
|
|
|
+ // after the offending RR. This will cause an additional warning.
|
|
|
+ stringstream zone_stream("a.example.org. IN A 192.0.2.1");
|
|
|
+ setLoader(zone_stream, Name("example.org."), RRClass::IN(),
|
|
|
+ MasterLoader::MANY_ERRORS);
|
|
|
+ loader_->load();
|
|
|
+ EXPECT_FALSE(loader_->loadedSucessfully());
|
|
|
+ EXPECT_TRUE(rrsets_.empty());
|
|
|
+
|
|
|
+ EXPECT_EQ(1, errors_.size());
|
|
|
+ checkCallbackMessage(errors_.at(0), "no TTL specified; load rejected", 1);
|
|
|
+
|
|
|
+ // RDATA implementation can complain about it, too. To be independent of
|
|
|
+ // its details, we focus on the very last warning.
|
|
|
+ EXPECT_FALSE(warnings_.empty());
|
|
|
+ checkCallbackMessage(*warnings_.rbegin(), "Unexpected end of file", 1);
|
|
|
+}
|
|
|
+
|
|
|
+TEST_F(MasterLoaderTest, ttlOverflow) {
|
|
|
+ stringstream zone_stream;
|
|
|
+ zone_stream << "example.org. IN SOA . . 0 0 0 0 2147483648\n";
|
|
|
+ zone_stream << "$TTL 3600\n"; // reset to an in-range value
|
|
|
+ zone_stream << "$TTL 2147483649\n" << "a.example.org. IN A 192.0.2.1\n";
|
|
|
+ zone_stream << "$TTL 3600\n"; // reset to an in-range value
|
|
|
+ zone_stream << "b.example.org. 2147483650 IN A 192.0.2.2\n";
|
|
|
+ setLoader(zone_stream, Name("example.org."), RRClass::IN(),
|
|
|
+ MasterLoader::DEFAULT);
|
|
|
+
|
|
|
+ loader_->load();
|
|
|
+ EXPECT_TRUE(loader_->loadedSucessfully());
|
|
|
+ EXPECT_EQ(3, rrsets_.size());
|
|
|
+
|
|
|
+ checkRR("example.org", RRType::SOA(), ". . 0 0 0 0 2147483648", RRTTL(0));
|
|
|
+ checkRR("a.example.org", RRType::A(), "192.0.2.1", RRTTL(0));
|
|
|
+ checkRR("b.example.org", RRType::A(), "192.0.2.2", RRTTL(0));
|
|
|
+
|
|
|
+ EXPECT_EQ(4, warnings_.size());
|
|
|
+ checkCallbackMessage(warnings_.at(1),
|
|
|
+ "TTL 2147483648 > MAXTTL, setting to 0 per RFC2181",
|
|
|
+ 1);
|
|
|
+ checkCallbackMessage(warnings_.at(2),
|
|
|
+ "TTL 2147483649 > MAXTTL, setting to 0 per RFC2181",
|
|
|
+ 3);
|
|
|
+ checkCallbackMessage(warnings_.at(3),
|
|
|
+ "TTL 2147483650 > MAXTTL, setting to 0 per RFC2181",
|
|
|
+ 6);
|
|
|
+}
|
|
|
+
|
|
|
// Test the constructor rejects empty add callback.
|
|
|
TEST_F(MasterLoaderTest, emptyCallback) {
|
|
|
EXPECT_THROW(MasterLoader(TEST_DATA_SRCDIR "/example.org",
|