Skip to content

Commit

Permalink
Add tests for unixsocket.
Browse files Browse the repository at this point in the history
  • Loading branch information
lcfyi committed Feb 21, 2024
1 parent 40c6598 commit 44fc8b9
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions t/t5565-http-unix-domain-socket.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/bin/sh

test_description="test fetching through http via unix domain socket"

. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-httpd.sh

test -z "$NO_UNIX_SOCKETS" || {
skip_all='skipping http-unix-socket tests, unix sockets not available'
test_done
}

UDS_TO_TCP_FIFO=uds_to_tcp
TCP_TO_UDS_FIFO=tcp_to_uds
UDS_PID=
TCP_PID=
UDS_SOCKET="$(pwd)/uds.sock"
UNRESOLVABLE_ENDPOINT=http://localhost:4242

start_proxy_unix_to_tcp() {
local socket_path="$UDS_SOCKET"
local host=127.0.0.1
local port=$LIB_HTTPD_PORT

rm -f "$UDS_TO_TCP_FIFO"
rm -f "$TCP_TO_UDS_FIFO"
rm -f "$socket_path"
mkfifo "$UDS_TO_TCP_FIFO"
mkfifo "$TCP_TO_UDS_FIFO"
nc -klU "$socket_path" <tcp_to_uds >uds_to_tcp &
UDS_PID=$!

nc "$host" "$port" >tcp_to_uds <uds_to_tcp &
TCP_PID=$!

test_atexit 'stop_proxy_unix_to_tcp'
}

stop_proxy_unix_to_tcp() {
kill "$UDS_PID"
kill "$TCP_PID"
rm -f "$UDS_TO_TCP_FIFO"
rm -f "$TCP_TO_UDS_FIFO"
}

start_httpd
start_proxy_unix_to_tcp

test_expect_success 'setup repository' '
test_commit foo &&
git init --bare "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
git push --mirror "$HTTPD_DOCUMENT_ROOT_PATH/repo.git"
'

# sanity check that we can't clone normally
test_expect_success 'cloning without UDS fails' '
test_must_fail git clone "$UNRESOLVABLE_ENDPOINT/smart/repo.git" clone
'

test_expect_success 'cloning with UDS succeeds' '
test_when_finished "rm -rf clone" &&
test_config_global http.unixsocket "$UDS_SOCKET" &&
git clone "$UNRESOLVABLE_ENDPOINT/smart/repo.git" clone
'

test_expect_success 'cloning with a non-existent http proxy fails' '
git clone $HTTPD_URL/smart/repo.git clone &&
rm -rf clone &&
test_config_global http.proxy 127.0.0.1:0 &&
test_must_fail git clone $HTTPD_URL/smart/repo.git clone
'

test_expect_success 'UDS socket takes precedence over http proxy' '
test_when_finished "rm -rf clone" &&
test_config_global http.proxy 127.0.0.1:0 &&
test_config_global http.unixsocket "$UDS_SOCKET" &&
git clone $HTTPD_URL/smart/repo.git clone
'

test_done

0 comments on commit 44fc8b9

Please sign in to comment.