6 NBT_HOME=$(getent passwd novaboot-test|cut -d: -f6)
8 export NOVABOOT_SHELL_CONFIG="$WV_BASE_DIR/.novaboot-shell"
9 cat <<EOF > $NOVABOOT_SHELL_CONFIG
10 console_cmd="/bin/sh -c 'while :; do sleep 0.1; date; done'"
11 reset_cmd="touch reset_done"
12 target_config='--prefix=asdf'
15 function run_server() {
16 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}"
19 function exec_server() {
25 WVSTART Help subcommand
26 WVPASS run_server help | WVPASS tee log
27 WVPASS grep 'Target commands:' log
28 WVFAIL grep 'add-key' log
30 WVSTART Get-config command works
31 run_server get-config > log
32 WVPASS grep -e '^--prefix=asdf$' log
34 WVSTART "Multi-word commands work when user not specified"
35 WVPASS $WV_BASE_DIR/../server/novaboot-shell -c "help xxx" | WVPASS tee log
36 WVPASS grep 'Target commands:' log
38 WVSTART "Console prints a 'connected' message"
39 coproc exec_server console
40 WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${COPROC[0]}
41 kill $COPROC_PID; wait
43 WVSTART "Console command is executed without any argument"
45 WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${COPROC[0]}
46 kill $COPROC_PID; wait
48 WVSTART 'Second connection to console prints queue'
49 coproc console1 { exec_server console; }
50 WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${console1[0]}
51 coproc console2 { exec_server console; }
52 WVPASS sed -e '/Target is occupied by:/q0' <&${console2[0]}
53 kill $console1_PID $console2_PID; wait
55 WVSTART 'Printed queue contains correct username'
56 coproc console1 { username=my_cool_username exec_server console; }
57 WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${console1[0]}
58 coproc console2 { username=another_username exec_server console; }
59 WVPASS sed -e '/my_cool_username/q0' -e '3q1' <&${console2[0]}
60 kill $console1_PID $console2_PID; wait
62 WVSTART Admin sees help for admin subcommands
63 admin=1 run_server help > log
64 WVPASS grep 'add-key' log
66 WVSTART Only admin can run shell
67 WVFAIL run_server shell
68 admin=1 WVPASS run_server shell < /dev/null
70 WVSTART 'Cannot reset when somebody else is connected to console'
71 coproc console1 { exec_server console; }
72 WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${console1[0]}
73 coproc console2 { run_server reset; }
74 WVPASS sed -e '/Target is occupied by:/q0' <&${console2[0]}
75 WVPASS test ! -e reset_done
76 WVPASS kill $console1_PID $console2_PID; wait
78 WVSTART "Can reset when I'm connected to console"
79 coproc exec_server console
80 WVPASS sed -e '/novaboot-shell: Connected/q0' <&${COPROC[0]}
81 WVPASS run_server reset
82 WVPASS test -e reset_done
83 WVPASS kill $COPROC_PID
85 WVSTART "Quoting of config variables"
87 export NOVABOOT_SHELL_CONFIG="./.novaboot-shell"
89 WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'reset_cmd="touch file1 file2"'
90 WVPASS run_server reset
91 WVPASS test -e file1 -a -e file2
93 WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'reset_cmd="touch \"file1 file2\""'
94 WVPASS run_server reset
95 WVPASS test -e "file1 file2"
97 WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'reset_cmd="touch \"file1 file2\""'
98 WVPASS run_server reset
99 WVPASS test -e "file1 file2"
101 WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'reset_cmd="touch \"\\\"file1 file2\\\"\""'
102 WVPASS run_server reset
103 WVPASS test -e '"file1 file2"'
106 WVSTART "Config variables can depend on user name"
108 export NOVABOOT_SHELL_CONFIG="./.novaboot-shell"
110 WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'console_cmd="echo Hello $NB_USER"'
111 username=asdf WVPASS run_server console | tee /dev/stderr | WVPASS grep -F "Hello asdf"
112 username=qwer WVPASS run_server console | tee /dev/stderr | WVPASS grep -F "Hello qwer"
115 SHELLRC="$NBT_HOME/.novaboot-shell"
116 TFTPROOT="$NBT_HOME/tftproot"
117 AUTH="$NBT_HOME/.ssh/authorized_keys"
118 sudo_() { sudo -u novaboot-test "$@"; }
120 WVSTART "Check that ssh-agent needed for following tests is running"
121 WVPASS test -n "$SSH_AUTH_SOCK" || exit 1
123 WVSTART "Setup SSH server's admin key"
124 WVPASS ssh-add -L > keys
125 WVPASS test $(wc -l < keys) -gt 0
126 WVPASS sudo_ mkdir -p $(dirname "$AUTH")
127 WVPASS sudo_ chmod 700 $(dirname "$AUTH")
128 WVPASS sudo_ tee "$AUTH" <<<"command=\"user test admin\" $(tail -n 1 keys)"
130 WVSTART "Novaboot --ssh option (connect, rsync, reset)"
131 WVPASS sudo_ rm -rf "$TFTPROOT"
132 TS=$(date --rfc-3339=ns)
133 WVPASS sudo_ tee "$SHELLRC" <<EOF
135 reset_cmd="echo $TS > reset.stamp"
139 WVPASS novaboot --ssh novaboot-test@localhost <<EOF
142 # Check that file was copied to tftproot
143 WVPASS diff -u file <(sudo_ cat $TFTPROOT/file)
144 # Check that reset command was executed
145 WVPASS test "$TS" = "$(sudo_ cat "$NBT_HOME/reset.stamp")"
147 WVSTART "Novaboot --ssh remote config"
148 WVPASS sudo_ rm -rf "$TFTPROOT"
149 WVPASS sudo_ tee "$SHELLRC" <<EOF
158 WVPASS novaboot --ssh novaboot-test@localhost <<EOF
161 WVPASS diff -u file <(sudo_ cat "$TFTPROOT/file")
162 WVPASS sudo_ grep /prefix/file "$TFTPROOT/grub.cfg"
164 WVSTART "Novaboot --ssh remote config fails on non-safe options"
165 WVPASS sudo_ tee "$SHELLRC" <<EOF
173 WVFAIL novaboot --ssh novaboot-test@localhost <<<"load file < date"
174 novaboot --ssh novaboot-test@localhost <<<"load file < date" 2>&1 >/dev/null |\
175 tee >(WVPASS grep -q -F 'Unknown option: make') \
176 >(WVPASS grep -q -F 'Error processing configuration from the server')
178 WVSTART "Novaboot --ssh remote config fails on unknown arguments"
179 WVPASS sudo_ tee "$SHELLRC" <<EOF
187 WVFAIL novaboot --ssh novaboot-test@localhost <<<"load file < date"
188 novaboot --ssh novaboot-test@localhost <<<"load file < date" 2>&1 >/dev/null |\
189 WVPASS grep -F "Unsuported configuration received from the server: blablabla"
191 WVSTART "add-key subcommand"
192 WVPASS ssh-keygen -t ed25519 -N '' -f key
193 WVFAIL sudo_ grep new_user "$AUTH"
194 WVPASS ssh novaboot-test@localhost add-key new_user < key.pub
195 WVPASS sudo_ grep -F "user new_user" "$AUTH"
197 WVSTART "add-key user must not contain spaces"
198 WVPASS sudo_ cat "$AUTH" > auth
199 WVFAIL ssh novaboot-test@localhost add-key "new user" < /dev/null
200 WVPASS diff -u <(sudo_ cat "$AUTH") auth
202 WVSTART "add-key requires username"
203 WVPASS sudo_ cat "$AUTH" > auth
204 WVFAIL ssh novaboot-test@localhost add-key < /dev/null
205 WVPASS diff -u <(sudo_ cat "$AUTH") auth
207 WVSTART "Suggest using ssh -t for shell"
208 WVPASS ssh novaboot-test@localhost shell < /dev/null | WVPASS grep -e 'ssh -t'
209 echo exit|WVPASS ssh -tt novaboot-test@localhost shell | WVFAIL grep -e 'ssh -t'
213 # Hi-lock: (("^.*\\(?:WVSTART\\).*$" (0 (quote hi-black-b) t)))