Commit c6e109f7 authored by Marcin Siodelski's avatar Marcin Siodelski

[2315] Do not allow to add option definitions to dhcp4 and dhcp6 spaces.

parent d831b49b
......@@ -34,6 +34,10 @@ CfgMgr::addOptionDef(const OptionDefinitionPtr& def,
// This will be implemented when #2313 is merged.
if (option_space.empty()) {
isc_throw(BadValue, "option space name must not be empty");
} else if (option_space == "dhcp4" || option_space == "dhcp6") {
isc_throw(BadValue, "unable to override definition of option"
<< " in standard option space '" << option_space
<< "'.");
} else if (!def) {
isc_throw(MalformedOptionDefinition, "option definition must not be NULL");
} else if (getOptionDef(option_space, def->getCode())) {
......
......@@ -86,7 +86,8 @@ public:
/// option definition already exists.
/// @throw isc::dhcp::MalformedOptionDefinition when the pointer to
/// an option definition is NULL.
/// @throw isc::BadValue when the option space name is empty.
/// @throw isc::BadValue when the option space name is empty or
/// option space name is one of reserved names: dhcp4 or dhcp6.
void addOptionDef(const OptionDefinitionPtr& def,
const std::string& option_space);
......
......@@ -156,6 +156,22 @@ TEST_F(CfgMgrTest, getOptionDef) {
ASSERT_FALSE(def);
}
// This test verifies that the function that adds new option definition
// throws exceptions when arguments are invalid.
TEST_F(CfgMgrTest, addOptionDefNegative) {
CfgMgr& cfg_mgr = CfgMgr::instance();
OptionDefinitionPtr def(new OptionDefinition("option-foo", 100, "uint16"));
// Try reserved option space names.
ASSERT_THROW(cfg_mgr.addOptionDef(def, "dhcp4"), isc::BadValue);
ASSERT_THROW(cfg_mgr.addOptionDef(def, "dhcp6"), isc::BadValue);
// Try empty option space name.
ASSERT_THROW(cfg_mgr.addOptionDef(def, ""), isc::BadValue);
// Try NULL option definition.
ASSERT_THROW(cfg_mgr.addOptionDef(OptionDefinitionPtr(), "isc"),
isc::dhcp::MalformedOptionDefinition);
}
// This test verifies if the configuration manager is able to hold and return
// valid leases
TEST_F(CfgMgrTest, subnet4) {
......
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