Parcourir la source

[3436] Found a couple of spots missig position info

Thomas Markwalder il y a 11 ans
Parent
commit
c7d730d7c2

+ 13 - 4
src/bin/d2/d2_cfg_mgr.cc

@@ -206,12 +206,21 @@ D2CfgMgr::buildParams(isc::data::ConstElementPtr params_config) {
     // We validate them here rather than just relying on D2Param constructor
     // so we can spit out config text position info with errors.
 
-    // Fetch and validate io_address.
+    // Fetch and validate ip_address.
     D2CfgContextPtr context = getD2CfgContext();
     isc::dhcp::StringStoragePtr strings = context->getStringStorage();
-    asiolink::IOAddress ip_address(strings->
-                                   getOptionalParam("ip_address",
-                                                    D2Params::DFT_IP_ADDRESS));
+    asiolink::IOAddress ip_address(D2Params::DFT_IP_ADDRESS);
+
+    std::string ip_address_str = strings->getOptionalParam("ip_address",
+                                                            D2Params::
+                                                            DFT_IP_ADDRESS);
+    try {
+        ip_address = asiolink::IOAddress(ip_address_str);
+    } catch (const std::exception& ex) {
+        isc_throw(D2CfgError, "IP address invalid : \""
+                  << ip_address_str << "\" : "
+                  << strings->getPosition("ip_address"));
+    }
 
     if ((ip_address.toText() == "0.0.0.0") || (ip_address.toText() == "::")) {
         isc_throw(D2CfgError, "IP address cannot be \"" << ip_address << "\" : "

+ 2 - 1
src/bin/d2/d2_config.cc

@@ -643,7 +643,8 @@ build(isc::data::ConstElementPtr server_list){
 
     // Domains must have at least one server.
     if (parsers_.size() == 0) {
-        isc_throw (D2CfgError, "Server List must contain at least one server");
+        isc_throw (D2CfgError, "Server List must contain at least one server"
+                   << " : " << server_list->getPosition());
     }
 }
 

+ 4 - 3
src/bin/d2/d_cfg_mgr.cc

@@ -206,9 +206,10 @@ DCfgMgrBase::parseConfig(isc::data::ConstElementPtr config_set) {
                     objects_map.erase(it);
                 }
                 else {
-                    isc_throw(DCfgMgrBaseError, "Element:" << element_id <<
-                              " is listed in the parse order but is not "
-                              " present in the configuration");
+                    isc_throw(DCfgMgrBaseError,
+                               "Element required by parsing order is missing: "
+                               << element_id << " : "
+                               << config_set->getPosition());
                 }
             }
 

+ 53 - 0
src/bin/d2/tests/testdata/d2_cfg_tests.json

@@ -851,6 +851,33 @@
 
 #-----
 ,{
+"description" : "D2.forward_ddns.dhcp_ddns.dns_servers.ip_address invalid address ",
+"should_fail" : true,
+"data" :
+    {
+    "forward_ddns" :
+    {
+        "ddns_domains" :
+        [
+            {
+            "name" : "four.example.com.",
+            "dns_servers" :
+                [
+                    {
+                    "ip_address" : "bogus"
+                    }
+                ]
+            }
+        ]
+    },
+    "reverse_ddns" : {},
+    "tsig_keys" : []
+    }
+}
+
+
+#-----
+,{
 "description" : "D2.forward_ddns.dhcp_ddns.dns_servers.port valid value ",
 "data" :
     {
@@ -1215,6 +1242,32 @@
     "tsig_keys" : []
     }
 }
+#-----
+,{
+"description" : "D2.reverse_ddns.dhcp_ddns.dns_servers.ip_address invalid value",
+"should_fail" : true,
+"data" :
+    {
+    "forward_ddns" : {},
+    "reverse_ddns" :
+    {
+        "ddns_domains" :
+        [
+            {
+            "name" : "2.0.192.in-addr.arpa.",
+            "dns_servers" :
+                [
+                    {
+                    "ip_address" : "bogus"
+                    }
+                ]
+            }
+        ]
+    },
+    "tsig_keys" : []
+    }
+}
+
 
 #-----
 ,{