}
x.subnet_id = static_cast<SubnetID>(tmp128);
- if (params->contains("iaid")) {
- x.iaid = params->get("iaid")->intValue();
+ tmp = params->get("iaid");
+ if (tmp) {
+ if (!v6) {
+ isc_throw(BadValue, "'iaid' parameter is specific to DHCPv6.");
+ }
+ if (tmp->getType() != Element::integer) {
+ isc_throw(BadValue, "'iaid' parameter is not integer.");
+ }
+ tmp128 = tmp->intValue();
+ if ((tmp128 < uint32_min) || (tmp128 > uint32_max)) {
+ isc_throw(BadValue, "'iaid' parameter is not a 32 bit unsigned integer.");
+ }
+ x.iaid = static_cast<uint32_t>(tmp128);
}
// No address specified. Ok, so it must be identifier based query.
// Structure detailing a test scenario.
struct Scenario {
string name_; // name
+ bool add_subnet_id_; // set to true to add a subnet-id
string param_; // parameter entry to test
string exp_rsp_; // expected response
};
std::vector<Scenario> scenarios = {
{
"Invalid family",
+ false,
"\"ip-address\": \"2001:db8:1::1\"",
"Invalid IPv4 address specified: 2001:db8:1::1"
},
{
"Bad address",
+ false,
"\"ip-address\": \"221B Baker St.\"",
"Failed to convert string to address '221B Baker St.': Invalid argument"
},
{
"Not numeric subnet id",
+ false,
"\"subnet-id\": \"foo\"",
"'subnet-id' parameter is not integer."
},
{
"Negative subnet id",
+ false,
"\"subnet-id\": -1",
"'subnet-id' parameter is not a 32 bit unsigned integer."
},
{
"Too large subnet id",
+ false,
"\"subnet-id\": 4294967297",
"'subnet-id' parameter is not a 32 bit unsigned integer."
+ },
+ {
+ "IAID is v6 only",
+ true,
+ "\"iaid\": 0",
+ "'iaid' parameter is specific to DHCPv6."
}
};
string prefix_cmd =
"{\n"
" \"command\": \"lease4-get\",\n"
- " \"arguments\": {"
+ " \"arguments\": {\n"
" ";
+ string subnet_id = " \"subnet-id\": 1\n,";
string end_cmd =
+ "\n"
" }\n"
- "}";
+ "}\n";
for (auto const& scenario : scenarios) {
SCOPED_TRACE(scenario.name_);
- string cmd = prefix_cmd + scenario.param_ + end_cmd;
+ string cmd = prefix_cmd;
+ if (scenario.add_subnet_id_) {
+ cmd += subnet_id;
+ }
+ cmd += scenario.param_ + end_cmd;
testCommand(cmd, CONTROL_RESULT_ERROR, scenario.exp_rsp_);
}
}
// Structure detailing a test scenario.
struct Scenario {
string name_; // name
+ bool add_subnet_id_; // set to true to add a subnet-id
string param_; // parameter entry to test
string exp_rsp_; // expected response
};
std::vector<Scenario> scenarios = {
{
"Invalid family",
+ false,
"\"ip-address\": \"192.0.2.1\"",
"Invalid IPv6 address specified: 192.0.2.1"
},
{
"Bad address",
+ false,
"\"ip-address\": \"221B Baker St.\"",
"Failed to convert string to address '221B Baker St.': Invalid argument"
},
{
"Not numeric subnet id",
+ false,
"\"subnet-id\": \"foo\"",
"'subnet-id' parameter is not integer."
},
{
"Negative subnet id",
+ false,
"\"subnet-id\": -1",
"'subnet-id' parameter is not a 32 bit unsigned integer."
},
{
"Too large subnet id",
+ false,
"\"subnet-id\": 4294967297",
"'subnet-id' parameter is not a 32 bit unsigned integer."
+ },
+ {
+ "Not numeric iaid",
+ true,
+ "\"iaid\": true",
+ "'iaid' parameter is not integer."
+ },
+ {
+ "Negative iaid",
+ true,
+ "\"iaid\": -1",
+ "'iaid' parameter is not a 32 bit unsigned integer."
+ },
+ {
+ "Too large iaid",
+ true,
+ "\"iaid\": 4294967297",
+ "'iaid' parameter is not a 32 bit unsigned integer."
}
};
string prefix_cmd =
"{\n"
" \"command\": \"lease6-get\",\n"
- " \"arguments\": {"
+ " \"arguments\": {\n"
" ";
+ string subnet_id = " \"subnet-id\": 1\n,";
string end_cmd =
+ "\n"
" }\n"
- "}";
+ "}\n";
for (auto const& scenario : scenarios) {
SCOPED_TRACE(scenario.name_);
- string cmd = prefix_cmd + scenario.param_ + end_cmd;
+ string cmd = prefix_cmd;
+ if (scenario.add_subnet_id_) {
+ cmd += subnet_id;
+ }
+ cmd += scenario.param_ + end_cmd;
testCommand(cmd, CONTROL_RESULT_ERROR, scenario.exp_rsp_);
}
}