2011-08-01 11:47:37 +02:00
|
|
|
// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice appear in all copies.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
|
|
|
|
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
|
|
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
|
|
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
|
|
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
|
|
|
|
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
|
// PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
#include <dns/name.h>
|
2011-08-09 11:19:13 +02:00
|
|
|
#include <dns/rrttl.h>
|
2011-08-11 17:31:06 +02:00
|
|
|
#include <dns/rrset.h>
|
2011-08-01 12:03:35 +02:00
|
|
|
#include <exceptions/exceptions.h>
|
2011-08-01 11:47:37 +02:00
|
|
|
|
|
|
|
#include <datasrc/database.h>
|
2011-08-04 14:32:53 +02:00
|
|
|
#include <datasrc/zone.h>
|
|
|
|
#include <datasrc/data_source.h>
|
2011-08-05 15:18:00 +02:00
|
|
|
#include <datasrc/iterator.h>
|
2011-08-04 14:32:53 +02:00
|
|
|
|
2011-08-11 17:31:06 +02:00
|
|
|
#include <testutils/dnsmessage_test.h>
|
|
|
|
|
2011-08-04 14:32:53 +02:00
|
|
|
#include <map>
|
2011-08-01 11:47:37 +02:00
|
|
|
|
|
|
|
using namespace isc::datasrc;
|
|
|
|
using namespace std;
|
|
|
|
using namespace boost;
|
2011-08-05 15:18:00 +02:00
|
|
|
using namespace isc::dns;
|
2011-08-01 11:47:37 +02:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
/*
|
2011-08-11 20:09:20 +02:00
|
|
|
* An accessor with minimum implementation, keeping the original
|
2011-08-05 15:18:00 +02:00
|
|
|
* "NotImplemented" methods.
|
2011-08-01 11:47:37 +02:00
|
|
|
*/
|
2011-08-11 20:09:20 +02:00
|
|
|
class NopAccessor : public DatabaseAccessor {
|
2011-08-01 11:47:37 +02:00
|
|
|
public:
|
2011-08-15 16:45:26 +02:00
|
|
|
NopAccessor() : database_name_("mock_database")
|
|
|
|
{ }
|
2011-08-04 14:32:53 +02:00
|
|
|
|
2011-08-01 11:47:37 +02:00
|
|
|
virtual std::pair<bool, int> getZone(const Name& name) const {
|
2011-08-01 13:06:13 +02:00
|
|
|
if (name == Name("example.org")) {
|
2011-08-01 11:47:37 +02:00
|
|
|
return (std::pair<bool, int>(true, 42));
|
2011-08-05 15:18:00 +02:00
|
|
|
} 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));
|
2011-08-01 11:47:37 +02:00
|
|
|
} else {
|
|
|
|
return (std::pair<bool, int>(false, 0));
|
|
|
|
}
|
|
|
|
}
|
2011-08-04 14:32:53 +02:00
|
|
|
|
2011-08-15 16:45:26 +02:00
|
|
|
virtual const std::string& getDBName() const {
|
|
|
|
return (database_name_);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const std::string database_name_;
|
|
|
|
|
2011-08-01 11:47:37 +02:00
|
|
|
};
|
|
|
|
|
2011-08-05 15:18:00 +02:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2011-08-11 20:09:20 +02:00
|
|
|
class MockAccessor : public NopAccessor {
|
2011-08-15 16:45:26 +02:00
|
|
|
public:
|
2011-08-18 12:19:56 +02:00
|
|
|
MockAccessor()
|
2011-08-15 16:45:26 +02:00
|
|
|
{
|
|
|
|
fillData();
|
|
|
|
}
|
2011-08-05 15:18:00 +02:00
|
|
|
private:
|
2011-08-18 12:01:50 +02:00
|
|
|
class MockNameIteratorContext : public IteratorContext {
|
|
|
|
public:
|
|
|
|
MockNameIteratorContext(const MockAccessor& mock_accessor, int zone_id,
|
|
|
|
const isc::dns::Name& name) :
|
|
|
|
searched_name_(name.toText()), cur_record_(0)
|
|
|
|
{
|
|
|
|
// '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 (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();
|
|
|
|
}
|
|
|
|
|
|
|
|
// we're not aiming for efficiency in this test, simply
|
|
|
|
// copy the relevant vector from records
|
|
|
|
if (zone_id == 42) {
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-18 15:34:50 +02:00
|
|
|
virtual bool getNext(std::string (&columns)[COLUMN_COUNT]) {
|
2011-08-18 12:01:50 +02:00
|
|
|
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 (cur_record_ < cur_name.size()) {
|
2011-08-18 15:34:50 +02:00
|
|
|
for (size_t i = 0; i < COLUMN_COUNT; ++i) {
|
2011-08-18 12:01:50 +02:00
|
|
|
columns[i] = cur_name[cur_record_][i];
|
|
|
|
}
|
|
|
|
cur_record_++;
|
|
|
|
return (true);
|
|
|
|
} else {
|
|
|
|
return (false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const std::string searched_name_;
|
|
|
|
int cur_record_;
|
|
|
|
std::vector< std::vector<std::string> > cur_name;
|
|
|
|
};
|
|
|
|
|
2011-08-05 15:18:00 +02:00
|
|
|
class MockIteratorContext : public IteratorContext {
|
|
|
|
private:
|
|
|
|
int step;
|
|
|
|
public:
|
|
|
|
MockIteratorContext() :
|
|
|
|
step(0)
|
|
|
|
{ }
|
2011-08-18 15:34:50 +02:00
|
|
|
virtual bool getNext(string (&data)[COLUMN_COUNT]) {
|
2011-08-05 15:18:00 +02:00
|
|
|
switch (step ++) {
|
|
|
|
case 0:
|
2011-08-16 11:53:45 +02:00
|
|
|
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. "
|
2011-08-05 15:18:00 +02:00
|
|
|
"1234 3600 1800 2419200 7200";
|
|
|
|
return (true);
|
|
|
|
case 1:
|
2011-08-16 11:53:45 +02:00
|
|
|
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";
|
2011-08-05 15:18:00 +02:00
|
|
|
return (true);
|
|
|
|
case 2:
|
2011-08-16 11:53:45 +02:00
|
|
|
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";
|
2011-08-05 15:18:00 +02:00
|
|
|
return (true);
|
|
|
|
case 3:
|
2011-08-16 11:53:45 +02:00
|
|
|
data[DatabaseAccessor::NAME_COLUMN] = "x.example.org";
|
|
|
|
data[DatabaseAccessor::TYPE_COLUMN] = "AAAA";
|
|
|
|
data[DatabaseAccessor::TTL_COLUMN] = "300";
|
|
|
|
data[DatabaseAccessor::RDATA_COLUMN] = "2001:db8::1";
|
2011-08-05 15:18:00 +02:00
|
|
|
return (true);
|
|
|
|
case 4:
|
2011-08-16 11:53:45 +02:00
|
|
|
data[DatabaseAccessor::NAME_COLUMN] = "x.example.org";
|
|
|
|
data[DatabaseAccessor::TYPE_COLUMN] = "AAAA";
|
|
|
|
data[DatabaseAccessor::TTL_COLUMN] = "300";
|
|
|
|
data[DatabaseAccessor::RDATA_COLUMN] = "2001:db8::2";
|
2011-08-05 15:18:00 +02:00
|
|
|
return (true);
|
|
|
|
default:
|
|
|
|
ADD_FAILURE() <<
|
|
|
|
"Request past the end of iterator context";
|
|
|
|
case 5:
|
|
|
|
return (false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
class EmptyIteratorContext : public IteratorContext {
|
|
|
|
public:
|
2011-08-18 15:34:50 +02:00
|
|
|
virtual bool getNext(string(&)[COLUMN_COUNT]) {
|
2011-08-05 15:18:00 +02:00
|
|
|
return (false);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
class BadIteratorContext : public IteratorContext {
|
|
|
|
private:
|
|
|
|
int step;
|
|
|
|
public:
|
|
|
|
BadIteratorContext() :
|
|
|
|
step(0)
|
|
|
|
{ }
|
2011-08-18 15:34:50 +02:00
|
|
|
virtual bool getNext(string (&data)[COLUMN_COUNT]) {
|
2011-08-05 15:18:00 +02:00
|
|
|
switch (step ++) {
|
|
|
|
case 0:
|
2011-08-16 11:53:45 +02:00
|
|
|
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";
|
2011-08-05 15:18:00 +02:00
|
|
|
return (true);
|
|
|
|
case 1:
|
2011-08-16 11:53:45 +02:00
|
|
|
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";
|
2011-08-05 15:18:00 +02:00
|
|
|
return (true);
|
|
|
|
default:
|
|
|
|
ADD_FAILURE() <<
|
|
|
|
"Request past the end of iterator context";
|
|
|
|
case 2:
|
|
|
|
return (false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
public:
|
2011-08-18 15:01:51 +02:00
|
|
|
virtual IteratorContextPtr getAllRecords(int id) const {
|
2011-08-05 15:18:00 +02:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
2011-08-15 16:45:26 +02:00
|
|
|
|
2011-08-18 12:01:50 +02:00
|
|
|
virtual IteratorContextPtr getRecords(const Name& name, int id) const {
|
|
|
|
if (id == 42) {
|
|
|
|
return (IteratorContextPtr(new MockNameIteratorContext(*this, id, name)));
|
|
|
|
} else {
|
|
|
|
isc_throw(isc::Unexpected, "Unknown zone ID");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-04 14:32:53 +02:00
|
|
|
private:
|
|
|
|
std::map<std::string, std::vector< std::vector<std::string> > > records;
|
2011-08-18 15:49:38 -07:00
|
|
|
// used as temporary storage during the building of the fake data
|
2011-08-04 14:32:53 +02:00
|
|
|
std::vector< std::vector<std::string> > cur_name;
|
|
|
|
|
2011-08-04 22:12:04 +02:00
|
|
|
// Adds one record to the current name in the database
|
|
|
|
// The actual data will not be added to 'records' until
|
|
|
|
// addCurName() is called
|
2011-08-04 14:32:53 +02:00
|
|
|
void addRecord(const std::string& name,
|
|
|
|
const std::string& type,
|
|
|
|
const std::string& sigtype,
|
|
|
|
const std::string& rdata) {
|
|
|
|
std::vector<std::string> columns;
|
|
|
|
columns.push_back(name);
|
|
|
|
columns.push_back(type);
|
|
|
|
columns.push_back(sigtype);
|
|
|
|
columns.push_back(rdata);
|
|
|
|
cur_name.push_back(columns);
|
|
|
|
}
|
|
|
|
|
2011-08-04 22:12:04 +02:00
|
|
|
// Adds all records we just built with calls to addRecords
|
|
|
|
// to the actual fake database. This will clear cur_name,
|
|
|
|
// so we can immediately start adding new records.
|
2011-08-04 14:32:53 +02:00
|
|
|
void addCurName(const std::string& name) {
|
2011-08-04 22:12:04 +02:00
|
|
|
ASSERT_EQ(0, records.count(name));
|
2011-08-16 11:13:30 +02:00
|
|
|
// 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);
|
|
|
|
}
|
2011-08-04 14:32:53 +02:00
|
|
|
records[name] = cur_name;
|
|
|
|
cur_name.clear();
|
|
|
|
}
|
|
|
|
|
2011-08-04 22:12:04 +02:00
|
|
|
// Fills the database with zone data.
|
|
|
|
// This method constructs a number of resource records (with addRecord),
|
|
|
|
// which will all be added for one domain name to the fake database
|
|
|
|
// (with addCurName). So for instance the first set of calls create
|
|
|
|
// data for the name 'www.example.org', which will consist of one A RRset
|
|
|
|
// of one record, and one AAAA RRset of two records.
|
|
|
|
// The order in which they are added is the order in which getNextRecord()
|
|
|
|
// will return them (so we can test whether find() etc. support data that
|
|
|
|
// might not come in 'normal' order)
|
|
|
|
// It shall immediately fail if you try to add the same name twice.
|
2011-08-04 14:32:53 +02:00
|
|
|
void fillData() {
|
2011-08-04 21:27:38 +02:00
|
|
|
// some plain data
|
2011-08-04 14:32:53 +02:00
|
|
|
addRecord("A", "3600", "", "192.0.2.1");
|
|
|
|
addRecord("AAAA", "3600", "", "2001:db8::1");
|
|
|
|
addRecord("AAAA", "3600", "", "2001:db8::2");
|
|
|
|
addCurName("www.example.org.");
|
2011-08-04 22:12:04 +02:00
|
|
|
|
2011-08-09 11:19:13 +02:00
|
|
|
addRecord("A", "3600", "", "192.0.2.1");
|
|
|
|
addRecord("AAAA", "3600", "", "2001:db8::1");
|
|
|
|
addRecord("A", "3600", "", "192.0.2.2");
|
|
|
|
addCurName("www2.example.org.");
|
|
|
|
|
2011-08-04 14:32:53 +02:00
|
|
|
addRecord("CNAME", "3600", "", "www.example.org.");
|
|
|
|
addCurName("cname.example.org.");
|
|
|
|
|
2011-08-04 21:27:38 +02:00
|
|
|
// some DNSSEC-'signed' data
|
|
|
|
addRecord("A", "3600", "", "192.0.2.1");
|
|
|
|
addRecord("RRSIG", "3600", "", "A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
|
2011-08-05 18:02:33 +02:00
|
|
|
addRecord("RRSIG", "3600", "", "A 5 3 3600 20000101000000 20000201000000 12346 example.org. FAKEFAKEFAKE");
|
2011-08-04 21:27:38 +02:00
|
|
|
addRecord("AAAA", "3600", "", "2001:db8::1");
|
|
|
|
addRecord("AAAA", "3600", "", "2001:db8::2");
|
|
|
|
addRecord("RRSIG", "3600", "", "AAAA 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
|
|
|
|
addCurName("signed1.example.org.");
|
2011-08-04 21:57:16 +02:00
|
|
|
addRecord("CNAME", "3600", "", "www.example.org.");
|
|
|
|
addRecord("RRSIG", "3600", "", "CNAME 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
|
|
|
|
addCurName("signedcname1.example.org.");
|
2011-08-05 18:02:33 +02:00
|
|
|
// special case might fail; sig is for cname, which isn't there (should be ignored)
|
|
|
|
// (ignoring of 'normal' other type is done above by www.)
|
|
|
|
addRecord("A", "3600", "", "192.0.2.1");
|
|
|
|
addRecord("RRSIG", "3600", "", "A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
|
|
|
|
addRecord("RRSIG", "3600", "", "CNAME 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
|
|
|
|
addCurName("acnamesig1.example.org.");
|
2011-08-04 21:27:38 +02:00
|
|
|
|
|
|
|
// let's pretend we have a database that is not careful
|
|
|
|
// about the order in which it returns data
|
|
|
|
addRecord("RRSIG", "3600", "", "A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
|
|
|
|
addRecord("AAAA", "3600", "", "2001:db8::2");
|
2011-08-05 18:02:33 +02:00
|
|
|
addRecord("RRSIG", "3600", "", "A 5 3 3600 20000101000000 20000201000000 12346 example.org. FAKEFAKEFAKE");
|
2011-08-04 21:27:38 +02:00
|
|
|
addRecord("A", "3600", "", "192.0.2.1");
|
|
|
|
addRecord("RRSIG", "3600", "", "AAAA 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
|
|
|
|
addRecord("AAAA", "3600", "", "2001:db8::1");
|
|
|
|
addCurName("signed2.example.org.");
|
|
|
|
addRecord("RRSIG", "3600", "", "CNAME 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
|
2011-08-04 21:57:16 +02:00
|
|
|
addRecord("CNAME", "3600", "", "www.example.org.");
|
|
|
|
addCurName("signedcname2.example.org.");
|
2011-08-04 21:27:38 +02:00
|
|
|
|
2011-08-05 18:02:33 +02:00
|
|
|
addRecord("RRSIG", "3600", "", "CNAME 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
|
|
|
|
addRecord("A", "3600", "", "192.0.2.1");
|
|
|
|
addRecord("RRSIG", "3600", "", "A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
|
|
|
|
addCurName("acnamesig2.example.org.");
|
|
|
|
|
|
|
|
addRecord("RRSIG", "3600", "", "CNAME 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
|
|
|
|
addRecord("RRSIG", "3600", "", "A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
|
|
|
|
addRecord("A", "3600", "", "192.0.2.1");
|
|
|
|
addCurName("acnamesig3.example.org.");
|
|
|
|
|
2011-08-09 11:19:13 +02:00
|
|
|
addRecord("A", "3600", "", "192.0.2.1");
|
|
|
|
addRecord("A", "360", "", "192.0.2.2");
|
|
|
|
addCurName("ttldiff1.example.org.");
|
|
|
|
addRecord("A", "360", "", "192.0.2.1");
|
|
|
|
addRecord("A", "3600", "", "192.0.2.2");
|
|
|
|
addCurName("ttldiff2.example.org.");
|
|
|
|
|
2011-08-04 14:32:53 +02:00
|
|
|
// also add some intentionally bad data
|
|
|
|
addRecord("A", "3600", "", "192.0.2.1");
|
|
|
|
addRecord("CNAME", "3600", "", "www.example.org.");
|
2011-08-09 11:19:13 +02:00
|
|
|
addCurName("badcname1.example.org.");
|
|
|
|
|
|
|
|
addRecord("CNAME", "3600", "", "www.example.org.");
|
|
|
|
addRecord("A", "3600", "", "192.0.2.1");
|
|
|
|
addCurName("badcname2.example.org.");
|
|
|
|
|
|
|
|
addRecord("CNAME", "3600", "", "www.example.org.");
|
|
|
|
addRecord("CNAME", "3600", "", "www.example2.org.");
|
|
|
|
addCurName("badcname3.example.org.");
|
|
|
|
|
2011-08-05 18:02:33 +02:00
|
|
|
addRecord("A", "3600", "", "bad");
|
|
|
|
addCurName("badrdata.example.org.");
|
2011-08-09 11:19:13 +02:00
|
|
|
|
2011-08-05 18:02:33 +02:00
|
|
|
addRecord("BAD_TYPE", "3600", "", "192.0.2.1");
|
|
|
|
addCurName("badtype.example.org.");
|
2011-08-09 11:19:13 +02:00
|
|
|
|
2011-08-05 18:02:33 +02:00
|
|
|
addRecord("A", "badttl", "", "192.0.2.1");
|
|
|
|
addCurName("badttl.example.org.");
|
2011-08-09 11:19:13 +02:00
|
|
|
|
|
|
|
addRecord("A", "badttl", "", "192.0.2.1");
|
|
|
|
addRecord("RRSIG", "3600", "", "A 5 3 3600 somebaddata 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
|
|
|
|
addCurName("badsig.example.org.");
|
|
|
|
|
|
|
|
addRecord("A", "3600", "", "192.0.2.1");
|
|
|
|
addRecord("RRSIG", "3600", "TXT", "A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
|
|
|
|
addCurName("badsigtype.example.org.");
|
2011-08-12 10:50:53 +02:00
|
|
|
|
|
|
|
// Data for testing delegation (with NS and DNAME)
|
|
|
|
addRecord("NS", "3600", "", "ns.example.com.");
|
|
|
|
addRecord("NS", "3600", "", "ns.delegation.example.org.");
|
2011-08-12 15:23:04 +02:00
|
|
|
addRecord("RRSIG", "3600", "", "NS 5 3 3600 20000101000000 "
|
|
|
|
"20000201000000 12345 example.org. FAKEFAKEFAKE");
|
2011-08-12 10:50:53 +02:00
|
|
|
addCurName("delegation.example.org.");
|
|
|
|
addRecord("A", "3600", "", "192.0.2.1");
|
|
|
|
addCurName("ns.delegation.example.org.");
|
2011-08-16 13:17:29 +02:00
|
|
|
addRecord("A", "3600", "", "192.0.2.1");
|
|
|
|
addCurName("deep.below.delegation.example.org.");
|
2011-08-12 10:50:53 +02:00
|
|
|
|
|
|
|
addRecord("A", "3600", "", "192.0.2.1");
|
|
|
|
addRecord("DNAME", "3600", "", "dname.example.com.");
|
2011-08-12 15:23:04 +02:00
|
|
|
addRecord("RRSIG", "3600", "", "DNAME 5 3 3600 20000101000000 "
|
|
|
|
"20000201000000 12345 example.org. FAKEFAKEFAKE");
|
2011-08-12 10:50:53 +02:00
|
|
|
addCurName("dname.example.org.");
|
|
|
|
addRecord("A", "3600", "", "192.0.2.1");
|
|
|
|
addCurName("below.dname.example.org.");
|
|
|
|
|
2011-08-12 14:43:33 +02:00
|
|
|
// Broken NS
|
|
|
|
addRecord("A", "3600", "", "192.0.2.1");
|
|
|
|
addRecord("NS", "3600", "", "ns.example.com.");
|
|
|
|
addCurName("brokenns1.example.org.");
|
|
|
|
addRecord("NS", "3600", "", "ns.example.com.");
|
|
|
|
addRecord("A", "3600", "", "192.0.2.1");
|
|
|
|
addCurName("brokenns2.example.org.");
|
|
|
|
|
2011-08-12 10:50:53 +02:00
|
|
|
// Now double DNAME, to test failure mode
|
|
|
|
addRecord("DNAME", "3600", "", "dname1.example.com.");
|
|
|
|
addRecord("DNAME", "3600", "", "dname2.example.com.");
|
|
|
|
addCurName("baddname.example.org.");
|
2011-08-12 14:35:33 +02:00
|
|
|
|
|
|
|
// Put some data into apex (including NS) so we can check our NS
|
|
|
|
// doesn't break anything
|
|
|
|
addRecord("NS", "3600", "", "ns.example.com.");
|
|
|
|
addRecord("A", "3600", "", "192.0.2.1");
|
2011-08-12 15:23:04 +02:00
|
|
|
addRecord("RRSIG", "3600", "", "NS 5 3 3600 20000101000000 "
|
|
|
|
"20000201000000 12345 example.org. FAKEFAKEFAKE");
|
2011-08-12 14:35:33 +02:00
|
|
|
addCurName("example.org.");
|
2011-08-04 14:32:53 +02:00
|
|
|
}
|
2011-08-01 11:47:37 +02:00
|
|
|
};
|
|
|
|
|
2011-08-18 15:01:51 +02:00
|
|
|
// This tests the default getRecords behaviour, throwing NotImplemented
|
|
|
|
TEST(DatabaseConnectionTest, getRecords) {
|
|
|
|
EXPECT_THROW(NopAccessor().getRecords(Name("."), 1),
|
|
|
|
isc::NotImplemented);
|
|
|
|
}
|
|
|
|
|
2011-08-15 16:54:30 +02:00
|
|
|
// This tests the default getAllRecords behaviour, throwing NotImplemented
|
|
|
|
TEST(DatabaseConnectionTest, getAllRecords) {
|
2011-08-05 12:52:13 +02:00
|
|
|
// The parameters don't matter
|
2011-08-18 15:01:51 +02:00
|
|
|
EXPECT_THROW(NopAccessor().getAllRecords(1),
|
2011-08-05 12:52:13 +02:00
|
|
|
isc::NotImplemented);
|
|
|
|
}
|
|
|
|
|
2011-08-01 11:47:37 +02:00
|
|
|
class DatabaseClientTest : public ::testing::Test {
|
|
|
|
public:
|
|
|
|
DatabaseClientTest() {
|
|
|
|
createClient();
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* We initialize the client from a function, so we can call it multiple
|
|
|
|
* times per test.
|
|
|
|
*/
|
|
|
|
void createClient() {
|
2011-08-09 09:02:03 +02:00
|
|
|
current_database_ = new MockAccessor();
|
|
|
|
client_.reset(new DatabaseClient(shared_ptr<DatabaseAccessor>(
|
2011-08-07 12:26:36 +02:00
|
|
|
current_database_)));
|
2011-08-01 11:47:37 +02:00
|
|
|
}
|
|
|
|
// Will be deleted by client_, just keep the current value for comparison.
|
2011-08-09 09:02:03 +02:00
|
|
|
MockAccessor* current_database_;
|
2011-08-04 17:18:54 +02:00
|
|
|
shared_ptr<DatabaseClient> client_;
|
2011-08-11 13:09:12 +02:00
|
|
|
const std::string database_name_;
|
|
|
|
|
2011-08-01 11:47:37 +02:00
|
|
|
/**
|
|
|
|
* Check the zone finder is a valid one and references the zone ID and
|
2011-08-07 12:26:36 +02:00
|
|
|
* database available here.
|
2011-08-01 11:47:37 +02:00
|
|
|
*/
|
|
|
|
void checkZoneFinder(const DataSourceClient::FindResult& zone) {
|
|
|
|
ASSERT_NE(ZoneFinderPtr(), zone.zone_finder) << "No zone finder";
|
|
|
|
shared_ptr<DatabaseClient::Finder> finder(
|
|
|
|
dynamic_pointer_cast<DatabaseClient::Finder>(zone.zone_finder));
|
|
|
|
ASSERT_NE(shared_ptr<DatabaseClient::Finder>(), finder) <<
|
|
|
|
"Wrong type of finder";
|
|
|
|
EXPECT_EQ(42, finder->zone_id());
|
2011-08-07 12:26:36 +02:00
|
|
|
EXPECT_EQ(current_database_, &finder->database());
|
2011-08-01 11:47:37 +02:00
|
|
|
}
|
2011-08-16 13:11:46 +02:00
|
|
|
|
|
|
|
shared_ptr<DatabaseClient::Finder> getFinder() {
|
|
|
|
DataSourceClient::FindResult zone(
|
|
|
|
client_->findZone(Name("example.org")));
|
|
|
|
EXPECT_EQ(result::SUCCESS, zone.code);
|
|
|
|
shared_ptr<DatabaseClient::Finder> finder(
|
|
|
|
dynamic_pointer_cast<DatabaseClient::Finder>(zone.zone_finder));
|
|
|
|
EXPECT_EQ(42, finder->zone_id());
|
|
|
|
|
|
|
|
return (finder);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> expected_rdatas_;
|
|
|
|
std::vector<std::string> expected_sig_rdatas_;
|
2011-08-01 11:47:37 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(DatabaseClientTest, zoneNotFound) {
|
|
|
|
DataSourceClient::FindResult zone(client_->findZone(Name("example.com")));
|
|
|
|
EXPECT_EQ(result::NOTFOUND, zone.code);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DatabaseClientTest, exactZone) {
|
|
|
|
DataSourceClient::FindResult zone(client_->findZone(Name("example.org")));
|
|
|
|
EXPECT_EQ(result::SUCCESS, zone.code);
|
|
|
|
checkZoneFinder(zone);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DatabaseClientTest, superZone) {
|
|
|
|
DataSourceClient::FindResult zone(client_->findZone(Name(
|
|
|
|
"sub.example.org")));
|
|
|
|
EXPECT_EQ(result::PARTIALMATCH, zone.code);
|
|
|
|
checkZoneFinder(zone);
|
|
|
|
}
|
|
|
|
|
2011-08-11 16:18:43 +02:00
|
|
|
TEST_F(DatabaseClientTest, noAccessorException) {
|
2011-08-12 12:40:04 +02:00
|
|
|
// We need a dummy variable here; some compiler would regard it a mere
|
|
|
|
// declaration instead of an instantiation and make the test fail.
|
|
|
|
EXPECT_THROW(DatabaseClient dummy((shared_ptr<DatabaseAccessor>())),
|
2011-08-01 12:03:35 +02:00
|
|
|
isc::InvalidParameter);
|
|
|
|
}
|
|
|
|
|
2011-08-05 15:18:00 +02:00
|
|
|
// 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) {
|
2011-08-11 20:09:20 +02:00
|
|
|
EXPECT_THROW(DatabaseClient(boost::shared_ptr<DatabaseAccessor>(
|
|
|
|
new NopAccessor())).getIterator(Name("example.com")),
|
2011-08-05 15:18:00 +02:00
|
|
|
DataSourceError);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DatabaseClientTest, notImplementedIterator) {
|
2011-08-11 20:09:20 +02:00
|
|
|
EXPECT_THROW(DatabaseClient(shared_ptr<DatabaseAccessor>(
|
|
|
|
new NopAccessor())).getIterator(Name("example.org")),
|
2011-08-05 15:18:00 +02:00
|
|
|
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) {
|
2011-08-17 15:45:40 +02:00
|
|
|
// It should not throw, but get the lowest one of them
|
2011-08-05 15:18:00 +02:00
|
|
|
ZoneIteratorPtr it(client_->getIterator(Name("bad.example.org")));
|
2011-08-17 15:45:40 +02:00
|
|
|
EXPECT_EQ(it->getNextRRset()->getTTL(), isc::dns::RRTTL(300));
|
2011-08-05 15:18:00 +02:00
|
|
|
}
|
|
|
|
|
2011-08-11 22:52:21 +02:00
|
|
|
// checks if the given rrset matches the
|
|
|
|
// given name, class, type and rdatas
|
|
|
|
void
|
|
|
|
checkRRset(isc::dns::ConstRRsetPtr rrset,
|
|
|
|
const isc::dns::Name& name,
|
|
|
|
const isc::dns::RRClass& rrclass,
|
|
|
|
const isc::dns::RRType& rrtype,
|
|
|
|
const isc::dns::RRTTL& rrttl,
|
2011-08-12 11:00:12 +02:00
|
|
|
const std::vector<std::string>& rdatas) {
|
2011-08-11 22:52:21 +02:00
|
|
|
isc::dns::RRsetPtr expected_rrset(
|
|
|
|
new isc::dns::RRset(name, rrclass, rrtype, rrttl));
|
|
|
|
for (unsigned int i = 0; i < rdatas.size(); ++i) {
|
|
|
|
expected_rrset->addRdata(
|
|
|
|
isc::dns::rdata::createRdata(rrtype, rrclass,
|
|
|
|
rdatas[i]));
|
|
|
|
}
|
|
|
|
isc::testutils::rrsetCheck(expected_rrset, rrset);
|
|
|
|
}
|
|
|
|
|
2011-08-04 21:57:16 +02:00
|
|
|
void
|
|
|
|
doFindTest(shared_ptr<DatabaseClient::Finder> finder,
|
|
|
|
const isc::dns::Name& name,
|
|
|
|
const isc::dns::RRType& type,
|
|
|
|
const isc::dns::RRType& expected_type,
|
2011-08-09 11:19:13 +02:00
|
|
|
const isc::dns::RRTTL expected_ttl,
|
2011-08-04 21:57:16 +02:00
|
|
|
ZoneFinder::Result expected_result,
|
2011-08-11 17:31:06 +02:00
|
|
|
const std::vector<std::string>& expected_rdatas,
|
2011-08-12 13:44:46 +02:00
|
|
|
const std::vector<std::string>& expected_sig_rdatas,
|
2011-08-13 14:37:14 +02:00
|
|
|
const isc::dns::Name& expected_name = isc::dns::Name::ROOT_NAME(),
|
|
|
|
const ZoneFinder::FindOptions options = ZoneFinder::FIND_DEFAULT)
|
2011-08-04 21:57:16 +02:00
|
|
|
{
|
2011-08-12 13:44:46 +02:00
|
|
|
SCOPED_TRACE("doFindTest " + name.toText() + " " + type.toText());
|
2011-08-09 11:19:13 +02:00
|
|
|
ZoneFinder::FindResult result =
|
2011-08-13 14:37:14 +02:00
|
|
|
finder->find(name, type, NULL, options);
|
2011-08-09 11:19:13 +02:00
|
|
|
ASSERT_EQ(expected_result, result.code) << name << " " << type;
|
2011-08-11 17:31:06 +02:00
|
|
|
if (expected_rdatas.size() > 0) {
|
2011-08-12 13:44:46 +02:00
|
|
|
checkRRset(result.rrset, expected_name != Name(".") ? expected_name :
|
|
|
|
name, finder->getClass(), expected_type, expected_ttl,
|
|
|
|
expected_rdatas);
|
2011-08-11 17:31:06 +02:00
|
|
|
|
|
|
|
if (expected_sig_rdatas.size() > 0) {
|
2011-08-12 15:23:04 +02:00
|
|
|
checkRRset(result.rrset->getRRsig(), expected_name != Name(".") ?
|
|
|
|
expected_name : name, finder->getClass(),
|
|
|
|
isc::dns::RRType::RRSIG(), expected_ttl,
|
|
|
|
expected_sig_rdatas);
|
2011-08-04 21:57:16 +02:00
|
|
|
} else {
|
|
|
|
EXPECT_EQ(isc::dns::RRsetPtr(), result.rrset->getRRsig());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
EXPECT_EQ(isc::dns::RRsetPtr(), result.rrset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-04 14:32:53 +02:00
|
|
|
TEST_F(DatabaseClientTest, find) {
|
2011-08-16 13:11:46 +02:00
|
|
|
shared_ptr<DatabaseClient::Finder> finder(getFinder());
|
2011-08-04 14:32:53 +02:00
|
|
|
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_.clear();
|
|
|
|
expected_sig_rdatas_.clear();
|
|
|
|
expected_rdatas_.push_back("192.0.2.1");
|
2011-08-04 21:57:16 +02:00
|
|
|
doFindTest(finder, isc::dns::Name("www.example.org."),
|
|
|
|
isc::dns::RRType::A(), isc::dns::RRType::A(),
|
2011-08-09 11:19:13 +02:00
|
|
|
isc::dns::RRTTL(3600),
|
2011-08-11 17:31:06 +02:00
|
|
|
ZoneFinder::SUCCESS,
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_, expected_sig_rdatas_);
|
2011-08-11 17:31:06 +02:00
|
|
|
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_.clear();
|
|
|
|
expected_sig_rdatas_.clear();
|
|
|
|
expected_rdatas_.push_back("192.0.2.1");
|
|
|
|
expected_rdatas_.push_back("192.0.2.2");
|
2011-08-09 11:19:13 +02:00
|
|
|
doFindTest(finder, isc::dns::Name("www2.example.org."),
|
|
|
|
isc::dns::RRType::A(), isc::dns::RRType::A(),
|
|
|
|
isc::dns::RRTTL(3600),
|
2011-08-11 17:31:06 +02:00
|
|
|
ZoneFinder::SUCCESS,
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_, expected_sig_rdatas_);
|
2011-08-11 17:31:06 +02:00
|
|
|
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_.clear();
|
|
|
|
expected_sig_rdatas_.clear();
|
|
|
|
expected_rdatas_.push_back("2001:db8::1");
|
|
|
|
expected_rdatas_.push_back("2001:db8::2");
|
2011-08-04 21:57:16 +02:00
|
|
|
doFindTest(finder, isc::dns::Name("www.example.org."),
|
|
|
|
isc::dns::RRType::AAAA(), isc::dns::RRType::AAAA(),
|
2011-08-09 11:19:13 +02:00
|
|
|
isc::dns::RRTTL(3600),
|
2011-08-11 17:31:06 +02:00
|
|
|
ZoneFinder::SUCCESS,
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_, expected_sig_rdatas_);
|
2011-08-11 17:31:06 +02:00
|
|
|
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_.clear();
|
|
|
|
expected_sig_rdatas_.clear();
|
2011-08-04 21:57:16 +02:00
|
|
|
doFindTest(finder, isc::dns::Name("www.example.org."),
|
|
|
|
isc::dns::RRType::TXT(), isc::dns::RRType::TXT(),
|
2011-08-09 11:19:13 +02:00
|
|
|
isc::dns::RRTTL(3600),
|
2011-08-11 17:31:06 +02:00
|
|
|
ZoneFinder::NXRRSET,
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_, expected_sig_rdatas_);
|
2011-08-11 17:31:06 +02:00
|
|
|
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_.clear();
|
|
|
|
expected_sig_rdatas_.clear();
|
|
|
|
expected_rdatas_.push_back("www.example.org.");
|
2011-08-04 21:57:16 +02:00
|
|
|
doFindTest(finder, isc::dns::Name("cname.example.org."),
|
|
|
|
isc::dns::RRType::A(), isc::dns::RRType::CNAME(),
|
2011-08-09 11:19:13 +02:00
|
|
|
isc::dns::RRTTL(3600),
|
2011-08-11 17:31:06 +02:00
|
|
|
ZoneFinder::CNAME,
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_, expected_sig_rdatas_);
|
2011-08-11 17:31:06 +02:00
|
|
|
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_.clear();
|
|
|
|
expected_sig_rdatas_.clear();
|
|
|
|
expected_rdatas_.push_back("www.example.org.");
|
2011-08-09 11:19:13 +02:00
|
|
|
doFindTest(finder, isc::dns::Name("cname.example.org."),
|
|
|
|
isc::dns::RRType::CNAME(), isc::dns::RRType::CNAME(),
|
|
|
|
isc::dns::RRTTL(3600),
|
2011-08-11 17:31:06 +02:00
|
|
|
ZoneFinder::SUCCESS,
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_, expected_sig_rdatas_);
|
2011-08-11 17:31:06 +02:00
|
|
|
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_.clear();
|
|
|
|
expected_sig_rdatas_.clear();
|
2011-08-04 21:57:16 +02:00
|
|
|
doFindTest(finder, isc::dns::Name("doesnotexist.example.org."),
|
|
|
|
isc::dns::RRType::A(), isc::dns::RRType::A(),
|
2011-08-09 11:19:13 +02:00
|
|
|
isc::dns::RRTTL(3600),
|
2011-08-11 17:31:06 +02:00
|
|
|
ZoneFinder::NXDOMAIN,
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_, expected_sig_rdatas_);
|
2011-08-11 17:31:06 +02:00
|
|
|
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_.clear();
|
|
|
|
expected_sig_rdatas_.clear();
|
|
|
|
expected_rdatas_.push_back("192.0.2.1");
|
|
|
|
expected_sig_rdatas_.push_back("A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
|
|
|
|
expected_sig_rdatas_.push_back("A 5 3 3600 20000101000000 20000201000000 12346 example.org. FAKEFAKEFAKE");
|
2011-08-04 21:57:16 +02:00
|
|
|
doFindTest(finder, isc::dns::Name("signed1.example.org."),
|
|
|
|
isc::dns::RRType::A(), isc::dns::RRType::A(),
|
2011-08-09 11:19:13 +02:00
|
|
|
isc::dns::RRTTL(3600),
|
2011-08-11 17:31:06 +02:00
|
|
|
ZoneFinder::SUCCESS,
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_, expected_sig_rdatas_);
|
2011-08-11 17:31:06 +02:00
|
|
|
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_.clear();
|
|
|
|
expected_sig_rdatas_.clear();
|
|
|
|
expected_rdatas_.push_back("2001:db8::1");
|
|
|
|
expected_rdatas_.push_back("2001:db8::2");
|
|
|
|
expected_sig_rdatas_.push_back("AAAA 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
|
2011-08-04 21:57:16 +02:00
|
|
|
doFindTest(finder, isc::dns::Name("signed1.example.org."),
|
|
|
|
isc::dns::RRType::AAAA(), isc::dns::RRType::AAAA(),
|
2011-08-09 11:19:13 +02:00
|
|
|
isc::dns::RRTTL(3600),
|
2011-08-11 17:31:06 +02:00
|
|
|
ZoneFinder::SUCCESS,
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_, expected_sig_rdatas_);
|
2011-08-11 17:31:06 +02:00
|
|
|
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_.clear();
|
|
|
|
expected_sig_rdatas_.clear();
|
2011-08-04 21:57:16 +02:00
|
|
|
doFindTest(finder, isc::dns::Name("signed1.example.org."),
|
|
|
|
isc::dns::RRType::TXT(), isc::dns::RRType::TXT(),
|
2011-08-09 11:19:13 +02:00
|
|
|
isc::dns::RRTTL(3600),
|
2011-08-11 17:31:06 +02:00
|
|
|
ZoneFinder::NXRRSET,
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_, expected_sig_rdatas_);
|
2011-08-11 17:31:06 +02:00
|
|
|
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_.clear();
|
|
|
|
expected_sig_rdatas_.clear();
|
|
|
|
expected_rdatas_.push_back("www.example.org.");
|
|
|
|
expected_sig_rdatas_.push_back("CNAME 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
|
2011-08-04 21:57:16 +02:00
|
|
|
doFindTest(finder, isc::dns::Name("signedcname1.example.org."),
|
|
|
|
isc::dns::RRType::A(), isc::dns::RRType::CNAME(),
|
2011-08-09 11:19:13 +02:00
|
|
|
isc::dns::RRTTL(3600),
|
2011-08-11 17:31:06 +02:00
|
|
|
ZoneFinder::CNAME,
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_, expected_sig_rdatas_);
|
2011-08-04 21:57:16 +02:00
|
|
|
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_.clear();
|
|
|
|
expected_sig_rdatas_.clear();
|
|
|
|
expected_rdatas_.push_back("192.0.2.1");
|
|
|
|
expected_sig_rdatas_.push_back("A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
|
|
|
|
expected_sig_rdatas_.push_back("A 5 3 3600 20000101000000 20000201000000 12346 example.org. FAKEFAKEFAKE");
|
2011-08-04 21:57:16 +02:00
|
|
|
doFindTest(finder, isc::dns::Name("signed2.example.org."),
|
|
|
|
isc::dns::RRType::A(), isc::dns::RRType::A(),
|
2011-08-09 11:19:13 +02:00
|
|
|
isc::dns::RRTTL(3600),
|
2011-08-11 17:31:06 +02:00
|
|
|
ZoneFinder::SUCCESS,
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_, expected_sig_rdatas_);
|
2011-08-11 17:31:06 +02:00
|
|
|
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_.clear();
|
|
|
|
expected_sig_rdatas_.clear();
|
|
|
|
expected_rdatas_.push_back("2001:db8::2");
|
|
|
|
expected_rdatas_.push_back("2001:db8::1");
|
|
|
|
expected_sig_rdatas_.push_back("AAAA 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
|
2011-08-04 21:57:16 +02:00
|
|
|
doFindTest(finder, isc::dns::Name("signed2.example.org."),
|
|
|
|
isc::dns::RRType::AAAA(), isc::dns::RRType::AAAA(),
|
2011-08-09 11:19:13 +02:00
|
|
|
isc::dns::RRTTL(3600),
|
2011-08-11 17:31:06 +02:00
|
|
|
ZoneFinder::SUCCESS,
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_, expected_sig_rdatas_);
|
2011-08-11 17:31:06 +02:00
|
|
|
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_.clear();
|
|
|
|
expected_sig_rdatas_.clear();
|
2011-08-04 21:57:16 +02:00
|
|
|
doFindTest(finder, isc::dns::Name("signed2.example.org."),
|
|
|
|
isc::dns::RRType::TXT(), isc::dns::RRType::TXT(),
|
2011-08-09 11:19:13 +02:00
|
|
|
isc::dns::RRTTL(3600),
|
2011-08-11 17:31:06 +02:00
|
|
|
ZoneFinder::NXRRSET,
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_, expected_sig_rdatas_);
|
2011-08-11 17:31:06 +02:00
|
|
|
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_.clear();
|
|
|
|
expected_sig_rdatas_.clear();
|
|
|
|
expected_rdatas_.push_back("www.example.org.");
|
|
|
|
expected_sig_rdatas_.push_back("CNAME 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
|
2011-08-04 21:57:16 +02:00
|
|
|
doFindTest(finder, isc::dns::Name("signedcname2.example.org."),
|
|
|
|
isc::dns::RRType::A(), isc::dns::RRType::CNAME(),
|
2011-08-09 11:19:13 +02:00
|
|
|
isc::dns::RRTTL(3600),
|
2011-08-11 17:31:06 +02:00
|
|
|
ZoneFinder::CNAME,
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_, expected_sig_rdatas_);
|
2011-08-04 21:27:38 +02:00
|
|
|
|
2011-08-11 17:31:06 +02:00
|
|
|
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_.clear();
|
|
|
|
expected_sig_rdatas_.clear();
|
|
|
|
expected_rdatas_.push_back("192.0.2.1");
|
|
|
|
expected_sig_rdatas_.push_back("A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
|
2011-08-05 18:02:33 +02:00
|
|
|
doFindTest(finder, isc::dns::Name("acnamesig1.example.org."),
|
|
|
|
isc::dns::RRType::A(), isc::dns::RRType::A(),
|
2011-08-09 11:19:13 +02:00
|
|
|
isc::dns::RRTTL(3600),
|
2011-08-11 17:31:06 +02:00
|
|
|
ZoneFinder::SUCCESS,
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_, expected_sig_rdatas_);
|
2011-08-11 17:31:06 +02:00
|
|
|
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_.clear();
|
|
|
|
expected_sig_rdatas_.clear();
|
|
|
|
expected_rdatas_.push_back("192.0.2.1");
|
|
|
|
expected_sig_rdatas_.push_back("A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
|
2011-08-05 18:02:33 +02:00
|
|
|
doFindTest(finder, isc::dns::Name("acnamesig2.example.org."),
|
|
|
|
isc::dns::RRType::A(), isc::dns::RRType::A(),
|
2011-08-09 11:19:13 +02:00
|
|
|
isc::dns::RRTTL(3600),
|
2011-08-11 17:31:06 +02:00
|
|
|
ZoneFinder::SUCCESS,
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_, expected_sig_rdatas_);
|
2011-08-11 17:31:06 +02:00
|
|
|
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_.clear();
|
|
|
|
expected_sig_rdatas_.clear();
|
|
|
|
expected_rdatas_.push_back("192.0.2.1");
|
|
|
|
expected_sig_rdatas_.push_back("A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
|
2011-08-05 18:02:33 +02:00
|
|
|
doFindTest(finder, isc::dns::Name("acnamesig3.example.org."),
|
|
|
|
isc::dns::RRType::A(), isc::dns::RRType::A(),
|
2011-08-09 11:19:13 +02:00
|
|
|
isc::dns::RRTTL(3600),
|
2011-08-11 17:31:06 +02:00
|
|
|
ZoneFinder::SUCCESS,
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_, expected_sig_rdatas_);
|
2011-08-05 18:02:33 +02:00
|
|
|
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_.clear();
|
|
|
|
expected_sig_rdatas_.clear();
|
|
|
|
expected_rdatas_.push_back("192.0.2.1");
|
|
|
|
expected_rdatas_.push_back("192.0.2.2");
|
2011-08-09 11:19:13 +02:00
|
|
|
doFindTest(finder, isc::dns::Name("ttldiff1.example.org."),
|
|
|
|
isc::dns::RRType::A(), isc::dns::RRType::A(),
|
|
|
|
isc::dns::RRTTL(360),
|
2011-08-11 17:31:06 +02:00
|
|
|
ZoneFinder::SUCCESS,
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_, expected_sig_rdatas_);
|
2011-08-11 17:31:06 +02:00
|
|
|
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_.clear();
|
|
|
|
expected_sig_rdatas_.clear();
|
|
|
|
expected_rdatas_.push_back("192.0.2.1");
|
|
|
|
expected_rdatas_.push_back("192.0.2.2");
|
2011-08-09 11:19:13 +02:00
|
|
|
doFindTest(finder, isc::dns::Name("ttldiff2.example.org."),
|
|
|
|
isc::dns::RRType::A(), isc::dns::RRType::A(),
|
|
|
|
isc::dns::RRTTL(360),
|
2011-08-11 17:31:06 +02:00
|
|
|
ZoneFinder::SUCCESS,
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_, expected_sig_rdatas_);
|
2011-08-09 11:19:13 +02:00
|
|
|
|
2011-08-11 17:31:06 +02:00
|
|
|
|
2011-08-09 11:19:13 +02:00
|
|
|
EXPECT_THROW(finder->find(isc::dns::Name("badcname1.example.org."),
|
|
|
|
isc::dns::RRType::A(),
|
|
|
|
NULL, ZoneFinder::FIND_DEFAULT),
|
|
|
|
DataSourceError);
|
|
|
|
EXPECT_THROW(finder->find(isc::dns::Name("badcname2.example.org."),
|
2011-08-04 14:32:53 +02:00
|
|
|
isc::dns::RRType::A(),
|
|
|
|
NULL, ZoneFinder::FIND_DEFAULT),
|
|
|
|
DataSourceError);
|
2011-08-09 11:19:13 +02:00
|
|
|
EXPECT_THROW(finder->find(isc::dns::Name("badcname3.example.org."),
|
2011-08-04 14:32:53 +02:00
|
|
|
isc::dns::RRType::A(),
|
|
|
|
NULL, ZoneFinder::FIND_DEFAULT),
|
|
|
|
DataSourceError);
|
2011-08-05 18:02:33 +02:00
|
|
|
EXPECT_THROW(finder->find(isc::dns::Name("badrdata.example.org."),
|
|
|
|
isc::dns::RRType::A(),
|
|
|
|
NULL, ZoneFinder::FIND_DEFAULT),
|
|
|
|
DataSourceError);
|
|
|
|
EXPECT_THROW(finder->find(isc::dns::Name("badtype.example.org."),
|
|
|
|
isc::dns::RRType::A(),
|
|
|
|
NULL, ZoneFinder::FIND_DEFAULT),
|
|
|
|
DataSourceError);
|
|
|
|
EXPECT_THROW(finder->find(isc::dns::Name("badttl.example.org."),
|
|
|
|
isc::dns::RRType::A(),
|
|
|
|
NULL, ZoneFinder::FIND_DEFAULT),
|
|
|
|
DataSourceError);
|
2011-08-09 11:19:13 +02:00
|
|
|
EXPECT_THROW(finder->find(isc::dns::Name("badsig.example.org."),
|
|
|
|
isc::dns::RRType::A(),
|
|
|
|
NULL, ZoneFinder::FIND_DEFAULT),
|
|
|
|
DataSourceError);
|
|
|
|
|
|
|
|
// 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_THROW(finder->find(isc::dns::Name("iscexception.in.search."),
|
|
|
|
isc::dns::RRType::A(),
|
|
|
|
NULL, ZoneFinder::FIND_DEFAULT),
|
2011-08-18 16:43:36 +02:00
|
|
|
isc::Exception);
|
2011-08-09 11:19:13 +02:00
|
|
|
EXPECT_THROW(finder->find(isc::dns::Name("basicexception.in.search."),
|
|
|
|
isc::dns::RRType::A(),
|
|
|
|
NULL, ZoneFinder::FIND_DEFAULT),
|
|
|
|
std::exception);
|
2011-08-11 17:31:06 +02:00
|
|
|
|
2011-08-09 11:19:13 +02:00
|
|
|
EXPECT_THROW(finder->find(isc::dns::Name("dsexception.in.getnext."),
|
|
|
|
isc::dns::RRType::A(),
|
|
|
|
NULL, ZoneFinder::FIND_DEFAULT),
|
|
|
|
DataSourceError);
|
|
|
|
EXPECT_THROW(finder->find(isc::dns::Name("iscexception.in.getnext."),
|
|
|
|
isc::dns::RRType::A(),
|
|
|
|
NULL, ZoneFinder::FIND_DEFAULT),
|
2011-08-18 16:43:36 +02:00
|
|
|
isc::Exception);
|
2011-08-09 11:19:13 +02:00
|
|
|
EXPECT_THROW(finder->find(isc::dns::Name("basicexception.in.getnext."),
|
|
|
|
isc::dns::RRType::A(),
|
|
|
|
NULL, ZoneFinder::FIND_DEFAULT),
|
|
|
|
std::exception);
|
|
|
|
|
|
|
|
// This RRSIG has the wrong sigtype field, which should be
|
|
|
|
// an error if we decide to keep using that field
|
|
|
|
// Right now the field is ignored, so it does not error
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_.clear();
|
|
|
|
expected_sig_rdatas_.clear();
|
|
|
|
expected_rdatas_.push_back("192.0.2.1");
|
|
|
|
expected_sig_rdatas_.push_back("A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
|
2011-08-09 11:19:13 +02:00
|
|
|
doFindTest(finder, isc::dns::Name("badsigtype.example.org."),
|
|
|
|
isc::dns::RRType::A(), isc::dns::RRType::A(),
|
|
|
|
isc::dns::RRTTL(3600),
|
2011-08-11 17:31:06 +02:00
|
|
|
ZoneFinder::SUCCESS,
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_, expected_sig_rdatas_);
|
2011-08-04 14:32:53 +02:00
|
|
|
}
|
|
|
|
|
2011-08-16 13:11:46 +02:00
|
|
|
TEST_F(DatabaseClientTest, findDelegation) {
|
|
|
|
shared_ptr<DatabaseClient::Finder> finder(getFinder());
|
2011-08-12 10:50:53 +02:00
|
|
|
|
2011-08-12 14:35:33 +02:00
|
|
|
// The apex should not be considered delegation point and we can access
|
|
|
|
// data
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_.clear();
|
|
|
|
expected_sig_rdatas_.clear();
|
|
|
|
expected_rdatas_.push_back("192.0.2.1");
|
2011-08-12 14:35:33 +02:00
|
|
|
doFindTest(finder, isc::dns::Name("example.org."),
|
|
|
|
isc::dns::RRType::A(), isc::dns::RRType::A(),
|
2011-08-16 13:11:46 +02:00
|
|
|
isc::dns::RRTTL(3600), ZoneFinder::SUCCESS, expected_rdatas_,
|
|
|
|
expected_sig_rdatas_);
|
2011-08-12 14:35:33 +02:00
|
|
|
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_.clear();
|
|
|
|
expected_rdatas_.push_back("ns.example.com.");
|
|
|
|
expected_sig_rdatas_.push_back("NS 5 3 3600 20000101000000 20000201000000 "
|
2011-08-12 15:23:04 +02:00
|
|
|
"12345 example.org. FAKEFAKEFAKE");
|
2011-08-12 14:43:33 +02:00
|
|
|
doFindTest(finder, isc::dns::Name("example.org."),
|
|
|
|
isc::dns::RRType::NS(), isc::dns::RRType::NS(),
|
2011-08-16 13:11:46 +02:00
|
|
|
isc::dns::RRTTL(3600), ZoneFinder::SUCCESS, expected_rdatas_,
|
|
|
|
expected_sig_rdatas_);
|
2011-08-12 14:43:33 +02:00
|
|
|
|
2011-08-12 10:50:53 +02:00
|
|
|
// Check when we ask for something below delegation point, we get the NS
|
|
|
|
// (Both when the RRset there exists and doesn't)
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_.clear();
|
|
|
|
expected_sig_rdatas_.clear();
|
|
|
|
expected_rdatas_.push_back("ns.example.com.");
|
|
|
|
expected_rdatas_.push_back("ns.delegation.example.org.");
|
|
|
|
expected_sig_rdatas_.push_back("NS 5 3 3600 20000101000000 20000201000000 "
|
2011-08-12 15:23:04 +02:00
|
|
|
"12345 example.org. FAKEFAKEFAKE");
|
2011-08-12 10:50:53 +02:00
|
|
|
doFindTest(finder, isc::dns::Name("ns.delegation.example.org."),
|
|
|
|
isc::dns::RRType::A(), isc::dns::RRType::NS(),
|
2011-08-16 13:11:46 +02:00
|
|
|
isc::dns::RRTTL(3600), ZoneFinder::DELEGATION, expected_rdatas_,
|
|
|
|
expected_sig_rdatas_,
|
|
|
|
isc::dns::Name("delegation.example.org."));
|
2011-08-12 10:50:53 +02:00
|
|
|
doFindTest(finder, isc::dns::Name("ns.delegation.example.org."),
|
|
|
|
isc::dns::RRType::AAAA(), isc::dns::RRType::NS(),
|
2011-08-16 13:11:46 +02:00
|
|
|
isc::dns::RRTTL(3600), ZoneFinder::DELEGATION, expected_rdatas_,
|
|
|
|
expected_sig_rdatas_,
|
|
|
|
isc::dns::Name("delegation.example.org."));
|
2011-08-16 13:17:29 +02:00
|
|
|
doFindTest(finder, isc::dns::Name("deep.below.delegation.example.org."),
|
|
|
|
isc::dns::RRType::AAAA(), isc::dns::RRType::NS(),
|
|
|
|
isc::dns::RRTTL(3600), ZoneFinder::DELEGATION, expected_rdatas_,
|
|
|
|
expected_sig_rdatas_,
|
|
|
|
isc::dns::Name("delegation.example.org."));
|
2011-08-12 10:50:53 +02:00
|
|
|
|
|
|
|
// Even when we check directly at the delegation point, we should get
|
2011-08-12 15:23:04 +02:00
|
|
|
// the NS
|
2011-08-12 10:50:53 +02:00
|
|
|
doFindTest(finder, isc::dns::Name("delegation.example.org."),
|
|
|
|
isc::dns::RRType::AAAA(), isc::dns::RRType::NS(),
|
2011-08-16 13:11:46 +02:00
|
|
|
isc::dns::RRTTL(3600), ZoneFinder::DELEGATION, expected_rdatas_,
|
|
|
|
expected_sig_rdatas_);
|
2011-08-12 10:50:53 +02:00
|
|
|
|
2011-08-12 14:43:33 +02:00
|
|
|
// 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(),
|
2011-08-16 13:11:46 +02:00
|
|
|
isc::dns::RRTTL(3600), ZoneFinder::DELEGATION, expected_rdatas_,
|
|
|
|
expected_sig_rdatas_);
|
2011-08-12 14:43:33 +02:00
|
|
|
|
2011-08-12 10:50:53 +02:00
|
|
|
// 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
|
|
|
|
// the behaviour anyway just to make sure)
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_.clear();
|
|
|
|
expected_rdatas_.push_back("dname.example.com.");
|
|
|
|
expected_sig_rdatas_.clear();
|
|
|
|
expected_sig_rdatas_.push_back("DNAME 5 3 3600 20000101000000 "
|
2011-08-12 15:23:04 +02:00
|
|
|
"20000201000000 12345 example.org. "
|
|
|
|
"FAKEFAKEFAKE");
|
2011-08-12 10:50:53 +02:00
|
|
|
doFindTest(finder, isc::dns::Name("below.dname.example.org."),
|
|
|
|
isc::dns::RRType::A(), isc::dns::RRType::DNAME(),
|
2011-08-16 13:11:46 +02:00
|
|
|
isc::dns::RRTTL(3600), ZoneFinder::DNAME, expected_rdatas_,
|
|
|
|
expected_sig_rdatas_, isc::dns::Name("dname.example.org."));
|
2011-08-12 10:50:53 +02:00
|
|
|
doFindTest(finder, isc::dns::Name("below.dname.example.org."),
|
|
|
|
isc::dns::RRType::AAAA(), isc::dns::RRType::DNAME(),
|
2011-08-16 13:11:46 +02:00
|
|
|
isc::dns::RRTTL(3600), ZoneFinder::DNAME, expected_rdatas_,
|
|
|
|
expected_sig_rdatas_, isc::dns::Name("dname.example.org."));
|
2011-08-16 13:17:29 +02:00
|
|
|
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."));
|
2011-08-12 10:50:53 +02:00
|
|
|
|
2011-08-12 15:23:04 +02:00
|
|
|
// Asking direcly for DNAME should give SUCCESS
|
|
|
|
doFindTest(finder, isc::dns::Name("dname.example.org."),
|
|
|
|
isc::dns::RRType::DNAME(), isc::dns::RRType::DNAME(),
|
2011-08-16 13:11:46 +02:00
|
|
|
isc::dns::RRTTL(3600), ZoneFinder::SUCCESS, expected_rdatas_,
|
|
|
|
expected_sig_rdatas_);
|
2011-08-12 15:23:04 +02:00
|
|
|
|
2011-08-12 10:50:53 +02:00
|
|
|
// But we don't delegate at DNAME point
|
2011-08-16 13:11:46 +02:00
|
|
|
expected_rdatas_.clear();
|
|
|
|
expected_rdatas_.push_back("192.0.2.1");
|
|
|
|
expected_sig_rdatas_.clear();
|
2011-08-12 10:50:53 +02:00
|
|
|
doFindTest(finder, isc::dns::Name("dname.example.org."),
|
|
|
|
isc::dns::RRType::A(), isc::dns::RRType::A(),
|
2011-08-16 13:11:46 +02:00
|
|
|
isc::dns::RRTTL(3600), ZoneFinder::SUCCESS, expected_rdatas_,
|
|
|
|
expected_sig_rdatas_);
|
|
|
|
expected_rdatas_.clear();
|
2011-08-12 10:50:53 +02:00
|
|
|
doFindTest(finder, isc::dns::Name("dname.example.org."),
|
|
|
|
isc::dns::RRType::AAAA(), isc::dns::RRType::AAAA(),
|
2011-08-16 13:11:46 +02:00
|
|
|
isc::dns::RRTTL(3600), ZoneFinder::NXRRSET, expected_rdatas_,
|
|
|
|
expected_sig_rdatas_);
|
2011-08-12 10:50:53 +02:00
|
|
|
|
|
|
|
// 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);
|
2011-08-12 14:43:33 +02:00
|
|
|
|
|
|
|
// Broken NS - it lives together with something else
|
|
|
|
EXPECT_THROW(finder->find(isc::dns::Name("brokenns1.example.org."),
|
|
|
|
isc::dns::RRType::A(), NULL,
|
|
|
|
ZoneFinder::FIND_DEFAULT),
|
|
|
|
DataSourceError);
|
|
|
|
EXPECT_THROW(finder->find(isc::dns::Name("brokenns2.example.org."),
|
|
|
|
isc::dns::RRType::A(), NULL,
|
|
|
|
ZoneFinder::FIND_DEFAULT),
|
|
|
|
DataSourceError);
|
2011-08-12 14:35:33 +02:00
|
|
|
}
|
|
|
|
|
2011-08-16 16:24:30 +02:00
|
|
|
// Glue-OK mode. Just go trough NS delegations down (but not trough
|
|
|
|
// DNAME) and pretend it is not there.
|
|
|
|
TEST_F(DatabaseClientTest, glueOK) {
|
|
|
|
shared_ptr<DatabaseClient::Finder> finder(getFinder());
|
|
|
|
|
|
|
|
expected_rdatas_.clear();
|
|
|
|
expected_sig_rdatas_.clear();
|
|
|
|
doFindTest(finder, isc::dns::Name("ns.delegation.example.org."),
|
|
|
|
isc::dns::RRType::AAAA(), isc::dns::RRType::AAAA(),
|
|
|
|
isc::dns::RRTTL(3600), ZoneFinder::NXRRSET,
|
|
|
|
expected_rdatas_, expected_sig_rdatas_,
|
|
|
|
isc::dns::Name("ns.delegation.example.org."),
|
|
|
|
ZoneFinder::FIND_GLUE_OK);
|
|
|
|
doFindTest(finder, isc::dns::Name("nothere.delegation.example.org."),
|
|
|
|
isc::dns::RRType::AAAA(), isc::dns::RRType::AAAA(),
|
|
|
|
isc::dns::RRTTL(3600), ZoneFinder::NXDOMAIN,
|
|
|
|
expected_rdatas_, expected_sig_rdatas_,
|
|
|
|
isc::dns::Name("nothere.delegation.example.org."),
|
|
|
|
ZoneFinder::FIND_GLUE_OK);
|
|
|
|
expected_rdatas_.push_back("192.0.2.1");
|
|
|
|
doFindTest(finder, isc::dns::Name("ns.delegation.example.org."),
|
|
|
|
isc::dns::RRType::A(), isc::dns::RRType::A(),
|
|
|
|
isc::dns::RRTTL(3600), ZoneFinder::SUCCESS,
|
|
|
|
expected_rdatas_, expected_sig_rdatas_,
|
|
|
|
isc::dns::Name("ns.delegation.example.org."),
|
|
|
|
ZoneFinder::FIND_GLUE_OK);
|
|
|
|
expected_rdatas_.clear();
|
|
|
|
expected_rdatas_.push_back("ns.example.com.");
|
|
|
|
expected_rdatas_.push_back("ns.delegation.example.org.");
|
|
|
|
expected_sig_rdatas_.clear();
|
|
|
|
expected_sig_rdatas_.push_back("NS 5 3 3600 20000101000000 "
|
|
|
|
"20000201000000 12345 example.org. "
|
|
|
|
"FAKEFAKEFAKE");
|
|
|
|
// When we request the NS, it should be SUCCESS, not DELEGATION
|
|
|
|
// (different in GLUE_OK)
|
|
|
|
doFindTest(finder, isc::dns::Name("delegation.example.org."),
|
|
|
|
isc::dns::RRType::NS(), isc::dns::RRType::NS(),
|
|
|
|
isc::dns::RRTTL(3600), ZoneFinder::SUCCESS,
|
|
|
|
expected_rdatas_, expected_sig_rdatas_,
|
|
|
|
isc::dns::Name("delegation.example.org."),
|
|
|
|
ZoneFinder::FIND_GLUE_OK);
|
|
|
|
expected_rdatas_.clear();
|
|
|
|
expected_rdatas_.push_back("dname.example.com.");
|
|
|
|
expected_sig_rdatas_.clear();
|
|
|
|
expected_sig_rdatas_.push_back("DNAME 5 3 3600 20000101000000 "
|
|
|
|
"20000201000000 12345 example.org. "
|
|
|
|
"FAKEFAKEFAKE");
|
|
|
|
doFindTest(finder, isc::dns::Name("below.dname.example.org."),
|
|
|
|
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."),
|
|
|
|
ZoneFinder::FIND_GLUE_OK);
|
|
|
|
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);
|
2011-08-12 14:35:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DatabaseClientTest, getOrigin) {
|
|
|
|
DataSourceClient::FindResult zone(client_->findZone(Name("example.org")));
|
|
|
|
ASSERT_EQ(result::SUCCESS, zone.code);
|
|
|
|
shared_ptr<DatabaseClient::Finder> finder(
|
|
|
|
dynamic_pointer_cast<DatabaseClient::Finder>(zone.zone_finder));
|
|
|
|
EXPECT_EQ(42, finder->zone_id());
|
|
|
|
EXPECT_EQ(isc::dns::Name("example.org"), finder->getOrigin());
|
2011-08-04 14:32:53 +02:00
|
|
|
}
|
|
|
|
|
2011-08-01 11:47:37 +02:00
|
|
|
}
|