]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t5564: use a short path for the SOCKS proxy socket
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Wed, 29 Apr 2026 08:22:54 +0000 (08:22 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 29 Apr 2026 12:39:11 +0000 (21:39 +0900)
The SOCKS proxy test introduced in 0ca365c2ed4 (http: do not ignore
proxy path, 2024-08-02) creates a Unix domain socket in
`$TRASH_DIRECTORY`. When the trash directory path is long (e.g.
when running from a deeply nested worktree), the socket path can
exceed the 108-character limit for `struct sockaddr_un.sun_path` on
Linux, causing the test to fail with "Path length ... is longer
than maximum supported length (108)".

We cannot work around this using the chdir trick our own socket code
employs, because both sides of the connection are outside our control:
the socket is created by socks4-proxy.pl via Perl's IO::Socket::UNIX,
and the client side is libcurl.

Use `mktemp -d` to create a unique temporary directory with a short
path, and place the socket inside it. This avoids collisions between
concurrent test runs (e.g. `--stress`) and tmpdir-race vulnerabilities
that a static `/tmp` path would be susceptible to.

Helped-by: Jeff King <peff@peff.net>
Assisted-by: Claude Opus 4.6
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t5564-http-proxy.sh

index 3bcbdef409b25feaffce02567578521e5c2dc494..b4d95b12caeaf032984460c82fd475ddceae1f20 100755 (executable)
@@ -50,14 +50,20 @@ start_socks() {
 
 # The %30 tests that the correct amount of percent-encoding is applied to the
 # proxy string passed to curl.
+# Use a short path for the socket to avoid exceeding the 108-character
+# Unix domain socket limit when the trash directory path is long.
+SOCKS_TMPDIR=$(mktemp -d)
+SOCKS_SOCK="$SOCKS_TMPDIR/%30.sock"
+
 test_lazy_prereq SOCKS_PROXY '
        test_have_prereq PERL &&
-       start_socks "$TRASH_DIRECTORY/%30.sock"
+       start_socks "$SOCKS_SOCK"
 '
 
 test_atexit '
        test ! -e "$TRASH_DIRECTORY/socks.pid" ||
        kill "$(cat "$TRASH_DIRECTORY/socks.pid")"
+       rm -rf "$SOCKS_TMPDIR"
 '
 
 # The below tests morally ought to be gated on a prerequisite that Git is
@@ -70,7 +76,8 @@ old_libcurl_error() {
 
 test_expect_success SOCKS_PROXY 'clone via Unix socket' '
        test_when_finished "rm -rf clone" &&
-       test_config_global http.proxy "socks4://localhost$PWD/%2530.sock" && {
+       socks_proxy_url="socks4://localhost$(echo "$SOCKS_SOCK" | sed "s/%/%25/g")" &&
+       test_config_global http.proxy "$socks_proxy_url" && {
                {
                        GIT_TRACE_CURL=$PWD/trace \
                        GIT_TRACE_CURL_COMPONENTS=socks \