Skip to content

Commit faa4bc3

Browse files
Clemens Buchachergitster
authored andcommitted
http-push: add regression tests
http-push tests require a web server with WebDAV support. This commit introduces a HTTPD test library, which can be configured using the following environment variables. GIT_TEST_HTTPD enable HTTPD tests LIB_HTTPD_PATH web server path LIB_HTTPD_MODULE_PATH web server modules path LIB_HTTPD_PORT listening port LIB_HTTPD_DAV enable DAV LIB_HTTPD_SVN enable SVN LIB_HTTPD_SSL enable SSL Signed-off-by: Clemens Buchacher <drizzd@aon.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 6eaf406 commit faa4bc3

File tree

5 files changed

+218
-2
lines changed

5 files changed

+218
-2
lines changed

t/lib-httpd.sh

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (c) 2008 Clemens Buchacher <drizzd@aon.at>
4+
#
5+
6+
if test -z "$GIT_TEST_HTTPD"
7+
then
8+
say "skipping test, network testing disabled by default"
9+
say "(define GIT_TEST_HTTPD to enable)"
10+
test_done
11+
exit
12+
fi
13+
14+
LIB_HTTPD_PATH=${LIB_HTTPD_PATH-'/usr/sbin/apache2'}
15+
LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'8111'}
16+
17+
TEST_PATH="$PWD"/../lib-httpd
18+
HTTPD_ROOT_PATH="$PWD"/httpd
19+
HTTPD_DOCUMENT_ROOT_PATH=$HTTPD_ROOT_PATH/www
20+
21+
if ! test -x "$LIB_HTTPD_PATH"
22+
then
23+
say "skipping test, no web server found at '$LIB_HTTPD_PATH'"
24+
test_done
25+
exit
26+
fi
27+
28+
HTTPD_VERSION=`$LIB_HTTPD_PATH -v | \
29+
sed -n 's/^Server version: Apache\/\([0-9]*\)\..*$/\1/p; q'`
30+
31+
if test -n "$HTTPD_VERSION"
32+
then
33+
if test -z "$LIB_HTTPD_MODULE_PATH"
34+
then
35+
if ! test $HTTPD_VERSION -ge 2
36+
then
37+
say "skipping test, at least Apache version 2 is required"
38+
test_done
39+
exit
40+
fi
41+
42+
LIB_HTTPD_MODULE_PATH='/usr/lib/apache2/modules'
43+
fi
44+
else
45+
error "Could not identify web server at '$LIB_HTTPD_PATH'"
46+
fi
47+
48+
HTTPD_PARA="-d $HTTPD_ROOT_PATH -f $TEST_PATH/apache.conf"
49+
50+
prepare_httpd() {
51+
mkdir -p $HTTPD_DOCUMENT_ROOT_PATH
52+
53+
ln -s $LIB_HTTPD_MODULE_PATH $HTTPD_ROOT_PATH/modules
54+
55+
if test -n "$LIB_HTTPD_SSL"
56+
then
57+
HTTPD_URL=https://127.0.0.1:$LIB_HTTPD_PORT
58+
59+
RANDFILE_PATH="$HTTPD_ROOT_PATH"/.rnd openssl req \
60+
-config $TEST_PATH/ssl.cnf \
61+
-new -x509 -nodes \
62+
-out $HTTPD_ROOT_PATH/httpd.pem \
63+
-keyout $HTTPD_ROOT_PATH/httpd.pem
64+
export GIT_SSL_NO_VERIFY=t
65+
HTTPD_PARA="$HTTPD_PARA -DSSL"
66+
else
67+
HTTPD_URL=http://127.0.0.1:$LIB_HTTPD_PORT
68+
fi
69+
70+
if test -n "$LIB_HTTPD_DAV" -o -n "$LIB_HTTPD_SVN"
71+
then
72+
HTTPD_PARA="$HTTPD_PARA -DDAV"
73+
74+
if test -n "$LIB_HTTPD_SVN"
75+
then
76+
HTTPD_PARA="$HTTPD_PARA -DSVN"
77+
rawsvnrepo="$HTTPD_ROOT_PATH/svnrepo"
78+
svnrepo="http://127.0.0.1:$LIB_HTTPD_PORT/svn"
79+
fi
80+
fi
81+
}
82+
83+
start_httpd() {
84+
prepare_httpd
85+
86+
trap 'stop_httpd; die' exit
87+
88+
"$LIB_HTTPD_PATH" $HTTPD_PARA \
89+
-c "Listen 127.0.0.1:$LIB_HTTPD_PORT" -k start
90+
}
91+
92+
stop_httpd() {
93+
trap 'die' exit
94+
95+
"$LIB_HTTPD_PATH" $HTTPD_PARA -k stop
96+
}

t/lib-httpd/apache.conf

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
PidFile httpd.pid
2+
DocumentRoot www
3+
ErrorLog error.log
4+
5+
<IfDefine SSL>
6+
LoadModule ssl_module modules/mod_ssl.so
7+
8+
SSLCertificateFile httpd.pem
9+
SSLCertificateKeyFile httpd.pem
10+
SSLRandomSeed startup file:/dev/urandom 512
11+
SSLRandomSeed connect file:/dev/urandom 512
12+
SSLSessionCache none
13+
SSLMutex file:ssl_mutex
14+
SSLEngine On
15+
</IfDefine>
16+
17+
<IfDefine DAV>
18+
LoadModule dav_module modules/mod_dav.so
19+
LoadModule dav_fs_module modules/mod_dav_fs.so
20+
21+
DAVLockDB DAVLock
22+
<Location />
23+
Dav on
24+
</Location>
25+
</IfDefine>
26+
27+
<IfDefine SVN>
28+
LoadModule dav_svn_module modules/mod_dav_svn.so
29+
30+
<Location /svn>
31+
DAV svn
32+
SVNPath svnrepo
33+
</Location>
34+
</IfDefine>

t/lib-httpd/ssl.cnf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
RANDFILE = $ENV::RANDFILE_PATH
2+
3+
[ req ]
4+
default_bits = 1024
5+
distinguished_name = req_distinguished_name
6+
prompt = no
7+
[ req_distinguished_name ]
8+
commonName = 127.0.0.1

t/t5540-http-push.sh

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (c) 2008 Clemens Buchacher <drizzd@aon.at>
4+
#
5+
6+
test_description='test http-push
7+
8+
This test runs various sanity checks on http-push.'
9+
10+
. ./test-lib.sh
11+
12+
ROOT_PATH="$PWD"
13+
LIB_HTTPD_DAV=t
14+
15+
. ../lib-httpd.sh
16+
17+
if ! start_httpd >&3 2>&4
18+
then
19+
say "skipping test, web server setup failed"
20+
test_done
21+
exit
22+
fi
23+
24+
test_expect_success 'setup remote repository' '
25+
cd "$ROOT_PATH" &&
26+
mkdir test_repo &&
27+
cd test_repo &&
28+
git init &&
29+
: >path1 &&
30+
git add path1 &&
31+
test_tick &&
32+
git commit -m initial &&
33+
cd - &&
34+
git clone --bare test_repo test_repo.git &&
35+
cd test_repo.git &&
36+
git --bare update-server-info &&
37+
chmod +x hooks/post-update &&
38+
cd - &&
39+
mv test_repo.git $HTTPD_DOCUMENT_ROOT_PATH
40+
'
41+
42+
test_expect_success 'clone remote repository' '
43+
cd "$ROOT_PATH" &&
44+
git clone $HTTPD_URL/test_repo.git test_repo_clone
45+
'
46+
47+
test_expect_success 'push to remote repository' '
48+
cd "$ROOT_PATH"/test_repo_clone &&
49+
: >path2 &&
50+
git add path2 &&
51+
test_tick &&
52+
git commit -m path2 &&
53+
git push
54+
'
55+
56+
test_expect_success 'create and delete remote branch' '
57+
cd "$ROOT_PATH"/test_repo_clone &&
58+
git checkout -b dev &&
59+
: >path3 &&
60+
git add path3 &&
61+
test_tick &&
62+
git commit -m dev &&
63+
git push origin dev &&
64+
git fetch &&
65+
git push origin :dev &&
66+
git branch -d -r origin/dev &&
67+
git fetch &&
68+
! git show-ref --verify refs/remotes/origin/dev
69+
'
70+
71+
stop_httpd
72+
73+
test_done

t/test-lib.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ do
8080
-q|--q|--qu|--qui|--quie|--quiet)
8181
quiet=t; shift ;;
8282
--no-color)
83-
color=; shift ;;
83+
color=; shift ;;
8484
--no-python)
8585
# noop now...
8686
shift ;;
@@ -142,7 +142,12 @@ test_count=0
142142
test_fixed=0
143143
test_broken=0
144144

145-
trap 'echo >&5 "FATAL: Unexpected exit with code $?"; exit 1' exit
145+
die () {
146+
echo >&5 "FATAL: Unexpected exit with code $?"
147+
exit 1
148+
}
149+
150+
trap 'die' exit
146151

147152
test_tick () {
148153
if test -z "${test_tick+set}"

0 commit comments

Comments
 (0)