X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=tests%2Fbasic;h=5ba7a250b948affc504378ee09f2dce4ba79d76f;hb=80453e14e8c10071d9025c49b49e9feb3ed0f26c;hp=f6fa7fcbf1fed13bf33871594a2636da689b99d8;hpb=c5b6958858173044c74af2b0af6a8d46e5019221;p=monkeysphere.git diff --git a/tests/basic b/tests/basic index f6fa7fc..5ba7a25 100755 --- a/tests/basic +++ b/tests/basic @@ -13,15 +13,27 @@ # all subcommands in this script should complete without failure: set -e +# piped commands should return the code of the first non-zero return +set -o pipefail + +## make sure that the right tools are installed to run the test. the +## test has *more* requirements than plain ol' monkeysphere: +which socat || { echo "You must have socat installed to run this test." ; exit 1; } + +## FIXME: other checks? # gpg command for test admin user gpgadmin() { GNUPGHOME="$TEMPDIR"/admin/.gnupg gpg "$@" } +# test ssh connection +# first argument is expected return code from ssh connection ssh_test() { umask 0077 + CODE=${1:-0} + # start the ssh daemon on the socket echo "##### starting ssh server..." socat EXEC:"/usr/sbin/sshd -f ${SSHD_CONFIG} -i -D -e" "UNIX-LISTEN:${SOCKET}" 2> "$TEMPDIR"/sshd.log & @@ -32,16 +44,28 @@ ssh_test() { sleep 1 done + set +e + # make a client connection to the socket echo "##### starting ssh client..." ssh-agent bash -c \ "monkeysphere subkey-to-ssh-agent && ssh -F $TEMPDIR/testuser/.ssh/config testhost true" RETURN="$?" - # kill the previous sshd process if it's still running + # kill the sshd process if it's still running kill "$SSHD_PID" + SSHD_PID= - return "$RETURN" + set -e + + echo "##### return $RETURN" + if [ "$RETURN" = "$CODE" ] ; then + echo "##### ssh connection test returned as desired" + return 0 + else + echo "##### ssh connection test failed. expected return code $CODE" + return 1 + fi } failed_cleanup() { @@ -64,9 +88,16 @@ cleanup() { echo "### removing temp dir..." rm -rf "$TEMPDIR" + if [ "$SSHD_PID" ] ; then + echo "### killing off lingering sshd..." + kill "$SSHD_PID" + fi + wait } +SSHD_PID= + ## setup trap trap failed_cleanup EXIT @@ -98,8 +129,12 @@ export MONKEYSPHERE_LOG_LEVEL=DEBUG export SSHD_CONFIG="$TEMPDIR"/sshd_config export SOCKET="$TEMPDIR"/ssh-socket -export SSHD_PID= +# Make sure $DISPLAY is set to convince ssh and monkeysphere to fall +# back on $SSH_ASKPASS. Make sure it's not set to the current actual +# $DISPLAY (if one exists) because this test suite should not be doing +# *anything* with any running X11 session. +export DISPLAY=monkeys ### CONFIGURE ENVIRONMENTS @@ -195,20 +230,30 @@ monkeysphere-server update-users $(whoami) echo "### ssh connection test for success..." ssh_test -# remove the testuser's authorized_user_ids file and update -# authorized_keys file, this is to make sure that the ssh -# authentication FAILS... -echo "### removing testuser authorized_user_ids and reupdating authorized_keys..." -rm -f "$TESTHOME"/.monkeysphere/authorized_user_ids +# remove the testuser's authorized_user_ids file, update, and make +# sure that the ssh authentication FAILS +echo "### removing testuser authorized_user_ids and updating..." +mv "$TESTHOME"/.monkeysphere/authorized_user_ids{,.bak} monkeysphere-server update-users $(whoami) +echo "### ssh connection test for server authentication denial..." +ssh_test 255 +mv "$TESTHOME"/.monkeysphere/authorized_user_ids{.bak,} -# make sure the user can NOT connect +# put improper permissions on authorized_user_ids file, update, and +# make sure ssh authentication FAILS +echo "### setting group writability on authorized_user_ids and updating..." +chmod g+w "$TESTHOME"/.monkeysphere/authorized_user_ids +monkeysphere-server update-users $(whoami) echo "### ssh connection test for server authentication denial..." -ssh_test || ret="$?" -if [ "$ret" != '255' ] ; then - echo "### connection should have failed!" - exit "$ret" -fi +ssh_test 255 +chmod g-w "$TESTHOME"/.monkeysphere/authorized_user_ids +echo "### setting other writability on authorized_user_ids and updating..." +chmod o+w "$TESTHOME"/.monkeysphere/authorized_user_ids +monkeysphere-server update-users $(whoami) +echo "### ssh connection test for server authentication denial..." +ssh_test 255 +chmod o-w "$TESTHOME"/.monkeysphere/authorized_user_ids + trap - EXIT