Commit 9b8687e3 authored by Marcin Siodelski's avatar Marcin Siodelski
Browse files

[3810] Addressed review comments.

Removed static constant and updated tests for HostReservationParser.
parent 0f5c5c76
......@@ -31,12 +31,11 @@ namespace {
/// host reservation in DHCPv4.
const std::set<std::string>& getSupportedParams4() {
static const char* params[] = {
"duid", "hw-address", "hostname", "ip-address"
"duid", "hw-address", "hostname", "ip-address", NULL
};
static const size_t params_num = static_cast<const size_t>(sizeof(params) / sizeof(char*));
static std::set<std::string> params_set;
if (params_set.empty()) {
for (int i = 0; i < params_num; ++i) {
for (int i = 0; params[i] != NULL; ++i) {
params_set.insert(std::string(params[i]));
}
}
......@@ -49,12 +48,12 @@ const std::set<std::string>& getSupportedParams4() {
/// host reservation in DHCPv6.
const std::set<std::string>& getSupportedParams6() {
static const char* params[] = {
"duid", "hw-address", "hostname", "ip-addresses", "prefixes"
"duid", "hw-address", "hostname", "ip-addresses", "prefixes", NULL
};
static const size_t params_num = static_cast<const size_t>(sizeof(params) / sizeof(char*));
static std::set<std::string> params_set;
if (params_set.empty()) {
for (int i = 0; i < params_num; ++i) {
for (int i = 0; params[i] != NULL; ++i) {
params_set.insert(std::string(params[i]));
}
}
......
// Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2014-2015 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
......
......@@ -276,9 +276,12 @@ TEST_F(HostReservationParserTest, bcastAddress) {
// This test verifies that the configuration parser for host reservations
// throws an exception when unsupported parameter is specified.
TEST_F(HostReservationParserTest, invalidParameterName) {
// The "ip-addresses" parameter name is incorrect for the DHCPv4
// case - it is only valid for DHCPv6 case. Trying to set this
// parameter should result in error.
std::string config = "{ \"hw-address\": \"01:02:03:04:05:06\","
"\"hostname\": \"foo.bar.isc.org\","
"\"ip-addresses\": \"192.0.2.3\" }";
"\"ip-addresses\": \"2001:db8:1::1\" }";
ElementPtr config_element = Element::fromJSON(config);
......@@ -497,4 +500,20 @@ TEST_F(HostReservationParserTest, dhcp6DuplicatedPrefix) {
}
// This test verifies that the configuration parser for host reservations
// throws an exception when unsupported parameter is specified.
TEST_F(HostReservationParserTest, dhcp6invalidParameterName) {
// The "ip-address" parameter name is incorrect for the DHCPv6
// case - it is only valid for DHCPv4 case. Trying to set this
// parameter should result in error.
std::string config = "{ \"hw-address\": \"01:02:03:04:05:06\","
"\"hostname\": \"foo.bar.isc.org\","
"\"ip-address\": \"192.0.2.3\" }";
ElementPtr config_element = Element::fromJSON(config);
HostReservationParser6 parser(SubnetID(10));
EXPECT_THROW(parser.build(config_element), DhcpConfigError);
}
} // end of anonymous 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