]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5570-git-daemon.sh
Merge branch 'dl/reset-doc-no-wrt-abbrev'
[thirdparty/git.git] / t / t5570-git-daemon.sh
CommitLineData
71039fb9
CB
1#!/bin/sh
2
3test_description='test fetching over git protocol'
4. ./test-lib.sh
5
71039fb9
CB
6. "$TEST_DIRECTORY"/lib-git-daemon.sh
7start_git_daemon
8
25bb90b1 9check_verbose_connect () {
aad6fddb
NTND
10 test_i18ngrep -F "Looking up 127.0.0.1 ..." stderr &&
11 test_i18ngrep -F "Connecting to 127.0.0.1 (port " stderr &&
12 test_i18ngrep -F "done." stderr
25bb90b1
EW
13}
14
71039fb9 15test_expect_success 'setup repository' '
ac47a22a 16 git config push.default matching &&
71039fb9
CB
17 echo content >file &&
18 git add file &&
19 git commit -m one
20'
21
22test_expect_success 'create git-accessible bare repository' '
23 mkdir "$GIT_DAEMON_DOCUMENT_ROOT_PATH/repo.git" &&
24 (cd "$GIT_DAEMON_DOCUMENT_ROOT_PATH/repo.git" &&
25 git --bare init &&
26 : >git-daemon-export-ok
27 ) &&
28 git remote add public "$GIT_DAEMON_DOCUMENT_ROOT_PATH/repo.git" &&
29 git push public master:master
30'
31
32test_expect_success 'clone git repository' '
25bb90b1
EW
33 git clone -v "$GIT_DAEMON_URL/repo.git" clone 2>stderr &&
34 check_verbose_connect &&
71039fb9
CB
35 test_cmp file clone/file
36'
37
38test_expect_success 'fetch changes via git protocol' '
39 echo content >>file &&
40 git commit -a -m two &&
41 git push public &&
25bb90b1
EW
42 (cd clone && git pull -v) 2>stderr &&
43 check_verbose_connect &&
71039fb9
CB
44 test_cmp file clone/file
45'
46
25bb90b1
EW
47test_expect_success 'no-op fetch -v stderr is as expected' '
48 (cd clone && git fetch -v) 2>stderr &&
49 check_verbose_connect
50'
51
52test_expect_success 'no-op fetch without "-v" is quiet' '
91538d0c 53 (cd clone && git fetch 2>../stderr) &&
ec10b018 54 test_must_be_empty stderr
25bb90b1
EW
55'
56
2ecb573b 57test_expect_success 'remote detects correct HEAD' '
71039fb9
CB
58 git push public master:other &&
59 (cd clone &&
60 git remote set-head -d origin &&
61 git remote set-head -a origin &&
62 git symbolic-ref refs/remotes/origin/HEAD > output &&
63 echo refs/remotes/origin/master > expect &&
64 test_cmp expect output
65 )
66'
67
68test_expect_success 'prepare pack objects' '
69 cp -R "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo.git "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_pack.git &&
70 (cd "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_pack.git &&
71 git --bare repack -a -d
72 )
73'
74
75test_expect_success 'fetch notices corrupt pack' '
76 cp -R "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_pack.git "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
77 (cd "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
c747cf33 78 p=$(ls objects/pack/pack-*.pack) &&
71039fb9
CB
79 chmod u+w $p &&
80 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
81 ) &&
82 mkdir repo_bad1.git &&
83 (cd repo_bad1.git &&
84 git --bare init &&
85 test_must_fail git --bare fetch "$GIT_DAEMON_URL/repo_bad1.git" &&
c747cf33 86 test 0 = $(ls objects/pack/pack-*.pack | wc -l)
71039fb9
CB
87 )
88'
89
90test_expect_success 'fetch notices corrupt idx' '
91 cp -R "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_pack.git "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
92 (cd "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
c747cf33 93 p=$(ls objects/pack/pack-*.idx) &&
71039fb9
CB
94 chmod u+w $p &&
95 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
96 ) &&
97 mkdir repo_bad2.git &&
98 (cd repo_bad2.git &&
99 git --bare init &&
100 test_must_fail git --bare fetch "$GIT_DAEMON_URL/repo_bad2.git" &&
c747cf33 101 test 0 = $(ls objects/pack | wc -l)
71039fb9
CB
102 )
103'
104
105test_remote_error()
106{
107 do_export=YesPlease
108 while test $# -gt 0
109 do
110 case $1 in
111 -x)
112 shift
113 chmod -x "$GIT_DAEMON_DOCUMENT_ROOT_PATH/repo.git"
114 ;;
115 -n)
116 shift
117 do_export=
118 ;;
119 *)
120 break
121 esac
122 done
123
aecff47d
CB
124 msg=$1
125 shift
71039fb9 126 cmd=$1
aecff47d
CB
127 shift
128 repo=$1
129 shift || error "invalid number of arguments"
71039fb9
CB
130
131 if test -x "$GIT_DAEMON_DOCUMENT_ROOT_PATH/$repo"
132 then
133 if test -n "$do_export"
134 then
135 : >"$GIT_DAEMON_DOCUMENT_ROOT_PATH/$repo/git-daemon-export-ok"
136 else
137 rm -f "$GIT_DAEMON_DOCUMENT_ROOT_PATH/$repo/git-daemon-export-ok"
138 fi
139 fi
140
aecff47d 141 test_must_fail git "$cmd" "$GIT_DAEMON_URL/$repo" "$@" 2>output &&
360a3261 142 test_i18ngrep "fatal: remote error: $msg: /$repo" output &&
71039fb9
CB
143 ret=$?
144 chmod +x "$GIT_DAEMON_DOCUMENT_ROOT_PATH/repo.git"
145 (exit $ret)
146}
147
148msg="access denied or repository not exported"
aecff47d
CB
149test_expect_success 'clone non-existent' "test_remote_error '$msg' clone nowhere.git "
150test_expect_success 'push disabled' "test_remote_error '$msg' push repo.git master"
151test_expect_success 'read access denied' "test_remote_error -x '$msg' fetch repo.git "
152test_expect_success 'not exported' "test_remote_error -n '$msg' fetch repo.git "
71039fb9
CB
153
154stop_git_daemon
155start_git_daemon --informative-errors
156
aecff47d
CB
157test_expect_success 'clone non-existent' "test_remote_error 'no such repository' clone nowhere.git "
158test_expect_success 'push disabled' "test_remote_error 'service not enabled' push repo.git master"
159test_expect_success 'read access denied' "test_remote_error -x 'no such repository' fetch repo.git "
160test_expect_success 'not exported' "test_remote_error -n 'repository not exported' fetch repo.git "
71039fb9 161
5248f2dd
JK
162stop_git_daemon
163start_git_daemon --interpolated-path="$GIT_DAEMON_DOCUMENT_ROOT_PATH/%H%D"
164
165test_expect_success 'access repo via interpolated hostname' '
166 repo="$GIT_DAEMON_DOCUMENT_ROOT_PATH/localhost/interp.git" &&
167 git init --bare "$repo" &&
168 git push "$repo" HEAD &&
169 >"$repo"/git-daemon-export-ok &&
5248f2dd 170 GIT_OVERRIDE_VIRTUAL_HOST=localhost \
02adf84a 171 git ls-remote "$GIT_DAEMON_URL/interp.git" &&
5248f2dd 172 GIT_OVERRIDE_VIRTUAL_HOST=LOCALHOST \
02adf84a 173 git ls-remote "$GIT_DAEMON_URL/interp.git"
5248f2dd
JK
174'
175
b4853730 176test_expect_success 'hostname cannot break out of directory' '
b4853730
JK
177 repo="$GIT_DAEMON_DOCUMENT_ROOT_PATH/../escape.git" &&
178 git init --bare "$repo" &&
179 git push "$repo" HEAD &&
180 >"$repo"/git-daemon-export-ok &&
181 test_must_fail \
182 env GIT_OVERRIDE_VIRTUAL_HOST=.. \
02adf84a 183 git ls-remote "$GIT_DAEMON_URL/escape.git"
b4853730
JK
184'
185
ed15e58e
JK
186test_expect_success FAKENC 'hostname interpolation works after LF-stripping' '
187 {
188 printf "git-upload-pack /interp.git\n\0host=localhost" | packetize
189 printf "0000"
190 } >input &&
191 fake_nc "$GIT_DAEMON_HOST_PORT" <input >output &&
192 depacketize <output >output.raw &&
193
194 # just pick out the value of master, which avoids any protocol
195 # particulars
196 perl -lne "print \$1 if m{^(\\S+) refs/heads/master}" <output.raw >actual &&
197 git -C "$repo" rev-parse master >expect &&
198 test_cmp expect actual
199'
200
71039fb9
CB
201stop_git_daemon
202test_done