Merge branch 'cb/git-daemon-tests'
* cb/git-daemon-tests: git-daemon tests: wait until daemon is ready git-daemon: produce output when ready git-daemon: add tests
This commit is contained in:
commit
86faaf90b3
6
daemon.c
6
daemon.c
@ -1086,6 +1086,8 @@ static int serve(struct string_list *listen_addr, int listen_port,
|
|||||||
|
|
||||||
drop_privileges(cred);
|
drop_privileges(cred);
|
||||||
|
|
||||||
|
loginfo("Ready to rumble");
|
||||||
|
|
||||||
return service_loop(&socklist);
|
return service_loop(&socklist);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1270,10 +1272,8 @@ int main(int argc, char **argv)
|
|||||||
if (inetd_mode || serve_mode)
|
if (inetd_mode || serve_mode)
|
||||||
return execute();
|
return execute();
|
||||||
|
|
||||||
if (detach) {
|
if (detach)
|
||||||
daemonize();
|
daemonize();
|
||||||
loginfo("Ready to rumble");
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
sanitize_stdfds();
|
sanitize_stdfds();
|
||||||
|
|
||||||
|
69
t/lib-git-daemon.sh
Normal file
69
t/lib-git-daemon.sh
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
if test -z "$GIT_TEST_GIT_DAEMON"
|
||||||
|
then
|
||||||
|
skip_all="git-daemon testing disabled (define GIT_TEST_GIT_DAEMON to enable)"
|
||||||
|
test_done
|
||||||
|
fi
|
||||||
|
|
||||||
|
LIB_GIT_DAEMON_PORT=${LIB_GIT_DAEMON_PORT-'8121'}
|
||||||
|
|
||||||
|
GIT_DAEMON_PID=
|
||||||
|
GIT_DAEMON_DOCUMENT_ROOT_PATH="$PWD"/repo
|
||||||
|
GIT_DAEMON_URL=git://127.0.0.1:$LIB_GIT_DAEMON_PORT
|
||||||
|
|
||||||
|
start_git_daemon() {
|
||||||
|
if test -n "$GIT_DAEMON_PID"
|
||||||
|
then
|
||||||
|
error "start_git_daemon already called"
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir -p "$GIT_DAEMON_DOCUMENT_ROOT_PATH"
|
||||||
|
|
||||||
|
trap 'code=$?; stop_git_daemon; (exit $code); die' EXIT
|
||||||
|
|
||||||
|
say >&3 "Starting git daemon ..."
|
||||||
|
mkfifo git_daemon_output
|
||||||
|
git daemon --listen=127.0.0.1 --port="$LIB_GIT_DAEMON_PORT" \
|
||||||
|
--reuseaddr --verbose \
|
||||||
|
--base-path="$GIT_DAEMON_DOCUMENT_ROOT_PATH" \
|
||||||
|
"$@" "$GIT_DAEMON_DOCUMENT_ROOT_PATH" \
|
||||||
|
>&3 2>git_daemon_output &
|
||||||
|
GIT_DAEMON_PID=$!
|
||||||
|
{
|
||||||
|
read line
|
||||||
|
echo >&4 "$line"
|
||||||
|
cat >&4 &
|
||||||
|
|
||||||
|
# Check expected output
|
||||||
|
if test x"$(expr "$line" : "\[[0-9]*\] \(.*\)")" != x"Ready to rumble"
|
||||||
|
then
|
||||||
|
kill "$GIT_DAEMON_PID"
|
||||||
|
wait "$GIT_DAEMON_PID"
|
||||||
|
trap 'die' EXIT
|
||||||
|
error "git daemon failed to start"
|
||||||
|
fi
|
||||||
|
} <git_daemon_output
|
||||||
|
}
|
||||||
|
|
||||||
|
stop_git_daemon() {
|
||||||
|
if test -z "$GIT_DAEMON_PID"
|
||||||
|
then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
trap 'die' EXIT
|
||||||
|
|
||||||
|
# kill git-daemon child of git
|
||||||
|
say >&3 "Stopping git daemon ..."
|
||||||
|
kill "$GIT_DAEMON_PID"
|
||||||
|
wait "$GIT_DAEMON_PID" >&3 2>&4
|
||||||
|
ret=$?
|
||||||
|
# expect exit with status 143 = 128+15 for signal TERM=15
|
||||||
|
if test $ret -ne 143
|
||||||
|
then
|
||||||
|
error "git daemon exited with status: $ret"
|
||||||
|
fi
|
||||||
|
GIT_DAEMON_PID=
|
||||||
|
rm -f git_daemon_output
|
||||||
|
}
|
148
t/t5570-git-daemon.sh
Executable file
148
t/t5570-git-daemon.sh
Executable file
@ -0,0 +1,148 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
test_description='test fetching over git protocol'
|
||||||
|
. ./test-lib.sh
|
||||||
|
|
||||||
|
LIB_GIT_DAEMON_PORT=${LIB_GIT_DAEMON_PORT-5570}
|
||||||
|
. "$TEST_DIRECTORY"/lib-git-daemon.sh
|
||||||
|
start_git_daemon
|
||||||
|
|
||||||
|
test_expect_success 'setup repository' '
|
||||||
|
echo content >file &&
|
||||||
|
git add file &&
|
||||||
|
git commit -m one
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'create git-accessible bare repository' '
|
||||||
|
mkdir "$GIT_DAEMON_DOCUMENT_ROOT_PATH/repo.git" &&
|
||||||
|
(cd "$GIT_DAEMON_DOCUMENT_ROOT_PATH/repo.git" &&
|
||||||
|
git --bare init &&
|
||||||
|
: >git-daemon-export-ok
|
||||||
|
) &&
|
||||||
|
git remote add public "$GIT_DAEMON_DOCUMENT_ROOT_PATH/repo.git" &&
|
||||||
|
git push public master:master
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'clone git repository' '
|
||||||
|
git clone "$GIT_DAEMON_URL/repo.git" clone &&
|
||||||
|
test_cmp file clone/file
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'fetch changes via git protocol' '
|
||||||
|
echo content >>file &&
|
||||||
|
git commit -a -m two &&
|
||||||
|
git push public &&
|
||||||
|
(cd clone && git pull) &&
|
||||||
|
test_cmp file clone/file
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_failure 'remote detects correct HEAD' '
|
||||||
|
git push public master:other &&
|
||||||
|
(cd clone &&
|
||||||
|
git remote set-head -d origin &&
|
||||||
|
git remote set-head -a origin &&
|
||||||
|
git symbolic-ref refs/remotes/origin/HEAD > output &&
|
||||||
|
echo refs/remotes/origin/master > expect &&
|
||||||
|
test_cmp expect output
|
||||||
|
)
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'prepare pack objects' '
|
||||||
|
cp -R "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo.git "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_pack.git &&
|
||||||
|
(cd "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_pack.git &&
|
||||||
|
git --bare repack -a -d
|
||||||
|
)
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'fetch notices corrupt pack' '
|
||||||
|
cp -R "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_pack.git "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
|
||||||
|
(cd "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
|
||||||
|
p=`ls objects/pack/pack-*.pack` &&
|
||||||
|
chmod u+w $p &&
|
||||||
|
printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
|
||||||
|
) &&
|
||||||
|
mkdir repo_bad1.git &&
|
||||||
|
(cd repo_bad1.git &&
|
||||||
|
git --bare init &&
|
||||||
|
test_must_fail git --bare fetch "$GIT_DAEMON_URL/repo_bad1.git" &&
|
||||||
|
test 0 = `ls objects/pack/pack-*.pack | wc -l`
|
||||||
|
)
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'fetch notices corrupt idx' '
|
||||||
|
cp -R "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_pack.git "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
|
||||||
|
(cd "$GIT_DAEMON_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
|
||||||
|
p=`ls objects/pack/pack-*.idx` &&
|
||||||
|
chmod u+w $p &&
|
||||||
|
printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
|
||||||
|
) &&
|
||||||
|
mkdir repo_bad2.git &&
|
||||||
|
(cd repo_bad2.git &&
|
||||||
|
git --bare init &&
|
||||||
|
test_must_fail git --bare fetch "$GIT_DAEMON_URL/repo_bad2.git" &&
|
||||||
|
test 0 = `ls objects/pack | wc -l`
|
||||||
|
)
|
||||||
|
'
|
||||||
|
|
||||||
|
test_remote_error()
|
||||||
|
{
|
||||||
|
do_export=YesPlease
|
||||||
|
while test $# -gt 0
|
||||||
|
do
|
||||||
|
case $1 in
|
||||||
|
-x)
|
||||||
|
shift
|
||||||
|
chmod -x "$GIT_DAEMON_DOCUMENT_ROOT_PATH/repo.git"
|
||||||
|
;;
|
||||||
|
-n)
|
||||||
|
shift
|
||||||
|
do_export=
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
break
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if test $# -ne 3
|
||||||
|
then
|
||||||
|
error "invalid number of arguments"
|
||||||
|
fi
|
||||||
|
|
||||||
|
cmd=$1
|
||||||
|
repo=$2
|
||||||
|
msg=$3
|
||||||
|
|
||||||
|
if test -x "$GIT_DAEMON_DOCUMENT_ROOT_PATH/$repo"
|
||||||
|
then
|
||||||
|
if test -n "$do_export"
|
||||||
|
then
|
||||||
|
: >"$GIT_DAEMON_DOCUMENT_ROOT_PATH/$repo/git-daemon-export-ok"
|
||||||
|
else
|
||||||
|
rm -f "$GIT_DAEMON_DOCUMENT_ROOT_PATH/$repo/git-daemon-export-ok"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
test_must_fail git "$cmd" "$GIT_DAEMON_URL/$repo" 2>output &&
|
||||||
|
echo "fatal: remote error: $msg: /$repo" >expect &&
|
||||||
|
test_cmp expect output
|
||||||
|
ret=$?
|
||||||
|
chmod +x "$GIT_DAEMON_DOCUMENT_ROOT_PATH/repo.git"
|
||||||
|
(exit $ret)
|
||||||
|
}
|
||||||
|
|
||||||
|
msg="access denied or repository not exported"
|
||||||
|
test_expect_success 'clone non-existent' "test_remote_error clone nowhere.git '$msg'"
|
||||||
|
test_expect_success 'push disabled' "test_remote_error push repo.git '$msg'"
|
||||||
|
test_expect_success 'read access denied' "test_remote_error -x fetch repo.git '$msg'"
|
||||||
|
test_expect_success 'not exported' "test_remote_error -n fetch repo.git '$msg'"
|
||||||
|
|
||||||
|
stop_git_daemon
|
||||||
|
start_git_daemon --informative-errors
|
||||||
|
|
||||||
|
test_expect_success 'clone non-existent' "test_remote_error clone nowhere.git 'no such repository'"
|
||||||
|
test_expect_success 'push disabled' "test_remote_error push repo.git 'service not enabled'"
|
||||||
|
test_expect_success 'read access denied' "test_remote_error -x fetch repo.git 'no such repository'"
|
||||||
|
test_expect_success 'not exported' "test_remote_error -n fetch repo.git 'repository not exported'"
|
||||||
|
|
||||||
|
stop_git_daemon
|
||||||
|
test_done
|
Loading…
Reference in New Issue
Block a user