]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1928] Do not re-order classes
authorMarcin Siodelski <marcin@isc.org>
Mon, 12 Jul 2021 11:05:41 +0000 (13:05 +0200)
committerMarcin Siodelski <marcin@isc.org>
Wed, 21 Jul 2021 10:49:50 +0000 (10:49 +0000)
When follow_client_class is not specified for an updatedc class, the class
should not be moved.

src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc
src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp4_unittest.cc

index e248668334947fbf31cc142c0519c6329b9a0bcb..81e587264ff9fb7402ba094b7d9318bea2d573f2 100644 (file)
@@ -3429,6 +3429,7 @@ TaggedStatementArray tagged_statements = { {
       MYSQL_UPDATE_OPTION4_NO_TAG(o.scope_id = 2 AND o.dhcp_client_class = ? AND o.code = ? AND o.space = ?)
     },
 
+    // Update existing client class with specifying its position.
     { MySqlConfigBackendDHCPv4Impl::UPDATE_CLIENT_CLASS4,
       "UPDATE dhcp4_client_class SET"
       "  name = ?,"
index 5d8f3b9c52e61ce76329b42d28e86bf8241fb835..ae394c0e11c2cdca306ac56f531b98cd0b5d387f 100644 (file)
@@ -4226,6 +4226,17 @@ TEST_F(MySqlConfigBackendDHCPv4Test, setAndGetAllClientClasses4) {
     EXPECT_EQ("foo", (*classes_list->begin())->getName());
     EXPECT_EQ("foobar", (*(classes_list->begin() + 1))->getName());
     EXPECT_EQ("bar", (*(classes_list->begin() + 2))->getName());
+
+    // Update the foobar class without specifying its position. It should not
+    // be moved.
+    ASSERT_NO_THROW(cbptr_->createUpdateClientClass4(ServerSelector::ONE("server1"), class3, ""));
+
+    client_classes = cbptr_->getAllClientClasses4(ServerSelector::ONE("server1"));
+    classes_list = client_classes.getClasses();
+    ASSERT_EQ(3, classes_list->size());
+    EXPECT_EQ("foo", (*classes_list->begin())->getName());
+    EXPECT_EQ("foobar", (*(classes_list->begin() + 1))->getName());
+    EXPECT_EQ("bar", (*(classes_list->begin() + 2))->getName());
 }
 
 // This test verifies that a single class can be retrieved from the database.
@@ -4702,6 +4713,11 @@ TEST_F(MySqlConfigBackendDHCPv4Test, clientClassDependencies4) {
     class3->setTest("member('bar')");
     EXPECT_NO_THROW(cbptr_->createUpdateClientClass4(ServerSelector::ALL(), class3, ""));
 
+    // An attempt to move the first class to the end of the class hierarchy should
+    // fail because other classes depend on it.
+    EXPECT_THROW(cbptr_->createUpdateClientClass4(ServerSelector::ALL(), class1, "bar"),
+                 DbOperationError);
+
     // Try to change the dependency of the first class. There are other classes
     // having indirect dependency on KNOWN class via this class. Therefore, the
     // update should be unsuccessful.