Git fork
1#!/bin/sh
2
3test_description="test fetching through http proxy"
4
5. ./test-lib.sh
6. "$TEST_DIRECTORY"/lib-httpd.sh
7
8LIB_HTTPD_PROXY=1
9start_httpd
10
11test_expect_success 'setup repository' '
12 test_commit foo &&
13 git init --bare "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
14 git push --mirror "$HTTPD_DOCUMENT_ROOT_PATH/repo.git"
15'
16
17setup_askpass_helper
18
19# sanity check that our test setup is correctly using proxy
20test_expect_success 'proxy requires password' '
21 test_config_global http.proxy $HTTPD_DEST &&
22 test_must_fail git clone $HTTPD_URL/smart/repo.git 2>err &&
23 grep "error.*407" err
24'
25
26test_expect_success 'clone through proxy with auth' '
27 test_when_finished "rm -rf clone" &&
28 test_config_global http.proxy http://proxuser:proxpass@$HTTPD_DEST &&
29 GIT_TRACE_CURL=$PWD/trace git clone $HTTPD_URL/smart/repo.git clone &&
30 grep -i "Proxy-Authorization: Basic <redacted>" trace
31'
32
33test_expect_success 'clone can prompt for proxy password' '
34 test_when_finished "rm -rf clone" &&
35 test_config_global http.proxy http://proxuser@$HTTPD_DEST &&
36 set_askpass nobody proxpass &&
37 GIT_TRACE_CURL=$PWD/trace git clone $HTTPD_URL/smart/repo.git clone &&
38 expect_askpass pass proxuser
39'
40
41start_socks() {
42 mkfifo socks_output &&
43 {
44 "$PERL_PATH" "$TEST_DIRECTORY/socks4-proxy.pl" "$1" >socks_output &
45 echo $! > "$TRASH_DIRECTORY/socks.pid"
46 } &&
47 read line <socks_output &&
48 test "$line" = ready
49}
50
51# The %30 tests that the correct amount of percent-encoding is applied to the
52# proxy string passed to curl.
53test_lazy_prereq SOCKS_PROXY '
54 test_have_prereq PERL &&
55 start_socks "$TRASH_DIRECTORY/%30.sock"
56'
57
58test_atexit '
59 test ! -e "$TRASH_DIRECTORY/socks.pid" ||
60 kill "$(cat "$TRASH_DIRECTORY/socks.pid")"
61'
62
63# The below tests morally ought to be gated on a prerequisite that Git is
64# linked with a libcurl that supports Unix socket paths for proxies (7.84 or
65# later), but this is not easy to test right now. Instead, we || the tests with
66# this function.
67old_libcurl_error() {
68 grep -Fx "fatal: libcurl 7.84 or later is required to support paths in proxy URLs" "$1"
69}
70
71test_expect_success SOCKS_PROXY 'clone via Unix socket' '
72 test_when_finished "rm -rf clone" &&
73 test_config_global http.proxy "socks4://localhost$PWD/%2530.sock" && {
74 {
75 GIT_TRACE_CURL=$PWD/trace \
76 GIT_TRACE_CURL_COMPONENTS=socks \
77 git clone "$HTTPD_URL/smart/repo.git" clone 2>err &&
78 grep -i "SOCKS4 request granted" trace
79 } ||
80 old_libcurl_error err
81 }
82'
83
84test_expect_success 'Unix socket requires socks*:' - <<\EOT
85 ! git clone -c http.proxy=localhost/path https://example.com/repo.git 2>err && {
86 grep -Fx "fatal: Invalid proxy URL 'localhost/path': only SOCKS proxies support paths" err ||
87 old_libcurl_error err
88 }
89EOT
90
91test_expect_success 'Unix socket requires localhost' - <<\EOT
92 ! git clone -c http.proxy=socks4://127.0.0.1/path https://example.com/repo.git 2>err && {
93 grep -Fx "fatal: Invalid proxy URL 'socks4://127.0.0.1/path': host must be localhost if a path is present" err ||
94 old_libcurl_error err
95 }
96EOT
97
98test_done