7 export NOVABOOT_SHELL_CONFIG="$WV_BASE_DIR/.novaboot-shell"
8 cat <<EOF > $NOVABOOT_SHELL_CONFIG
9 console_cmd="/bin/sh -c 'while :; do sleep 0.1; date; done'"
10 reset_cmd="touch reset_done"
11 target_config='--prefix=asdf'
14 function run_server() {
15 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}"
18 function exec_server() {
24 WVSTART Help subcommand
25 WVPASS run_server help | WVPASS tee log
26 WVPASS grep 'Target commands:' log
27 WVFAIL grep 'add-key' log
29 WVSTART Get-config command works
30 run_server get-config > log
31 WVPASS grep -e '^--prefix=asdf$' log
33 WVSTART "Multi-word commands work when user not specified"
34 WVPASS $WV_BASE_DIR/../server/novaboot-shell -c "help xxx" | WVPASS tee log
35 WVPASS grep 'Target commands:' log
37 WVSTART "Console prints a 'connected' message"
38 coproc exec_server console
39 WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${COPROC[0]}
40 kill $COPROC_PID; wait
42 WVSTART "Console command is executed without any argument"
44 WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${COPROC[0]}
45 kill $COPROC_PID; wait
47 WVSTART 'Second connection to console prints queue'
48 coproc console1 { exec_server console; }
49 WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${console1[0]}
50 coproc console2 { exec_server console; }
51 WVPASS sed -e '/Target is occupied by:/q0' <&${console2[0]}
52 kill $console1_PID $console2_PID; wait
54 WVSTART 'Printed queue contains correct username'
55 coproc console1 { username=my_cool_username exec_server console; }
56 WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${console1[0]}
57 coproc console2 { username=another_username exec_server console; }
58 WVPASS sed -e '/my_cool_username/q0' -e '3q1' <&${console2[0]}
59 kill $console1_PID $console2_PID; wait
61 WVSTART Admin sees help for admin subcommands
62 admin=1 run_server help > log
63 WVPASS grep 'add-key' log
65 WVSTART Only admin can run shell
66 WVFAIL run_server shell
67 admin=1 WVPASS run_server shell < /dev/null
69 WVSTART 'Cannot reset when somebody else is connected to console'
70 coproc console1 { exec_server console; }
71 WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${console1[0]}
72 coproc console2 { run_server reset; }
73 WVPASS sed -e '/Target is occupied by:/q0' <&${console2[0]}
74 WVPASS test ! -e reset_done
75 WVPASS kill $console1_PID $console2_PID; wait
77 WVSTART "Can reset when I'm connected to console"
78 coproc exec_server console
79 WVPASS sed -e '/novaboot-shell: Connected/q0' <&${COPROC[0]}
80 WVPASS run_server reset
81 WVPASS test -e reset_done
82 WVPASS kill $COPROC_PID
84 WVSTART "Quoting of config variables"
86 export NOVABOOT_SHELL_CONFIG="./.novaboot-shell"
88 WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'reset_cmd="touch file1 file2"'
89 WVPASS run_server reset
90 WVPASS test -e file1 -a -e file2
92 WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'reset_cmd="touch \"file1 file2\""'
93 WVPASS run_server reset
94 WVPASS test -e "file1 file2"
96 WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'reset_cmd="touch \"file1 file2\""'
97 WVPASS run_server reset
98 WVPASS test -e "file1 file2"
100 WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'reset_cmd="touch \"\\\"file1 file2\\\"\""'
101 WVPASS run_server reset
102 WVPASS test -e '"file1 file2"'
105 SHELLRC="$WV_BASE_DIR/home-novaboot-test/.novaboot-shell"
106 TFTPROOT="$WV_BASE_DIR/home-novaboot-test/tftproot"
107 AUTH="$WV_BASE_DIR/home-novaboot-test/.ssh/authorized_keys"
109 if [ -z "$SSH_AUTH_SOCK" ]; then
110 WVSTART "!!! Skipping SSH tests because no ssh-agent was detected !!!"
114 WVSTART "Setup SSH server's admin key"
115 WVPASS ssh-add -L > keys
116 WVPASS test $(wc -l < keys) -gt 0
117 WVPASS mkdir -p $(dirname $AUTH)
118 WVPASS chmod 700 $(dirname $AUTH)
119 WVPASS echo 'command="user test admin"' $(tail -n 1 keys) > $AUTH
121 WVSTART "Novaboot --ssh option (connect, rsync, reset)"
122 WVPASS rm -rf $TFTPROOT
123 TS=$(date --rfc-3339=ns)
124 WVPASS tee $SHELLRC <<EOF
126 reset_cmd="echo $TS > reset.stamp"
130 WVPASS novaboot --ssh novaboot-test@localhost <<EOF
133 WVPASS diff -u file $TFTPROOT/file
134 WVPASS diff -u <(echo $TS) "$WV_BASE_DIR/home-novaboot-test/reset.stamp"
137 WVSTART "Novaboot --ssh remote config"
138 WVPASS rm -rf $TFTPROOT
139 WVPASS tee $SHELLRC <<EOF
148 WVPASS novaboot --ssh novaboot-test@localhost <<EOF
151 WVPASS diff -u file $TFTPROOT/file
152 WVPASS grep /prefix/file $TFTPROOT/grub.cfg
154 WVSTART "Novaboot --ssh remote config fails on non-safe options"
155 WVPASS tee $SHELLRC <<EOF
163 WVFAIL novaboot --ssh novaboot-test@localhost <<EOF
167 WVSTART "Novaboot --ssh remote config fails on unknown arguments"
168 WVPASS tee $SHELLRC <<EOF
176 WVFAIL novaboot --ssh novaboot-test@localhost <<EOF
180 WVSTART "add-key subcommand"
181 WVPASS ssh-keygen -t ed25519 -N '' -f key
182 WVFAIL grep new_user $AUTH
183 WVPASS ssh novaboot-test@localhost add-key new_user < key.pub
184 WVPASS grep new_user $AUTH
186 WVSTART "add-key user must not contain spaces"
188 WVFAIL ssh novaboot-test@localhost add-key "new user" < /dev/null
189 WVPASS diff -u $AUTH auth
191 WVSTART "add-key requires username"
193 WVFAIL ssh novaboot-test@localhost add-key < /dev/null
194 WVPASS diff -u $AUTH auth
196 WVSTART Suggest using ssh -t for shell
197 WVPASS ssh novaboot-test@localhost shell < /dev/null | WVPASS grep -e 'ssh -t'
198 echo exit|WVPASS ssh -tt novaboot-test@localhost shell | WVFAIL grep -e 'ssh -t'
202 # Hi-lock: (("^.*\\(?:WVSTART\\).*$" (0 (quote hi-black-b) t)))