Commit 451b0017 by Edward Thomson

ci: improved flexibility for citest.sh

Refactor citest.sh to enable local testing by developers.
parent bf418f09
#!/bin/sh #!/usr/bin/env bash
set -e set -e
if [ -n "$SKIP_TESTS" ]; then if [ -n "$SKIP_TESTS" ]; then
exit $? exit 0
fi fi
cleanup() {
echo "Cleaning up..."
if [ ! -z "$GITDAEMON_DIR" -a -f "${GITDAEMON_DIR}/pid" ]; then
kill $(cat "${GITDAEMON_DIR}/pid")
fi
if [ ! -z "$SSHD_DIR" -a -f "${SSHD_DIR}/pid" ]; then
kill $(cat "${SSHD_DIR}/pid")
fi
}
die() {
cleanup
exit $1
}
TMPDIR=${TMPDIR:-/tmp}
USER=${USER:-$(whoami)}
# Configure the test environment; run them early so that we're certain # Configure the test environment; run them early so that we're certain
# that they're started by the time we need them. # that they're started by the time we need them.
echo "################################################################################" echo "##############################################################################"
echo "## Configuring test environment" echo "## Configuring test environment"
echo "################################################################################" echo "##############################################################################"
echo "Starting HTTP proxy..." if [ -z "$SKIP_GITDAEMON_TESTS" ]; then
curl -L https://github.com/ethomson/poxyproxy/releases/download/v0.1.0/poxyproxy-0.1.0.jar >poxyproxy.jar echo "Starting git daemon..."
java -jar poxyproxy.jar -d --port 8080 --credentials foo:bar >/dev/null 2>&1 & GITDAEMON_DIR=`mktemp -d ${TMPDIR}/gitdaemon.XXXXXXXX`
git init --bare "${GITDAEMON_DIR}/test.git"
echo "Starting git daemon..." git daemon --listen=localhost --export-all --enable=receive-pack --pid-file="${GITDAEMON_DIR}/pid" --base-path="${GITDAEMON_DIR}" "${GITDAEMON_DIR}" 2>/dev/null &
GITDAEMON_DIR=`mktemp -d ${TMPDIR}/gitdaemon.XXXXXXXX` fi
git init --bare "${GITDAEMON_DIR}/test.git"
git daemon --listen=localhost --export-all --enable=receive-pack --base-path="${GITDAEMON_DIR}" "${GITDAEMON_DIR}" 2>/dev/null & if [ -z "$SKIP_PROXY_TESTS" ]; then
echo "Starting HTTP proxy..."
echo "Starting ssh daemon..." curl -L https://github.com/ethomson/poxyproxy/releases/download/v0.1.0/poxyproxy-0.1.0.jar >poxyproxy.jar
HOME=`mktemp -d ${TMPDIR}/home.XXXXXXXX` java -jar poxyproxy.jar -d --port 8080 --credentials foo:bar >/dev/null 2>&1 &
SSH_DIR="${HOME}/.ssh" fi
SSHD_DIR=`mktemp -d ${TMPDIR}/sshd.XXXXXXXX`
mkdir ${SSH_DIR} if [ -z "$SKIP_SSH_TESTS" ]; then
cat >"${SSHD_DIR}/sshd_config" <<-EOF echo "Starting ssh daemon..."
HOME=`mktemp -d ${TMPDIR}/home.XXXXXXXX`
SSHD_DIR=`mktemp -d ${TMPDIR}/sshd.XXXXXXXX`
git init --bare "${SSHD_DIR}/test.git"
cat >"${SSHD_DIR}/sshd_config" <<-EOF
Port 2222 Port 2222
ListenAddress 0.0.0.0 ListenAddress 0.0.0.0
Protocol 2 Protocol 2
HostKey ${SSHD_DIR}/id_rsa HostKey ${SSHD_DIR}/id_rsa
PidFile ${SSHD_DIR}/pid PidFile ${SSHD_DIR}/pid
AuthorizedKeysFile ${HOME}/.ssh/authorized_keys
LogLevel DEBUG
RSAAuthentication yes RSAAuthentication yes
PasswordAuthentication yes PasswordAuthentication yes
PubkeyAuthentication yes PubkeyAuthentication yes
ChallengeResponseAuthentication no ChallengeResponseAuthentication no
StrictModes no
# Required here as sshd will simply close connection otherwise # Required here as sshd will simply close connection otherwise
UsePAM no UsePAM no
EOF EOF
ssh-keygen -t rsa -f "${SSHD_DIR}/id_rsa" -N "" -q ssh-keygen -t rsa -f "${SSHD_DIR}/id_rsa" -N "" -q
/usr/sbin/sshd -f "${SSHD_DIR}/sshd_config" /usr/sbin/sshd -f "${SSHD_DIR}/sshd_config" -E "${SSHD_DIR}/log"
# Set up keys # Set up keys
ssh-keygen -t rsa -f "${SSH_DIR}/id_rsa" -N "" -q mkdir "${HOME}/.ssh"
cat "${SSH_DIR}/id_rsa.pub" >>"${SSH_DIR}/authorized_keys" ssh-keygen -t rsa -f "${HOME}/.ssh/id_rsa" -N "" -q
while read algorithm key comment; do cat "${HOME}/.ssh/id_rsa.pub" >>"${HOME}/.ssh/authorized_keys"
echo "[localhost]:2222 $algorithm $key" >>"${SSH_DIR}/known_hosts" while read algorithm key comment; do
done <"${SSHD_DIR}/id_rsa.pub" 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. The Mac version is newer so it has a different output format. # Get the fingerprint for localhost and remove the colons so we can
if [ "$TRAVIS_OS_NAME" = "osx" ]; then # parse it as a hex number. Older versions have a different output
export GITTEST_REMOTE_SSH_FINGERPRINT=$(ssh-keygen -E md5 -F '[localhost]:2222' -l | tail -n 1 | cut -d ' ' -f 3 | cut -d : -f2- | tr -d :) # format.
else if [[ $(ssh -V 2>&1) == OpenSSH_6* ]]; then
export GITTEST_REMOTE_SSH_FINGERPRINT=$(ssh-keygen -F '[localhost]:2222' -l | tail -n 1 | cut -d ' ' -f 2 | tr -d ':') 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
fi fi
# Run the tests that do not require network connectivity. # Run the tests that do not require network connectivity.
echo "" if [ -z "$SKIP_OFFLINE_TESTS" ]; then
echo "################################################################################" echo ""
echo "## Running (non-online) tests ##" echo "##############################################################################"
echo "################################################################################" echo "## Running (offline) tests"
echo "##############################################################################"
#ctest -V -R offline ctest -V -R offline || die $?
fi
# Run the various online tests. The "online" test suite only includes the if [ -z "$SKIP_ONLINE_TESTS" ]; then
# default online tests that do not require additional configuration. The # Run the various online tests. The "online" test suite only includes the
# "proxy" and "ssh" test suites require further setup. # default online tests that do not require additional configuration. The
# "proxy" and "ssh" test suites require further setup.
echo "" echo ""
echo "################################################################################" echo "##############################################################################"
echo "## Running (online) tests ##" echo "## Running (online) tests"
echo "################################################################################" echo "##############################################################################"
#ctest -V -R online ctest -V -R online || die $?
fi
echo "" if [ -z "$SKIP_GITDAEMON_TESTS" ]; then
echo "Running proxy tests" echo ""
echo "" echo "Running gitdaemon tests"
echo ""
export GITTEST_REMOTE_PROXY_URL="localhost:8080" export GITTEST_REMOTE_URL="git://localhost/test.git"
export GITTEST_REMOTE_PROXY_USER="foo" ctest -V -R gitdaemon || die $?
export GITTEST_REMOTE_PROXY_PASS="bar" unset GITTEST_REMOTE_URL
ctest -V -R proxy fi
echo "" if [ -z "$SKIP_PROXY_TESTS" ]; then
echo "Running ssh tests" echo ""
echo "" echo "Running proxy tests"
echo ""
export GITTEST_REMOTE_PROXY_URL="localhost:8080"
export GITTEST_REMOTE_PROXY_USER="foo"
export GITTEST_REMOTE_PROXY_PASS="bar"
ctest -V -R proxy || die $?
unset GITTEST_REMOTE_PROXY_URL
unset GITTEST_REMOTE_PROXY_USER
unset GITTEST_REMOTE_PROXY_PASS
fi
export GITTEST_REMOTE_URL="ssh://localhost:2222/$HOME/_temp/test.git" if [ -z "$SKIP_SSH_TESTS" ]; then
export GITTEST_REMOTE_USER=$USER echo ""
export GITTEST_REMOTE_SSH_KEY="${SSH_DIR}/id_rsa" echo "Running ssh tests"
export GITTEST_REMOTE_SSH_PUBKEY="${SSH_DIR}/id_rsa.pub" echo ""
export GITTEST_REMOTE_SSH_PASSPHRASE=""
ctest -V -R ssh export GITTEST_REMOTE_URL="ssh://localhost:2222/$SSHD_DIR/test.git"
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}"
ctest -V -R ssh || die $?
unset GITTEST_REMOTE_URL
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
kill $(cat "${SSHD_DIR}/pid") cleanup
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment