mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-10-03 13:16:15 +00:00
[trac1062] refactor/cleanup of tests
This commit is contained in:
@@ -74,7 +74,6 @@ DatabaseClient::Finder::find(const isc::dns::Name& name,
|
|||||||
{
|
{
|
||||||
bool records_found = false;
|
bool records_found = false;
|
||||||
connection_.searchForRecords(zone_id_, name.toText());
|
connection_.searchForRecords(zone_id_, name.toText());
|
||||||
|
|
||||||
isc::dns::RRsetPtr result_rrset;
|
isc::dns::RRsetPtr result_rrset;
|
||||||
ZoneFinder::Result result_status = SUCCESS;
|
ZoneFinder::Result result_status = SUCCESS;
|
||||||
|
|
||||||
@@ -114,13 +113,16 @@ DatabaseClient::Finder::find(const isc::dns::Name& name,
|
|||||||
} else if (cur_type == isc::dns::RRType::CNAME()) {
|
} else if (cur_type == isc::dns::RRType::CNAME()) {
|
||||||
// There should be no other data, so cur_rrset should be empty,
|
// There should be no other data, so cur_rrset should be empty,
|
||||||
// except for signatures
|
// except for signatures
|
||||||
if (result_rrset && result_rrset->getRdataCount() > 0) {
|
if (result_rrset) {
|
||||||
isc_throw(DataSourceError, "CNAME found but it is not the only record for " + name.toText());
|
if (result_rrset->getRdataCount() > 0) {
|
||||||
|
isc_throw(DataSourceError, "CNAME found but it is not the only record for " + name.toText());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
result_rrset = isc::dns::RRsetPtr(new isc::dns::RRset(name,
|
||||||
|
getClass(),
|
||||||
|
cur_type,
|
||||||
|
cur_ttl));
|
||||||
}
|
}
|
||||||
result_rrset = isc::dns::RRsetPtr(new isc::dns::RRset(name,
|
|
||||||
getClass(),
|
|
||||||
cur_type,
|
|
||||||
cur_ttl));
|
|
||||||
result_rrset->addRdata(isc::dns::rdata::createRdata(cur_type,
|
result_rrset->addRdata(isc::dns::rdata::createRdata(cur_type,
|
||||||
getClass(),
|
getClass(),
|
||||||
columns[3]));
|
columns[3]));
|
||||||
@@ -139,9 +141,9 @@ DatabaseClient::Finder::find(const isc::dns::Name& name,
|
|||||||
// no data at all yet, assume the RRset data is coming, and
|
// no data at all yet, assume the RRset data is coming, and
|
||||||
// that the type covered will match
|
// that the type covered will match
|
||||||
result_rrset = isc::dns::RRsetPtr(new isc::dns::RRset(name,
|
result_rrset = isc::dns::RRsetPtr(new isc::dns::RRset(name,
|
||||||
getClass(),
|
getClass(),
|
||||||
type_covered,
|
type_covered,
|
||||||
cur_ttl));
|
cur_ttl));
|
||||||
}
|
}
|
||||||
result_rrset->addRRsig(cur_rrsig);
|
result_rrset->addRRsig(cur_rrsig);
|
||||||
}
|
}
|
||||||
|
@@ -113,6 +113,9 @@ private:
|
|||||||
addRecord("AAAA", "3600", "", "2001:db8::2");
|
addRecord("AAAA", "3600", "", "2001:db8::2");
|
||||||
addRecord("RRSIG", "3600", "", "AAAA 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
|
addRecord("RRSIG", "3600", "", "AAAA 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
|
||||||
addCurName("signed1.example.org.");
|
addCurName("signed1.example.org.");
|
||||||
|
addRecord("CNAME", "3600", "", "www.example.org.");
|
||||||
|
addRecord("RRSIG", "3600", "", "CNAME 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
|
||||||
|
addCurName("signedcname1.example.org.");
|
||||||
|
|
||||||
// let's pretend we have a database that is not careful
|
// let's pretend we have a database that is not careful
|
||||||
// about the order in which it returns data
|
// about the order in which it returns data
|
||||||
@@ -122,10 +125,9 @@ private:
|
|||||||
addRecord("RRSIG", "3600", "", "AAAA 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
|
addRecord("RRSIG", "3600", "", "AAAA 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
|
||||||
addRecord("AAAA", "3600", "", "2001:db8::1");
|
addRecord("AAAA", "3600", "", "2001:db8::1");
|
||||||
addCurName("signed2.example.org.");
|
addCurName("signed2.example.org.");
|
||||||
|
|
||||||
addRecord("CNAME", "3600", "", "www.example.org.");
|
|
||||||
addRecord("RRSIG", "3600", "", "CNAME 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
|
addRecord("RRSIG", "3600", "", "CNAME 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
|
||||||
addCurName("signedcname.example.org.");
|
addRecord("CNAME", "3600", "", "www.example.org.");
|
||||||
|
addCurName("signedcname2.example.org.");
|
||||||
|
|
||||||
// also add some intentionally bad data
|
// also add some intentionally bad data
|
||||||
cur_name.push_back(std::vector<std::string>());
|
cur_name.push_back(std::vector<std::string>());
|
||||||
@@ -192,6 +194,33 @@ TEST_F(DatabaseClientTest, noConnException) {
|
|||||||
isc::InvalidParameter);
|
isc::InvalidParameter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
void
|
||||||
|
doFindTest(shared_ptr<DatabaseClient::Finder> finder,
|
||||||
|
const isc::dns::Name& name,
|
||||||
|
const isc::dns::RRType& type,
|
||||||
|
const isc::dns::RRType& expected_type,
|
||||||
|
ZoneFinder::Result expected_result,
|
||||||
|
unsigned int expected_rdata_count,
|
||||||
|
unsigned int expected_signature_count)
|
||||||
|
{
|
||||||
|
ZoneFinder::FindResult result = finder->find(name, type,
|
||||||
|
NULL, ZoneFinder::FIND_DEFAULT);
|
||||||
|
ASSERT_EQ(expected_result, result.code) << name.toText() << " " << type.toText();
|
||||||
|
if (expected_rdata_count > 0) {
|
||||||
|
EXPECT_EQ(expected_rdata_count, result.rrset->getRdataCount());
|
||||||
|
EXPECT_EQ(expected_type, result.rrset->getType());
|
||||||
|
if (expected_signature_count > 0) {
|
||||||
|
EXPECT_EQ(expected_signature_count, result.rrset->getRRsig()->getRdataCount());
|
||||||
|
} else {
|
||||||
|
EXPECT_EQ(isc::dns::RRsetPtr(), result.rrset->getRRsig());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
EXPECT_EQ(isc::dns::RRsetPtr(), result.rrset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // end anonymous namespace
|
||||||
|
|
||||||
TEST_F(DatabaseClientTest, find) {
|
TEST_F(DatabaseClientTest, find) {
|
||||||
DataSourceClient::FindResult zone(client_->findZone(Name("example.org")));
|
DataSourceClient::FindResult zone(client_->findZone(Name("example.org")));
|
||||||
ASSERT_EQ(result::SUCCESS, zone.code);
|
ASSERT_EQ(result::SUCCESS, zone.code);
|
||||||
@@ -200,62 +229,46 @@ TEST_F(DatabaseClientTest, find) {
|
|||||||
EXPECT_EQ(42, finder->zone_id());
|
EXPECT_EQ(42, finder->zone_id());
|
||||||
isc::dns::Name name("www.example.org.");
|
isc::dns::Name name("www.example.org.");
|
||||||
|
|
||||||
ZoneFinder::FindResult result1 = finder->find(name, isc::dns::RRType::A(),
|
doFindTest(finder, isc::dns::Name("www.example.org."),
|
||||||
NULL, ZoneFinder::FIND_DEFAULT);
|
isc::dns::RRType::A(), isc::dns::RRType::A(),
|
||||||
ASSERT_EQ(ZoneFinder::SUCCESS, result1.code);
|
ZoneFinder::SUCCESS, 1, 0);
|
||||||
EXPECT_EQ(1, result1.rrset->getRdataCount());
|
doFindTest(finder, isc::dns::Name("www.example.org."),
|
||||||
EXPECT_EQ(isc::dns::RRType::A(), result1.rrset->getType());
|
isc::dns::RRType::AAAA(), isc::dns::RRType::AAAA(),
|
||||||
EXPECT_EQ(isc::dns::RRsetPtr(), result1.rrset->getRRsig());
|
ZoneFinder::SUCCESS, 2, 0);
|
||||||
|
doFindTest(finder, isc::dns::Name("www.example.org."),
|
||||||
|
isc::dns::RRType::TXT(), isc::dns::RRType::TXT(),
|
||||||
|
ZoneFinder::NXRRSET, 0, 0);
|
||||||
|
doFindTest(finder, isc::dns::Name("cname.example.org."),
|
||||||
|
isc::dns::RRType::A(), isc::dns::RRType::CNAME(),
|
||||||
|
ZoneFinder::CNAME, 1, 0);
|
||||||
|
doFindTest(finder, isc::dns::Name("doesnotexist.example.org."),
|
||||||
|
isc::dns::RRType::A(), isc::dns::RRType::A(),
|
||||||
|
ZoneFinder::NXDOMAIN, 0, 0);
|
||||||
|
doFindTest(finder, isc::dns::Name("signed1.example.org."),
|
||||||
|
isc::dns::RRType::A(), isc::dns::RRType::A(),
|
||||||
|
ZoneFinder::SUCCESS, 1, 1);
|
||||||
|
doFindTest(finder, isc::dns::Name("signed1.example.org."),
|
||||||
|
isc::dns::RRType::AAAA(), isc::dns::RRType::AAAA(),
|
||||||
|
ZoneFinder::SUCCESS, 2, 1);
|
||||||
|
doFindTest(finder, isc::dns::Name("signed1.example.org."),
|
||||||
|
isc::dns::RRType::TXT(), isc::dns::RRType::TXT(),
|
||||||
|
ZoneFinder::NXRRSET, 0, 0);
|
||||||
|
doFindTest(finder, isc::dns::Name("signedcname1.example.org."),
|
||||||
|
isc::dns::RRType::A(), isc::dns::RRType::CNAME(),
|
||||||
|
ZoneFinder::CNAME, 1, 1);
|
||||||
|
|
||||||
ZoneFinder::FindResult result2 = finder->find(name, isc::dns::RRType::AAAA(),
|
doFindTest(finder, isc::dns::Name("signed2.example.org."),
|
||||||
NULL, ZoneFinder::FIND_DEFAULT);
|
isc::dns::RRType::A(), isc::dns::RRType::A(),
|
||||||
ASSERT_EQ(ZoneFinder::SUCCESS, result2.code);
|
ZoneFinder::SUCCESS, 1, 1);
|
||||||
EXPECT_EQ(2, result2.rrset->getRdataCount());
|
doFindTest(finder, isc::dns::Name("signed2.example.org."),
|
||||||
EXPECT_EQ(isc::dns::RRType::AAAA(), result2.rrset->getType());
|
isc::dns::RRType::AAAA(), isc::dns::RRType::AAAA(),
|
||||||
EXPECT_EQ(isc::dns::RRsetPtr(), result2.rrset->getRRsig());
|
ZoneFinder::SUCCESS, 2, 1);
|
||||||
|
doFindTest(finder, isc::dns::Name("signed2.example.org."),
|
||||||
ZoneFinder::FindResult result3 = finder->find(name, isc::dns::RRType::TXT(),
|
isc::dns::RRType::TXT(), isc::dns::RRType::TXT(),
|
||||||
NULL, ZoneFinder::FIND_DEFAULT);
|
ZoneFinder::NXRRSET, 0, 0);
|
||||||
ASSERT_EQ(ZoneFinder::NXRRSET, result3.code);
|
doFindTest(finder, isc::dns::Name("signedcname2.example.org."),
|
||||||
EXPECT_EQ(isc::dns::ConstRRsetPtr(), result3.rrset);
|
isc::dns::RRType::A(), isc::dns::RRType::CNAME(),
|
||||||
|
ZoneFinder::CNAME, 1, 1);
|
||||||
ZoneFinder::FindResult result4 = finder->find(isc::dns::Name("cname.example.org."),
|
|
||||||
isc::dns::RRType::A(),
|
|
||||||
NULL, ZoneFinder::FIND_DEFAULT);
|
|
||||||
ASSERT_EQ(ZoneFinder::CNAME, result4.code);
|
|
||||||
EXPECT_EQ(1, result4.rrset->getRdataCount());
|
|
||||||
EXPECT_EQ(isc::dns::RRType::CNAME(), result4.rrset->getType());
|
|
||||||
EXPECT_EQ(isc::dns::RRsetPtr(), result4.rrset->getRRsig());
|
|
||||||
|
|
||||||
ZoneFinder::FindResult result5 = finder->find(isc::dns::Name("doesnotexist.example.org."),
|
|
||||||
isc::dns::RRType::A(),
|
|
||||||
NULL, ZoneFinder::FIND_DEFAULT);
|
|
||||||
ASSERT_EQ(ZoneFinder::NXDOMAIN, result5.code);
|
|
||||||
EXPECT_EQ(isc::dns::ConstRRsetPtr(), result5.rrset);
|
|
||||||
|
|
||||||
ZoneFinder::FindResult result6 = finder->find(isc::dns::Name("signed1.example.org."),
|
|
||||||
isc::dns::RRType::A(),
|
|
||||||
NULL, ZoneFinder::FIND_DEFAULT);
|
|
||||||
ASSERT_EQ(ZoneFinder::SUCCESS, result6.code);
|
|
||||||
EXPECT_EQ(1, result6.rrset->getRdataCount());
|
|
||||||
EXPECT_EQ(isc::dns::RRType::A(), result6.rrset->getType());
|
|
||||||
EXPECT_NE(isc::dns::RRsetPtr(), result6.rrset->getRRsig());
|
|
||||||
|
|
||||||
ZoneFinder::FindResult result7 = finder->find(isc::dns::Name("signed1.example.org."),
|
|
||||||
isc::dns::RRType::AAAA(),
|
|
||||||
NULL, ZoneFinder::FIND_DEFAULT);
|
|
||||||
ASSERT_EQ(ZoneFinder::SUCCESS, result7.code);
|
|
||||||
EXPECT_EQ(2, result7.rrset->getRdataCount());
|
|
||||||
EXPECT_EQ(isc::dns::RRType::AAAA(), result7.rrset->getType());
|
|
||||||
EXPECT_NE(isc::dns::RRsetPtr(), result7.rrset->getRRsig());
|
|
||||||
|
|
||||||
ZoneFinder::FindResult result8 = finder->find(isc::dns::Name("signedcname.example.org."),
|
|
||||||
isc::dns::RRType::A(),
|
|
||||||
NULL, ZoneFinder::FIND_DEFAULT);
|
|
||||||
ASSERT_EQ(ZoneFinder::SUCCESS, result8.code);
|
|
||||||
EXPECT_EQ(1, result8.rrset->getRdataCount());
|
|
||||||
EXPECT_EQ(isc::dns::RRType::CNAME(), result8.rrset->getType());
|
|
||||||
EXPECT_NE(isc::dns::RRsetPtr(), result8.rrset->getRRsig());
|
|
||||||
|
|
||||||
EXPECT_THROW(finder->find(isc::dns::Name("emptyvector.example.org."),
|
EXPECT_THROW(finder->find(isc::dns::Name("emptyvector.example.org."),
|
||||||
isc::dns::RRType::A(),
|
isc::dns::RRType::A(),
|
||||||
|
Reference in New Issue
Block a user