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="echo 'Hello console'; while :; do sleep 0.1; date; done"
11 reset_cmd="touch reset_done"
12 target_config='--prefix=asdf'
15 # Run server synchronously
16 function run_server() {
17 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}"
20 # Exec server (for use with coproc - then the server can be easily killed)
21 function exec_server() {
27 WVSTART Help subcommand
28 WVPASS run_server help | WVPASS tee log
29 WVPASS grep 'Target commands:' log
30 WVFAIL grep 'add-key' log
32 WVSTART Get-config command works
33 run_server get-config > log
34 WVPASS grep -e '^--prefix=asdf$' log
36 WVSTART "Multi-word commands work when user not specified"
37 WVPASS $WV_BASE_DIR/../server/novaboot-shell -c "help xxx" | WVPASS tee log
38 WVPASS grep 'Target commands:' log
40 WVSTART "Console prints a 'connected' message"
41 coproc exec_server console
42 WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${COPROC[0]}
43 kill $COPROC_PID; wait
45 WVSTART "Without any argument console_cmd is executed if no default_cmd is configured"
47 WVPASS sed -e '/Hello console/q0' -e '3q1' <&${COPROC[0]}
48 kill $COPROC_PID; wait
50 WVSTART "Without any argument default_cmd is executed if configured"
52 export NOVABOOT_SHELL_CONFIG="./.novaboot-shell"
53 cat <<EOF > $NOVABOOT_SHELL_CONFIG
54 default_cmd='echo "Hello default"'
55 console_cmd='echo "Hello console"'
57 WVPASS run_server | WVPASS grep -F 'Hello default'
59 WVPASS run_server console | WVPASS grep -F 'Hello console'
62 WVSTART "default_cmd can be set to run_novaboot"
64 export NOVABOOT_SHELL_CONFIG="./.novaboot-shell"
65 cat <<EOF > default_nb_script
66 run echo "Hello default_nb_script"
68 cat <<'EOF' > $NOVABOOT_SHELL_CONFIG
69 default_cmd='run_novaboot default_nb_script --scriptmod=s/default_nb_script/default_nb_script_mod/'
70 console_cmd='while sleep 0.01; do echo "Hello console"; done'
71 reset_cmd='echo "Hello reset"'
73 --name=some name with spaces and hash #
74 --exiton=Hello console
79 WVPASS grep -F 'Hello default_nb_script' <<<"$stdout"
80 WVPASS grep -F 'Hello default_nb_script_mod' <<<"$stdout"
81 WVPASS grep -F 'Hello console' <<<"$stdout"
85 WVSTART 'Second connection to console prints queue'
86 coproc console1 { exec_server console; }
87 WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${console1[0]}
88 coproc console2 { exec_server console; }
89 WVPASS sed -e '/Target is occupied by:/q0' <&${console2[0]}
90 kill $console1_PID $console2_PID; wait
92 WVSTART 'Printed queue contains correct username'
93 coproc console1 { username=my_cool_username exec_server console; }
94 WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${console1[0]}
95 coproc console2 { username=another_username exec_server console; }
96 WVPASS sed -e '/my_cool_username/q0' -e '3q1' <&${console2[0]}
97 kill $console1_PID $console2_PID; wait
99 WVSTART Admin sees help for admin subcommands
100 admin=1 run_server help > log
101 WVPASS grep 'add-key' log
103 WVSTART Only admin can run shell
104 WVFAIL run_server shell
105 admin=1 WVPASS run_server shell < /dev/null
107 WVSTART 'Cannot reset when somebody else is connected to console'
108 coproc console1 { exec_server console; }
109 WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${console1[0]}
110 coproc console2 { run_server reset; }
111 WVPASS sed -e '/Target is occupied by:/q0' <&${console2[0]}
112 WVPASS test ! -e reset_done
113 WVPASS kill $console1_PID $console2_PID; wait
115 WVSTART "Can reset when I'm connected to console"
116 coproc exec_server console
117 WVPASS sed -e '/novaboot-shell: Connected/q0' <&${COPROC[0]}
118 WVPASS run_server reset
119 WVPASS test -e reset_done
120 WVPASS kill $COPROC_PID
122 WVSTART "Quoting of config variables"
124 export NOVABOOT_SHELL_CONFIG="./.novaboot-shell"
126 WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'reset_cmd="touch file1 file2"'
127 WVPASS run_server reset
128 WVPASS test -e file1 -a -e file2
130 WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'reset_cmd="touch \"file1 file2\""'
131 WVPASS run_server reset
132 WVPASS test -e "file1 file2"
134 WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'reset_cmd="touch \"file1 file2\""'
135 WVPASS run_server reset
136 WVPASS test -e "file1 file2"
138 WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'reset_cmd="touch \"\\\"file1 file2\\\"\""'
139 WVPASS run_server reset
140 WVPASS test -e '"file1 file2"'
143 WVSTART "Config variables can depend on user name"
145 export NOVABOOT_SHELL_CONFIG="./.novaboot-shell"
147 WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'console_cmd="echo Hello $NB_USER"'
148 username=asdf WVPASS run_server console | tee /dev/stderr | WVPASS grep -F "Hello asdf"
149 username=qwer WVPASS run_server console | tee /dev/stderr | WVPASS grep -F "Hello qwer"
152 WVSTART "Missing console_cmd results in failure"
153 NOVABOOT_SHELL_CONFIG="/dev/null" WVFAIL run_server console
155 WVSTART "console_cmd may contain a shell function name"
157 export NOVABOOT_SHELL_CONFIG="./.novaboot-shell"
158 WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'console_cmd () { echo Hello user; }
159 console_cmd=console_cmd'
160 WVPASS run_server console | tee /dev/stderr | WVPASS grep -F "Hello user"
163 WVSTART "reset_cmd may contain a shell function name"
165 export NOVABOOT_SHELL_CONFIG="./.novaboot-shell"
166 WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'reset_cmd () { echo Hello user; }
168 WVPASS run_server reset | tee /dev/stderr | WVPASS grep -F "Hello user"
171 if [ -n "$DEB_HOST_ARCH" ]; then
172 echo >&2 "Skipping server tests in Debian package build, because these cannot pass."
176 SHELLRC="$NBT_HOME/.novaboot-shell"
177 TFTPROOT="$NBT_HOME/tftproot"
178 AUTH="$NBT_HOME/.ssh/authorized_keys"
179 sudo_() { sudo -u novaboot-test "$@"; }
181 WVSTART "Create and check ssh keys needed for following tests"
182 # Start our custom ssh-agent to not mess up with the user's agent
184 trap 'ssh-agent -k' EXIT
185 WVPASS test -n "$SSH_AUTH_SOCK" || exit 1
186 if [ ! -f id_rsa ]; then
187 ssh-keygen -t rsa -C "generated by $0" -N '' -f ./id_rsa
189 ID_RSA=$(realpath ./id_rsa)
190 WVPASS ssh-add ./id_rsa
192 WVSTART "Setup SSH server's admin key"
193 WVPASS sudo_ mkdir -p $(dirname "$AUTH")
194 WVPASS sudo_ chmod 700 $(dirname "$AUTH")
195 WVPASS sudo_ tee "$AUTH" <<<"command=\"user test admin\" $(cat "$ID_RSA".pub)"
196 # Check that we can really log in
197 WVPASS ssh novaboot-test@localhost help
199 WVSTART "Novaboot --ssh option (connect, rsync, reset)"
200 WVPASS sudo_ rm -rf "$TFTPROOT"
201 TS=$(date --rfc-3339=ns)
202 WVPASS sudo_ tee "$SHELLRC" <<EOF
204 reset_cmd="echo $TS > reset.stamp"
208 WVPASS novaboot --ssh novaboot-test@localhost <<EOF
211 # Check that file was copied to tftproot
212 WVPASS diff -u file <(sudo_ cat $TFTPROOT/file)
213 # Check that reset command was executed
214 WVPASS test "$TS" = "$(sudo_ cat "$NBT_HOME/reset.stamp")"
216 WVSTART "Novaboot --ssh remote config"
217 WVPASS sudo_ rm -rf "$TFTPROOT"
218 WVPASS sudo_ tee "$SHELLRC" <<EOF
227 WVPASS novaboot --ssh novaboot-test@localhost <<EOF
230 WVPASS diff -u file <(sudo_ cat "$TFTPROOT/file")
231 WVPASS sudo_ grep /prefix/file "$TFTPROOT/boot/grub/grub.cfg"
233 WVSTART "Novaboot --ssh remote config fails on non-safe options"
234 WVPASS sudo_ tee "$SHELLRC" <<EOF
242 WVFAIL novaboot --ssh novaboot-test@localhost <<<"load file < date"
243 stderr=$(novaboot --ssh novaboot-test@localhost <<<"load file < date" 2>&1 >/dev/null)
244 echo "$stderr" | WVPASS grep -q -F 'Unknown option: make'
245 echo "$stderr" | WVPASS grep -q -F 'Error processing configuration from the server'
247 WVSTART "Novaboot --ssh remote config fails on unknown arguments"
248 WVPASS sudo_ tee "$SHELLRC" <<EOF
256 WVFAIL novaboot --ssh novaboot-test@localhost <<<"load file < date"
257 novaboot --ssh novaboot-test@localhost <<<"load file < date" 2>&1 >/dev/null |\
258 WVPASS grep -F "Unsuported configuration received from the server: blablabla"
260 WVSTART "add-key subcommand"
261 WVPASS ssh-keygen -t ed25519 -N '' -f key
262 WVFAIL sudo_ grep new_user "$AUTH"
263 WVPASS ssh novaboot-test@localhost add-key new_user < key.pub
264 WVPASS sudo_ grep -F "user new_user" "$AUTH"
266 WVSTART "add-key user must not contain spaces"
267 WVPASS sudo_ cat "$AUTH" > auth
268 WVFAIL ssh novaboot-test@localhost add-key "new user" < /dev/null
269 WVPASS diff -u <(sudo_ cat "$AUTH") auth
271 WVSTART "add-key requires username"
272 WVPASS sudo_ cat "$AUTH" > auth
273 WVFAIL ssh novaboot-test@localhost add-key < /dev/null
274 WVPASS diff -u <(sudo_ cat "$AUTH") auth
276 WVSTART "Suggest using ssh -t for shell"
277 WVPASS ssh novaboot-test@localhost shell < /dev/null | WVPASS grep -e 'ssh -t'
278 echo exit|WVPASS ssh -tt novaboot-test@localhost shell | WVFAIL grep -e 'ssh -t'
282 # Hi-lock: (("^.*\\(?:WVSTART\\).*$" (0 (quote hi-black-b) t)))