X-Git-Url: http://rtime.felk.cvut.cz/gitweb/novaboot.git/blobdiff_plain/9304caeb0696b5f4361a75451c07016a23812b46..6dcb21a0b297867324ee581a6a5306afbd965577:/tests/server.wv diff --git a/tests/server.wv b/tests/server.wv index 72ed352..3c74f15 100755 --- a/tests/server.wv +++ b/tests/server.wv @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash cd $(dirname $0) . wvtest.sh @@ -7,15 +7,17 @@ NBT_HOME=$(getent passwd novaboot-test|cut -d: -f6) export WV_BASE_DIR export NOVABOOT_SHELL_CONFIG="$WV_BASE_DIR/.novaboot-shell" cat < $NOVABOOT_SHELL_CONFIG -console_cmd="/bin/sh -c 'while :; do sleep 0.1; date; done'" +console_cmd="echo 'Hello console'; while :; do sleep 0.1; date; done" reset_cmd="touch reset_done" target_config='--prefix=asdf' EOF +# Run server synchronously function run_server() { SSH_ORIGINAL_COMMAND="$*" SSH_CONNECTION="127.0.0.1 1234 127.0.0.1 22" $exec $WV_BASE_DIR/../server/novaboot-shell -c "${account:-user} ${username:-test} ${admin:+admin}" } +# Exec server (for use with coproc - then the server can be easily killed) function exec_server() { local exec exec=exec @@ -40,11 +42,46 @@ coproc exec_server console WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${COPROC[0]} kill $COPROC_PID; wait -WVSTART "Console command is executed without any argument" +WVSTART "Without any argument console_cmd is executed if no default_cmd is configured" coproc exec_server -WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${COPROC[0]} +WVPASS sed -e '/Hello console/q0' -e '3q1' <&${COPROC[0]} kill $COPROC_PID; wait +WVSTART "Without any argument default_cmd is executed if configured" +( + export NOVABOOT_SHELL_CONFIG="./.novaboot-shell" + cat < $NOVABOOT_SHELL_CONFIG +default_cmd='echo "Hello default"' +console_cmd='echo "Hello console"' +EOF + WVPASS run_server | WVPASS grep -F 'Hello default' + + WVPASS run_server console | WVPASS grep -F 'Hello console' +) + +WVSTART "default_cmd can be set to run_novaboot" +( + export NOVABOOT_SHELL_CONFIG="./.novaboot-shell" + cat < default_nb_script +run echo "Hello default_nb_script" +EOF + cat <<'EOF' > $NOVABOOT_SHELL_CONFIG +default_cmd='run_novaboot default_nb_script --scriptmod=s/default_nb_script/default_nb_script_mod/' +console_cmd='while sleep 0.01; do echo "Hello console"; done' +reset_cmd='echo "Hello reset"' +target_config="\ +--name=some name with spaces and hash # +--exiton=Hello console +" +EOF + WVPASS run_server | ( + stdout=$(cat) + WVPASS grep -F 'Hello default_nb_script' <<<"$stdout" + WVPASS grep -F 'Hello default_nb_script_mod' <<<"$stdout" + WVPASS grep -F 'Hello console' <<<"$stdout" + ) +) + WVSTART 'Second connection to console prints queue' coproc console1 { exec_server console; } WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${console1[0]} @@ -112,20 +149,50 @@ WVSTART "Config variables can depend on user name" username=qwer WVPASS run_server console | tee /dev/stderr | WVPASS grep -F "Hello qwer" ) +WVSTART "Missing console_cmd results in failure" +NOVABOOT_SHELL_CONFIG="/dev/null" WVFAIL run_server console + +WVSTART "console_cmd may contain a shell function name" +( + export NOVABOOT_SHELL_CONFIG="./.novaboot-shell" + WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'console_cmd () { echo Hello user; } +console_cmd=console_cmd' + WVPASS run_server console | tee /dev/stderr | WVPASS grep -F "Hello user" +) + +WVSTART "reset_cmd may contain a shell function name" +( + export NOVABOOT_SHELL_CONFIG="./.novaboot-shell" + WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'reset_cmd () { echo Hello user; } +reset_cmd=reset_cmd' + WVPASS run_server reset | tee /dev/stderr | WVPASS grep -F "Hello user" +) + +if [ -n "$DEB_HOST_ARCH" ]; then + echo >&2 "Skipping server tests in Debian package build, because these cannot pass." + exit 0 +fi + SHELLRC="$NBT_HOME/.novaboot-shell" TFTPROOT="$NBT_HOME/tftproot" AUTH="$NBT_HOME/.ssh/authorized_keys" sudo_() { sudo -u novaboot-test "$@"; } -WVSTART "Check that ssh-agent needed for following tests is running" +WVSTART "Create and check ssh keys needed for following tests" +# Start our custom ssh-agent to not mess up with the user's agent +eval "$(ssh-agent)" +trap 'ssh-agent -k' EXIT WVPASS test -n "$SSH_AUTH_SOCK" || exit 1 +if [ ! -f id_rsa ]; then + ssh-keygen -t rsa -C "generated by $0" -N '' -f ./id_rsa +fi +WVPASS ssh-add ./id_rsa WVSTART "Setup SSH server's admin key" -WVPASS ssh-add -L > keys -WVPASS test $(wc -l < keys) -gt 0 WVPASS sudo_ mkdir -p $(dirname "$AUTH") WVPASS sudo_ chmod 700 $(dirname "$AUTH") -WVPASS sudo_ tee "$AUTH" <<<"command=\"user test admin\" $(tail -n 1 keys)" +WVPASS sudo_ tee "$AUTH" <<<"command=\"user test admin\" $(cat ./id_rsa.pub)" +exit WVSTART "Novaboot --ssh option (connect, rsync, reset)" WVPASS sudo_ rm -rf "$TFTPROOT"