Commit c0042a40 authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰
Browse files

[3918] Changes after review:

 - filename length is printed if path is too long
 - unit-test added for too long path
parent 1538e266
......@@ -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.");
}
......
......@@ -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);
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment