]>
Commit | Line | Data |
---|---|---|
6c7cee42 RD |
1 | #!/usr/bin/env bash |
2 | ||
3 | set -e | |
4 | ||
5 | if [ -n "$SKIP_TESTS" ]; then | |
6 | exit 0 | |
7 | fi | |
8 | ||
22a2d3d5 UG |
9 | # Windows doesn't run the NTLM tests properly (yet) |
10 | if [[ "$(uname -s)" == MINGW* ]]; then | |
11 | SKIP_NTLM_TESTS=1 | |
12 | fi | |
13 | ||
6c7cee42 RD |
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 | |
c25aa7cd | 20 | CONTINUE_ON_FAILURE=0 |
6c7cee42 | 21 | |
6c7cee42 RD |
22 | cleanup() { |
23 | echo "Cleaning up..." | |
24 | ||
22a2d3d5 | 25 | if [ ! -z "$GITDAEMON_PID" ]; then |
6c7cee42 | 26 | echo "Stopping git daemon..." |
22a2d3d5 | 27 | kill $GITDAEMON_PID |
6c7cee42 RD |
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 | ||
6c7cee42 | 38 | run_test() { |
22a2d3d5 UG |
39 | if [[ "$GITTEST_FLAKY_RETRY" > 0 ]]; then |
40 | ATTEMPTS_REMAIN=$GITTEST_FLAKY_RETRY | |
41 | else | |
42 | ATTEMPTS_REMAIN=1 | |
ac3d33df JK |
43 | fi |
44 | ||
22a2d3d5 UG |
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 | |
6c7cee42 | 52 | |
22a2d3d5 UG |
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 | |
6c7cee42 | 66 | |
22a2d3d5 | 67 | if [ "$FAILED" -ne 0 ]; then |
c25aa7cd PP |
68 | if [ "$CONTINUE_ON_FAILURE" -ne 1 ]; then |
69 | exit 1 | |
70 | fi | |
71 | ||
22a2d3d5 UG |
72 | SUCCESS=0 |
73 | fi | |
6c7cee42 RD |
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` | |
e579e0f7 | 86 | git init --bare "${GITDAEMON_DIR}/test.git" >/dev/null |
22a2d3d5 UG |
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 | |
6c7cee42 RD |
90 | fi |
91 | ||
92 | if [ -z "$SKIP_PROXY_TESTS" ]; then | |
22a2d3d5 UG |
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 | ||
e579e0f7 MB |
104 | if [ -z "$SKIP_NTLM_TESTS" -o -z "$SKIP_ONLINE_TESTS" ]; then |
105 | curl --location --silent --show-error https://github.com/ethomson/poxygit/releases/download/v0.5.1/poxygit-0.5.1.jar >poxygit.jar | |
22a2d3d5 UG |
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}" & | |
6c7cee42 RD |
112 | fi |
113 | ||
114 | if [ -z "$SKIP_SSH_TESTS" ]; then | |
e579e0f7 | 115 | echo "" |
6c7cee42 RD |
116 | echo "Starting ssh daemon..." |
117 | HOME=`mktemp -d ${TMPDIR}/home.XXXXXXXX` | |
118 | SSHD_DIR=`mktemp -d ${TMPDIR}/sshd.XXXXXXXX` | |
e579e0f7 | 119 | git init --bare "${SSHD_DIR}/test.git" >/dev/null |
6c7cee42 RD |
120 | cat >"${SSHD_DIR}/sshd_config" <<-EOF |
121 | Port 2222 | |
122 | ListenAddress 0.0.0.0 | |
123 | Protocol 2 | |
124 | HostKey ${SSHD_DIR}/id_rsa | |
125 | PidFile ${SSHD_DIR}/pid | |
126 | AuthorizedKeysFile ${HOME}/.ssh/authorized_keys | |
127 | LogLevel DEBUG | |
128 | RSAAuthentication yes | |
129 | PasswordAuthentication yes | |
130 | PubkeyAuthentication yes | |
131 | ChallengeResponseAuthentication no | |
132 | StrictModes no | |
133 | # Required here as sshd will simply close connection otherwise | |
134 | UsePAM no | |
135 | EOF | |
136 | ssh-keygen -t rsa -f "${SSHD_DIR}/id_rsa" -N "" -q | |
137 | /usr/sbin/sshd -f "${SSHD_DIR}/sshd_config" -E "${SSHD_DIR}/log" | |
138 | ||
139 | # Set up keys | |
140 | mkdir "${HOME}/.ssh" | |
141 | ssh-keygen -t rsa -f "${HOME}/.ssh/id_rsa" -N "" -q | |
142 | cat "${HOME}/.ssh/id_rsa.pub" >>"${HOME}/.ssh/authorized_keys" | |
143 | while read algorithm key comment; do | |
144 | echo "[localhost]:2222 $algorithm $key" >>"${HOME}/.ssh/known_hosts" | |
145 | done <"${SSHD_DIR}/id_rsa.pub" | |
146 | ||
147 | # Get the fingerprint for localhost and remove the colons so we can | |
148 | # parse it as a hex number. Older versions have a different output | |
149 | # format. | |
150 | if [[ $(ssh -V 2>&1) == OpenSSH_6* ]]; then | |
151 | SSH_FINGERPRINT=$(ssh-keygen -F '[localhost]:2222' -f "${HOME}/.ssh/known_hosts" -l | tail -n 1 | cut -d ' ' -f 2 | tr -d ':') | |
152 | else | |
153 | 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 :) | |
154 | fi | |
155 | fi | |
156 | ||
157 | # Run the tests that do not require network connectivity. | |
158 | ||
159 | if [ -z "$SKIP_OFFLINE_TESTS" ]; then | |
160 | echo "" | |
161 | echo "##############################################################################" | |
ad5611d8 | 162 | echo "## Running core tests" |
6c7cee42 RD |
163 | echo "##############################################################################" |
164 | ||
ad5611d8 TR |
165 | echo "" |
166 | echo "Running libgit2 integration (offline) tests" | |
167 | echo "" | |
6c7cee42 | 168 | run_test offline |
ad5611d8 TR |
169 | |
170 | echo "" | |
171 | echo "Running utility tests" | |
172 | echo "" | |
173 | run_test util | |
6c7cee42 RD |
174 | fi |
175 | ||
ac3d33df JK |
176 | if [ -n "$RUN_INVASIVE_TESTS" ]; then |
177 | echo "" | |
178 | echo "Running invasive tests" | |
179 | echo "" | |
180 | ||
181 | export GITTEST_INVASIVE_FS_SIZE=1 | |
182 | export GITTEST_INVASIVE_MEMORY=1 | |
183 | export GITTEST_INVASIVE_SPEED=1 | |
184 | run_test invasive | |
185 | unset GITTEST_INVASIVE_FS_SIZE | |
186 | unset GITTEST_INVASIVE_MEMORY | |
187 | unset GITTEST_INVASIVE_SPEED | |
188 | fi | |
189 | ||
6c7cee42 | 190 | if [ -z "$SKIP_ONLINE_TESTS" ]; then |
c25aa7cd PP |
191 | # Run the online tests. The "online" test suite only includes the |
192 | # default online tests that do not require additional configuration. | |
193 | # The "proxy" and "ssh" test suites require further setup. | |
6c7cee42 RD |
194 | |
195 | echo "" | |
196 | echo "##############################################################################" | |
ad5611d8 | 197 | echo "## Running networking (online) tests" |
6c7cee42 RD |
198 | echo "##############################################################################" |
199 | ||
e579e0f7 MB |
200 | export GITTEST_REMOTE_REDIRECT_INITIAL="http://localhost:9000/initial-redirect/libgit2/TestGitRepository" |
201 | export GITTEST_REMOTE_REDIRECT_SUBSEQUENT="http://localhost:9000/subsequent-redirect/libgit2/TestGitRepository" | |
6c7cee42 | 202 | run_test online |
e579e0f7 MB |
203 | unset GITTEST_REMOTE_REDIRECT_INITIAL |
204 | unset GITTEST_REMOTE_REDIRECT_SUBSEQUENT | |
c25aa7cd PP |
205 | |
206 | # Run the online tests that immutably change global state separately | |
207 | # to avoid polluting the test environment. | |
208 | echo "" | |
ad5611d8 TR |
209 | echo "Running custom certificate (online_customcert) tests" |
210 | echo "" | |
211 | ||
c25aa7cd | 212 | run_test online_customcert |
6c7cee42 RD |
213 | fi |
214 | ||
215 | if [ -z "$SKIP_GITDAEMON_TESTS" ]; then | |
216 | echo "" | |
217 | echo "Running gitdaemon tests" | |
218 | echo "" | |
219 | ||
220 | export GITTEST_REMOTE_URL="git://localhost/test.git" | |
221 | run_test gitdaemon | |
222 | unset GITTEST_REMOTE_URL | |
223 | fi | |
224 | ||
225 | if [ -z "$SKIP_PROXY_TESTS" ]; then | |
226 | echo "" | |
22a2d3d5 | 227 | echo "Running proxy tests (Basic authentication)" |
6c7cee42 RD |
228 | echo "" |
229 | ||
ac3d33df | 230 | export GITTEST_REMOTE_PROXY_HOST="localhost:8080" |
6c7cee42 RD |
231 | export GITTEST_REMOTE_PROXY_USER="foo" |
232 | export GITTEST_REMOTE_PROXY_PASS="bar" | |
233 | run_test proxy | |
ac3d33df | 234 | unset GITTEST_REMOTE_PROXY_HOST |
6c7cee42 RD |
235 | unset GITTEST_REMOTE_PROXY_USER |
236 | unset GITTEST_REMOTE_PROXY_PASS | |
22a2d3d5 UG |
237 | |
238 | echo "" | |
239 | echo "Running proxy tests (NTLM authentication)" | |
240 | echo "" | |
241 | ||
242 | export GITTEST_REMOTE_PROXY_HOST="localhost:8090" | |
243 | export GITTEST_REMOTE_PROXY_USER="foo" | |
244 | export GITTEST_REMOTE_PROXY_PASS="bar" | |
22a2d3d5 | 245 | run_test proxy |
22a2d3d5 UG |
246 | unset GITTEST_REMOTE_PROXY_HOST |
247 | unset GITTEST_REMOTE_PROXY_USER | |
248 | unset GITTEST_REMOTE_PROXY_PASS | |
249 | fi | |
250 | ||
251 | if [ -z "$SKIP_NTLM_TESTS" ]; then | |
252 | echo "" | |
253 | echo "Running NTLM tests (IIS emulation)" | |
254 | echo "" | |
255 | ||
256 | export GITTEST_REMOTE_URL="http://localhost:9000/ntlm/test.git" | |
257 | export GITTEST_REMOTE_USER="foo" | |
258 | export GITTEST_REMOTE_PASS="baz" | |
259 | run_test auth_clone_and_push | |
260 | unset GITTEST_REMOTE_URL | |
261 | unset GITTEST_REMOTE_USER | |
262 | unset GITTEST_REMOTE_PASS | |
263 | ||
264 | echo "" | |
265 | echo "Running NTLM tests (Apache emulation)" | |
266 | echo "" | |
267 | ||
268 | export GITTEST_REMOTE_URL="http://localhost:9000/broken-ntlm/test.git" | |
269 | export GITTEST_REMOTE_USER="foo" | |
270 | export GITTEST_REMOTE_PASS="baz" | |
271 | run_test auth_clone_and_push | |
272 | unset GITTEST_REMOTE_URL | |
273 | unset GITTEST_REMOTE_USER | |
274 | unset GITTEST_REMOTE_PASS | |
275 | fi | |
276 | ||
277 | if [ -z "$SKIP_NEGOTIATE_TESTS" -a -n "$GITTEST_NEGOTIATE_PASSWORD" ]; then | |
278 | echo "" | |
279 | echo "Running SPNEGO tests" | |
280 | echo "" | |
281 | ||
282 | if [ "$(uname -s)" = "Darwin" ]; then | |
283 | KINIT_FLAGS="--password-file=STDIN" | |
284 | fi | |
285 | ||
286 | echo $GITTEST_NEGOTIATE_PASSWORD | kinit $KINIT_FLAGS test@LIBGIT2.ORG | |
287 | klist -5f | |
288 | ||
289 | export GITTEST_REMOTE_URL="https://test.libgit2.org/kerberos/empty.git" | |
290 | export GITTEST_REMOTE_DEFAULT="true" | |
291 | run_test auth_clone | |
292 | unset GITTEST_REMOTE_URL | |
293 | unset GITTEST_REMOTE_DEFAULT | |
294 | ||
295 | echo "" | |
296 | echo "Running SPNEGO tests (expect/continue)" | |
297 | echo "" | |
298 | ||
299 | export GITTEST_REMOTE_URL="https://test.libgit2.org/kerberos/empty.git" | |
300 | export GITTEST_REMOTE_DEFAULT="true" | |
301 | export GITTEST_REMOTE_EXPECTCONTINUE="true" | |
302 | run_test auth_clone | |
303 | unset GITTEST_REMOTE_URL | |
304 | unset GITTEST_REMOTE_DEFAULT | |
305 | unset GITTEST_REMOTE_EXPECTCONTINUE | |
306 | ||
307 | kdestroy -A | |
6c7cee42 RD |
308 | fi |
309 | ||
310 | if [ -z "$SKIP_SSH_TESTS" ]; then | |
6c7cee42 RD |
311 | export GITTEST_REMOTE_USER=$USER |
312 | export GITTEST_REMOTE_SSH_KEY="${HOME}/.ssh/id_rsa" | |
313 | export GITTEST_REMOTE_SSH_PUBKEY="${HOME}/.ssh/id_rsa.pub" | |
314 | export GITTEST_REMOTE_SSH_PASSPHRASE="" | |
315 | export GITTEST_REMOTE_SSH_FINGERPRINT="${SSH_FINGERPRINT}" | |
e579e0f7 MB |
316 | |
317 | echo "" | |
318 | echo "Running ssh tests" | |
319 | echo "" | |
320 | ||
321 | export GITTEST_REMOTE_URL="ssh://localhost:2222/$SSHD_DIR/test.git" | |
322 | run_test ssh | |
323 | unset GITTEST_REMOTE_URL | |
324 | ||
325 | echo "" | |
326 | echo "Running ssh tests (scp-style paths)" | |
327 | echo "" | |
328 | ||
329 | export GITTEST_REMOTE_URL="[localhost:2222]:$SSHD_DIR/test.git" | |
6c7cee42 RD |
330 | run_test ssh |
331 | unset GITTEST_REMOTE_URL | |
e579e0f7 | 332 | |
6c7cee42 RD |
333 | unset GITTEST_REMOTE_USER |
334 | unset GITTEST_REMOTE_SSH_KEY | |
335 | unset GITTEST_REMOTE_SSH_PUBKEY | |
336 | unset GITTEST_REMOTE_SSH_PASSPHRASE | |
337 | unset GITTEST_REMOTE_SSH_FINGERPRINT | |
338 | fi | |
339 | ||
ac3d33df JK |
340 | if [ -z "$SKIP_FUZZERS" ]; then |
341 | echo "" | |
342 | echo "##############################################################################" | |
343 | echo "## Running fuzzers" | |
344 | echo "##############################################################################" | |
345 | ||
22a2d3d5 | 346 | ctest -V -R 'fuzzer' |
ac3d33df JK |
347 | fi |
348 | ||
6c7cee42 RD |
349 | cleanup |
350 | ||
22a2d3d5 | 351 | if [ "$SUCCESS" -ne 1 ]; then |
6c7cee42 RD |
352 | echo "Some tests failed." |
353 | exit 1 | |
354 | fi | |
355 | ||
356 | echo "Success." | |
357 | exit 0 |