summaryrefslogtreecommitdiffstats
path: root/src/lib/dhcp_ddns
diff options
context:
space:
mode:
authorThomas Markwalder <tmark@isc.org>2020-10-16 20:47:28 +0200
committerThomas Markwalder <tmark@isc.org>2020-10-21 20:00:25 +0200
commit4cac21adc8d61b36388918e36eba06e243ff82da (patch)
treea340ecbc9f74bda6f3dc855834e12fdc15d2532f /src/lib/dhcp_ddns
parent[1386] Made SimpleRemoveTranscation explicitly deletes PTR,DHCID RRs (diff)
downloadkea-4cac21adc8d61b36388918e36eba06e243ff82da.tar.xz
kea-4cac21adc8d61b36388918e36eba06e243ff82da.zip
[1386] Made NCR use-conflict-resoltuion optional
NCR parameter, use-conflict-resolution, now optional with a default to true for backward compatibility. src/lib/dhcp_ddns/ncr_msg.cc NameChangeRequest::fromJSON() - made use-conflict-resolution option, defaults to true. src/lib/dhcp_ddns/tests/ncr_unittests.cc TEST(NameChangeRequestTest, useConflictResolutionParsing) - new test
Diffstat (limited to 'src/lib/dhcp_ddns')
-rw-r--r--src/lib/dhcp_ddns/ncr_msg.cc13
-rw-r--r--src/lib/dhcp_ddns/tests/ncr_unittests.cc51
2 files changed, 49 insertions, 15 deletions
diff --git a/src/lib/dhcp_ddns/ncr_msg.cc b/src/lib/dhcp_ddns/ncr_msg.cc
index f385484349..f2b2718a25 100644
--- a/src/lib/dhcp_ddns/ncr_msg.cc
+++ b/src/lib/dhcp_ddns/ncr_msg.cc
@@ -319,7 +319,7 @@ NameChangeRequest::fromJSON(const std::string& json) {
// NcrMessageError if the given Element is the wrong type or its data
// content is lexically invalid. If the element is NOT found in the
// map, getElement will throw NcrMessageError indicating the missing
- // member. Currently there are no optional values.
+ // member.
element = ncr->getElement("change-type", element_map);
ncr->setChangeType(element);
@@ -344,9 +344,14 @@ NameChangeRequest::fromJSON(const std::string& json) {
element = ncr->getElement("lease-length", element_map);
ncr->setLeaseLength(element);
- /// @todo Should this be optional (i.e. backward compatible)?
- element = ncr->getElement("use-conflict-resolution", element_map);
- ncr->setConflictResolution(element);
+ // For backward compatiblity use-conflict-resolution is optional
+ // and defaults to true.
+ auto found = element_map.find("use-conflict-resolution");
+ if (found != element_map.end()) {
+ ncr->setConflictResolution(found->second);
+ } else {
+ ncr->setConflictResolution(true);
+ }
// All members were in the Element set and were correct lexically. Now
// validate the overall content semantically. This will throw an
diff --git a/src/lib/dhcp_ddns/tests/ncr_unittests.cc b/src/lib/dhcp_ddns/tests/ncr_unittests.cc
index 059c6bd76b..ddbf0f631d 100644
--- a/src/lib/dhcp_ddns/tests/ncr_unittests.cc
+++ b/src/lib/dhcp_ddns/tests/ncr_unittests.cc
@@ -61,6 +61,17 @@ const char *valid_msgs[] =
" \"lease-expires-on\" : \"20130121132405\" , "
" \"lease-length\" : 1300, "
" \"use-conflict-resolution\": true"
+ "}",
+ // Missing use-conflict-resolution
+ "{"
+ " \"change-type\" : 0 , "
+ " \"forward-change\" : true , "
+ " \"reverse-change\" : false , "
+ " \"fqdn\" : \"walah.walah.com\" , "
+ " \"ip-address\" : \"192.168.2.1\" , "
+ " \"dhcid\" : \"010203040A7F8E3D\" , "
+ " \"lease-expires-on\" : \"20130121132405\" , "
+ " \"lease-length\" : 1300 "
"}"
};
@@ -212,17 +223,6 @@ const char *invalid_msgs[] =
" \"lease-length\" : \"BOGUS\", "
" \"use-conflict-resolution\": true"
"}",
- // Missing use-conflict-resolution
- "{"
- " \"change-type\" : 0 , "
- " \"forward-change\" : true , "
- " \"reverse-change\" : false , "
- " \"fqdn\" : \"walah.walah.com\" , "
- " \"ip-address\" : \"192.168.2.1\" , "
- " \"dhcid\" : \"010203040A7F8E3D\" , "
- " \"lease-expires-on\" : \"20130121132405\" , "
- " \"lease-length\" : 1300 "
- "}",
// Invalid use-conflict-resolution
"{"
" \"change-type\" : 0 , "
@@ -667,5 +667,34 @@ TEST(NameChangeProtocolTest, protocolEnumConversion){
ASSERT_EQ(ncrProtocolToString(dhcp_ddns::NCR_TCP), "TCP");
}
+TEST(NameChangeRequestTest, useConflictResolutionParsing) {
+ std::string base_json =
+ "{"
+ " \"change-type\" : 0 , "
+ " \"forward-change\" : true , "
+ " \"reverse-change\" : false , "
+ " \"fqdn\" : \"walah.walah.com\" , "
+ " \"ip-address\" : \"192.168.2.1\" , "
+ " \"dhcid\" : \"010203040A7F8E3D\" , "
+ " \"lease-expires-on\" : \"20130121132405\" , "
+ " \"lease-length\" : 1300 ";
+
+ std::string its_true(base_json + ",\"use-conflict-resolution\": true}");
+ NameChangeRequestPtr ncr;
+ ASSERT_NO_THROW_LOG(ncr = NameChangeRequest::fromJSON(its_true));
+ ASSERT_TRUE(ncr);
+ EXPECT_TRUE(ncr->useConflictResolution());
+
+ std::string its_false(base_json + ",\"use-conflict-resolution\": false}");
+ ASSERT_NO_THROW_LOG(ncr = NameChangeRequest::fromJSON(its_false));
+ ASSERT_TRUE(ncr);
+ EXPECT_FALSE(ncr->useConflictResolution());
+
+ std::string its_missing(base_json + "}");
+ ASSERT_NO_THROW_LOG(ncr = NameChangeRequest::fromJSON(its_true));
+ ASSERT_TRUE(ncr);
+ EXPECT_TRUE(ncr->useConflictResolution());
+}
+
} // end of anonymous namespace