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