]> git.proxmox.com Git - libgit2.git/blob - ci/test.sh
4d6c41f7675a62851fd1e1c247dadd08c366af42
[libgit2.git] / ci / test.sh
1 #!/usr/bin/env bash
2
3 set -e
4
5 if [ -n "$SKIP_TESTS" ]; then
6 exit 0
7 fi
8
9 # Windows doesn't run the NTLM tests properly (yet)
10 if [[ "$(uname -s)" == MINGW* ]]; then
11 SKIP_NTLM_TESTS=1
12 fi
13
14 SOURCE_DIR=${SOURCE_DIR:-$( cd "$( dirname "${BASH_SOURCE[0]}" )" && dirname $( pwd ) )}
15 BUILD_DIR=$(pwd)
16 TMPDIR=${TMPDIR:-/tmp}
17 USER=${USER:-$(whoami)}
18
19 SUCCESS=1
20 CONTINUE_ON_FAILURE=0
21
22 cleanup() {
23 echo "Cleaning up..."
24
25 if [ ! -z "$GITDAEMON_PID" ]; then
26 echo "Stopping git daemon..."
27 kill $GITDAEMON_PID
28 fi
29
30 if [ ! -z "$SSHD_DIR" -a -f "${SSHD_DIR}/pid" ]; then
31 echo "Stopping SSH..."
32 kill $(cat "${SSHD_DIR}/pid")
33 fi
34
35 echo "Done."
36 }
37
38 run_test() {
39 if [[ "$GITTEST_FLAKY_RETRY" > 0 ]]; then
40 ATTEMPTS_REMAIN=$GITTEST_FLAKY_RETRY
41 else
42 ATTEMPTS_REMAIN=1
43 fi
44
45 FAILED=0
46 while [[ "$ATTEMPTS_REMAIN" > 0 ]]; do
47 if [ "$FAILED" -eq 1 ]; then
48 echo ""
49 echo "Re-running flaky ${1} tests..."
50 echo ""
51 fi
52
53 RETURN_CODE=0
54
55 CLAR_SUMMARY="${BUILD_DIR}/results_${1}.xml" ctest -V -R "^${1}$" || RETURN_CODE=$? && true
56
57 if [ "$RETURN_CODE" -eq 0 ]; then
58 FAILED=0
59 break
60 fi
61
62 echo "Test exited with code: $RETURN_CODE"
63 ATTEMPTS_REMAIN="$(($ATTEMPTS_REMAIN-1))"
64 FAILED=1
65 done
66
67 if [ "$FAILED" -ne 0 ]; then
68 if [ "$CONTINUE_ON_FAILURE" -ne 1 ]; then
69 exit 1
70 fi
71
72 SUCCESS=0
73 fi
74 }
75
76 # Configure the test environment; run them early so that we're certain
77 # that they're started by the time we need them.
78
79 echo "##############################################################################"
80 echo "## Configuring test environment"
81 echo "##############################################################################"
82
83 if [ -z "$SKIP_GITDAEMON_TESTS" ]; then
84 echo "Starting git daemon..."
85 GITDAEMON_DIR=`mktemp -d ${TMPDIR}/gitdaemon.XXXXXXXX`
86 git init --bare "${GITDAEMON_DIR}/test.git"
87 git daemon --listen=localhost --export-all --enable=receive-pack --base-path="${GITDAEMON_DIR}" "${GITDAEMON_DIR}" 2>/dev/null &
88 GITDAEMON_PID=$!
89 disown $GITDAEMON_PID
90 fi
91
92 if [ -z "$SKIP_PROXY_TESTS" ]; then
93 curl --location --silent --show-error https://github.com/ethomson/poxyproxy/releases/download/v0.7.0/poxyproxy-0.7.0.jar >poxyproxy.jar
94
95 echo ""
96 echo "Starting HTTP proxy (Basic)..."
97 java -jar poxyproxy.jar --address 127.0.0.1 --port 8080 --credentials foo:bar --auth-type basic --quiet &
98
99 echo ""
100 echo "Starting HTTP proxy (NTLM)..."
101 java -jar poxyproxy.jar --address 127.0.0.1 --port 8090 --credentials foo:bar --auth-type ntlm --quiet &
102 fi
103
104 if [ -z "$SKIP_NTLM_TESTS" ]; then
105 curl --location --silent --show-error https://github.com/ethomson/poxygit/releases/download/v0.4.0/poxygit-0.4.0.jar >poxygit.jar
106
107 echo ""
108 echo "Starting HTTP server..."
109 NTLM_DIR=`mktemp -d ${TMPDIR}/ntlm.XXXXXXXX`
110 git init --bare "${NTLM_DIR}/test.git"
111 java -jar poxygit.jar --address 127.0.0.1 --port 9000 --credentials foo:baz --quiet "${NTLM_DIR}" &
112 fi
113
114 if [ -z "$SKIP_SSH_TESTS" ]; then
115 echo "Starting ssh daemon..."
116 HOME=`mktemp -d ${TMPDIR}/home.XXXXXXXX`
117 SSHD_DIR=`mktemp -d ${TMPDIR}/sshd.XXXXXXXX`
118 git init --bare "${SSHD_DIR}/test.git"
119 cat >"${SSHD_DIR}/sshd_config" <<-EOF
120 Port 2222
121 ListenAddress 0.0.0.0
122 Protocol 2
123 HostKey ${SSHD_DIR}/id_rsa
124 PidFile ${SSHD_DIR}/pid
125 AuthorizedKeysFile ${HOME}/.ssh/authorized_keys
126 LogLevel DEBUG
127 RSAAuthentication yes
128 PasswordAuthentication yes
129 PubkeyAuthentication yes
130 ChallengeResponseAuthentication no
131 StrictModes no
132 # Required here as sshd will simply close connection otherwise
133 UsePAM no
134 EOF
135 ssh-keygen -t rsa -f "${SSHD_DIR}/id_rsa" -N "" -q
136 /usr/sbin/sshd -f "${SSHD_DIR}/sshd_config" -E "${SSHD_DIR}/log"
137
138 # Set up keys
139 mkdir "${HOME}/.ssh"
140 ssh-keygen -t rsa -f "${HOME}/.ssh/id_rsa" -N "" -q
141 cat "${HOME}/.ssh/id_rsa.pub" >>"${HOME}/.ssh/authorized_keys"
142 while read algorithm key comment; do
143 echo "[localhost]:2222 $algorithm $key" >>"${HOME}/.ssh/known_hosts"
144 done <"${SSHD_DIR}/id_rsa.pub"
145
146 # Get the fingerprint for localhost and remove the colons so we can
147 # parse it as a hex number. Older versions have a different output
148 # format.
149 if [[ $(ssh -V 2>&1) == OpenSSH_6* ]]; then
150 SSH_FINGERPRINT=$(ssh-keygen -F '[localhost]:2222' -f "${HOME}/.ssh/known_hosts" -l | tail -n 1 | cut -d ' ' -f 2 | tr -d ':')
151 else
152 SSH_FINGERPRINT=$(ssh-keygen -E md5 -F '[localhost]:2222' -f "${HOME}/.ssh/known_hosts" -l | tail -n 1 | cut -d ' ' -f 3 | cut -d : -f2- | tr -d :)
153 fi
154 fi
155
156 # Run the tests that do not require network connectivity.
157
158 if [ -z "$SKIP_OFFLINE_TESTS" ]; then
159 echo ""
160 echo "##############################################################################"
161 echo "## Running (offline) tests"
162 echo "##############################################################################"
163
164 run_test offline
165 fi
166
167 if [ -n "$RUN_INVASIVE_TESTS" ]; then
168 echo ""
169 echo "Running invasive tests"
170 echo ""
171
172 export GITTEST_INVASIVE_FS_SIZE=1
173 export GITTEST_INVASIVE_MEMORY=1
174 export GITTEST_INVASIVE_SPEED=1
175 run_test invasive
176 unset GITTEST_INVASIVE_FS_SIZE
177 unset GITTEST_INVASIVE_MEMORY
178 unset GITTEST_INVASIVE_SPEED
179 fi
180
181 if [ -z "$SKIP_ONLINE_TESTS" ]; then
182 # Run the online tests. The "online" test suite only includes the
183 # default online tests that do not require additional configuration.
184 # The "proxy" and "ssh" test suites require further setup.
185
186 echo ""
187 echo "##############################################################################"
188 echo "## Running (online) tests"
189 echo "##############################################################################"
190
191 export GITTEST_FLAKY_RETRY=5
192 run_test online
193 unset GITTEST_FLAKY_RETRY
194
195 # Run the online tests that immutably change global state separately
196 # to avoid polluting the test environment.
197 echo ""
198 echo "##############################################################################"
199 echo "## Running (online_customcert) tests"
200 echo "##############################################################################"
201 run_test online_customcert
202 fi
203
204 if [ -z "$SKIP_GITDAEMON_TESTS" ]; then
205 echo ""
206 echo "Running gitdaemon tests"
207 echo ""
208
209 export GITTEST_REMOTE_URL="git://localhost/test.git"
210 run_test gitdaemon
211 unset GITTEST_REMOTE_URL
212 fi
213
214 if [ -z "$SKIP_PROXY_TESTS" ]; then
215 echo ""
216 echo "Running proxy tests (Basic authentication)"
217 echo ""
218
219 export GITTEST_REMOTE_PROXY_HOST="localhost:8080"
220 export GITTEST_REMOTE_PROXY_USER="foo"
221 export GITTEST_REMOTE_PROXY_PASS="bar"
222 run_test proxy
223 unset GITTEST_REMOTE_PROXY_HOST
224 unset GITTEST_REMOTE_PROXY_USER
225 unset GITTEST_REMOTE_PROXY_PASS
226
227 echo ""
228 echo "Running proxy tests (NTLM authentication)"
229 echo ""
230
231 export GITTEST_REMOTE_PROXY_HOST="localhost:8090"
232 export GITTEST_REMOTE_PROXY_USER="foo"
233 export GITTEST_REMOTE_PROXY_PASS="bar"
234 export GITTEST_FLAKY_RETRY=5
235 run_test proxy
236 unset GITTEST_FLAKY_RETRY
237 unset GITTEST_REMOTE_PROXY_HOST
238 unset GITTEST_REMOTE_PROXY_USER
239 unset GITTEST_REMOTE_PROXY_PASS
240 fi
241
242 if [ -z "$SKIP_NTLM_TESTS" ]; then
243 echo ""
244 echo "Running NTLM tests (IIS emulation)"
245 echo ""
246
247 export GITTEST_REMOTE_URL="http://localhost:9000/ntlm/test.git"
248 export GITTEST_REMOTE_USER="foo"
249 export GITTEST_REMOTE_PASS="baz"
250 run_test auth_clone_and_push
251 unset GITTEST_REMOTE_URL
252 unset GITTEST_REMOTE_USER
253 unset GITTEST_REMOTE_PASS
254
255 echo ""
256 echo "Running NTLM tests (Apache emulation)"
257 echo ""
258
259 export GITTEST_REMOTE_URL="http://localhost:9000/broken-ntlm/test.git"
260 export GITTEST_REMOTE_USER="foo"
261 export GITTEST_REMOTE_PASS="baz"
262 run_test auth_clone_and_push
263 unset GITTEST_REMOTE_URL
264 unset GITTEST_REMOTE_USER
265 unset GITTEST_REMOTE_PASS
266 fi
267
268 if [ -z "$SKIP_NEGOTIATE_TESTS" -a -n "$GITTEST_NEGOTIATE_PASSWORD" ]; then
269 echo ""
270 echo "Running SPNEGO tests"
271 echo ""
272
273 if [ "$(uname -s)" = "Darwin" ]; then
274 KINIT_FLAGS="--password-file=STDIN"
275 fi
276
277 echo $GITTEST_NEGOTIATE_PASSWORD | kinit $KINIT_FLAGS test@LIBGIT2.ORG
278 klist -5f
279
280 export GITTEST_REMOTE_URL="https://test.libgit2.org/kerberos/empty.git"
281 export GITTEST_REMOTE_DEFAULT="true"
282 run_test auth_clone
283 unset GITTEST_REMOTE_URL
284 unset GITTEST_REMOTE_DEFAULT
285
286 echo ""
287 echo "Running SPNEGO tests (expect/continue)"
288 echo ""
289
290 export GITTEST_REMOTE_URL="https://test.libgit2.org/kerberos/empty.git"
291 export GITTEST_REMOTE_DEFAULT="true"
292 export GITTEST_REMOTE_EXPECTCONTINUE="true"
293 run_test auth_clone
294 unset GITTEST_REMOTE_URL
295 unset GITTEST_REMOTE_DEFAULT
296 unset GITTEST_REMOTE_EXPECTCONTINUE
297
298 kdestroy -A
299 fi
300
301 if [ -z "$SKIP_SSH_TESTS" ]; then
302 echo ""
303 echo "Running ssh tests"
304 echo ""
305
306 export GITTEST_REMOTE_URL="ssh://localhost:2222/$SSHD_DIR/test.git"
307 export GITTEST_REMOTE_USER=$USER
308 export GITTEST_REMOTE_SSH_KEY="${HOME}/.ssh/id_rsa"
309 export GITTEST_REMOTE_SSH_PUBKEY="${HOME}/.ssh/id_rsa.pub"
310 export GITTEST_REMOTE_SSH_PASSPHRASE=""
311 export GITTEST_REMOTE_SSH_FINGERPRINT="${SSH_FINGERPRINT}"
312 run_test ssh
313 unset GITTEST_REMOTE_URL
314 unset GITTEST_REMOTE_USER
315 unset GITTEST_REMOTE_SSH_KEY
316 unset GITTEST_REMOTE_SSH_PUBKEY
317 unset GITTEST_REMOTE_SSH_PASSPHRASE
318 unset GITTEST_REMOTE_SSH_FINGERPRINT
319 fi
320
321 if [ -z "$SKIP_FUZZERS" ]; then
322 echo ""
323 echo "##############################################################################"
324 echo "## Running fuzzers"
325 echo "##############################################################################"
326
327 ctest -V -R 'fuzzer'
328 fi
329
330 cleanup
331
332 if [ "$SUCCESS" -ne 1 ]; then
333 echo "Some tests failed."
334 exit 1
335 fi
336
337 echo "Success."
338 exit 0