2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-09-18 14:00:15 +00:00

[1183] remove searchForRecords(), getNextRecord() and resetSearch()

since they can now be done through getRecords()
This commit is contained in:
Jelte Jansen
2011-08-18 12:19:56 +02:00
parent 171088e69f
commit d88becea33
5 changed files with 3 additions and 296 deletions

View File

@@ -62,12 +62,6 @@ public:
return (database_name_);
}
// These are just to compile, they won't be called
virtual void searchForRecords(int, const std::string&) { }
virtual bool getNextRecord(string*, size_t) {
return (false);
}
virtual void resetSearch() { }
private:
const std::string database_name_;
@@ -82,7 +76,7 @@ private:
*/
class MockAccessor : public NopAccessor {
public:
MockAccessor() : cur_record(0), search_running_(false)
MockAccessor()
{
fillData();
}
@@ -267,83 +261,11 @@ public:
}
}
virtual void searchForRecords(int zone_id, const std::string& name) {
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;
// we're not aiming for efficiency in this test, simply
// copy the relevant vector from records
cur_record = 0;
if (zone_id == 42) {
if (records.count(name) > 0) {
cur_name = records.find(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();
}
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 {
resetSearch();
return (false);
}
};
virtual void resetSearch() {
search_running_ = false;
};
bool searchRunning() const {
return (search_running_);
}
private:
std::map<std::string, std::vector< std::vector<std::string> > > 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
// used as temporary storageduring 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_;
// Adds one record to the current name in the database
// The actual data will not be added to 'records' until
// addCurName() is called
@@ -567,7 +489,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);
}
@@ -753,7 +674,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();
@@ -764,7 +684,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();
@@ -775,7 +694,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();
@@ -784,7 +702,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();
@@ -794,7 +711,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();
@@ -804,7 +720,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();
@@ -813,7 +728,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();
@@ -825,7 +739,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();
@@ -837,7 +750,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();
@@ -846,7 +758,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();
@@ -857,7 +768,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();
@@ -869,7 +779,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();
@@ -881,7 +790,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();
@@ -890,7 +798,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();
@@ -901,7 +808,6 @@ TEST_F(DatabaseClientTest, find) {
isc::dns::RRTTL(3600),
ZoneFinder::CNAME,
expected_rdatas_, expected_sig_rdatas_);
EXPECT_FALSE(current_database_->searchRunning());
expected_rdatas_.clear();
@@ -913,7 +819,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();
@@ -924,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();
@@ -935,7 +839,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();
@@ -946,7 +849,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();
@@ -957,77 +859,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());
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());
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
@@ -1041,7 +929,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) {
@@ -1056,7 +943,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.");
@@ -1066,7 +952,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)
@@ -1081,7 +966,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_,
@@ -1092,7 +976,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
@@ -1100,14 +983,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
@@ -1122,17 +1003,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."),
@@ -1148,33 +1026,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());
}
// Glue-OK mode. Just go trough NS delegations down (but not trough
@@ -1229,13 +1101,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, getOrigin) {