]> rtime.felk.cvut.cz Git - novaboot.git/blobdiff - tests/server.wv
tests: Convert server tests to use the account from last commit
[novaboot.git] / tests / server.wv
index e69bed5e50b8ddd172989dfc9efde5efd31fceed..1c90891d7dfdc7f748879a899168ccdbc82b0555 100755 (executable)
@@ -3,17 +3,17 @@
 cd $(dirname $0)
 . wvtest.sh
 
+NBT_HOME=$(getent passwd novaboot-test|cut -d: -f6)
 export WV_BASE_DIR
-export NOVABOOT_SERVER_CONFIG="$WV_BASE_DIR/.novaboot-server"
-cat <<EOF > "$NOVABOOT_SERVER_CONFIG"
-target_console="/bin/sh -c 'while :; do sleep 0.1; date; done'"
-target_reset="touch reset"
+export NOVABOOT_SHELL_CONFIG="$WV_BASE_DIR/.novaboot-shell"
+cat <<EOF > $NOVABOOT_SHELL_CONFIG
+console_cmd="/bin/sh -c 'while :; do sleep 0.1; date; done'"
+reset_cmd="touch reset_done"
+target_config='--prefix=asdf'
 EOF
 
-export MAIN_PID=$$
-
 function run_server() {
-    SSH_ORIGINAL_COMMAND="$*" SSH_CONNECTION="127.0.0.1 1234 127.0.0.1 22" $exec $WV_BASE_DIR/../server/novaboot-server -c "${account:-user} ${username:-test} ${admin:+admin}"
+    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}"
 }
 
 function exec_server() {
@@ -22,54 +22,183 @@ function exec_server() {
     run_server "$@"
 }
 
-trap 'kill "$COPROC_PID"' EXIT
-
 WVSTART Help subcommand
-run_server help > log
+WVPASS run_server help | WVPASS tee log
 WVPASS grep 'Target commands:' log
 WVFAIL grep 'add-key' log
 
-WVSTART Help is printed without any arguments
-run_server > log
+WVSTART Get-config command works
+run_server get-config > log
+WVPASS grep -e '^--prefix=asdf$' log
+
+WVSTART "Multi-word commands work when user not specified"
+WVPASS $WV_BASE_DIR/../server/novaboot-shell -c "help xxx" | WVPASS tee log
 WVPASS grep 'Target commands:' log
 
 WVSTART "Console prints a 'connected' message"
 coproc exec_server console
-sed -e '/novaboot-server: Connected/q0' <&${COPROC[0]}
-WVPASSRC
+WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${COPROC[0]}
 kill $COPROC_PID; wait
 
-WVSTART 'Second connection to console prints queue'
-coproc exec_server console
-sed -e '/novaboot-server: Connected/q0' <&${COPROC[0]}
-WVPASSRC
-run_server console | sed -e '/Target is occupied by:/q0'
+WVSTART "Console command is executed without any argument"
+coproc exec_server
+WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${COPROC[0]}
 kill $COPROC_PID; wait
 
+WVSTART 'Second connection to console prints queue'
+coproc console1 { exec_server console; }
+WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${console1[0]}
+coproc console2 { exec_server console; }
+WVPASS sed -e '/Target is occupied by:/q0' <&${console2[0]}
+kill $console1_PID $console2_PID; wait
+
 WVSTART 'Printed queue contains correct username'
 coproc console1 { username=my_cool_username exec_server console; }
-WVPASS sed -e '/novaboot-server: Connected/q0' <&${console1[0]}
+WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${console1[0]}
 coproc console2 { username=another_username exec_server console; }
-WVPASS sed -e '/my_cool_username/q0' <&${console2[0]}
+WVPASS sed -e '/my_cool_username/q0' -e '3q1' <&${console2[0]}
 kill $console1_PID $console2_PID; wait
 
 WVSTART Admin sees help for admin subcommands
 admin=1 run_server help > log
 WVPASS grep 'add-key' log
 
+WVSTART Only admin can run shell
+WVFAIL run_server shell
+admin=1 WVPASS run_server shell < /dev/null
+
 WVSTART 'Cannot reset when somebody else is connected to console'
-coproc exec_server console
-sed -e '/novaboot-server: Connected/q0' <&${COPROC[0]}
-run_server reset | sed -e '/Target is occupied by:/q0'
-WVPASSRC
-WVFAIL test -e reset
-kill $COPROC_PID; wait
+coproc console1 { exec_server console; }
+WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${console1[0]}
+coproc console2 { run_server reset; }
+WVPASS sed -e '/Target is occupied by:/q0' <&${console2[0]}
+WVPASS test ! -e reset_done
+WVPASS kill $console1_PID $console2_PID; wait
 
 WVSTART "Can reset when I'm connected to console"
 coproc exec_server console
-sed -e '/novaboot-server: Connected/q0'  <&${COPROC[0]}
-run_server reset
-WVPASS test -e reset
-kill $COPROC_PID
+WVPASS sed -e '/novaboot-shell: Connected/q0' <&${COPROC[0]}
+WVPASS run_server reset
+WVPASS test -e reset_done
+WVPASS kill $COPROC_PID
+
+WVSTART "Quoting of config variables"
+(
+    export NOVABOOT_SHELL_CONFIG="./.novaboot-shell"
+
+    WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'reset_cmd="touch file1 file2"'
+    WVPASS run_server reset
+    WVPASS test -e file1 -a -e file2
+
+    WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'reset_cmd="touch \"file1 file2\""'
+    WVPASS run_server reset
+    WVPASS test -e "file1 file2"
+
+    WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'reset_cmd="touch \"file1   file2\""'
+    WVPASS run_server reset
+    WVPASS test -e "file1   file2"
+
+    WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'reset_cmd="touch \"\\\"file1 file2\\\"\""'
+    WVPASS run_server reset
+    WVPASS test -e '"file1 file2"'
+)
+
+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"
+WVPASS test -n "$SSH_AUTH_SOCK" || exit 1
+
+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)"
+
+WVSTART "Novaboot --ssh option (connect, rsync, reset)"
+WVPASS sudo_ rm -rf "$TFTPROOT"
+TS=$(date --rfc-3339=ns)
+WVPASS sudo_ tee "$SHELLRC" <<EOF
+console_cmd=cat
+reset_cmd="echo $TS > reset.stamp"
+target_config=""
+EOF
+date > file
+WVPASS novaboot --ssh novaboot-test@localhost <<EOF
+copy file
+EOF
+# Check that file was copied to tftproot
+WVPASS diff -u file <(sudo_ cat $TFTPROOT/file)
+# Check that reset command was executed
+WVPASS test "$TS" = "$(sudo_ cat "$NBT_HOME/reset.stamp")"
+
+WVSTART "Novaboot --ssh remote config"
+WVPASS sudo_ rm -rf "$TFTPROOT"
+WVPASS sudo_ tee "$SHELLRC" <<EOF
+console_cmd=cat
+reset_cmd=true
+target_config="\
+--prefix=/prefix
+--grub2
+"
+EOF
+date > file
+WVPASS novaboot --ssh novaboot-test@localhost <<EOF
+load file
+EOF
+WVPASS diff -u file <(sudo_ cat "$TFTPROOT/file")
+WVPASS sudo_ grep /prefix/file "$TFTPROOT/grub.cfg"
+
+WVSTART "Novaboot --ssh remote config fails on non-safe options"
+WVPASS sudo_ tee "$SHELLRC" <<EOF
+console_cmd=cat
+reset_cmd=true
+target_config="\
+--prefix=/prefix
+--make
+"
+EOF
+WVFAIL novaboot --ssh novaboot-test@localhost <<<"load file < date"
+novaboot --ssh novaboot-test@localhost <<<"load file < date" 2>&1 >/dev/null |\
+    tee >(WVPASS grep -q -F 'Unknown option: make') \
+       >(WVPASS grep -q -F 'Error processing configuration from the server')
+
+WVSTART "Novaboot --ssh remote config fails on unknown arguments"
+WVPASS sudo_ tee "$SHELLRC" <<EOF
+console_cmd=cat
+reset_cmd=true
+target_config="\
+--prefix=/prefix
+blablabla
+"
+EOF
+WVFAIL novaboot --ssh novaboot-test@localhost <<<"load file < date"
+novaboot --ssh novaboot-test@localhost <<<"load file < date" 2>&1 >/dev/null |\
+    WVPASS grep -F "Unsuported configuration received from the server: blablabla"
+
+WVSTART "add-key subcommand"
+WVPASS ssh-keygen -t ed25519 -N '' -f key
+WVFAIL sudo_ grep new_user "$AUTH"
+WVPASS ssh novaboot-test@localhost add-key new_user < key.pub
+WVPASS sudo_ grep -F "user new_user" "$AUTH"
+
+WVSTART "add-key user must not contain spaces"
+WVPASS sudo_ cat "$AUTH" > auth
+WVFAIL ssh novaboot-test@localhost add-key "new user" < /dev/null
+WVPASS diff -u <(sudo_ cat "$AUTH") auth
+
+WVSTART "add-key requires username"
+WVPASS sudo_ cat "$AUTH" > auth
+WVFAIL ssh novaboot-test@localhost add-key < /dev/null
+WVPASS diff -u <(sudo_ cat "$AUTH") auth
+
+WVSTART "Suggest using ssh -t for shell"
+WVPASS ssh novaboot-test@localhost shell < /dev/null | WVPASS grep -e 'ssh -t'
+echo exit|WVPASS ssh -tt novaboot-test@localhost shell | WVFAIL grep -e 'ssh -t'
+
+
 
-trap - EXIT
+# Hi-lock: (("^.*\\(?:WVSTART\\).*$" (0 (quote hi-black-b) t)))