]> rtime.felk.cvut.cz Git - novaboot.git/blobdiff - tests/server.wv
server: Add novaboot users to the novaboot group
[novaboot.git] / tests / server.wv
index 68ad6df4e6c31e0739b1a900078be1f85cfa9b48..0fac2569336a6a1493141c426becf285ad5bb911 100755 (executable)
@@ -5,14 +5,12 @@ cd $(dirname $0)
 
 export WV_BASE_DIR
 export NOVABOOT_SHELL_CONFIG="$WV_BASE_DIR/.novaboot-shell"
-cat <<EOF > "$NOVABOOT_SHELL_CONFIG"
+cat <<EOF > $NOVABOOT_SHELL_CONFIG
 console_cmd="/bin/sh -c 'while :; do sleep 0.1; date; done'"
-reset_cmd="touch reset"
-target_config() echo --prefix=asdf
+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-shell -c "${account:-user} ${username:-test} ${admin:+admin}"
 }
@@ -24,23 +22,28 @@ function exec_server() {
 }
 
 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
-WVPASS grep 'Target commands:' 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
 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]}
@@ -59,27 +62,55 @@ 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 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"
+(
+    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="$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"
 
+if [ -z "$SSH_AUTH_SOCK" ]; then
+    WVSTART "!!! Skipping SSH tests because no ssh-agent was detected !!!"
+    exit 0
+fi
+
 WVSTART "Setup SSH server's admin key"
 WVPASS ssh-add -L > keys
 WVPASS test $(wc -l < keys) -gt 0
@@ -93,7 +124,7 @@ TS=$(date --rfc-3339=ns)
 WVPASS tee $SHELLRC <<EOF
 console_cmd=cat
 reset_cmd="echo $TS > reset.stamp"
-target_config() :
+target_config=""
 EOF
 date > file
 WVPASS novaboot --ssh novaboot-test@localhost <<EOF
@@ -108,7 +139,10 @@ WVPASS rm -rf $TFTPROOT
 WVPASS tee $SHELLRC <<EOF
 console_cmd=cat
 reset_cmd=true
-target_config() { echo --prefix=/prefix; echo --grub2; }
+target_config="\
+--prefix=/prefix
+--grub2
+"
 EOF
 date > file
 WVPASS novaboot --ssh novaboot-test@localhost <<EOF
@@ -121,7 +155,10 @@ WVSTART "Novaboot --ssh remote config fails on non-safe options"
 WVPASS tee $SHELLRC <<EOF
 console_cmd=cat
 reset_cmd=true
-config() { echo --prefix=/prefix; echo --make; }
+target_config="\
+--prefix=/prefix
+--make
+"
 EOF
 WVFAIL novaboot --ssh novaboot-test@localhost <<EOF
 load file < date
@@ -131,7 +168,10 @@ WVSTART "Novaboot --ssh remote config fails on unknown arguments"
 WVPASS tee $SHELLRC <<EOF
 console_cmd=cat
 reset_cmd=true
-target_config() { echo --prefix=/prefix; echo blablabla; }
+target_config="\
+--prefix=/prefix
+blablabla
+"
 EOF
 WVFAIL novaboot --ssh novaboot-test@localhost <<EOF
 load file < date
@@ -152,3 +192,11 @@ WVSTART "add-key requires username"
 WVPASS cp $AUTH auth
 WVFAIL ssh novaboot-test@localhost add-key < /dev/null
 WVPASS diff -u $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)))