]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[1386] Made NCR use-conflict-resoltuion optional
authorThomas Markwalder <tmark@isc.org>
Fri, 16 Oct 2020 18:47:28 +0000 (14:47 -0400)
committerThomas Markwalder <tmark@isc.org>
Wed, 21 Oct 2020 18:00:25 +0000 (14:00 -0400)
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

src/lib/dhcp_ddns/ncr_msg.cc
src/lib/dhcp_ddns/tests/ncr_unittests.cc

index f38548434948600324ee58e2ae7a286bba9b7cc8..f2b2718a259d669d1b1c39bf4ea174a4a168bdd9 100644 (file)
@@ -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
index 059c6bd76bb9cc053afbb430b82d79213e43d823..ddbf0f631d6f0abcc36cb6512b1cd671aa3309ef 100644 (file)
@@ -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