From c008fbeb8f27e29de7cf5b6b5c8be1fd29f493a9 Mon Sep 17 00:00:00 2001 From: Francis Dupont Date: Fri, 12 Sep 2025 11:08:32 +0200 Subject: [PATCH] [#4094] Checkpoint: added server UTs --- .../dhcp4/tests/ctrl_dhcp4_srv_unittest.cc | 23 ++++++++++++++++++ .../tests/http_control_socket_unittest.cc | 24 +++++++++++++++++++ .../dhcp6/tests/ctrl_dhcp6_srv_unittest.cc | 23 ++++++++++++++++++ .../tests/http_control_socket_unittest.cc | 24 +++++++++++++++++++ 4 files changed, 94 insertions(+) diff --git a/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc b/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc index bfd5c6b8c5..493611ac72 100644 --- a/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc +++ b/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc @@ -3563,6 +3563,29 @@ TEST_F(CtrlChannelDhcpv4SrvTest, subnet4o6SelectTestIface) { EXPECT_EQ(expected, response); } +/// Verify that kea-lfc-start requires a lease backend. +TEST_F(CtrlChannelDhcpv4SrvTest, keaLfcStartNoBackend) { + ASSERT_NO_THROW(server_.reset(new NakedControlledDhcpv4Srv())); + ConstElementPtr command = createCommand("kea-lfc-start"); + ConstElementPtr response; + ASSERT_NO_THROW(response = CommandMgr::instance().processCommand(command)); + ASSERT_TRUE(response); + EXPECT_EQ("{ \"result\": 2, \"text\": \"no lease backend\" }", + response->str()); +} + +/// Verify that kea-lfc-start requires persist true. +TEST_F(CtrlChannelDhcpv4SrvTest, keaLfcStartPersistFalse) { + createUnixChannelServer(); + std::string response; + + sendUnixCommand("{ \"command\" : \"kea-lfc-start\" }", response); + std::string expected = "{ \"result\": 2, \"text\": "; + expected += "\"'persist` parameter of `memfile` lease backend "; + expected += "was configured to `false`\" }"; + EXPECT_EQ(expected, response); +} + /// Verify that concurrent connections over the control channel can be /// established. /// @todo Future Kea 1.3 tickets will modify the behavior of the CommandMgr diff --git a/src/bin/dhcp4/tests/http_control_socket_unittest.cc b/src/bin/dhcp4/tests/http_control_socket_unittest.cc index dfb92b354c..1197d6ca80 100644 --- a/src/bin/dhcp4/tests/http_control_socket_unittest.cc +++ b/src/bin/dhcp4/tests/http_control_socket_unittest.cc @@ -571,6 +571,9 @@ public: // the origin-id. void testDhcpEnableOriginId(); + // This test verifies that kea-lfc-start requires persist true. + void testKeaLfcStartPersistFalse(); + // This test verifies that the server can receive and process a // large command. void testLongCommand(); @@ -3522,6 +3525,27 @@ TEST_F(HttpsCtrlChannelDhcpv4Test, dhcpEnableOriginId) { testDhcpEnableOriginId(); } +/// Verify that kea-lfc-start requires persist true. +void +BaseCtrlChannelDhcpv4Test::testKeaLfcStartPersistFalse() { + createHttpChannelServer(); + std::string response; + + sendHttpCommand("{ \"command\" : \"kea-lfc-start\" }", response); + std::string expected = "[ { \"result\": 2, \"text\": "; + expected += "\"'persist` parameter of `memfile` lease backend "; + expected += "was configured to `false`\" } ]"; + EXPECT_EQ(expected, response); +} + +TEST_F(HttpCtrlChannelDhcpv4Test, keaLfcStartPersistFalse) { + testKeaLfcStartPersistFalse(); +} + +TEST_F(HttpsCtrlChannelDhcpv4Test, keaLfcStartPersistFalse) { + testKeaLfcStartPersistFalse(); +} + /// Verify that concurrent connections over the HTTP control channel can be /// established. TEST_F(HttpCtrlChannelDhcpv4Test, concurrentConnections) { diff --git a/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc b/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc index 9618ff51ff..c3a993b43d 100644 --- a/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc +++ b/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc @@ -2850,6 +2850,29 @@ TEST_F(CtrlChannelDhcpv6SrvTest, subnet6SelectTestClass) { EXPECT_EQ(expected, response); } +/// Verify that kea-lfc-start requires a lease backend. +TEST_F(CtrlChannelDhcpv6SrvTest, keaLfcStartNoBackend) { + ASSERT_NO_THROW(server_.reset(new NakedControlledDhcpv6Srv())); + ConstElementPtr command = createCommand("kea-lfc-start"); + ConstElementPtr response; + ASSERT_NO_THROW(response = CommandMgr::instance().processCommand(command)); + ASSERT_TRUE(response); + EXPECT_EQ("{ \"result\": 2, \"text\": \"no lease backend\" }", + response->str()); +} + +/// Verify that kea-lfc-start requires persist true. +TEST_F(CtrlChannelDhcpv6SrvTest, keaLfcStartPersistFalse) { + createUnixChannelServer(); + std::string response; + + sendUnixCommand("{ \"command\" : \"kea-lfc-start\" }", response); + std::string expected = "{ \"result\": 2, \"text\": "; + expected += "\"'persist` parameter of `memfile` lease backend "; + expected += "was configured to `false`\" }"; + EXPECT_EQ(expected, response); +} + /// Verify that concurrent connections over the control channel can be /// established. /// @todo Future Kea 1.3 tickets will modify the behavior of the CommandMgr diff --git a/src/bin/dhcp6/tests/http_control_socket_unittest.cc b/src/bin/dhcp6/tests/http_control_socket_unittest.cc index 8be9d533a6..269a1ecc7e 100644 --- a/src/bin/dhcp6/tests/http_control_socket_unittest.cc +++ b/src/bin/dhcp6/tests/http_control_socket_unittest.cc @@ -582,6 +582,9 @@ public: // the origin-id. void testDhcpEnableOriginId(); + // This test verifies that kea-lfc-start requires persist true. + void testKeaLfcStartPersistFalse(); + // This test verifies that the server can receive and process a // large command. void testLongCommand(); @@ -3518,6 +3521,27 @@ TEST_F(HttpsCtrlChannelDhcpv6Test, dhcpEnableOriginId) { testDhcpEnableOriginId(); } +/// Verify that kea-lfc-start requires persist true. +void +BaseCtrlChannelDhcpv6Test::testKeaLfcStartPersistFalse() { + createHttpChannelServer(); + std::string response; + + sendHttpCommand("{ \"command\" : \"kea-lfc-start\" }", response); + std::string expected = "[ { \"result\": 2, \"text\": "; + expected += "\"'persist` parameter of `memfile` lease backend "; + expected += "was configured to `false`\" } ]"; + EXPECT_EQ(expected, response); +} + +TEST_F(HttpCtrlChannelDhcpv6Test, keaLfcStartPersistFalse) { + testKeaLfcStartPersistFalse(); +} + +TEST_F(HttpsCtrlChannelDhcpv6Test, keaLfcStartPersistFalse) { + testKeaLfcStartPersistFalse(); +} + /// Verify that concurrent connections over the HTTP control channel can be /// established. TEST_F(HttpCtrlChannelDhcpv6Test, concurrentConnections) { -- 2.47.3