Skip to content

Commit 0661990

Browse files
committed
travis: cibuild: set up our own sshd server
Some tests of ours require to be running against an SSH server. Currently, we simply run against the SSH server provided and started by Travis itself. As our Linux tests run in a sudo-less environment, we have no control over its configuration and startup/shutdown procedure. While this has been no problem until now, it will become a problem as soon as we migrate over to newer Precise images, as the SSH server does not have any host keys set up. Luckily, we can simply set up our own unpriviledged SSH server. This has the benefit of us being able to modify its configuration even in a sudo-less environment. This commit sets up the unpriviledged SSH server on port 2222.
1 parent c2c95ad commit 0661990

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

script/cibuild.sh

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,39 @@ ctest -V -R libgit2_clar || exit $?
4343

4444
killall git-daemon
4545

46-
if [ "$TRAVIS_OS_NAME" = "osx" ]; then
47-
echo 'PasswordAuthentication yes' | sudo tee -a /etc/sshd_config
48-
fi
49-
46+
# Set up sshd
47+
mkdir ~/sshd/
48+
cat >~/sshd/sshd_config<<-EOF
49+
Port 2222
50+
ListenAddress 0.0.0.0
51+
Protocol 2
52+
HostKey ${HOME}/sshd/id_rsa
53+
RSAAuthentication yes
54+
PasswordAuthentication yes
55+
PubkeyAuthentication yes
56+
ChallengeResponseAuthentication no
57+
# Required here as sshd will simply close connection otherwise
58+
UsePAM no
59+
EOF
60+
ssh-keygen -t rsa -f ~/sshd/id_rsa -N "" -q
61+
/usr/sbin/sshd -f ~/sshd/sshd_config
62+
63+
# Set up keys
5064
ssh-keygen -t rsa -f ~/.ssh/id_rsa -N "" -q
5165
cat ~/.ssh/id_rsa.pub >>~/.ssh/authorized_keys
52-
ssh-keyscan -t rsa localhost >>~/.ssh/known_hosts
66+
while read algorithm key comment; do
67+
echo "[localhost]:2222 $algorithm $key" >>~/.ssh/known_hosts
68+
done <~/sshd/id_rsa.pub
5369

5470
# Get the fingerprint for localhost and remove the colons so we can parse it as
5571
# a hex number. The Mac version is newer so it has a different output format.
5672
if [ "$TRAVIS_OS_NAME" = "osx" ]; then
57-
export GITTEST_REMOTE_SSH_FINGERPRINT=$(ssh-keygen -E md5 -F localhost -l | tail -n 1 | cut -d ' ' -f 3 | cut -d : -f2- | tr -d :)
73+
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 :)
5874
else
59-
export GITTEST_REMOTE_SSH_FINGERPRINT=$(ssh-keygen -F localhost -l | tail -n 1 | cut -d ' ' -f 2 | tr -d ':')
75+
export GITTEST_REMOTE_SSH_FINGERPRINT=$(ssh-keygen -F '[localhost]:2222' -l | tail -n 1 | cut -d ' ' -f 2 | tr -d ':')
6076
fi
6177

62-
export GITTEST_REMOTE_URL="ssh://localhost/$HOME/_temp/test.git"
78+
export GITTEST_REMOTE_URL="ssh://localhost:2222/$HOME/_temp/test.git"
6379
export GITTEST_REMOTE_USER=$USER
6480
export GITTEST_REMOTE_SSH_KEY="$HOME/.ssh/id_rsa"
6581
export GITTEST_REMOTE_SSH_PUBKEY="$HOME/.ssh/id_rsa.pub"
@@ -83,6 +99,8 @@ if [ -e ./libgit2_clar ]; then
8399

84100
fi
85101

102+
killall sshd
103+
86104
export GITTEST_REMOTE_URL="https://github.com/libgit2/non-existent"
87105
export GITTEST_REMOTE_USER="libgit2test"
88106
ctest -V -R libgit2_clar-cred_callback

0 commit comments

Comments
 (0)