]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5390] Forgotten unit tests added. trac5390
authorTomek Mrugalski <tomasz@isc.org>
Tue, 30 Jan 2018 19:23:59 +0000 (20:23 +0100)
committerTomek Mrugalski <tomasz@isc.org>
Tue, 30 Jan 2018 19:23:59 +0000 (20:23 +0100)
src/lib/dhcpsrv/tests/cfg_iface_unittest.cc

index 2f30565987ff28ceac4fd52557cb9aaa8c1524a5..4246fc735eaff8061cc10e704dbd08115b9092b9 100644 (file)
@@ -238,6 +238,20 @@ TEST_F(CfgIfaceTest, explicitLoopbackV4) {
     EXPECT_FALSE(socketOpen("lo", "127.0.0.1"));
 }
 
+// Tests that the loopback socket is not opened in raw mode.
+TEST_F(CfgIfaceTest, explicitLoopbackV4Negative) {
+    CfgIface cfg;
+    ASSERT_NO_THROW(cfg.use(AF_INET, "lo"));
+
+    // Use UDP sockets
+    ASSERT_NO_THROW(cfg.useSocketType(AF_INET, CfgIface::SOCKET_RAW));
+
+    // Open sockets on specified interfaces and addresses.
+    cfg.openSockets(AF_INET, DHCP4_SERVER_PORT);
+    EXPECT_FALSE(socketOpen("lo", "127.0.0.1"));
+    EXPECT_FALSE(socketOpen("lo", AF_INET));
+}
+
 // This test checks that the interface names can be explicitly selected
 // by their names and IPv6 sockets are opened on these interfaces.
 TEST_F(CfgIfaceTest, explicitNamesV6) {
@@ -277,6 +291,20 @@ TEST_F(CfgIfaceTest, explicitNamesV6) {
     EXPECT_FALSE(socketOpen("lo", AF_INET6));
 }
 
+// This test checks that the loopback socket can be opened.
+TEST_F(CfgIfaceTest, loopback6) {
+    CfgIface cfg;
+    // Specify valid interface names. There should be no error.
+    ASSERT_NO_THROW(cfg.use(AF_INET6, "lo"));
+
+    // Open sockets on specified interfaces.
+    cfg.openSockets(AF_INET6, DHCP6_SERVER_PORT);
+
+    // There should be a socket open.
+    EXPECT_FALSE(socketOpen("lo", AF_INET6));
+    EXPECT_FALSE(socketOpen("lo", "::1"));
+}
+
 // This test checks that the wildcard interface name can be specified to
 // select all interfaces to open IPv4 sockets.
 TEST_F(CfgIfaceTest, wildcardV4) {