]> 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 d589681c1e507a9b9500813eac8783e743148420..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"
-target_console="/bin/sh -c 'while :; do sleep 0.1; date; done'"
-target_reset="touch reset"
-target_config() echo --prefix=asdf
+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-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,34 +62,69 @@ 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
+WVPASS mkdir -p $(dirname $AUTH)
+WVPASS chmod 700 $(dirname $AUTH)
+WVPASS echo 'command="user test admin"' $(tail -n 1 keys) > $AUTH
 
 WVSTART "Novaboot --ssh option (connect, rsync, reset)"
 WVPASS rm -rf $TFTPROOT
 TS=$(date --rfc-3339=ns)
 WVPASS tee $SHELLRC <<EOF
-target_console=cat
-target_reset="echo $TS > reset.stamp"
-target_config() :
+console_cmd=cat
+reset_cmd="echo $TS > reset.stamp"
+target_config=""
 EOF
 date > file
 WVPASS novaboot --ssh novaboot-test@localhost <<EOF
@@ -99,9 +137,12 @@ WVPASS diff -u <(echo $TS) "$WV_BASE_DIR/home-novaboot-test/reset.stamp"
 WVSTART "Novaboot --ssh remote config"
 WVPASS rm -rf $TFTPROOT
 WVPASS tee $SHELLRC <<EOF
-target_console=cat
-target_reset=true
-target_config() { echo --prefix=/prefix; echo --grub2; }
+console_cmd=cat
+reset_cmd=true
+target_config="\
+--prefix=/prefix
+--grub2
+"
 EOF
 date > file
 WVPASS novaboot --ssh novaboot-test@localhost <<EOF
@@ -112,9 +153,12 @@ WVPASS grep /prefix/file $TFTPROOT/grub.cfg
 
 WVSTART "Novaboot --ssh remote config fails on non-safe options"
 WVPASS tee $SHELLRC <<EOF
-target_console=cat
-target_reset=true
-target_config() { echo --prefix=/prefix; echo --make; }
+console_cmd=cat
+reset_cmd=true
+target_config="\
+--prefix=/prefix
+--make
+"
 EOF
 WVFAIL novaboot --ssh novaboot-test@localhost <<EOF
 load file < date
@@ -122,10 +166,37 @@ EOF
 
 WVSTART "Novaboot --ssh remote config fails on unknown arguments"
 WVPASS tee $SHELLRC <<EOF
-target_console=cat
-target_reset=true
-target_config() { echo --prefix=/prefix; echo blablabla; }
+console_cmd=cat
+reset_cmd=true
+target_config="\
+--prefix=/prefix
+blablabla
+"
 EOF
 WVFAIL novaboot --ssh novaboot-test@localhost <<EOF
 load file < date
 EOF
+
+WVSTART "add-key subcommand"
+WVPASS ssh-keygen -t ed25519 -N '' -f key
+WVFAIL grep new_user $AUTH
+WVPASS ssh novaboot-test@localhost add-key new_user < key.pub
+WVPASS grep new_user $AUTH
+
+WVSTART "add-key user must not contain spaces"
+WVPASS cp $AUTH auth
+WVFAIL ssh novaboot-test@localhost add-key "new user" < /dev/null
+WVPASS diff -u $AUTH auth
+
+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)))