3 test_description
="test fetching through http proxy"
5 TEST_PASSES_SANITIZE_LEAK
=true
7 .
"$TEST_DIRECTORY"/lib-httpd.sh
12 test_expect_success
'setup repository' '
14 git init --bare "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
15 git push --mirror "$HTTPD_DOCUMENT_ROOT_PATH/repo.git"
20 # sanity check that our test setup is correctly using proxy
21 test_expect_success
'proxy requires password' '
22 test_config_global http.proxy $HTTPD_DEST &&
23 test_must_fail git clone $HTTPD_URL/smart/repo.git 2>err &&
27 test_expect_success
'clone through proxy with auth' '
28 test_when_finished "rm -rf clone" &&
29 test_config_global http.proxy http://proxuser:proxpass@$HTTPD_DEST &&
30 GIT_TRACE_CURL=$PWD/trace git clone $HTTPD_URL/smart/repo.git clone &&
31 grep -i "Proxy-Authorization: Basic <redacted>" trace
34 test_expect_success
'clone can prompt for proxy password' '
35 test_when_finished "rm -rf clone" &&
36 test_config_global http.proxy http://proxuser@$HTTPD_DEST &&
37 set_askpass nobody proxpass &&
38 GIT_TRACE_CURL=$PWD/trace git clone $HTTPD_URL/smart/repo.git clone &&
39 expect_askpass pass proxuser
43 mkfifo socks_output
&&
45 "$PERL_PATH" "$TEST_DIRECTORY/socks4-proxy.pl" "$1" >socks_output
&
46 echo $
! > "$TRASH_DIRECTORY/socks.pid"
48 read line
<socks_output
&&
52 # The %30 tests that the correct amount of percent-encoding is applied to the
53 # proxy string passed to curl.
54 test_lazy_prereq SOCKS_PROXY
'
55 test_have_prereq PERL &&
56 start_socks "$TRASH_DIRECTORY/%30.sock"
60 test ! -e "$TRASH_DIRECTORY/socks.pid" ||
61 kill "$(cat "$TRASH_DIRECTORY/socks.pid")"
64 # The below tests morally ought to be gated on a prerequisite that Git is
65 # linked with a libcurl that supports Unix socket paths for proxies (7.84 or
66 # later), but this is not easy to test right now. Instead, we || the tests with
69 grep -Fx "fatal: libcurl 7.84 or later is required to support paths in proxy URLs" "$1"
72 test_expect_success SOCKS_PROXY
'clone via Unix socket' '
73 test_when_finished "rm -rf clone" &&
74 test_config_global http.proxy "socks4://localhost$PWD/%2530.sock" && {
76 GIT_TRACE_CURL=$PWD/trace git clone "$HTTPD_URL/smart/repo.git" clone 2>err &&
77 grep -i "SOCKS4 request granted" trace
83 test_expect_success
'Unix socket requires socks*:' - <<\EOT
84 ! git clone
-c http.proxy
=localhost
/path https
://example.com
/repo.git
2>err
&& {
85 grep -Fx "fatal: Invalid proxy URL 'localhost/path': only SOCKS proxies support paths" err ||
90 test_expect_success
'Unix socket requires localhost' - <<\EOT
91 ! git clone
-c http.proxy
=socks4
://127.0.0.1/path https
://example.com
/repo.git
2>err
&& {
92 grep -Fx "fatal: Invalid proxy URL 'socks4://127.0.0.1/path': host must be localhost if a path is present" err ||