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 'Second connection to console prints queue'
63 coproc console1 { exec_server console; }
64 WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${console1[0]}
65 coproc console2 { exec_server console; }
66 WVPASS sed -e '/Target is occupied by:/q0' <&${console2[0]}
67 kill $console1_PID $console2_PID; wait
69 WVSTART 'Printed queue contains correct username'
70 coproc console1 { username=my_cool_username exec_server console; }
71 WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${console1[0]}
72 coproc console2 { username=another_username exec_server console; }
73 WVPASS sed -e '/my_cool_username/q0' -e '3q1' <&${console2[0]}
74 kill $console1_PID $console2_PID; wait
76 WVSTART Admin sees help for admin subcommands
77 admin=1 run_server help > log
78 WVPASS grep 'add-key' log
80 WVSTART Only admin can run shell
81 WVFAIL run_server shell
82 admin=1 WVPASS run_server shell < /dev/null
84 WVSTART 'Cannot reset when somebody else is connected to console'
85 coproc console1 { exec_server console; }
86 WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${console1[0]}
87 coproc console2 { run_server reset; }
88 WVPASS sed -e '/Target is occupied by:/q0' <&${console2[0]}
89 WVPASS test ! -e reset_done
90 WVPASS kill $console1_PID $console2_PID; wait
92 WVSTART "Can reset when I'm connected to console"
93 coproc exec_server console
94 WVPASS sed -e '/novaboot-shell: Connected/q0' <&${COPROC[0]}
95 WVPASS run_server reset
96 WVPASS test -e reset_done
97 WVPASS kill $COPROC_PID
99 WVSTART "Quoting of config variables"
101 export NOVABOOT_SHELL_CONFIG="./.novaboot-shell"
103 WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'reset_cmd="touch file1 file2"'
104 WVPASS run_server reset
105 WVPASS test -e file1 -a -e file2
107 WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'reset_cmd="touch \"file1 file2\""'
108 WVPASS run_server reset
109 WVPASS test -e "file1 file2"
111 WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'reset_cmd="touch \"file1 file2\""'
112 WVPASS run_server reset
113 WVPASS test -e "file1 file2"
115 WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'reset_cmd="touch \"\\\"file1 file2\\\"\""'
116 WVPASS run_server reset
117 WVPASS test -e '"file1 file2"'
120 WVSTART "Config variables can depend on user name"
122 export NOVABOOT_SHELL_CONFIG="./.novaboot-shell"
124 WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'console_cmd="echo Hello $NB_USER"'
125 username=asdf WVPASS run_server console | tee /dev/stderr | WVPASS grep -F "Hello asdf"
126 username=qwer WVPASS run_server console | tee /dev/stderr | WVPASS grep -F "Hello qwer"
129 WVSTART "Missing console_cmd results in failure"
130 NOVABOOT_SHELL_CONFIG="/dev/null" WVFAIL run_server console
132 WVSTART "console_cmd may contain a shell function name"
134 export NOVABOOT_SHELL_CONFIG="./.novaboot-shell"
135 WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'console_cmd () { echo Hello user; }
136 console_cmd=console_cmd'
137 WVPASS run_server console | tee /dev/stderr | WVPASS grep -F "Hello user"
140 if [ -n "$DEB_HOST_ARCH" ]; then
141 echo >&2 "Skipping server tests in Debian package build, because these cannot pass."
145 SHELLRC="$NBT_HOME/.novaboot-shell"
146 TFTPROOT="$NBT_HOME/tftproot"
147 AUTH="$NBT_HOME/.ssh/authorized_keys"
148 sudo_() { sudo -u novaboot-test "$@"; }
150 WVSTART "Create and check ssh keys needed for following tests"
151 # Start our custom ssh-agent to not mess up with the user's agent
153 trap 'ssh-agent -k' EXIT
154 WVPASS test -n "$SSH_AUTH_SOCK" || exit 1
155 if [ ! -f id_rsa ]; then
156 ssh-keygen -t rsa -C "generated by $0" -N '' -f ./id_rsa
158 WVPASS ssh-add ./id_rsa
160 WVSTART "Setup SSH server's admin key"
161 WVPASS sudo_ mkdir -p $(dirname "$AUTH")
162 WVPASS sudo_ chmod 700 $(dirname "$AUTH")
163 WVPASS sudo_ tee "$AUTH" <<<"command=\"user test admin\" $(cat ./id_rsa.pub)"
166 WVSTART "Novaboot --ssh option (connect, rsync, reset)"
167 WVPASS sudo_ rm -rf "$TFTPROOT"
168 TS=$(date --rfc-3339=ns)
169 WVPASS sudo_ tee "$SHELLRC" <<EOF
171 reset_cmd="echo $TS > reset.stamp"
175 WVPASS novaboot --ssh novaboot-test@localhost <<EOF
178 # Check that file was copied to tftproot
179 WVPASS diff -u file <(sudo_ cat $TFTPROOT/file)
180 # Check that reset command was executed
181 WVPASS test "$TS" = "$(sudo_ cat "$NBT_HOME/reset.stamp")"
183 WVSTART "Novaboot --ssh remote config"
184 WVPASS sudo_ rm -rf "$TFTPROOT"
185 WVPASS sudo_ tee "$SHELLRC" <<EOF
194 WVPASS novaboot --ssh novaboot-test@localhost <<EOF
197 WVPASS diff -u file <(sudo_ cat "$TFTPROOT/file")
198 WVPASS sudo_ grep /prefix/file "$TFTPROOT/grub.cfg"
200 WVSTART "Novaboot --ssh remote config fails on non-safe options"
201 WVPASS sudo_ tee "$SHELLRC" <<EOF
209 WVFAIL novaboot --ssh novaboot-test@localhost <<<"load file < date"
210 stderr=$(novaboot --ssh novaboot-test@localhost <<<"load file < date" 2>&1 >/dev/null)
211 echo "$stderr" | WVPASS grep -q -F 'Unknown option: make'
212 echo "$stderr" | WVPASS grep -q -F 'Error processing configuration from the server'
214 WVSTART "Novaboot --ssh remote config fails on unknown arguments"
215 WVPASS sudo_ tee "$SHELLRC" <<EOF
223 WVFAIL novaboot --ssh novaboot-test@localhost <<<"load file < date"
224 novaboot --ssh novaboot-test@localhost <<<"load file < date" 2>&1 >/dev/null |\
225 WVPASS grep -F "Unsuported configuration received from the server: blablabla"
227 WVSTART "add-key subcommand"
228 WVPASS ssh-keygen -t ed25519 -N '' -f key
229 WVFAIL sudo_ grep new_user "$AUTH"
230 WVPASS ssh novaboot-test@localhost add-key new_user < key.pub
231 WVPASS sudo_ grep -F "user new_user" "$AUTH"
233 WVSTART "add-key user must not contain spaces"
234 WVPASS sudo_ cat "$AUTH" > auth
235 WVFAIL ssh novaboot-test@localhost add-key "new user" < /dev/null
236 WVPASS diff -u <(sudo_ cat "$AUTH") auth
238 WVSTART "add-key requires username"
239 WVPASS sudo_ cat "$AUTH" > auth
240 WVFAIL ssh novaboot-test@localhost add-key < /dev/null
241 WVPASS diff -u <(sudo_ cat "$AUTH") auth
243 WVSTART "Suggest using ssh -t for shell"
244 WVPASS ssh novaboot-test@localhost shell < /dev/null | WVPASS grep -e 'ssh -t'
245 echo exit|WVPASS ssh -tt novaboot-test@localhost shell | WVFAIL grep -e 'ssh -t'
249 # Hi-lock: (("^.*\\(?:WVSTART\\).*$" (0 (quote hi-black-b) t)))