]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[4501] Added invalid pool (outside subnet) unit tests
authorFrancis Dupont <fdupont@isc.org>
Fri, 27 Jan 2017 20:16:02 +0000 (21:16 +0100)
committerFrancis Dupont <fdupont@isc.org>
Fri, 27 Jan 2017 20:16:02 +0000 (21:16 +0100)
src/bin/dhcp4/tests/config_parser_unittest.cc
src/bin/dhcp6/tests/config_parser_unittest.cc

index 0d3230b26e1d007cadddca9d697696195d089b3f..675685f4327fde9fec5e065d6550697acba3927f 100644 (file)
@@ -4716,7 +4716,40 @@ TEST_F(Dhcp4ParserTest, invalidPoolRange) {
     ASSERT_NO_THROW(text = comment->stringValue());
 
     EXPECT_EQ(1, rcode);
-    string expected = "Failed to create pool defined by: 192.0.2.1-19.2.0.200 (<string>:6:26)";
+    string expected = "Failed to create pool defined by: "
+       "192.0.2.1-19.2.0.200 (<string>:6:26)";
+    EXPECT_EQ(expected, text);
+}
+
+// Test verifies the error message for an outside subnet pool range
+// is what we expect.
+TEST_F(Dhcp4ParserTest, outsideSubnetPool) {
+    string config = "{ " + genIfaceConfig() + ", \n" +
+        "\"valid-lifetime\": 4000, \n"
+        "\"rebind-timer\": 2000, \n"
+        "\"renew-timer\": 1000, \n"
+        "\"subnet4\": [ {  \n"
+        "    \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ], \n"
+        "    \"subnet\": \"10.0.2.0/24\"  \n"
+        " } ] \n"
+        "} \n";
+
+    ConstElementPtr json;
+    ASSERT_NO_THROW(json = parseDHCP4(config, true));
+
+    ConstElementPtr status;
+    EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json));
+    ASSERT_TRUE(status);
+    int rcode;
+    ConstElementPtr comment = parseAnswer(rcode, status);
+    string text;
+    ASSERT_NO_THROW(text = comment->stringValue());
+
+    EXPECT_EQ(1, rcode);
+    string expected = "subnet configuration failed (<string>:5:14): "
+       "a pool of type V4, with the following address range: "
+       "192.0.2.1-192.0.2.100 does not match the prefix of a subnet: "
+       "10.0.2.0/24 to which it is being added";
     EXPECT_EQ(expected, text);
 }
 
index ffe90fc1c188e018c1bd2efd03b71c3700cb760a..7829d6d36089c0cbb16381da766006a09be642f2 100644 (file)
@@ -5188,7 +5188,41 @@ TEST_F(Dhcp6ParserTest, invalidPoolRange) {
     ASSERT_NO_THROW(text = comment->stringValue());
 
     EXPECT_EQ(1, rcode);
-    string expected = "Failed to create pool defined by: 2001:db8::-200:1db8::ffff (<string>:7:26)";
+    string expected = "Failed to create pool defined by: "
+        "2001:db8::-200:1db8::ffff (<string>:7:26)";
+    EXPECT_EQ(expected, text);
+}
+
+// Test verifies the error message for an outside subnet pool range
+// is what we expect.
+TEST_F(Dhcp6ParserTest, outsideSubnetPool) {
+    string config = "{ " + genIfaceConfig() + ", \n" +
+        "\"valid-lifetime\": 4000, \n"
+        "\"preferred-lifetime\": 3000, \n"
+        "\"rebind-timer\": 2000, \n"
+        "\"renew-timer\": 1000, \n"
+        "\"subnet6\": [ {  \n"
+        "    \"pools\": [ { \"pool\": \"2001:db8:: - 2001:db8::ffff\" } ], \n"
+        "    \"subnet\": \"2001:dc8::/32\"  \n"
+        " } ] \n"
+        "} \n";
+
+    ConstElementPtr json;
+    ASSERT_NO_THROW(json = parseDHCP6(config, true));
+
+    ConstElementPtr status;
+    EXPECT_NO_THROW(status = configureDhcp6Server(srv_, json));
+    ASSERT_TRUE(status);
+    int rcode;
+    ConstElementPtr comment = parseAnswer(rcode, status);
+    string text;
+    ASSERT_NO_THROW(text = comment->stringValue());
+
+    EXPECT_EQ(1, rcode);
+    string expected = "subnet configuration failed (<string>:6:14): "
+        "a pool of type IA_NA, with the following address range: "
+        "2001:db8::-2001:db8::ffff does not match the prefix of "
+        "a subnet: 2001:dc8::/32 to which it is being added";
     EXPECT_EQ(expected, text);
 }