]> git.ipfire.org Git - thirdparty/git.git/blame - t/lib-httpd.sh
t5541-http-push: check that ref is unchanged for non-ff test
[thirdparty/git.git] / t / lib-httpd.sh
CommitLineData
faa4bc35
CB
1#!/bin/sh
2#
3# Copyright (c) 2008 Clemens Buchacher <drizzd@aon.at>
4#
5
6if test -z "$GIT_TEST_HTTPD"
7then
8 say "skipping test, network testing disabled by default"
9 say "(define GIT_TEST_HTTPD to enable)"
10 test_done
faa4bc35
CB
11fi
12
69707d61
JS
13HTTPD_PARA=""
14
0d344738
TC
15for DEFAULT_HTTPD_PATH in '/usr/sbin/httpd' '/usr/sbin/apache2'
16do
17 if test -x "$DEFAULT_HTTPD_PATH"
18 then
19 break
20 fi
21done
22
23for DEFAULT_HTTPD_MODULE_PATH in '/usr/libexec/apache2' \
24 '/usr/lib/apache2/modules' \
25 '/usr/lib64/httpd/modules' \
26 '/usr/lib/httpd/modules'
27do
28 if test -d "$DEFAULT_HTTPD_MODULE_PATH"
29 then
30 break
31 fi
32done
33
69707d61
JS
34case $(uname) in
35 Darwin)
69707d61
JS
36 HTTPD_PARA="$HTTPD_PARA -DDarwin"
37 ;;
69707d61
JS
38esac
39
40LIB_HTTPD_PATH=${LIB_HTTPD_PATH-"$DEFAULT_HTTPD_PATH"}
faa4bc35
CB
41LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'8111'}
42
bfdbee98 43TEST_PATH="$TEST_DIRECTORY"/lib-httpd
faa4bc35
CB
44HTTPD_ROOT_PATH="$PWD"/httpd
45HTTPD_DOCUMENT_ROOT_PATH=$HTTPD_ROOT_PATH/www
46
47if ! test -x "$LIB_HTTPD_PATH"
48then
35641310
MH
49 say "skipping test, no web server found at '$LIB_HTTPD_PATH'"
50 test_done
faa4bc35
CB
51fi
52
53HTTPD_VERSION=`$LIB_HTTPD_PATH -v | \
54 sed -n 's/^Server version: Apache\/\([0-9]*\)\..*$/\1/p; q'`
55
56if test -n "$HTTPD_VERSION"
57then
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
faa4bc35 64 fi
0d344738
TC
65 if ! test -d "$DEFAULT_HTTPD_MODULE_PATH"
66 then
67 say "Apache module directory not found. Skipping tests."
68 test_done
69 fi
faa4bc35 70
69707d61 71 LIB_HTTPD_MODULE_PATH="$DEFAULT_HTTPD_MODULE_PATH"
faa4bc35
CB
72 fi
73else
74 error "Could not identify web server at '$LIB_HTTPD_PATH'"
75fi
76
faa4bc35 77prepare_httpd() {
13b5481e 78 mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH"
faa4bc35 79
13b5481e 80 ln -s "$LIB_HTTPD_MODULE_PATH" "$HTTPD_ROOT_PATH/modules"
faa4bc35
CB
81
82 if test -n "$LIB_HTTPD_SSL"
83 then
84 HTTPD_URL=https://127.0.0.1:$LIB_HTTPD_PORT
85
86 RANDFILE_PATH="$HTTPD_ROOT_PATH"/.rnd openssl req \
13b5481e 87 -config "$TEST_PATH/ssl.cnf" \
faa4bc35 88 -new -x509 -nodes \
13b5481e
MH
89 -out "$HTTPD_ROOT_PATH/httpd.pem" \
90 -keyout "$HTTPD_ROOT_PATH/httpd.pem"
0e46e704
BD
91 GIT_SSL_NO_VERIFY=t
92 export GIT_SSL_NO_VERIFY
faa4bc35
CB
93 HTTPD_PARA="$HTTPD_PARA -DSSL"
94 else
95 HTTPD_URL=http://127.0.0.1:$LIB_HTTPD_PORT
96 fi
97
98 if test -n "$LIB_HTTPD_DAV" -o -n "$LIB_HTTPD_SVN"
99 then
100 HTTPD_PARA="$HTTPD_PARA -DDAV"
101
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"
107 fi
108 fi
109}
110
111start_httpd() {
75318a3b 112 prepare_httpd >&3 2>&4
faa4bc35 113
a5adcbe3 114 trap 'code=$?; stop_httpd; (exit $code); die' EXIT
faa4bc35 115
13b5481e
MH
116 "$LIB_HTTPD_PATH" -d "$HTTPD_ROOT_PATH" \
117 -f "$TEST_PATH/apache.conf" $HTTPD_PARA \
75318a3b
JK
118 -c "Listen 127.0.0.1:$LIB_HTTPD_PORT" -k start \
119 >&3 2>&4
a5adcbe3
CB
120 if test $? -ne 0
121 then
75318a3b 122 say "skipping test, web server setup failed"
a5adcbe3 123 trap 'die' EXIT
75318a3b
JK
124 test_done
125 fi
faa4bc35
CB
126}
127
128stop_httpd() {
35641310 129 trap 'die' EXIT
faa4bc35 130
13b5481e 131 "$LIB_HTTPD_PATH" -d "$HTTPD_ROOT_PATH" \
69707d61 132 -f "$TEST_PATH/apache.conf" $HTTPD_PARA -k stop
faa4bc35 133}