test.sh 10.6 KB
Newer Older
1
#!/usr/bin/env bash
2 3 4 5

set -e

if [ -n "$SKIP_TESTS" ]; then
6
	exit 0
7 8
fi

Edward Thomson committed
9 10 11 12 13
# Windows doesn't run the NTLM tests properly (yet)
if [[ "$(uname -s)" == MINGW* ]]; then
        SKIP_NTLM_TESTS=1
fi

14 15 16 17 18
SOURCE_DIR=${SOURCE_DIR:-$( cd "$( dirname "${BASH_SOURCE[0]}" )" && dirname $( pwd ) )}
BUILD_DIR=$(pwd)
TMPDIR=${TMPDIR:-/tmp}
USER=${USER:-$(whoami)}

19
SUCCESS=1
20
CONTINUE_ON_FAILURE=0
21

22 23 24
cleanup() {
	echo "Cleaning up..."

25 26 27 28 29 30 31 32
	if [ ! -z "$GIT_STANDARD_PID" ]; then
		echo "Stopping git daemon (standard)..."
		kill $GIT_STANDARD_PID
	fi

	if [ ! -z "$GIT_NAMESPACE_PID" ]; then
		echo "Stopping git daemon (namespace)..."
		kill $GIT_NAMESPACE_PID
33 34
	fi

35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
	if [ ! -z "$PROXY_BASIC_PID" ]; then
		echo "Stopping proxy (Basic)..."
		kill $PROXY_BASIC_PID
	fi

	if [ ! -z "$PROXY_NTLM_PID" ]; then
		echo "Stopping proxy (NTLM)..."
		kill $PROXY_NTLM_PID
	fi

	if [ ! -z "$HTTP_PID" ]; then
		echo "Stopping HTTP server..."
		kill $HTTP_PID
	fi

50
	if [ ! -z "$SSHD_DIR" -a -f "${SSHD_DIR}/pid" ]; then
51
		echo "Stopping SSH server..."
52 53
		kill $(cat "${SSHD_DIR}/pid")
	fi
54 55

	echo "Done."
56 57
}

58
run_test() {
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
	if [[ "$GITTEST_FLAKY_RETRY" > 0 ]]; then
		ATTEMPTS_REMAIN=$GITTEST_FLAKY_RETRY
	else
		ATTEMPTS_REMAIN=1
	fi

	FAILED=0
	while [[ "$ATTEMPTS_REMAIN" > 0 ]]; do
		if [ "$FAILED" -eq 1 ]; then
			echo ""
			echo "Re-running flaky ${1} tests..."
			echo ""
		fi

		RETURN_CODE=0
74 75

		CLAR_SUMMARY="${BUILD_DIR}/results_${1}.xml" ctest -V -R "^${1}$" || RETURN_CODE=$? && true
76 77

		if [ "$RETURN_CODE" -eq 0 ]; then
78
			FAILED=0
79 80 81 82 83 84 85 86 87
			break
		fi

		echo "Test exited with code: $RETURN_CODE"
		ATTEMPTS_REMAIN="$(($ATTEMPTS_REMAIN-1))"
		FAILED=1
	done

	if [ "$FAILED" -ne 0 ]; then
88 89 90 91
		if [ "$CONTINUE_ON_FAILURE" -ne 1 ]; then
			exit 1
		fi

92 93
		SUCCESS=0
	fi
94
}
95

96 97 98
# Configure the test environment; run them early so that we're certain
# that they're started by the time we need them.

99
echo "##############################################################################"
100
echo "## Configuring test environment"
101 102
echo "##############################################################################"

103 104
echo ""

105
if [ -z "$SKIP_GITDAEMON_TESTS" ]; then
106 107 108 109 110 111 112 113 114 115 116
	echo "Starting git daemon (standard)..."
	GIT_STANDARD_DIR=`mktemp -d ${TMPDIR}/git_standard.XXXXXXXX`
	git init --bare "${GIT_STANDARD_DIR}/test.git" >/dev/null
	git daemon --listen=localhost --export-all --enable=receive-pack --base-path="${GIT_STANDARD_DIR}" "${GIT_STANDARD_DIR}" 2>/dev/null &
	GIT_STANDARD_PID=$!

	echo "Starting git daemon (namespace)..."
	GIT_NAMESPACE_DIR=`mktemp -d ${TMPDIR}/git_namespace.XXXXXXXX`
	cp -R "${SOURCE_DIR}/tests/resources/namespace.git" "${GIT_NAMESPACE_DIR}/namespace.git"
	GIT_NAMESPACE="name1" git daemon --listen=localhost --port=9419 --export-all --enable=receive-pack --base-path="${GIT_NAMESPACE_DIR}" "${GIT_NAMESPACE_DIR}" &
	GIT_NAMESPACE_PID=$!
117 118 119
fi

if [ -z "$SKIP_PROXY_TESTS" ]; then
120
	curl --location --silent --show-error https://github.com/ethomson/poxyproxy/releases/download/v0.7.0/poxyproxy-0.7.0.jar >poxyproxy.jar
121 122 123

	echo "Starting HTTP proxy (Basic)..."
	java -jar poxyproxy.jar --address 127.0.0.1 --port 8080 --credentials foo:bar --auth-type basic --quiet &
124
	PROXY_BASIC_PID=$!
125 126 127

	echo "Starting HTTP proxy (NTLM)..."
	java -jar poxyproxy.jar --address 127.0.0.1 --port 8090 --credentials foo:bar --auth-type ntlm --quiet &
128
	PROXY_NTLM_PID=$!
129 130
fi

131
if [ -z "$SKIP_NTLM_TESTS" -o -z "$SKIP_ONLINE_TESTS" ]; then
132
	curl --location --silent --show-error https://github.com/ethomson/poxygit/releases/download/v0.5.1/poxygit-0.5.1.jar >poxygit.jar
Edward Thomson committed
133 134

	echo "Starting HTTP server..."
135 136 137 138
	HTTP_DIR=`mktemp -d ${TMPDIR}/http.XXXXXXXX`
	git init --bare "${HTTP_DIR}/test.git"
	java -jar poxygit.jar --address 127.0.0.1 --port 9000 --credentials foo:baz --quiet "${HTTP_DIR}" &
	HTTP_PID=$!
Edward Thomson committed
139 140
fi

141
if [ -z "$SKIP_SSH_TESTS" ]; then
142
	echo "Starting SSH server..."
143 144
	HOME=`mktemp -d ${TMPDIR}/home.XXXXXXXX`
	SSHD_DIR=`mktemp -d ${TMPDIR}/sshd.XXXXXXXX`
145
	git init --bare "${SSHD_DIR}/test.git" >/dev/null
146
	cat >"${SSHD_DIR}/sshd_config" <<-EOF
147 148 149 150 151
	Port 2222
	ListenAddress 0.0.0.0
	Protocol 2
	HostKey ${SSHD_DIR}/id_rsa
	PidFile ${SSHD_DIR}/pid
152 153
	AuthorizedKeysFile ${HOME}/.ssh/authorized_keys
	LogLevel DEBUG
154 155 156 157
	RSAAuthentication yes
	PasswordAuthentication yes
	PubkeyAuthentication yes
	ChallengeResponseAuthentication no
158
	StrictModes no
159 160
	# Required here as sshd will simply close connection otherwise
	UsePAM no
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
	EOF
	ssh-keygen -t rsa -f "${SSHD_DIR}/id_rsa" -N "" -q
	/usr/sbin/sshd -f "${SSHD_DIR}/sshd_config" -E "${SSHD_DIR}/log"

	# Set up keys
	mkdir "${HOME}/.ssh"
	ssh-keygen -t rsa -f "${HOME}/.ssh/id_rsa" -N "" -q
	cat "${HOME}/.ssh/id_rsa.pub" >>"${HOME}/.ssh/authorized_keys"
	while read algorithm key comment; do
		echo "[localhost]:2222 $algorithm $key" >>"${HOME}/.ssh/known_hosts"
	done <"${SSHD_DIR}/id_rsa.pub"

	# Get the fingerprint for localhost and remove the colons so we can
	# parse it as a hex number. Older versions have a different output
	# format.
	if [[ $(ssh -V 2>&1) == OpenSSH_6* ]]; then
		SSH_FINGERPRINT=$(ssh-keygen -F '[localhost]:2222' -f "${HOME}/.ssh/known_hosts" -l | tail -n 1 | cut -d ' ' -f 2 | tr -d ':')
	else
		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 :)
	fi
181 182 183 184
fi

# Run the tests that do not require network connectivity.

185 186 187
if [ -z "$SKIP_OFFLINE_TESTS" ]; then
	echo ""
	echo "##############################################################################"
188
	echo "## Running core tests"
189
	echo "##############################################################################"
190

191 192 193
	echo ""
	echo "Running libgit2 integration (offline) tests"
	echo ""
194
	run_test offline
195 196 197 198 199

	echo ""
	echo "Running utility tests"
	echo ""
	run_test util
200
fi
201

202
if [ -n "$RUN_INVASIVE_TESTS" ]; then
203 204 205 206 207 208 209 210 211 212 213 214 215
	echo ""
	echo "Running invasive tests"
	echo ""

	export GITTEST_INVASIVE_FS_SIZE=1
	export GITTEST_INVASIVE_MEMORY=1
	export GITTEST_INVASIVE_SPEED=1
	run_test invasive
	unset GITTEST_INVASIVE_FS_SIZE
	unset GITTEST_INVASIVE_MEMORY
	unset GITTEST_INVASIVE_SPEED
fi

216
if [ -z "$SKIP_ONLINE_TESTS" ]; then
217 218 219
	# Run the online tests.  The "online" test suite only includes the
	# default online tests that do not require additional configuration.
	# The "proxy" and "ssh" test suites require further setup.
220

221 222
	echo ""
	echo "##############################################################################"
223
	echo "## Running networking (online) tests"
224
	echo "##############################################################################"
225

226 227
	export GITTEST_REMOTE_REDIRECT_INITIAL="http://localhost:9000/initial-redirect/libgit2/TestGitRepository"
	export GITTEST_REMOTE_REDIRECT_SUBSEQUENT="http://localhost:9000/subsequent-redirect/libgit2/TestGitRepository"
228
	run_test online
229 230
	unset GITTEST_REMOTE_REDIRECT_INITIAL
	unset GITTEST_REMOTE_REDIRECT_SUBSEQUENT
231 232 233 234

	# Run the online tests that immutably change global state separately
	# to avoid polluting the test environment.
	echo ""
235 236 237
	echo "Running custom certificate (online_customcert) tests"
	echo ""

238
	run_test online_customcert
239
fi
240

241 242
if [ -z "$SKIP_GITDAEMON_TESTS" ]; then
	echo ""
243
	echo "Running gitdaemon (standard) tests"
244
	echo ""
245

246
	export GITTEST_REMOTE_URL="git://localhost/test.git"
247
	run_test gitdaemon
248
	unset GITTEST_REMOTE_URL
249 250 251 252 253 254

	echo ""
	echo "Running gitdaemon (namespace) tests"
	echo ""

	export GITTEST_REMOTE_URL="git://localhost:9419/namespace.git"
255
	export GITTEST_REMOTE_BRANCH="four"
256 257
	run_test gitdaemon_namespace
	unset GITTEST_REMOTE_URL
258
	unset GITTEST_REMOTE_BRANCH
259
fi
260

261 262
if [ -z "$SKIP_PROXY_TESTS" ]; then
	echo ""
263
	echo "Running proxy tests (Basic authentication)"
264 265
	echo ""

266
	export GITTEST_REMOTE_PROXY_HOST="localhost:8080"
267 268
	export GITTEST_REMOTE_PROXY_USER="foo"
	export GITTEST_REMOTE_PROXY_PASS="bar"
269
	run_test proxy
270
	unset GITTEST_REMOTE_PROXY_HOST
271 272
	unset GITTEST_REMOTE_PROXY_USER
	unset GITTEST_REMOTE_PROXY_PASS
273 274 275 276 277 278 279 280 281 282 283 284

	echo ""
	echo "Running proxy tests (NTLM authentication)"
	echo ""

	export GITTEST_REMOTE_PROXY_HOST="localhost:8090"
	export GITTEST_REMOTE_PROXY_USER="foo"
	export GITTEST_REMOTE_PROXY_PASS="bar"
	run_test proxy
	unset GITTEST_REMOTE_PROXY_HOST
	unset GITTEST_REMOTE_PROXY_USER
	unset GITTEST_REMOTE_PROXY_PASS
285
fi
286

Edward Thomson committed
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
if [ -z "$SKIP_NTLM_TESTS" ]; then
	echo ""
	echo "Running NTLM tests (IIS emulation)"
	echo ""

	export GITTEST_REMOTE_URL="http://localhost:9000/ntlm/test.git"
	export GITTEST_REMOTE_USER="foo"
	export GITTEST_REMOTE_PASS="baz"
	run_test auth_clone_and_push
	unset GITTEST_REMOTE_URL
	unset GITTEST_REMOTE_USER
	unset GITTEST_REMOTE_PASS

	echo ""
	echo "Running NTLM tests (Apache emulation)"
	echo ""

	export GITTEST_REMOTE_URL="http://localhost:9000/broken-ntlm/test.git"
	export GITTEST_REMOTE_USER="foo"
	export GITTEST_REMOTE_PASS="baz"
	run_test auth_clone_and_push
	unset GITTEST_REMOTE_URL
	unset GITTEST_REMOTE_USER
	unset GITTEST_REMOTE_PASS
fi

313 314 315 316 317 318 319 320 321 322 323 324 325 326
if [ -z "$SKIP_NEGOTIATE_TESTS" -a -n "$GITTEST_NEGOTIATE_PASSWORD" ]; then
	echo ""
	echo "Running SPNEGO tests"
	echo ""

	if [ "$(uname -s)" = "Darwin" ]; then
		KINIT_FLAGS="--password-file=STDIN"
	fi

	echo $GITTEST_NEGOTIATE_PASSWORD | kinit $KINIT_FLAGS test@LIBGIT2.ORG
	klist -5f

	export GITTEST_REMOTE_URL="https://test.libgit2.org/kerberos/empty.git"
	export GITTEST_REMOTE_DEFAULT="true"
Edward Thomson committed
327
	run_test auth_clone
328 329 330
	unset GITTEST_REMOTE_URL
	unset GITTEST_REMOTE_DEFAULT

331 332 333 334 335 336 337
	echo ""
	echo "Running SPNEGO tests (expect/continue)"
	echo ""

	export GITTEST_REMOTE_URL="https://test.libgit2.org/kerberos/empty.git"
	export GITTEST_REMOTE_DEFAULT="true"
	export GITTEST_REMOTE_EXPECTCONTINUE="true"
Edward Thomson committed
338
	run_test auth_clone
339 340 341 342
	unset GITTEST_REMOTE_URL
	unset GITTEST_REMOTE_DEFAULT
	unset GITTEST_REMOTE_EXPECTCONTINUE

343 344 345
	kdestroy -A
fi

346 347 348 349 350 351
if [ -z "$SKIP_SSH_TESTS" ]; then
	export GITTEST_REMOTE_USER=$USER
	export GITTEST_REMOTE_SSH_KEY="${HOME}/.ssh/id_rsa"
	export GITTEST_REMOTE_SSH_PUBKEY="${HOME}/.ssh/id_rsa.pub"
	export GITTEST_REMOTE_SSH_PASSPHRASE=""
	export GITTEST_REMOTE_SSH_FINGERPRINT="${SSH_FINGERPRINT}"
352 353 354 355 356 357

	echo ""
	echo "Running ssh tests"
	echo ""

	export GITTEST_REMOTE_URL="ssh://localhost:2222/$SSHD_DIR/test.git"
358
	run_test ssh
359
	unset GITTEST_REMOTE_URL
360 361 362 363 364 365 366 367 368

	echo ""
	echo "Running ssh tests (scp-style paths)"
	echo ""

	export GITTEST_REMOTE_URL="[localhost:2222]:$SSHD_DIR/test.git"
	run_test ssh
	unset GITTEST_REMOTE_URL

369 370 371 372 373 374
	unset GITTEST_REMOTE_USER
	unset GITTEST_REMOTE_SSH_KEY
	unset GITTEST_REMOTE_SSH_PUBKEY
	unset GITTEST_REMOTE_SSH_PASSPHRASE
	unset GITTEST_REMOTE_SSH_FINGERPRINT
fi
375

376 377 378 379 380 381
if [ -z "$SKIP_FUZZERS" ]; then
	echo ""
	echo "##############################################################################"
	echo "## Running fuzzers"
	echo "##############################################################################"

382
	ctest -V -R 'fuzzer'
383 384
fi

385
cleanup
386

387
if [ "$SUCCESS" -ne 1 ]; then
388 389 390 391 392
	echo "Some tests failed."
	exit 1
fi

echo "Success."
393
exit 0