|
@@ -22,6 +22,7 @@
|
|
|
#include <datasrc/database.h>
|
|
|
#include <datasrc/zone.h>
|
|
|
#include <datasrc/data_source.h>
|
|
|
+#include <datasrc/iterator.h>
|
|
|
|
|
|
#include <testutils/dnsmessage_test.h>
|
|
|
|
|
@@ -30,132 +31,258 @@
|
|
|
using namespace isc::datasrc;
|
|
|
using namespace std;
|
|
|
using namespace boost;
|
|
|
-using isc::dns::Name;
|
|
|
+using namespace isc::dns;
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
/*
|
|
|
- * A virtual database database that pretends it contains single zone --
|
|
|
- * example.org.
|
|
|
+ * An accessor with minimum implementation, keeping the original
|
|
|
+ * "NotImplemented" methods.
|
|
|
*/
|
|
|
-class MockAccessor : public DatabaseAccessor {
|
|
|
+class NopAccessor : public DatabaseAccessor {
|
|
|
public:
|
|
|
- MockAccessor() : search_running_(false),
|
|
|
- database_name_("mock_database")
|
|
|
- {
|
|
|
- fillData();
|
|
|
- }
|
|
|
+ NopAccessor() : database_name_("mock_database")
|
|
|
+ { }
|
|
|
|
|
|
virtual std::pair<bool, int> getZone(const Name& name) const {
|
|
|
if (name == Name("example.org")) {
|
|
|
return (std::pair<bool, int>(true, 42));
|
|
|
+ } else if (name == Name("null.example.org")) {
|
|
|
+ return (std::pair<bool, int>(true, 13));
|
|
|
+ } else if (name == Name("empty.example.org")) {
|
|
|
+ return (std::pair<bool, int>(true, 0));
|
|
|
+ } else if (name == Name("bad.example.org")) {
|
|
|
+ return (std::pair<bool, int>(true, -1));
|
|
|
} else {
|
|
|
return (std::pair<bool, int>(false, 0));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- virtual void searchForRecords(int zone_id, const std::string& name,
|
|
|
- bool subdomains)
|
|
|
+ virtual const std::string& getDBName() const {
|
|
|
+ return (database_name_);
|
|
|
+ }
|
|
|
+
|
|
|
+ virtual IteratorContextPtr getRecords(const std::string&, int, bool)
|
|
|
+ const
|
|
|
+ {
|
|
|
+ isc_throw(isc::NotImplemented,
|
|
|
+ "This database datasource can't be iterated");
|
|
|
+ };
|
|
|
+
|
|
|
+ virtual IteratorContextPtr getAllRecords(int) const {
|
|
|
+ isc_throw(isc::NotImplemented,
|
|
|
+ "This database datasource can't be iterated");
|
|
|
+ };
|
|
|
+private:
|
|
|
+ const std::string database_name_;
|
|
|
+
|
|
|
+};
|
|
|
+
|
|
|
+/*
|
|
|
+ * A virtual database connection that pretends it contains single zone --
|
|
|
+ * example.org.
|
|
|
+ *
|
|
|
+ * It has the same getZone method as NopConnection, but it provides
|
|
|
+ * implementation of the optional functionality.
|
|
|
+ */
|
|
|
+class MockAccessor : public NopAccessor {
|
|
|
+public:
|
|
|
+ MockAccessor()
|
|
|
{
|
|
|
- search_running_ = true;
|
|
|
-
|
|
|
- // 'hardcoded' name to trigger exceptions (for testing
|
|
|
- // the error handling of find() (the other on is below in
|
|
|
- // if the name is "exceptiononsearch" it'll raise an exception here
|
|
|
- if (name == "dsexception.in.search.") {
|
|
|
- isc_throw(DataSourceError, "datasource exception on search");
|
|
|
- } else if (name == "iscexception.in.search.") {
|
|
|
- isc_throw(isc::Exception, "isc exception on search");
|
|
|
- } else if (name == "basicexception.in.search.") {
|
|
|
- throw std::exception();
|
|
|
- }
|
|
|
- searched_name_ = name;
|
|
|
-
|
|
|
- cur_record = 0;
|
|
|
- if (zone_id == 42) {
|
|
|
- if (subdomains) {
|
|
|
- cur_name.clear();
|
|
|
- // Just walk everything and check if it is a subdomain.
|
|
|
- // If it is, just copy all data from there.
|
|
|
- for (Domains::iterator i(records.begin()); i != records.end();
|
|
|
- ++ i) {
|
|
|
- Name local(i->first);
|
|
|
- if (local.compare(isc::dns::Name(name)).getRelation() ==
|
|
|
- isc::dns::NameComparisonResult::SUBDOMAIN) {
|
|
|
- cur_name.insert(cur_name.end(), i->second.begin(),
|
|
|
- i->second.end());
|
|
|
+ fillData();
|
|
|
+ }
|
|
|
+private:
|
|
|
+ class MockNameIteratorContext : public IteratorContext {
|
|
|
+ public:
|
|
|
+ MockNameIteratorContext(const MockAccessor& mock_accessor, int zone_id,
|
|
|
+ const std::string& name, bool subdomains) :
|
|
|
+ searched_name_(name), cur_record_(0)
|
|
|
+ {
|
|
|
+ // 'hardcoded' names to trigger exceptions
|
|
|
+ // On these names some exceptions are thrown, to test the robustness
|
|
|
+ // of the find() method.
|
|
|
+ if (searched_name_ == "dsexception.in.search.") {
|
|
|
+ isc_throw(DataSourceError, "datasource exception on search");
|
|
|
+ } else if (searched_name_ == "iscexception.in.search.") {
|
|
|
+ isc_throw(isc::Exception, "isc exception on search");
|
|
|
+ } else if (searched_name_ == "basicexception.in.search.") {
|
|
|
+ throw std::exception();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (zone_id == 42) {
|
|
|
+ if (subdomains) {
|
|
|
+ cur_name.clear();
|
|
|
+ // Just walk everything and check if it is a subdomain.
|
|
|
+ // If it is, just copy all data from there.
|
|
|
+ for (Domains::const_iterator
|
|
|
+ i(mock_accessor.records.begin());
|
|
|
+ i != mock_accessor.records.end(); ++ i) {
|
|
|
+ Name local(i->first);
|
|
|
+ if (local.compare(isc::dns::Name(name)).
|
|
|
+ getRelation() ==
|
|
|
+ isc::dns::NameComparisonResult::SUBDOMAIN) {
|
|
|
+ cur_name.insert(cur_name.end(), i->second.begin(),
|
|
|
+ i->second.end());
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (records.count(name) > 0) {
|
|
|
+ } else {
|
|
|
// we're not aiming for efficiency in this test, simply
|
|
|
// copy the relevant vector from records
|
|
|
- cur_name = records.find(name)->second;
|
|
|
- } else {
|
|
|
- cur_name.clear();
|
|
|
+ if (mock_accessor.records.count(searched_name_) > 0) {
|
|
|
+ cur_name = mock_accessor.records.find(searched_name_)->
|
|
|
+ second;
|
|
|
+ } else {
|
|
|
+ cur_name.clear();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- } else {
|
|
|
- cur_name.clear();
|
|
|
}
|
|
|
- };
|
|
|
|
|
|
- virtual bool getNextRecord(std::string columns[], size_t column_count) {
|
|
|
- if (searched_name_ == "dsexception.in.getnext.") {
|
|
|
- isc_throw(DataSourceError, "datasource exception on getnextrecord");
|
|
|
- } else if (searched_name_ == "iscexception.in.getnext.") {
|
|
|
- isc_throw(isc::Exception, "isc exception on getnextrecord");
|
|
|
- } else if (searched_name_ == "basicexception.in.getnext.") {
|
|
|
- throw std::exception();
|
|
|
- }
|
|
|
+ virtual bool getNext(std::string (&columns)[COLUMN_COUNT]) {
|
|
|
+ if (searched_name_ == "dsexception.in.getnext.") {
|
|
|
+ isc_throw(DataSourceError, "datasource exception on getnextrecord");
|
|
|
+ } else if (searched_name_ == "iscexception.in.getnext.") {
|
|
|
+ isc_throw(isc::Exception, "isc exception on getnextrecord");
|
|
|
+ } else if (searched_name_ == "basicexception.in.getnext.") {
|
|
|
+ throw std::exception();
|
|
|
+ }
|
|
|
|
|
|
- if (column_count != DatabaseAccessor::COLUMN_COUNT) {
|
|
|
- isc_throw(DataSourceError, "Wrong column count in getNextRecord");
|
|
|
+ if (cur_record_ < cur_name.size()) {
|
|
|
+ for (size_t i = 0; i < COLUMN_COUNT; ++i) {
|
|
|
+ columns[i] = cur_name[cur_record_][i];
|
|
|
+ }
|
|
|
+ cur_record_++;
|
|
|
+ return (true);
|
|
|
+ } else {
|
|
|
+ return (false);
|
|
|
+ }
|
|
|
}
|
|
|
- if (cur_record < cur_name.size()) {
|
|
|
- for (size_t i = 0; i < column_count; ++i) {
|
|
|
- columns[i] = cur_name[cur_record][i];
|
|
|
+
|
|
|
+ private:
|
|
|
+ const std::string searched_name_;
|
|
|
+ int cur_record_;
|
|
|
+ std::vector< std::vector<std::string> > cur_name;
|
|
|
+ };
|
|
|
+
|
|
|
+ class MockIteratorContext : public IteratorContext {
|
|
|
+ private:
|
|
|
+ int step;
|
|
|
+ public:
|
|
|
+ MockIteratorContext() :
|
|
|
+ step(0)
|
|
|
+ { }
|
|
|
+ virtual bool getNext(string (&data)[COLUMN_COUNT]) {
|
|
|
+ switch (step ++) {
|
|
|
+ case 0:
|
|
|
+ data[DatabaseAccessor::NAME_COLUMN] = "example.org";
|
|
|
+ data[DatabaseAccessor::TYPE_COLUMN] = "SOA";
|
|
|
+ data[DatabaseAccessor::TTL_COLUMN] = "300";
|
|
|
+ data[DatabaseAccessor::RDATA_COLUMN] = "ns1.example.org. admin.example.org. "
|
|
|
+ "1234 3600 1800 2419200 7200";
|
|
|
+ return (true);
|
|
|
+ case 1:
|
|
|
+ data[DatabaseAccessor::NAME_COLUMN] = "x.example.org";
|
|
|
+ data[DatabaseAccessor::TYPE_COLUMN] = "A";
|
|
|
+ data[DatabaseAccessor::TTL_COLUMN] = "300";
|
|
|
+ data[DatabaseAccessor::RDATA_COLUMN] = "192.0.2.1";
|
|
|
+ return (true);
|
|
|
+ case 2:
|
|
|
+ data[DatabaseAccessor::NAME_COLUMN] = "x.example.org";
|
|
|
+ data[DatabaseAccessor::TYPE_COLUMN] = "A";
|
|
|
+ data[DatabaseAccessor::TTL_COLUMN] = "300";
|
|
|
+ data[DatabaseAccessor::RDATA_COLUMN] = "192.0.2.2";
|
|
|
+ return (true);
|
|
|
+ case 3:
|
|
|
+ data[DatabaseAccessor::NAME_COLUMN] = "x.example.org";
|
|
|
+ data[DatabaseAccessor::TYPE_COLUMN] = "AAAA";
|
|
|
+ data[DatabaseAccessor::TTL_COLUMN] = "300";
|
|
|
+ data[DatabaseAccessor::RDATA_COLUMN] = "2001:db8::1";
|
|
|
+ return (true);
|
|
|
+ case 4:
|
|
|
+ data[DatabaseAccessor::NAME_COLUMN] = "x.example.org";
|
|
|
+ data[DatabaseAccessor::TYPE_COLUMN] = "AAAA";
|
|
|
+ data[DatabaseAccessor::TTL_COLUMN] = "300";
|
|
|
+ data[DatabaseAccessor::RDATA_COLUMN] = "2001:db8::2";
|
|
|
+ return (true);
|
|
|
+ default:
|
|
|
+ ADD_FAILURE() <<
|
|
|
+ "Request past the end of iterator context";
|
|
|
+ case 5:
|
|
|
+ return (false);
|
|
|
}
|
|
|
- cur_record++;
|
|
|
- return (true);
|
|
|
- } else {
|
|
|
- resetSearch();
|
|
|
+ }
|
|
|
+ };
|
|
|
+ class EmptyIteratorContext : public IteratorContext {
|
|
|
+ public:
|
|
|
+ virtual bool getNext(string(&)[COLUMN_COUNT]) {
|
|
|
return (false);
|
|
|
}
|
|
|
};
|
|
|
-
|
|
|
- virtual void resetSearch() {
|
|
|
- search_running_ = false;
|
|
|
+ class BadIteratorContext : public IteratorContext {
|
|
|
+ private:
|
|
|
+ int step;
|
|
|
+ public:
|
|
|
+ BadIteratorContext() :
|
|
|
+ step(0)
|
|
|
+ { }
|
|
|
+ virtual bool getNext(string (&data)[COLUMN_COUNT]) {
|
|
|
+ switch (step ++) {
|
|
|
+ case 0:
|
|
|
+ data[DatabaseAccessor::NAME_COLUMN] = "x.example.org";
|
|
|
+ data[DatabaseAccessor::TYPE_COLUMN] = "A";
|
|
|
+ data[DatabaseAccessor::TTL_COLUMN] = "300";
|
|
|
+ data[DatabaseAccessor::RDATA_COLUMN] = "192.0.2.1";
|
|
|
+ return (true);
|
|
|
+ case 1:
|
|
|
+ data[DatabaseAccessor::NAME_COLUMN] = "x.example.org";
|
|
|
+ data[DatabaseAccessor::TYPE_COLUMN] = "A";
|
|
|
+ data[DatabaseAccessor::TTL_COLUMN] = "301";
|
|
|
+ data[DatabaseAccessor::RDATA_COLUMN] = "192.0.2.2";
|
|
|
+ return (true);
|
|
|
+ default:
|
|
|
+ ADD_FAILURE() <<
|
|
|
+ "Request past the end of iterator context";
|
|
|
+ case 2:
|
|
|
+ return (false);
|
|
|
+ }
|
|
|
+ }
|
|
|
};
|
|
|
-
|
|
|
- bool searchRunning() const {
|
|
|
- return (search_running_);
|
|
|
+public:
|
|
|
+ virtual IteratorContextPtr getAllRecords(int id) const {
|
|
|
+ if (id == 42) {
|
|
|
+ return (IteratorContextPtr(new MockIteratorContext()));
|
|
|
+ } else if (id == 13) {
|
|
|
+ return (IteratorContextPtr());
|
|
|
+ } else if (id == 0) {
|
|
|
+ return (IteratorContextPtr(new EmptyIteratorContext()));
|
|
|
+ } else if (id == -1) {
|
|
|
+ return (IteratorContextPtr(new BadIteratorContext()));
|
|
|
+ } else {
|
|
|
+ isc_throw(isc::Unexpected, "Unknown zone ID");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- virtual const std::string& getDBName() const {
|
|
|
- return (database_name_);
|
|
|
+ virtual IteratorContextPtr getRecords(const std::string& name, int id,
|
|
|
+ bool subdomains) const
|
|
|
+ {
|
|
|
+ if (id == 42) {
|
|
|
+ return (IteratorContextPtr(new MockNameIteratorContext(*this, id,
|
|
|
+ name, subdomains)));
|
|
|
+ } else {
|
|
|
+ isc_throw(isc::Unexpected, "Unknown zone ID");
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
private:
|
|
|
typedef std::map<std::string, std::vector< std::vector<std::string> > >
|
|
|
Domains;
|
|
|
+ // used as temporary storage during the building of the fake data
|
|
|
Domains records;
|
|
|
- // used as internal index for getNextRecord()
|
|
|
- size_t cur_record;
|
|
|
// used as temporary storage after searchForRecord() and during
|
|
|
// getNextRecord() calls, as well as during the building of the
|
|
|
// fake data
|
|
|
std::vector< std::vector<std::string> > cur_name;
|
|
|
|
|
|
- // This boolean is used to make sure find() calls resetSearch
|
|
|
- // when it encounters an error
|
|
|
- bool search_running_;
|
|
|
-
|
|
|
- // We store the name passed to searchForRecords, so we can
|
|
|
- // hardcode some exceptions into getNextRecord
|
|
|
- std::string searched_name_;
|
|
|
-
|
|
|
- const std::string database_name_;
|
|
|
-
|
|
|
// Adds one record to the current name in the database
|
|
|
// The actual data will not be added to 'records' until
|
|
|
// addCurName() is called
|
|
@@ -176,6 +303,11 @@ private:
|
|
|
// so we can immediately start adding new records.
|
|
|
void addCurName(const std::string& name) {
|
|
|
ASSERT_EQ(0, records.count(name));
|
|
|
+ // Append the name to all of them
|
|
|
+ for (std::vector<std::vector<std::string> >::iterator
|
|
|
+ i(cur_name.begin()); i != cur_name.end(); ++ i) {
|
|
|
+ i->push_back(name);
|
|
|
+ }
|
|
|
records[name] = cur_name;
|
|
|
cur_name.clear();
|
|
|
}
|
|
@@ -343,6 +475,19 @@ private:
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+// This tests the default getRecords behaviour, throwing NotImplemented
|
|
|
+TEST(DatabaseConnectionTest, getRecords) {
|
|
|
+ EXPECT_THROW(NopAccessor().getRecords(".", 1, false),
|
|
|
+ isc::NotImplemented);
|
|
|
+}
|
|
|
+
|
|
|
+// This tests the default getAllRecords behaviour, throwing NotImplemented
|
|
|
+TEST(DatabaseConnectionTest, getAllRecords) {
|
|
|
+ // The parameters don't matter
|
|
|
+ EXPECT_THROW(NopAccessor().getAllRecords(1),
|
|
|
+ isc::NotImplemented);
|
|
|
+}
|
|
|
+
|
|
|
class DatabaseClientTest : public ::testing::Test {
|
|
|
public:
|
|
|
DatabaseClientTest() {
|
|
@@ -383,7 +528,6 @@ public:
|
|
|
shared_ptr<DatabaseClient::Finder> finder(
|
|
|
dynamic_pointer_cast<DatabaseClient::Finder>(zone.zone_finder));
|
|
|
EXPECT_EQ(42, finder->zone_id());
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
|
|
|
return (finder);
|
|
|
}
|
|
@@ -417,7 +561,94 @@ TEST_F(DatabaseClientTest, noAccessorException) {
|
|
|
isc::InvalidParameter);
|
|
|
}
|
|
|
|
|
|
-namespace {
|
|
|
+// If the zone doesn't exist, exception is thrown
|
|
|
+TEST_F(DatabaseClientTest, noZoneIterator) {
|
|
|
+ EXPECT_THROW(client_->getIterator(Name("example.com")), DataSourceError);
|
|
|
+}
|
|
|
+
|
|
|
+// If the zone doesn't exist and iteration is not implemented, it still throws
|
|
|
+// the exception it doesn't exist
|
|
|
+TEST_F(DatabaseClientTest, noZoneNotImplementedIterator) {
|
|
|
+ EXPECT_THROW(DatabaseClient(boost::shared_ptr<DatabaseAccessor>(
|
|
|
+ new NopAccessor())).getIterator(Name("example.com")),
|
|
|
+ DataSourceError);
|
|
|
+}
|
|
|
+
|
|
|
+TEST_F(DatabaseClientTest, notImplementedIterator) {
|
|
|
+ EXPECT_THROW(DatabaseClient(shared_ptr<DatabaseAccessor>(
|
|
|
+ new NopAccessor())).getIterator(Name("example.org")),
|
|
|
+ isc::NotImplemented);
|
|
|
+}
|
|
|
+
|
|
|
+// Pretend a bug in the connection and pass NULL as the context
|
|
|
+// Should not crash, but gracefully throw
|
|
|
+TEST_F(DatabaseClientTest, nullIteratorContext) {
|
|
|
+ EXPECT_THROW(client_->getIterator(Name("null.example.org")),
|
|
|
+ isc::Unexpected);
|
|
|
+}
|
|
|
+
|
|
|
+// It doesn't crash or anything if the zone is completely empty
|
|
|
+TEST_F(DatabaseClientTest, emptyIterator) {
|
|
|
+ ZoneIteratorPtr it(client_->getIterator(Name("empty.example.org")));
|
|
|
+ EXPECT_EQ(ConstRRsetPtr(), it->getNextRRset());
|
|
|
+ // This is past the end, it should throw
|
|
|
+ EXPECT_THROW(it->getNextRRset(), isc::Unexpected);
|
|
|
+}
|
|
|
+
|
|
|
+// Iterate trough a zone
|
|
|
+TEST_F(DatabaseClientTest, iterator) {
|
|
|
+ ZoneIteratorPtr it(client_->getIterator(Name("example.org")));
|
|
|
+ ConstRRsetPtr rrset(it->getNextRRset());
|
|
|
+ ASSERT_NE(ConstRRsetPtr(), rrset);
|
|
|
+ EXPECT_EQ(Name("example.org"), rrset->getName());
|
|
|
+ EXPECT_EQ(RRClass::IN(), rrset->getClass());
|
|
|
+ EXPECT_EQ(RRType::SOA(), rrset->getType());
|
|
|
+ EXPECT_EQ(RRTTL(300), rrset->getTTL());
|
|
|
+ RdataIteratorPtr rit(rrset->getRdataIterator());
|
|
|
+ ASSERT_FALSE(rit->isLast());
|
|
|
+ rit->next();
|
|
|
+ EXPECT_TRUE(rit->isLast());
|
|
|
+
|
|
|
+ rrset = it->getNextRRset();
|
|
|
+ ASSERT_NE(ConstRRsetPtr(), rrset);
|
|
|
+ EXPECT_EQ(Name("x.example.org"), rrset->getName());
|
|
|
+ EXPECT_EQ(RRClass::IN(), rrset->getClass());
|
|
|
+ EXPECT_EQ(RRType::A(), rrset->getType());
|
|
|
+ EXPECT_EQ(RRTTL(300), rrset->getTTL());
|
|
|
+ rit = rrset->getRdataIterator();
|
|
|
+ ASSERT_FALSE(rit->isLast());
|
|
|
+ EXPECT_EQ("192.0.2.1", rit->getCurrent().toText());
|
|
|
+ rit->next();
|
|
|
+ ASSERT_FALSE(rit->isLast());
|
|
|
+ EXPECT_EQ("192.0.2.2", rit->getCurrent().toText());
|
|
|
+ rit->next();
|
|
|
+ EXPECT_TRUE(rit->isLast());
|
|
|
+
|
|
|
+ rrset = it->getNextRRset();
|
|
|
+ ASSERT_NE(ConstRRsetPtr(), rrset);
|
|
|
+ EXPECT_EQ(Name("x.example.org"), rrset->getName());
|
|
|
+ EXPECT_EQ(RRClass::IN(), rrset->getClass());
|
|
|
+ EXPECT_EQ(RRType::AAAA(), rrset->getType());
|
|
|
+ EXPECT_EQ(RRTTL(300), rrset->getTTL());
|
|
|
+ EXPECT_EQ(ConstRRsetPtr(), it->getNextRRset());
|
|
|
+ rit = rrset->getRdataIterator();
|
|
|
+ ASSERT_FALSE(rit->isLast());
|
|
|
+ EXPECT_EQ("2001:db8::1", rit->getCurrent().toText());
|
|
|
+ rit->next();
|
|
|
+ ASSERT_FALSE(rit->isLast());
|
|
|
+ EXPECT_EQ("2001:db8::2", rit->getCurrent().toText());
|
|
|
+ rit->next();
|
|
|
+ EXPECT_TRUE(rit->isLast());
|
|
|
+}
|
|
|
+
|
|
|
+// This has inconsistent TTL in the set (the rest, like nonsense in
|
|
|
+// the data is handled in rdata itself).
|
|
|
+TEST_F(DatabaseClientTest, badIterator) {
|
|
|
+ // It should not throw, but get the lowest one of them
|
|
|
+ ZoneIteratorPtr it(client_->getIterator(Name("bad.example.org")));
|
|
|
+ EXPECT_EQ(it->getNextRRset()->getTTL(), isc::dns::RRTTL(300));
|
|
|
+}
|
|
|
+
|
|
|
// checks if the given rrset matches the
|
|
|
// given name, class, type and rdatas
|
|
|
void
|
|
@@ -453,12 +684,12 @@ doFindTest(shared_ptr<DatabaseClient::Finder> finder,
|
|
|
ZoneFinder::FindResult result =
|
|
|
finder->find(name, type, NULL, options);
|
|
|
ASSERT_EQ(expected_result, result.code) << name << " " << type;
|
|
|
- if (expected_rdatas.size() > 0) {
|
|
|
+ if (!expected_rdatas.empty()) {
|
|
|
checkRRset(result.rrset, expected_name != Name(".") ? expected_name :
|
|
|
name, finder->getClass(), expected_type, expected_ttl,
|
|
|
expected_rdatas);
|
|
|
|
|
|
- if (expected_sig_rdatas.size() > 0) {
|
|
|
+ if (!expected_sig_rdatas.empty()) {
|
|
|
checkRRset(result.rrset->getRRsig(), expected_name != Name(".") ?
|
|
|
expected_name : name, finder->getClass(),
|
|
|
isc::dns::RRType::RRSIG(), expected_ttl,
|
|
@@ -470,7 +701,6 @@ doFindTest(shared_ptr<DatabaseClient::Finder> finder,
|
|
|
EXPECT_EQ(isc::dns::RRsetPtr(), result.rrset);
|
|
|
}
|
|
|
}
|
|
|
-} // end anonymous namespace
|
|
|
|
|
|
TEST_F(DatabaseClientTest, find) {
|
|
|
shared_ptr<DatabaseClient::Finder> finder(getFinder());
|
|
@@ -483,7 +713,6 @@ TEST_F(DatabaseClientTest, find) {
|
|
|
isc::dns::RRTTL(3600),
|
|
|
ZoneFinder::SUCCESS,
|
|
|
expected_rdatas_, expected_sig_rdatas_);
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
|
|
|
expected_rdatas_.clear();
|
|
|
expected_sig_rdatas_.clear();
|
|
@@ -494,7 +723,6 @@ TEST_F(DatabaseClientTest, find) {
|
|
|
isc::dns::RRTTL(3600),
|
|
|
ZoneFinder::SUCCESS,
|
|
|
expected_rdatas_, expected_sig_rdatas_);
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
|
|
|
expected_rdatas_.clear();
|
|
|
expected_sig_rdatas_.clear();
|
|
@@ -505,7 +733,6 @@ TEST_F(DatabaseClientTest, find) {
|
|
|
isc::dns::RRTTL(3600),
|
|
|
ZoneFinder::SUCCESS,
|
|
|
expected_rdatas_, expected_sig_rdatas_);
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
|
|
|
expected_rdatas_.clear();
|
|
|
expected_sig_rdatas_.clear();
|
|
@@ -514,7 +741,6 @@ TEST_F(DatabaseClientTest, find) {
|
|
|
isc::dns::RRTTL(3600),
|
|
|
ZoneFinder::NXRRSET,
|
|
|
expected_rdatas_, expected_sig_rdatas_);
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
|
|
|
expected_rdatas_.clear();
|
|
|
expected_sig_rdatas_.clear();
|
|
@@ -524,7 +750,6 @@ TEST_F(DatabaseClientTest, find) {
|
|
|
isc::dns::RRTTL(3600),
|
|
|
ZoneFinder::CNAME,
|
|
|
expected_rdatas_, expected_sig_rdatas_);
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
|
|
|
expected_rdatas_.clear();
|
|
|
expected_sig_rdatas_.clear();
|
|
@@ -534,7 +759,6 @@ TEST_F(DatabaseClientTest, find) {
|
|
|
isc::dns::RRTTL(3600),
|
|
|
ZoneFinder::SUCCESS,
|
|
|
expected_rdatas_, expected_sig_rdatas_);
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
|
|
|
expected_rdatas_.clear();
|
|
|
expected_sig_rdatas_.clear();
|
|
@@ -543,7 +767,6 @@ TEST_F(DatabaseClientTest, find) {
|
|
|
isc::dns::RRTTL(3600),
|
|
|
ZoneFinder::NXDOMAIN,
|
|
|
expected_rdatas_, expected_sig_rdatas_);
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
|
|
|
expected_rdatas_.clear();
|
|
|
expected_sig_rdatas_.clear();
|
|
@@ -555,7 +778,6 @@ TEST_F(DatabaseClientTest, find) {
|
|
|
isc::dns::RRTTL(3600),
|
|
|
ZoneFinder::SUCCESS,
|
|
|
expected_rdatas_, expected_sig_rdatas_);
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
|
|
|
expected_rdatas_.clear();
|
|
|
expected_sig_rdatas_.clear();
|
|
@@ -567,7 +789,6 @@ TEST_F(DatabaseClientTest, find) {
|
|
|
isc::dns::RRTTL(3600),
|
|
|
ZoneFinder::SUCCESS,
|
|
|
expected_rdatas_, expected_sig_rdatas_);
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
|
|
|
expected_rdatas_.clear();
|
|
|
expected_sig_rdatas_.clear();
|
|
@@ -576,7 +797,6 @@ TEST_F(DatabaseClientTest, find) {
|
|
|
isc::dns::RRTTL(3600),
|
|
|
ZoneFinder::NXRRSET,
|
|
|
expected_rdatas_, expected_sig_rdatas_);
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
|
|
|
expected_rdatas_.clear();
|
|
|
expected_sig_rdatas_.clear();
|
|
@@ -587,7 +807,6 @@ TEST_F(DatabaseClientTest, find) {
|
|
|
isc::dns::RRTTL(3600),
|
|
|
ZoneFinder::CNAME,
|
|
|
expected_rdatas_, expected_sig_rdatas_);
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
|
|
|
expected_rdatas_.clear();
|
|
|
expected_sig_rdatas_.clear();
|
|
@@ -599,7 +818,6 @@ TEST_F(DatabaseClientTest, find) {
|
|
|
isc::dns::RRTTL(3600),
|
|
|
ZoneFinder::SUCCESS,
|
|
|
expected_rdatas_, expected_sig_rdatas_);
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
|
|
|
expected_rdatas_.clear();
|
|
|
expected_sig_rdatas_.clear();
|
|
@@ -611,7 +829,6 @@ TEST_F(DatabaseClientTest, find) {
|
|
|
isc::dns::RRTTL(3600),
|
|
|
ZoneFinder::SUCCESS,
|
|
|
expected_rdatas_, expected_sig_rdatas_);
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
|
|
|
expected_rdatas_.clear();
|
|
|
expected_sig_rdatas_.clear();
|
|
@@ -620,7 +837,6 @@ TEST_F(DatabaseClientTest, find) {
|
|
|
isc::dns::RRTTL(3600),
|
|
|
ZoneFinder::NXRRSET,
|
|
|
expected_rdatas_, expected_sig_rdatas_);
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
|
|
|
expected_rdatas_.clear();
|
|
|
expected_sig_rdatas_.clear();
|
|
@@ -631,7 +847,6 @@ TEST_F(DatabaseClientTest, find) {
|
|
|
isc::dns::RRTTL(3600),
|
|
|
ZoneFinder::CNAME,
|
|
|
expected_rdatas_, expected_sig_rdatas_);
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
|
|
|
|
|
|
expected_rdatas_.clear();
|
|
@@ -643,7 +858,6 @@ TEST_F(DatabaseClientTest, find) {
|
|
|
isc::dns::RRTTL(3600),
|
|
|
ZoneFinder::SUCCESS,
|
|
|
expected_rdatas_, expected_sig_rdatas_);
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
|
|
|
expected_rdatas_.clear();
|
|
|
expected_sig_rdatas_.clear();
|
|
@@ -654,7 +868,6 @@ TEST_F(DatabaseClientTest, find) {
|
|
|
isc::dns::RRTTL(3600),
|
|
|
ZoneFinder::SUCCESS,
|
|
|
expected_rdatas_, expected_sig_rdatas_);
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
|
|
|
expected_rdatas_.clear();
|
|
|
expected_sig_rdatas_.clear();
|
|
@@ -665,7 +878,6 @@ TEST_F(DatabaseClientTest, find) {
|
|
|
isc::dns::RRTTL(3600),
|
|
|
ZoneFinder::SUCCESS,
|
|
|
expected_rdatas_, expected_sig_rdatas_);
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
|
|
|
expected_rdatas_.clear();
|
|
|
expected_sig_rdatas_.clear();
|
|
@@ -676,7 +888,6 @@ TEST_F(DatabaseClientTest, find) {
|
|
|
isc::dns::RRTTL(360),
|
|
|
ZoneFinder::SUCCESS,
|
|
|
expected_rdatas_, expected_sig_rdatas_);
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
|
|
|
expected_rdatas_.clear();
|
|
|
expected_sig_rdatas_.clear();
|
|
@@ -687,77 +898,63 @@ TEST_F(DatabaseClientTest, find) {
|
|
|
isc::dns::RRTTL(360),
|
|
|
ZoneFinder::SUCCESS,
|
|
|
expected_rdatas_, expected_sig_rdatas_);
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
|
|
|
|
|
|
EXPECT_THROW(finder->find(isc::dns::Name("badcname1.example.org."),
|
|
|
isc::dns::RRType::A(),
|
|
|
NULL, ZoneFinder::FIND_DEFAULT),
|
|
|
DataSourceError);
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
EXPECT_THROW(finder->find(isc::dns::Name("badcname2.example.org."),
|
|
|
isc::dns::RRType::A(),
|
|
|
NULL, ZoneFinder::FIND_DEFAULT),
|
|
|
DataSourceError);
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
EXPECT_THROW(finder->find(isc::dns::Name("badcname3.example.org."),
|
|
|
isc::dns::RRType::A(),
|
|
|
NULL, ZoneFinder::FIND_DEFAULT),
|
|
|
DataSourceError);
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
EXPECT_THROW(finder->find(isc::dns::Name("badrdata.example.org."),
|
|
|
isc::dns::RRType::A(),
|
|
|
NULL, ZoneFinder::FIND_DEFAULT),
|
|
|
DataSourceError);
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
EXPECT_THROW(finder->find(isc::dns::Name("badtype.example.org."),
|
|
|
isc::dns::RRType::A(),
|
|
|
NULL, ZoneFinder::FIND_DEFAULT),
|
|
|
DataSourceError);
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
EXPECT_THROW(finder->find(isc::dns::Name("badttl.example.org."),
|
|
|
isc::dns::RRType::A(),
|
|
|
NULL, ZoneFinder::FIND_DEFAULT),
|
|
|
DataSourceError);
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
EXPECT_THROW(finder->find(isc::dns::Name("badsig.example.org."),
|
|
|
isc::dns::RRType::A(),
|
|
|
NULL, ZoneFinder::FIND_DEFAULT),
|
|
|
DataSourceError);
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
|
|
|
// Trigger the hardcoded exceptions and see if find() has cleaned up
|
|
|
EXPECT_THROW(finder->find(isc::dns::Name("dsexception.in.search."),
|
|
|
isc::dns::RRType::A(),
|
|
|
NULL, ZoneFinder::FIND_DEFAULT),
|
|
|
DataSourceError);
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
EXPECT_THROW(finder->find(isc::dns::Name("iscexception.in.search."),
|
|
|
isc::dns::RRType::A(),
|
|
|
NULL, ZoneFinder::FIND_DEFAULT),
|
|
|
- DataSourceError);
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
+ isc::Exception);
|
|
|
EXPECT_THROW(finder->find(isc::dns::Name("basicexception.in.search."),
|
|
|
isc::dns::RRType::A(),
|
|
|
NULL, ZoneFinder::FIND_DEFAULT),
|
|
|
std::exception);
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
|
|
|
EXPECT_THROW(finder->find(isc::dns::Name("dsexception.in.getnext."),
|
|
|
isc::dns::RRType::A(),
|
|
|
NULL, ZoneFinder::FIND_DEFAULT),
|
|
|
DataSourceError);
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
EXPECT_THROW(finder->find(isc::dns::Name("iscexception.in.getnext."),
|
|
|
isc::dns::RRType::A(),
|
|
|
NULL, ZoneFinder::FIND_DEFAULT),
|
|
|
- DataSourceError);
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
+ isc::Exception);
|
|
|
EXPECT_THROW(finder->find(isc::dns::Name("basicexception.in.getnext."),
|
|
|
isc::dns::RRType::A(),
|
|
|
NULL, ZoneFinder::FIND_DEFAULT),
|
|
|
std::exception);
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
|
|
|
// This RRSIG has the wrong sigtype field, which should be
|
|
|
// an error if we decide to keep using that field
|
|
@@ -771,7 +968,6 @@ TEST_F(DatabaseClientTest, find) {
|
|
|
isc::dns::RRTTL(3600),
|
|
|
ZoneFinder::SUCCESS,
|
|
|
expected_rdatas_, expected_sig_rdatas_);
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
}
|
|
|
|
|
|
TEST_F(DatabaseClientTest, findDelegation) {
|
|
@@ -786,7 +982,6 @@ TEST_F(DatabaseClientTest, findDelegation) {
|
|
|
isc::dns::RRType::A(), isc::dns::RRType::A(),
|
|
|
isc::dns::RRTTL(3600), ZoneFinder::SUCCESS, expected_rdatas_,
|
|
|
expected_sig_rdatas_);
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
|
|
|
expected_rdatas_.clear();
|
|
|
expected_rdatas_.push_back("ns.example.com.");
|
|
@@ -796,7 +991,6 @@ TEST_F(DatabaseClientTest, findDelegation) {
|
|
|
isc::dns::RRType::NS(), isc::dns::RRType::NS(),
|
|
|
isc::dns::RRTTL(3600), ZoneFinder::SUCCESS, expected_rdatas_,
|
|
|
expected_sig_rdatas_);
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
|
|
|
// Check when we ask for something below delegation point, we get the NS
|
|
|
// (Both when the RRset there exists and doesn't)
|
|
@@ -811,7 +1005,6 @@ TEST_F(DatabaseClientTest, findDelegation) {
|
|
|
isc::dns::RRTTL(3600), ZoneFinder::DELEGATION, expected_rdatas_,
|
|
|
expected_sig_rdatas_,
|
|
|
isc::dns::Name("delegation.example.org."));
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
doFindTest(finder, isc::dns::Name("ns.delegation.example.org."),
|
|
|
isc::dns::RRType::AAAA(), isc::dns::RRType::NS(),
|
|
|
isc::dns::RRTTL(3600), ZoneFinder::DELEGATION, expected_rdatas_,
|
|
@@ -822,7 +1015,6 @@ TEST_F(DatabaseClientTest, findDelegation) {
|
|
|
isc::dns::RRTTL(3600), ZoneFinder::DELEGATION, expected_rdatas_,
|
|
|
expected_sig_rdatas_,
|
|
|
isc::dns::Name("delegation.example.org."));
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
|
|
|
// Even when we check directly at the delegation point, we should get
|
|
|
// the NS
|
|
@@ -830,14 +1022,12 @@ TEST_F(DatabaseClientTest, findDelegation) {
|
|
|
isc::dns::RRType::AAAA(), isc::dns::RRType::NS(),
|
|
|
isc::dns::RRTTL(3600), ZoneFinder::DELEGATION, expected_rdatas_,
|
|
|
expected_sig_rdatas_);
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
|
|
|
// And when we ask direcly for the NS, we should still get delegation
|
|
|
doFindTest(finder, isc::dns::Name("delegation.example.org."),
|
|
|
isc::dns::RRType::NS(), isc::dns::RRType::NS(),
|
|
|
isc::dns::RRTTL(3600), ZoneFinder::DELEGATION, expected_rdatas_,
|
|
|
expected_sig_rdatas_);
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
|
|
|
// Now test delegation. If it is below the delegation point, we should get
|
|
|
// the DNAME (the one with data under DNAME is invalid zone, but we test
|
|
@@ -852,17 +1042,14 @@ TEST_F(DatabaseClientTest, findDelegation) {
|
|
|
isc::dns::RRType::A(), isc::dns::RRType::DNAME(),
|
|
|
isc::dns::RRTTL(3600), ZoneFinder::DNAME, expected_rdatas_,
|
|
|
expected_sig_rdatas_, isc::dns::Name("dname.example.org."));
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
doFindTest(finder, isc::dns::Name("below.dname.example.org."),
|
|
|
isc::dns::RRType::AAAA(), isc::dns::RRType::DNAME(),
|
|
|
isc::dns::RRTTL(3600), ZoneFinder::DNAME, expected_rdatas_,
|
|
|
expected_sig_rdatas_, isc::dns::Name("dname.example.org."));
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
doFindTest(finder, isc::dns::Name("really.deep.below.dname.example.org."),
|
|
|
isc::dns::RRType::AAAA(), isc::dns::RRType::DNAME(),
|
|
|
isc::dns::RRTTL(3600), ZoneFinder::DNAME, expected_rdatas_,
|
|
|
expected_sig_rdatas_, isc::dns::Name("dname.example.org."));
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
|
|
|
// Asking direcly for DNAME should give SUCCESS
|
|
|
doFindTest(finder, isc::dns::Name("dname.example.org."),
|
|
@@ -878,33 +1065,27 @@ TEST_F(DatabaseClientTest, findDelegation) {
|
|
|
isc::dns::RRType::A(), isc::dns::RRType::A(),
|
|
|
isc::dns::RRTTL(3600), ZoneFinder::SUCCESS, expected_rdatas_,
|
|
|
expected_sig_rdatas_);
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
expected_rdatas_.clear();
|
|
|
doFindTest(finder, isc::dns::Name("dname.example.org."),
|
|
|
isc::dns::RRType::AAAA(), isc::dns::RRType::AAAA(),
|
|
|
isc::dns::RRTTL(3600), ZoneFinder::NXRRSET, expected_rdatas_,
|
|
|
expected_sig_rdatas_);
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
|
|
|
// This is broken dname, it contains two targets
|
|
|
EXPECT_THROW(finder->find(isc::dns::Name("below.baddname.example.org."),
|
|
|
isc::dns::RRType::A(), NULL,
|
|
|
ZoneFinder::FIND_DEFAULT),
|
|
|
DataSourceError);
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
|
|
|
// Broken NS - it lives together with something else
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
EXPECT_THROW(finder->find(isc::dns::Name("brokenns1.example.org."),
|
|
|
isc::dns::RRType::A(), NULL,
|
|
|
ZoneFinder::FIND_DEFAULT),
|
|
|
DataSourceError);
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
EXPECT_THROW(finder->find(isc::dns::Name("brokenns2.example.org."),
|
|
|
isc::dns::RRType::A(), NULL,
|
|
|
ZoneFinder::FIND_DEFAULT),
|
|
|
DataSourceError);
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
}
|
|
|
|
|
|
TEST_F(DatabaseClientTest, emptyDomain) {
|
|
@@ -969,13 +1150,11 @@ TEST_F(DatabaseClientTest, glueOK) {
|
|
|
isc::dns::RRTTL(3600), ZoneFinder::DNAME, expected_rdatas_,
|
|
|
expected_sig_rdatas_, isc::dns::Name("dname.example.org."),
|
|
|
ZoneFinder::FIND_GLUE_OK);
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
doFindTest(finder, isc::dns::Name("below.dname.example.org."),
|
|
|
isc::dns::RRType::AAAA(), isc::dns::RRType::DNAME(),
|
|
|
isc::dns::RRTTL(3600), ZoneFinder::DNAME, expected_rdatas_,
|
|
|
expected_sig_rdatas_, isc::dns::Name("dname.example.org."),
|
|
|
ZoneFinder::FIND_GLUE_OK);
|
|
|
- EXPECT_FALSE(current_database_->searchRunning());
|
|
|
}
|
|
|
|
|
|
TEST_F(DatabaseClientTest, wildcard) {
|