Commit c1ba429f authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner
Browse files

[2378] Detect class mismatch with copy mode

parent 235a1870
......@@ -42,7 +42,8 @@ class MockClient : public DataSourceClient {
public:
MockClient() :
commit_called_(false),
missing_zone_(false)
missing_zone_(false),
rrclass_(RRClass::IN())
{}
virtual FindResult findZone(const Name&) const {
isc_throw(isc::NotImplemented, "Method not used in tests");
......@@ -67,6 +68,8 @@ public:
bool commit_called_;
// If set to true, getUpdater returns NULL
bool missing_zone_;
// The pretended class of the client. Usualy IN, but can be overriden.
RRClass rrclass_;
};
// The updater isn't really correct according to the API. For example,
......@@ -77,10 +80,11 @@ public:
class Updater : public ZoneUpdater {
public:
Updater(MockClient* client) :
client_(client)
client_(client),
finder_(client_->rrclass_)
{}
virtual ZoneFinder& getFinder() {
isc_throw(isc::NotImplemented, "Method not used in tests");
return (finder_);
}
virtual void addRRset(const isc::dns::AbstractRRset& rrset) {
if (client_->commit_called_) {
......@@ -96,6 +100,34 @@ public:
}
private:
MockClient* client_;
class Finder : public ZoneFinder {
public:
Finder(const RRClass& rrclass) :
class_(rrclass)
{}
virtual RRClass getClass() const {
return (class_);
}
virtual Name getOrigin() const {
isc_throw(isc::NotImplemented, "Method not used in tests");
}
virtual shared_ptr<Context> find(const Name&, const RRType&,
const FindOptions)
{
isc_throw(isc::NotImplemented, "Method not used in tests");
}
virtual shared_ptr<Context> findAll(const Name&,
vector<ConstRRsetPtr>&,
const FindOptions)
{
isc_throw(isc::NotImplemented, "Method not used in tests");
}
virtual FindNSEC3Result findNSEC3(const Name&, bool) {
isc_throw(isc::NotImplemented, "Method not used in tests");
}
private:
const RRClass class_;
} finder_;
};
ZoneUpdaterPtr
......@@ -242,6 +274,14 @@ TEST_F(ZoneLoaderTest, copyMissingSource) {
source_client_), DataSourceError);
}
// The class of the source and destination are different
TEST_F(ZoneLoaderTest, classMismatch) {
destination_client_.rrclass_ = RRClass::CH();
prepareSource(Name::ROOT_NAME(), "root.zone");
EXPECT_THROW(ZoneLoader(destination_client_, Name::ROOT_NAME(),
source_client_), isc::InvalidParameter);
}
// Load an unsigned zone, all at once
TEST_F(ZoneLoaderTest, loadUnsigned) {
ZoneLoader loader(destination_client_, Name::ROOT_NAME(),
......
......@@ -43,6 +43,17 @@ ZoneLoader::ZoneLoader(DataSourceClient& destination, const Name& zone_name,
isc_throw(DataSourceError, "Zone " << zone_name << " not found in "
"destination data source, can't fill it with data");
}
// The dereference of zone_finder is safe, if we can get iterator, we can
// get a finder.
//
// TODO: We probably need a getClass on the data source itself.
if (source.findZone(zone_name).zone_finder->getClass() !=
updater_->getFinder().getClass()) {
isc_throw(isc::InvalidParameter,
"Source and destination class mismatch");
}
}
}
namespace {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment