]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[3918] Changes after review:
authorTomek Mrugalski <tomasz@isc.org>
Wed, 24 Jun 2015 12:42:57 +0000 (14:42 +0200)
committerTomek Mrugalski <tomasz@isc.org>
Wed, 24 Jun 2015 12:42:57 +0000 (14:42 +0200)
 - filename length is printed if path is too long
 - unit-test added for too long path

src/lib/config/command_socket_factory.cc
src/lib/config/tests/command_socket_factory_unittests.cc

index a36a8c959c190c6c500c6977cca18b09aa9ca23d..bc4448be257776eb1aac88c9bb30882d2870015c 100644 (file)
@@ -69,7 +69,8 @@ private:
         // we need 1 extra byte for terminating 0.
         if (file_name.size() > sizeof(addr.sun_path) - 1) {
             isc_throw(SocketError, "Failed to open socket: path specified ("
-                      << file_name << ") is longer than allowed "
+                      << file_name << ") is longer (" << file_name.size()
+                      << " bytes) than allowed "
                       << (sizeof(addr.sun_path) - 1) << " bytes.");
         }
 
index 470aac60477edf81b06f529abc851aa028ef2415..5e47800361d2a610f9f83de9d743a0636f1c4b5f 100644 (file)
@@ -60,6 +60,8 @@ public:
     std::string SOCKET_NAME;
 };
 
+// This test verifies that a Unix socket can be opened properly and that input
+// parameters (socket-type and socket-name) are verified.
 TEST_F(CommandSocketFactoryTest, unixCreate) {
     // Null pointer is obviously a bad idea.
     EXPECT_THROW(CommandSocketFactory::create(ConstElementPtr()),
@@ -88,3 +90,13 @@ TEST_F(CommandSocketFactoryTest, unixCreate) {
     // It should be possible to close the socket.
     EXPECT_NO_THROW(sock->close());
 }
+
+// This test checks that when unix path is too long, the socket cannot be opened.
+TEST_F(CommandSocketFactoryTest, unixCreateTooLong) {
+    ElementPtr socket_info = Element::fromJSON("{ \"socket-type\": \"unix\","
+        "\"socket-name\": \"/tmp/toolongtoolongtoolongtoolongtoolongtoolong"
+        "toolongtoolongtoolongtoolongtoolongtoolongtoolongtoolongtoolong"
+        "\" }");
+
+    EXPECT_THROW(CommandSocketFactory::create(socket_info), SocketError);
+}