mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-09-01 06:25:34 +00:00
[1791] fixed one remaining regression: 'separate_rrs' case was broken.
added a test for that case to confirm the regression and the fix. also introduced some more cleanups: removed rdata_txt_ so we simplify the code further, made isSameType static class function (it doesn't refer to any class attributes), constified separate_rrs_.
This commit is contained in:
@@ -1011,12 +1011,8 @@ public:
|
|||||||
const RRType rtype(rtype_txt_);
|
const RRType rtype(rtype_txt_);
|
||||||
RRsetPtr rrset(new RRset(Name(name_txt_), class_, rtype,
|
RRsetPtr rrset(new RRset(Name(name_txt_), class_, rtype,
|
||||||
RRTTL(ttl_txt_)));
|
RRTTL(ttl_txt_)));
|
||||||
// For the first RR, rdata_ is null, so we need to create it here.
|
// Remember the first RDATA of the RRset for comparison:
|
||||||
// After that, rdata_ will be updated in the while loop below.
|
const ConstRdataPtr rdata_base = rdata_;
|
||||||
if (!rdata_) {
|
|
||||||
rdata_ = rdata::createRdata(rtype, class_, rdata_txt_);
|
|
||||||
}
|
|
||||||
const ConstRdataPtr rdata_base = rdata_; // remember it for comparison
|
|
||||||
while (true) {
|
while (true) {
|
||||||
// Extend the RRset with the new RDATA.
|
// Extend the RRset with the new RDATA.
|
||||||
rrset->addRdata(rdata_);
|
rrset->addRdata(rdata_);
|
||||||
@@ -1030,13 +1026,11 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if the next record belongs to the same RRset. If not,
|
// Check if the next record belongs to the same RRset. If not,
|
||||||
// we are done. The next RDATA is stored in rdata_, which is used
|
// we are done. The next RDATA has been stored in rdata_, which
|
||||||
// within this loop (if it belongs to the same RRset) or in the
|
// is used within this loop (if it belongs to the same RRset) or
|
||||||
// next call.
|
// in the next call.
|
||||||
const RRType next_rtype(rtype_txt_);
|
|
||||||
rdata_ = rdata::createRdata(next_rtype, class_, rdata_txt_);
|
|
||||||
if (Name(name_txt_) != rrset->getName() ||
|
if (Name(name_txt_) != rrset->getName() ||
|
||||||
!isSameType(rtype, rdata_base, next_rtype, rdata_)) {
|
!isSameType(rtype, rdata_base, RRType(rtype_txt_), rdata_)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1059,7 +1053,7 @@ private:
|
|||||||
// Check two RDATA types are equivalent. Basically it's a trivial
|
// Check two RDATA types are equivalent. Basically it's a trivial
|
||||||
// comparison, but if both are of RRSIG, we should also compare the types
|
// comparison, but if both are of RRSIG, we should also compare the types
|
||||||
// covered.
|
// covered.
|
||||||
bool isSameType(RRType type1, ConstRdataPtr rdata1,
|
static bool isSameType(RRType type1, ConstRdataPtr rdata1,
|
||||||
RRType type2, ConstRdataPtr rdata2)
|
RRType type2, ConstRdataPtr rdata2)
|
||||||
{
|
{
|
||||||
if (type1 != type2) {
|
if (type1 != type2) {
|
||||||
@@ -1077,10 +1071,13 @@ private:
|
|||||||
void getData() {
|
void getData() {
|
||||||
string data[DatabaseAccessor::COLUMN_COUNT];
|
string data[DatabaseAccessor::COLUMN_COUNT];
|
||||||
data_ready_ = context_->getNext(data);
|
data_ready_ = context_->getNext(data);
|
||||||
|
if (data_ready_) {
|
||||||
name_txt_ = data[DatabaseAccessor::NAME_COLUMN];
|
name_txt_ = data[DatabaseAccessor::NAME_COLUMN];
|
||||||
rtype_txt_ = data[DatabaseAccessor::TYPE_COLUMN];
|
rtype_txt_ = data[DatabaseAccessor::TYPE_COLUMN];
|
||||||
ttl_txt_ = data[DatabaseAccessor::TTL_COLUMN];
|
ttl_txt_ = data[DatabaseAccessor::TTL_COLUMN];
|
||||||
rdata_txt_= data[DatabaseAccessor::RDATA_COLUMN];
|
rdata_ = rdata::createRdata(RRType(rtype_txt_), class_,
|
||||||
|
data[DatabaseAccessor::RDATA_COLUMN]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The dedicated accessor
|
// The dedicated accessor
|
||||||
@@ -1094,12 +1091,12 @@ private:
|
|||||||
// Status
|
// Status
|
||||||
bool ready_, data_ready_;
|
bool ready_, data_ready_;
|
||||||
// Data of the next row
|
// Data of the next row
|
||||||
string name_txt_, rtype_txt_, rdata_txt_, ttl_txt_;
|
string name_txt_, rtype_txt_, ttl_txt_;
|
||||||
// RDATA of the next row; created from rdata_txt_.
|
// RDATA of the next row
|
||||||
ConstRdataPtr rdata_;
|
ConstRdataPtr rdata_;
|
||||||
// Whether to modify differing TTL values, or treat a different TTL as
|
// Whether to modify differing TTL values, or treat a different TTL as
|
||||||
// a different RRset
|
// a different RRset
|
||||||
bool separate_rrs_;
|
const bool separate_rrs_;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1333,7 +1333,7 @@ checkRRset(isc::dns::ConstRRsetPtr rrset,
|
|||||||
isc::testutils::rrsetCheck(expected_rrset, rrset);
|
isc::testutils::rrsetCheck(expected_rrset, rrset);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterate through a zone
|
// Iterate through a zone, common case
|
||||||
TYPED_TEST(DatabaseClientTest, iterator) {
|
TYPED_TEST(DatabaseClientTest, iterator) {
|
||||||
ZoneIteratorPtr it(this->client_->getIterator(Name("example.org")));
|
ZoneIteratorPtr it(this->client_->getIterator(Name("example.org")));
|
||||||
ConstRRsetPtr rrset(it->getNextRRset());
|
ConstRRsetPtr rrset(it->getNextRRset());
|
||||||
@@ -1341,71 +1341,100 @@ TYPED_TEST(DatabaseClientTest, iterator) {
|
|||||||
|
|
||||||
// The first name should be the zone origin.
|
// The first name should be the zone origin.
|
||||||
EXPECT_EQ(this->zname_, rrset->getName());
|
EXPECT_EQ(this->zname_, rrset->getName());
|
||||||
|
}
|
||||||
|
|
||||||
// The rest of the checks work only for the mock accessor.
|
// Supplemental structure used in the couple of tests below. It represents
|
||||||
if (!this->is_mock_) {
|
// parameters of an expected RRset containing up to two RDATAs. If it contains
|
||||||
return;
|
// only one RDATA, rdata2 is NULL.
|
||||||
|
struct ExpectedRRset {
|
||||||
|
const char* const name;
|
||||||
|
const RRType rrtype;
|
||||||
|
const RRTTL rrttl;
|
||||||
|
const char* const rdata1;
|
||||||
|
const char* const rdata2;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Common checker for the iterator tests below. It extracts RRsets from the
|
||||||
|
// give iterator and compare them to the expected sequence.
|
||||||
|
void
|
||||||
|
checkIteratorSequence(ZoneIterator& it, ExpectedRRset expected_sequence[],
|
||||||
|
size_t num_rrsets)
|
||||||
|
{
|
||||||
|
vector<string> expected_rdatas;
|
||||||
|
for (size_t i = 0; i < num_rrsets; ++i) {
|
||||||
|
const ConstRRsetPtr rrset = it.getNextRRset();
|
||||||
|
ASSERT_TRUE(rrset);
|
||||||
|
|
||||||
|
expected_rdatas.clear();
|
||||||
|
expected_rdatas.push_back(expected_sequence[i].rdata1);
|
||||||
|
if (expected_sequence[i].rdata2 != NULL) {
|
||||||
|
expected_rdatas.push_back(expected_sequence[i].rdata2);
|
||||||
}
|
}
|
||||||
|
checkRRset(rrset, Name(expected_sequence[i].name), RRClass::IN(),
|
||||||
|
expected_sequence[i].rrtype, expected_sequence[i].rrttl,
|
||||||
|
expected_rdatas);
|
||||||
|
}
|
||||||
|
EXPECT_FALSE(it.getNextRRset());
|
||||||
|
}
|
||||||
|
|
||||||
this->expected_rdatas_.clear();
|
TEST_F(MockDatabaseClientTest, iterator) {
|
||||||
this->expected_rdatas_.push_back("192.0.2.1");
|
// This version of test creates an iterator that combines same types of
|
||||||
checkRRset(rrset, Name("example.org"), this->qclass_, RRType::A(),
|
// RRs into single RRsets.
|
||||||
this->rrttl_, this->expected_rdatas_);
|
ExpectedRRset expected_sequence[] = {
|
||||||
|
{"example.org", RRType::A(), rrttl_, "192.0.2.1", NULL},
|
||||||
|
{"example.org", RRType::SOA(), rrttl_,
|
||||||
|
"ns1.example.org. admin.example.org. 1234 3600 1800 2419200 7200",
|
||||||
|
NULL},
|
||||||
|
{"x.example.org", RRType::A(), RRTTL(300), "192.0.2.1", "192.0.2.2"},
|
||||||
|
{"x.example.org", RRType::AAAA(), RRTTL(300),
|
||||||
|
"2001:db8::1", "2001:db8::2"},
|
||||||
|
{"x.example.org", RRType::RRSIG(), RRTTL(300),
|
||||||
|
"A 5 3 3600 20000101000000 20000201000000 12345 example.org. "
|
||||||
|
"FAKEFAKEFAKE", NULL},
|
||||||
|
{"x.example.org", RRType::RRSIG(), RRTTL(300),
|
||||||
|
"AAAA 5 3 3600 20000101000000 20000201000000 12345 example.org. "
|
||||||
|
"FAKEFAKEFAKEFAKE", NULL},
|
||||||
|
{"ttldiff.example.org", RRType::A(), RRTTL(300),
|
||||||
|
"192.0.2.1", "192.0.2.2"},
|
||||||
|
{"ttldiff2.example.org", RRType::AAAA(), RRTTL(300),
|
||||||
|
"2001:db8::1", "2001:db8::2"}
|
||||||
|
};
|
||||||
|
checkIteratorSequence(*client_->getIterator(Name("example.org")),
|
||||||
|
expected_sequence,
|
||||||
|
sizeof(expected_sequence) /
|
||||||
|
sizeof(expected_sequence[0]));
|
||||||
|
}
|
||||||
|
|
||||||
rrset = it->getNextRRset();
|
TEST_F(MockDatabaseClientTest, iteratorSeparateRRs) {
|
||||||
this->expected_rdatas_.clear();
|
// This version of test creates an iterator that separates all RRs as
|
||||||
this->expected_rdatas_.push_back("ns1.example.org. admin.example.org. "
|
// individual RRsets. In particular, it preserves the TTLs of an RRset
|
||||||
"1234 3600 1800 2419200 7200");
|
// even if they are different.
|
||||||
checkRRset(rrset, Name("example.org"), this->qclass_, RRType::SOA(),
|
ExpectedRRset expected_sequence[] = {
|
||||||
this->rrttl_, this->expected_rdatas_);
|
{"example.org", RRType::A(), rrttl_, "192.0.2.1", NULL},
|
||||||
|
{"example.org", RRType::SOA(), rrttl_,
|
||||||
rrset = it->getNextRRset();
|
"ns1.example.org. admin.example.org. 1234 3600 1800 2419200 7200",
|
||||||
this->expected_rdatas_.clear();
|
NULL},
|
||||||
this->expected_rdatas_.push_back("192.0.2.1");
|
{"x.example.org", RRType::A(), RRTTL(300), "192.0.2.1", NULL},
|
||||||
this->expected_rdatas_.push_back("192.0.2.2");
|
{"x.example.org", RRType::A(), RRTTL(300), "192.0.2.2", NULL},
|
||||||
checkRRset(rrset, Name("x.example.org"), this->qclass_, RRType::A(),
|
{"x.example.org", RRType::AAAA(), RRTTL(300), "2001:db8::1", NULL},
|
||||||
RRTTL(300), this->expected_rdatas_);
|
{"x.example.org", RRType::AAAA(), RRTTL(300), "2001:db8::2", NULL},
|
||||||
|
{"x.example.org", RRType::RRSIG(), RRTTL(300),
|
||||||
rrset = it->getNextRRset();
|
"A 5 3 3600 20000101000000 20000201000000 12345 example.org. "
|
||||||
this->expected_rdatas_.clear();
|
"FAKEFAKEFAKE", NULL},
|
||||||
this->expected_rdatas_.push_back("2001:db8::1");
|
{"x.example.org", RRType::RRSIG(), RRTTL(300),
|
||||||
this->expected_rdatas_.push_back("2001:db8::2");
|
"AAAA 5 3 3600 20000101000000 20000201000000 12345 example.org. "
|
||||||
checkRRset(rrset, Name("x.example.org"), this->qclass_, RRType::AAAA(),
|
"FAKEFAKEFAKEFAKE", NULL},
|
||||||
RRTTL(300), this->expected_rdatas_);
|
{"ttldiff.example.org", RRType::A(), RRTTL(300), "192.0.2.1", NULL},
|
||||||
|
{"ttldiff.example.org", RRType::A(), RRTTL(600), "192.0.2.2", NULL},
|
||||||
rrset = it->getNextRRset();
|
{"ttldiff2.example.org", RRType::AAAA(), RRTTL(600), "2001:db8::1",
|
||||||
this->expected_rdatas_.clear();
|
NULL},
|
||||||
this->expected_rdatas_.push_back(
|
{"ttldiff2.example.org", RRType::AAAA(), RRTTL(300), "2001:db8::2",
|
||||||
"A 5 3 3600 20000101000000 20000201000000 "
|
NULL}
|
||||||
"12345 example.org. FAKEFAKEFAKE");
|
};
|
||||||
checkRRset(rrset, Name("x.example.org"), this->qclass_, RRType::RRSIG(),
|
checkIteratorSequence(*client_->getIterator(Name("example.org"), true),
|
||||||
RRTTL(300), this->expected_rdatas_);
|
expected_sequence,
|
||||||
|
sizeof(expected_sequence) /
|
||||||
rrset = it->getNextRRset();
|
sizeof(expected_sequence[0]));
|
||||||
this->expected_rdatas_.clear();
|
|
||||||
this->expected_rdatas_.push_back(
|
|
||||||
"AAAA 5 3 3600 20000101000000 20000201000000 "
|
|
||||||
"12345 example.org. FAKEFAKEFAKEFAKE");
|
|
||||||
checkRRset(rrset, Name("x.example.org"), this->qclass_, RRType::RRSIG(),
|
|
||||||
RRTTL(300), this->expected_rdatas_);
|
|
||||||
|
|
||||||
rrset = it->getNextRRset();
|
|
||||||
ASSERT_NE(ConstRRsetPtr(), rrset);
|
|
||||||
this->expected_rdatas_.clear();
|
|
||||||
this->expected_rdatas_.push_back("192.0.2.1");
|
|
||||||
this->expected_rdatas_.push_back("192.0.2.2");
|
|
||||||
checkRRset(rrset, Name("ttldiff.example.org"), this->qclass_, RRType::A(),
|
|
||||||
RRTTL(300), this->expected_rdatas_);
|
|
||||||
|
|
||||||
rrset = it->getNextRRset();
|
|
||||||
ASSERT_NE(ConstRRsetPtr(), rrset);
|
|
||||||
this->expected_rdatas_.clear();
|
|
||||||
this->expected_rdatas_.push_back("2001:db8::1");
|
|
||||||
this->expected_rdatas_.push_back("2001:db8::2");
|
|
||||||
checkRRset(rrset, Name("ttldiff2.example.org"), this->qclass_,
|
|
||||||
RRType::AAAA(), RRTTL(300), this->expected_rdatas_);
|
|
||||||
|
|
||||||
EXPECT_EQ(ConstRRsetPtr(), it->getNextRRset());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This has inconsistent TTL in the set (the rest, like nonsense in
|
// This has inconsistent TTL in the set (the rest, like nonsense in
|
||||||
|
Reference in New Issue
Block a user