tests: work around socket path name too long on Linux
What changed, and why it matters
This commit only changes test infrastructure. It makes integration tests work when run from very deeply nested directories by shortening the file paths used for internal Unix sockets. There is no change to the actual Core Lightning node software that users run, and no security issue is being fixed or introduced.
No security action needed. Treat as a normal test-suite reliability improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch modifies three test files to avoid ENAMETOOLONG-style failures for AF_UNIX socket paths on Linux. When a constructed socket path exceeds the Linux sockaddr_un limit (108 bytes), the code substitutes a path relative to /proc/self/cwd. The changes are confined to tests/fixtures.py, tests/test_cln_rs.py, and tests/test_misc.py. No production code paths are touched.
Changed components
tests/fixtures.pytests/test_cln_rs.pytests/test_misc.pyInspect captured patch +27 / −9
diff --git a/tests/fixtures.py b/tests/fixtures.py
index cde3a18d..d3a4a114 100644
--- a/tests/fixtures.py
+++ b/tests/fixtures.py
@@ -21,6 +21,11 @@ class LightningNode(utils.LightningNode):
kwargs["executable"] = "lightningd/lightningd"
utils.LightningNode.__init__(self, *args, **kwargs)
+ # Avoid socket path name too long on Linux
+ if os.uname()[0] == 'Linux' and \
+ len(str(self.lightning_dir / TEST_NETWORK / 'lightning-rpc')) >= 108:
+ self.daemon.opts['rpc-file'] = '/proc/self/cwd/lightning-rpc'
+
# This is a recent innovation, and we don't want to nail pyln-testing to this version.
self.daemon.opts['dev-crash-after'] = 3600
diff --git a/tests/test_cln_rs.py b/tests/test_cln_rs.py
index 7ddc5047..e14bba45 100644
--- a/tests/test_cln_rs.py
+++ b/tests/test_cln_rs.py
@@ -27,6 +27,8 @@ def test_rpc_client(node_factory):
l1 = node_factory.get_node()
bin_path = Path.cwd() / "target" / RUST_PROFILE / "examples" / "cln-rpc-getinfo"
rpc_path = Path(l1.daemon.lightning_dir) / TEST_NETWORK / "lightning-rpc"
+ if len(str(rpc_path)) >= 108 and os.uname()[0] == 'Linux':
+ rpc_path = Path('/proc/self/cwd') / os.path.relpath(rpc_path)
out = subprocess.check_output([bin_path, rpc_path], stderr=subprocess.STDOUT)
assert(b'0266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c03518' in out)
diff --git a/tests/test_misc.py b/tests/test_misc.py
index a9846832..6adcfad8 100644
--- a/tests/test_misc.py
+++ b/tests/test_misc.py
@@ -822,7 +822,12 @@ def test_address(node_factory):
# Now test UNIX domain binding
l1.stop()
- l1.daemon.opts['bind-addr'] = os.path.join(l1.daemon.lightning_dir, TEST_NETWORK, "sock")
+ bind_addr = os.path.join(l1.daemon.lightning_dir, TEST_NETWORK, "sock")
+ if len(bind_addr) >= 108 and os.uname()[0] == "Linux":
+ bind_addr = os.path.join('/proc/self/cwd',
+ os.path.relpath(node_factory.directory, os.path.dirname(bind_addr)),
+ os.path.relpath(bind_addr, node_factory.directory))
+ l1.daemon.opts['bind-addr'] = bind_addr
l1.start()
# Test dev-allow-localhost
@@ -878,12 +883,21 @@ def test_listconfigs_plugins(node_factory, bitcoind, chainparams):
assert [p['active'] for p in plugins if p['name'].endswith('offers')] == [True]
+def connect_unix(socket_path: str):
+ sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+ try:
+ sock.connect(socket_path)
+ except OSError as err:
+ if err.args[0] == 'AF_UNIX path too long' and os.uname()[0] == 'Linux':
+ sock.connect(os.path.join('/proc/self/cwd', os.path.relpath(socket_path)))
+ return sock
+
+
def test_multirpc(node_factory):
"""Test that we can do multiple RPC without waiting for response"""
l1 = node_factory.get_node()
- sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
- sock.connect(l1.rpc.socket_path)
+ sock = connect_unix(l1.rpc.socket_path)
commands = [
b'{"id":1,"jsonrpc":"2.0","method":"listpeers","params":[]}',
@@ -909,8 +923,7 @@ def test_multiplexed_rpc(node_factory):
"""Test that we can do multiple RPCs which exit in different orders"""
l1 = node_factory.get_node()
- sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
- sock.connect(l1.rpc.socket_path)
+ sock = connect_unix(l1.rpc.socket_path)
# Neighbouring ones may be in or out of order.
commands = [
@@ -940,8 +953,7 @@ def test_malformed_rpc(node_factory):
"""Test that we get a correct response to malformed RPC commands"""
l1 = node_factory.get_node()
- sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
- sock.connect(l1.rpc.socket_path)
+ sock = connect_unix(l1.rpc.socket_path)
# No ID
sock.sendall(b'{"jsonrpc":"2.0","method":"getinfo","params":[]}')
@@ -2032,8 +2044,7 @@ def test_check_command(node_factory):
host='x', port="abcd")
# FIXME: python wrapper doesn't let us test array params.
- sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
- sock.connect(l1.rpc.socket_path)
+ sock = connect_unix(l1.rpc.socket_path)
sock.sendall(b'{"id":1, "jsonrpc":"2.0","method":"check","params":["help"]}')
obj, _ = l1.rpc._readobj(sock, b'')
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.