Merge branch 'np/pack-broken-boundary' into next
[git] / t / lib-httpd.sh
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         skip_all="Network testing disabled (define GIT_TEST_HTTPD to enable)"
9         test_done
10 fi
11
12 HTTPD_PARA=""
13
14 for DEFAULT_HTTPD_PATH in '/usr/sbin/httpd' '/usr/sbin/apache2'
15 do
16         if test -x "$DEFAULT_HTTPD_PATH"
17         then
18                 break
19         fi
20 done
21
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'
26 do
27         if test -d "$DEFAULT_HTTPD_MODULE_PATH"
28         then
29                 break
30         fi
31 done
32
33 case $(uname) in
34         Darwin)
35                 HTTPD_PARA="$HTTPD_PARA -DDarwin"
36         ;;
37 esac
38
39 LIB_HTTPD_PATH=${LIB_HTTPD_PATH-"$DEFAULT_HTTPD_PATH"}
40 LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'8111'}
41
42 TEST_PATH="$TEST_DIRECTORY"/lib-httpd
43 HTTPD_ROOT_PATH="$PWD"/httpd
44 HTTPD_DOCUMENT_ROOT_PATH=$HTTPD_ROOT_PATH/www
45
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
50 fi
51
52 HTTPD_VERSION=`$LIB_HTTPD_PATH -v | \
53         sed -n 's/^Server version: Apache\/\([0-9]*\)\..*$/\1/p; q'`
54
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
63                 fi
64                 if ! test -d "$DEFAULT_HTTPD_MODULE_PATH"
65                 then
66                         skip_all="Apache module directory not found.  Skipping tests."
67                         test_done
68                 fi
69
70                 LIB_HTTPD_MODULE_PATH="$DEFAULT_HTTPD_MODULE_PATH"
71         fi
72 else
73         error "Could not identify web server at '$LIB_HTTPD_PATH'"
74 fi
75
76 prepare_httpd() {
77         mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH"
78
79         ln -s "$LIB_HTTPD_MODULE_PATH" "$HTTPD_ROOT_PATH/modules"
80
81         if test -n "$LIB_HTTPD_SSL"
82         then
83                 HTTPD_URL=https://127.0.0.1:$LIB_HTTPD_PORT
84
85                 RANDFILE_PATH="$HTTPD_ROOT_PATH"/.rnd openssl req \
86                         -config "$TEST_PATH/ssl.cnf" \
87                         -new -x509 -nodes \
88                         -out "$HTTPD_ROOT_PATH/httpd.pem" \
89                         -keyout "$HTTPD_ROOT_PATH/httpd.pem"
90                 GIT_SSL_NO_VERIFY=t
91                 export GIT_SSL_NO_VERIFY
92                 HTTPD_PARA="$HTTPD_PARA -DSSL"
93         else
94                 HTTPD_URL=http://127.0.0.1:$LIB_HTTPD_PORT
95         fi
96
97         if test -n "$LIB_HTTPD_DAV" -o -n "$LIB_HTTPD_SVN"
98         then
99                 HTTPD_PARA="$HTTPD_PARA -DDAV"
100
101                 if test -n "$LIB_HTTPD_SVN"
102                 then
103                         HTTPD_PARA="$HTTPD_PARA -DSVN"
104                         rawsvnrepo="$HTTPD_ROOT_PATH/svnrepo"
105                         svnrepo="http://127.0.0.1:$LIB_HTTPD_PORT/svn"
106                 fi
107         fi
108 }
109
110 start_httpd() {
111         prepare_httpd >&3 2>&4
112
113         trap 'code=$?; stop_httpd; (exit $code); die' EXIT
114
115         "$LIB_HTTPD_PATH" -d "$HTTPD_ROOT_PATH" \
116                 -f "$TEST_PATH/apache.conf" $HTTPD_PARA \
117                 -c "Listen 127.0.0.1:$LIB_HTTPD_PORT" -k start \
118                 >&3 2>&4
119         if test $? -ne 0
120         then
121                 skip_all="skipping test, web server setup failed"
122                 trap 'die' EXIT
123                 test_done
124         fi
125 }
126
127 stop_httpd() {
128         trap 'die' EXIT
129
130         "$LIB_HTTPD_PATH" -d "$HTTPD_ROOT_PATH" \
131                 -f "$TEST_PATH/apache.conf" $HTTPD_PARA -k stop
132 }
133
134 test_http_push_nonff() {
135         REMOTE_REPO=$1
136         LOCAL_REPO=$2
137         BRANCH=$3
138
139         test_expect_success 'non-fast-forward push fails' '
140                 cd "$REMOTE_REPO" &&
141                 HEAD=$(git rev-parse --verify HEAD) &&
142
143                 cd "$LOCAL_REPO" &&
144                 git checkout $BRANCH &&
145                 echo "changed" > path2 &&
146                 git commit -a -m path2 --amend &&
147
148                 test_must_fail git push -v origin >output 2>&1 &&
149                 (cd "$REMOTE_REPO" &&
150                  test $HEAD = $(git rev-parse --verify HEAD))
151         '
152
153         test_expect_success 'non-fast-forward push show ref status' '
154                 grep "^ ! \[rejected\][ ]*$BRANCH -> $BRANCH (non-fast-forward)$" output
155         '
156
157         test_expect_success 'non-fast-forward push shows help message' '
158                 grep "To prevent you from losing history, non-fast-forward updates were rejected" \
159                         output
160         '
161 }