Merge branch 'cb/maint-stash-orphaned-file'
[git/debian.git] / t / lib-httpd.sh
blobda4b8d5a6fbf18adac103a5a6dd26ea3498c178f
1 #!/bin/sh
3 # Copyright (c) 2008 Clemens Buchacher <drizzd@aon.at>
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
13 HTTPD_PARA=""
15 for DEFAULT_HTTPD_PATH in '/usr/sbin/httpd' '/usr/sbin/apache2'
17 if test -x "$DEFAULT_HTTPD_PATH"
18 then
19 break
21 done
23 for DEFAULT_HTTPD_MODULE_PATH in '/usr/libexec/apache2' \
24 '/usr/lib/apache2/modules' \
25 '/usr/lib64/httpd/modules' \
26 '/usr/lib/httpd/modules'
28 if test -d "$DEFAULT_HTTPD_MODULE_PATH"
29 then
30 break
32 done
34 case $(uname) in
35 Darwin)
36 HTTPD_PARA="$HTTPD_PARA -DDarwin"
38 esac
40 LIB_HTTPD_PATH=${LIB_HTTPD_PATH-"$DEFAULT_HTTPD_PATH"}
41 LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'8111'}
43 TEST_PATH="$TEST_DIRECTORY"/lib-httpd
44 HTTPD_ROOT_PATH="$PWD"/httpd
45 HTTPD_DOCUMENT_ROOT_PATH=$HTTPD_ROOT_PATH/www
47 if ! test -x "$LIB_HTTPD_PATH"
48 then
49 say "skipping test, no web server found at '$LIB_HTTPD_PATH'"
50 test_done
53 HTTPD_VERSION=`$LIB_HTTPD_PATH -v | \
54 sed -n 's/^Server version: Apache\/\([0-9]*\)\..*$/\1/p; q'`
56 if test -n "$HTTPD_VERSION"
57 then
58 if test -z "$LIB_HTTPD_MODULE_PATH"
59 then
60 if ! test $HTTPD_VERSION -ge 2
61 then
62 say "skipping test, at least Apache version 2 is required"
63 test_done
65 if ! test -d "$DEFAULT_HTTPD_MODULE_PATH"
66 then
67 say "Apache module directory not found. Skipping tests."
68 test_done
71 LIB_HTTPD_MODULE_PATH="$DEFAULT_HTTPD_MODULE_PATH"
73 else
74 error "Could not identify web server at '$LIB_HTTPD_PATH'"
77 prepare_httpd() {
78 mkdir -p "$HTTPD_DOCUMENT_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
86 RANDFILE_PATH="$HTTPD_ROOT_PATH"/.rnd openssl req \
87 -config "$TEST_PATH/ssl.cnf" \
88 -new -x509 -nodes \
89 -out "$HTTPD_ROOT_PATH/httpd.pem" \
90 -keyout "$HTTPD_ROOT_PATH/httpd.pem"
91 GIT_SSL_NO_VERIFY=t
92 export GIT_SSL_NO_VERIFY
93 HTTPD_PARA="$HTTPD_PARA -DSSL"
94 else
95 HTTPD_URL=http://127.0.0.1:$LIB_HTTPD_PORT
98 if test -n "$LIB_HTTPD_DAV" -o -n "$LIB_HTTPD_SVN"
99 then
100 HTTPD_PARA="$HTTPD_PARA -DDAV"
102 if test -n "$LIB_HTTPD_SVN"
103 then
104 HTTPD_PARA="$HTTPD_PARA -DSVN"
105 rawsvnrepo="$HTTPD_ROOT_PATH/svnrepo"
106 svnrepo="http://127.0.0.1:$LIB_HTTPD_PORT/svn"
111 start_httpd() {
112 prepare_httpd >&3 2>&4
114 trap 'code=$?; stop_httpd; (exit $code); die' EXIT
116 "$LIB_HTTPD_PATH" -d "$HTTPD_ROOT_PATH" \
117 -f "$TEST_PATH/apache.conf" $HTTPD_PARA \
118 -c "Listen 127.0.0.1:$LIB_HTTPD_PORT" -k start \
119 >&3 2>&4
120 if test $? -ne 0
121 then
122 say "skipping test, web server setup failed"
123 trap 'die' EXIT
124 test_done
128 stop_httpd() {
129 trap 'die' EXIT
131 "$LIB_HTTPD_PATH" -d "$HTTPD_ROOT_PATH" \
132 -f "$TEST_PATH/apache.conf" $HTTPD_PARA -k stop
135 test_http_push_nonff() {
136 REMOTE_REPO=$1
137 LOCAL_REPO=$2
138 BRANCH=$3
140 test_expect_success 'non-fast-forward push fails' '
141 cd "$REMOTE_REPO" &&
142 HEAD=$(git rev-parse --verify HEAD) &&
144 cd "$LOCAL_REPO" &&
145 git checkout $BRANCH &&
146 echo "changed" > path2 &&
147 git commit -a -m path2 --amend &&
149 !(git push -v origin >output 2>&1) &&
150 (cd "$REMOTE_REPO" &&
151 test $HEAD = $(git rev-parse --verify HEAD))
154 test_expect_success 'non-fast-forward push show ref status' '
155 grep "^ ! \[rejected\][ ]*$BRANCH -> $BRANCH (non-fast-forward)$" output
158 test_expect_success 'non-fast-forward push shows help message' '
159 grep "To prevent you from losing history, non-fast-forward updates were rejected" \
160 output