]> 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 e3f989532fa3b5c0d31c96c9b05ec0cb040d42fc..1c90891d7dfdc7f748879a899168ccdbc82b0555 100755 (executable)
@@ -3,11 +3,12 @@
 cd $(dirname $0)
 . wvtest.sh
 
+NBT_HOME=$(getent passwd novaboot-test|cut -d: -f6)
 export WV_BASE_DIR
 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"
+reset_cmd="touch reset_done"
 target_config='--prefix=asdf'
 EOF
 
@@ -26,14 +27,6 @@ WVPASS run_server help | WVPASS tee log
 WVPASS grep 'Target commands:' log
 WVFAIL grep 'add-key' log
 
-WVSTART Help is printed without any arguments
-# Invocation with SSH_ORIGINAL_COMMAND
-WVPASS run_server help | WVPASS tee log
-WVPASS grep 'Target commands:' log
-# Invocation without SSH_ORIGINAL_COMMAND
-WVPASS $WV_BASE_DIR/../server/novaboot-shell | WVPASS tee log2
-WVPASS grep 'Target commands:' log2
-
 WVSTART Get-config command works
 run_server get-config > log
 WVPASS grep -e '^--prefix=asdf$' log
@@ -47,6 +40,11 @@ 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"
+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]}
@@ -74,14 +72,14 @@ 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
+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
 WVPASS sed -e '/novaboot-shell: Connected/q0' <&${COPROC[0]}
 WVPASS run_server reset
-WVPASS test -e reset
+WVPASS test -e reset_done
 WVPASS kill $COPROC_PID
 
 WVSTART "Quoting of config variables"
@@ -105,21 +103,25 @@ WVSTART "Quoting of config variables"
     WVPASS test -e '"file1 file2"'
 )
 
-SHELLRC="$WV_BASE_DIR/home-novaboot-test/.novaboot-shell"
-TFTPROOT="$WV_BASE_DIR/home-novaboot-test/tftproot"
-AUTH="$WV_BASE_DIR/home-novaboot-test/.ssh/authorized_keys"
+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 mkdir -p $(dirname $AUTH)
-WVPASS chmod 700 $(dirname $AUTH)
-WVPASS echo 'command="user test admin"' $(tail -n 1 keys) > $AUTH
+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 rm -rf $TFTPROOT
+WVPASS sudo_ rm -rf "$TFTPROOT"
 TS=$(date --rfc-3339=ns)
-WVPASS tee $SHELLRC <<EOF
+WVPASS sudo_ tee "$SHELLRC" <<EOF
 console_cmd=cat
 reset_cmd="echo $TS > reset.stamp"
 target_config=""
@@ -128,13 +130,14 @@ date > file
 WVPASS novaboot --ssh novaboot-test@localhost <<EOF
 copy file
 EOF
-WVPASS diff -u file $TFTPROOT/file
-WVPASS diff -u <(echo $TS) "$WV_BASE_DIR/home-novaboot-test/reset.stamp"
-
+# 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 rm -rf $TFTPROOT
-WVPASS tee $SHELLRC <<EOF
+WVPASS sudo_ rm -rf "$TFTPROOT"
+WVPASS sudo_ tee "$SHELLRC" <<EOF
 console_cmd=cat
 reset_cmd=true
 target_config="\
@@ -146,11 +149,11 @@ date > file
 WVPASS novaboot --ssh novaboot-test@localhost <<EOF
 load file
 EOF
-WVPASS diff -u file $TFTPROOT/file
-WVPASS grep /prefix/file $TFTPROOT/grub.cfg
+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 tee $SHELLRC <<EOF
+WVPASS sudo_ tee "$SHELLRC" <<EOF
 console_cmd=cat
 reset_cmd=true
 target_config="\
@@ -158,12 +161,13 @@ target_config="\
 --make
 "
 EOF
-WVFAIL novaboot --ssh novaboot-test@localhost <<EOF
-load file < date
-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 tee $SHELLRC <<EOF
+WVPASS sudo_ tee "$SHELLRC" <<EOF
 console_cmd=cat
 reset_cmd=true
 target_config="\
@@ -171,24 +175,30 @@ target_config="\
 blablabla
 "
 EOF
-WVFAIL novaboot --ssh novaboot-test@localhost <<EOF
-load file < date
-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 grep new_user $AUTH
+WVFAIL sudo_ grep new_user "$AUTH"
 WVPASS ssh novaboot-test@localhost add-key new_user < key.pub
-WVPASS grep new_user $AUTH
+WVPASS sudo_ grep -F "user new_user" "$AUTH"
 
 WVSTART "add-key user must not contain spaces"
-WVPASS cp $AUTH auth
+WVPASS sudo_ cat "$AUTH" > auth
 WVFAIL ssh novaboot-test@localhost add-key "new user" < /dev/null
-WVPASS diff -u $AUTH auth
+WVPASS diff -u <(sudo_ cat "$AUTH") auth
 
 WVSTART "add-key requires username"
-WVPASS cp $AUTH auth
+WVPASS sudo_ cat "$AUTH" > auth
 WVFAIL ssh novaboot-test@localhost add-key < /dev/null
-WVPASS diff -u $AUTH auth
+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'
+
+
 
 # Hi-lock: (("^.*\\(?:WVSTART\\).*$" (0 (quote hi-black-b) t)))