// 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.");
}
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()),
// 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);
+}