Merge branch 'jc/add-u-migration-2' (early part) into next
[git/dscho.git] / t / lib-httpd.sh
blobd3829b8d0a18d15590f4cbde4606d130a9293ead
1 #!/bin/sh
3 # Copyright (c) 2008 Clemens Buchacher <drizzd@aon.at>
6 if test -z "$GIT_TEST_HTTPD"
7 then
8 skip_all="Network testing disabled (define GIT_TEST_HTTPD to enable)"
9 test_done
12 HTTPD_PARA=""
14 for DEFAULT_HTTPD_PATH in '/usr/sbin/httpd' '/usr/sbin/apache2'
16 if test -x "$DEFAULT_HTTPD_PATH"
17 then
18 break
20 done
22 for DEFAULT_HTTPD_MODULE_PATH in '/usr/libexec/apache2' \
23 '/usr/lib/apache2/modules' \
24 '/usr/lib64/httpd/modules' \
25 '/usr/lib/httpd/modules'
27 if test -d "$DEFAULT_HTTPD_MODULE_PATH"
28 then
29 break
31 done
33 case $(uname) in
34 Darwin)
35 HTTPD_PARA="$HTTPD_PARA -DDarwin"
37 esac
39 LIB_HTTPD_PATH=${LIB_HTTPD_PATH-"$DEFAULT_HTTPD_PATH"}
40 LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'8111'}
42 TEST_PATH="$TEST_DIRECTORY"/lib-httpd
43 HTTPD_ROOT_PATH="$PWD"/httpd
44 HTTPD_DOCUMENT_ROOT_PATH=$HTTPD_ROOT_PATH/www
46 if ! test -x "$LIB_HTTPD_PATH"
47 then
48 skip_all="skipping test, no web server found at '$LIB_HTTPD_PATH'"
49 test_done
52 HTTPD_VERSION=`$LIB_HTTPD_PATH -v | \
53 sed -n 's/^Server version: Apache\/\([0-9]*\)\..*$/\1/p; q'`
55 if test -n "$HTTPD_VERSION"
56 then
57 if test -z "$LIB_HTTPD_MODULE_PATH"
58 then
59 if ! test $HTTPD_VERSION -ge 2
60 then
61 skip_all="skipping test, at least Apache version 2 is required"
62 test_done
64 if ! test -d "$DEFAULT_HTTPD_MODULE_PATH"
65 then
66 skip_all="Apache module directory not found. Skipping tests."
67 test_done
70 LIB_HTTPD_MODULE_PATH="$DEFAULT_HTTPD_MODULE_PATH"
72 else
73 error "Could not identify web server at '$LIB_HTTPD_PATH'"
76 prepare_httpd() {
77 mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH"
78 cp "$TEST_PATH"/passwd "$HTTPD_ROOT_PATH"
80 ln -s "$LIB_HTTPD_MODULE_PATH" "$HTTPD_ROOT_PATH/modules"
82 if test -n "$LIB_HTTPD_SSL"
83 then
84 HTTPD_URL=https://127.0.0.1:$LIB_HTTPD_PORT
85 AUTH_HTTPD_URL=https://user%40host:user%40host@127.0.0.1:$LIB_HTTPD_PORT
87 RANDFILE_PATH="$HTTPD_ROOT_PATH"/.rnd openssl req \
88 -config "$TEST_PATH/ssl.cnf" \
89 -new -x509 -nodes \
90 -out "$HTTPD_ROOT_PATH/httpd.pem" \
91 -keyout "$HTTPD_ROOT_PATH/httpd.pem"
92 GIT_SSL_NO_VERIFY=t
93 export GIT_SSL_NO_VERIFY
94 HTTPD_PARA="$HTTPD_PARA -DSSL"
95 else
96 HTTPD_URL=http://127.0.0.1:$LIB_HTTPD_PORT
97 AUTH_HTTPD_URL=http://user%40host:user%40host@127.0.0.1:$LIB_HTTPD_PORT
100 if test -n "$LIB_HTTPD_DAV" -o -n "$LIB_HTTPD_SVN"
101 then
102 HTTPD_PARA="$HTTPD_PARA -DDAV"
104 if test -n "$LIB_HTTPD_SVN"
105 then
106 HTTPD_PARA="$HTTPD_PARA -DSVN"
107 rawsvnrepo="$HTTPD_ROOT_PATH/svnrepo"
108 svnrepo="http://127.0.0.1:$LIB_HTTPD_PORT/svn"
113 start_httpd() {
114 prepare_httpd >&3 2>&4
116 trap 'code=$?; stop_httpd; (exit $code); die' EXIT
118 "$LIB_HTTPD_PATH" -d "$HTTPD_ROOT_PATH" \
119 -f "$TEST_PATH/apache.conf" $HTTPD_PARA \
120 -c "Listen 127.0.0.1:$LIB_HTTPD_PORT" -k start \
121 >&3 2>&4
122 if test $? -ne 0
123 then
124 skip_all="skipping test, web server setup failed"
125 trap 'die' EXIT
126 test_done
130 stop_httpd() {
131 trap 'die' EXIT
133 "$LIB_HTTPD_PATH" -d "$HTTPD_ROOT_PATH" \
134 -f "$TEST_PATH/apache.conf" $HTTPD_PARA -k stop
137 test_http_push_nonff() {
138 REMOTE_REPO=$1
139 LOCAL_REPO=$2
140 BRANCH=$3
142 test_expect_success 'non-fast-forward push fails' '
143 cd "$REMOTE_REPO" &&
144 HEAD=$(git rev-parse --verify HEAD) &&
146 cd "$LOCAL_REPO" &&
147 git checkout $BRANCH &&
148 echo "changed" > path2 &&
149 git commit -a -m path2 --amend &&
151 test_must_fail git push -v origin >output 2>&1 &&
152 (cd "$REMOTE_REPO" &&
153 test $HEAD = $(git rev-parse --verify HEAD))
156 test_expect_success 'non-fast-forward push show ref status' '
157 grep "^ ! \[rejected\][ ]*$BRANCH -> $BRANCH (non-fast-forward)$" output
160 test_expect_success C_LOCALE_OUTPUT 'non-fast-forward push shows help message' '
161 grep "To prevent you from losing history, non-fast-forward updates were rejected" \
162 output