Browse Source

[3918] Changes after review:

 - filename length is printed if path is too long
 - unit-test added for too long path
Tomek Mrugalski 9 years ago
parent
commit
c0042a40c9

+ 2 - 1
src/lib/config/command_socket_factory.cc

@@ -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.");
         }
 

+ 12 - 0
src/lib/config/tests/command_socket_factory_unittests.cc

@@ -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);
+}