From: Marcin Siodelski Date: Mon, 12 Jul 2021 11:05:41 +0000 (+0200) Subject: [#1928] Do not re-order classes X-Git-Tag: Kea-1.9.10~92 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=44a0436113af49e6fce0abc467dae44cfd3fcc0b;p=thirdparty%2Fkea.git [#1928] Do not re-order classes When follow_client_class is not specified for an updatedc class, the class should not be moved. --- diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc index e248668334..81e587264f 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc @@ -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 = ?," diff --git a/src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp4_unittest.cc b/src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp4_unittest.cc index 5d8f3b9c52..ae394c0e11 100644 --- a/src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp4_unittest.cc +++ b/src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp4_unittest.cc @@ -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.