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 SHELLRC="$NBT_HOME/.novaboot-shell"
107 TFTPROOT="$NBT_HOME/tftproot"
108 AUTH="$NBT_HOME/.ssh/authorized_keys"
109 sudo_() { sudo -u novaboot-test "$@"; }
111 WVSTART "Check that ssh-agent needed for following tests is running"
112 WVPASS test -n "$SSH_AUTH_SOCK" || exit 1
114 WVSTART "Setup SSH server's admin key"
115 WVPASS ssh-add -L > keys
116 WVPASS test $(wc -l < keys) -gt 0
117 WVPASS sudo_ mkdir -p $(dirname "$AUTH")
118 WVPASS sudo_ chmod 700 $(dirname "$AUTH")
119 WVPASS sudo_ tee "$AUTH" <<<"command=\"user test admin\" $(tail -n 1 keys)"
121 WVSTART "Novaboot --ssh option (connect, rsync, reset)"
122 WVPASS sudo_ rm -rf "$TFTPROOT"
123 TS=$(date --rfc-3339=ns)
124 WVPASS sudo_ tee "$SHELLRC" <<EOF
126 reset_cmd="echo $TS > reset.stamp"
130 WVPASS novaboot --ssh novaboot-test@localhost <<EOF
133 # Check that file was copied to tftproot
134 WVPASS diff -u file <(sudo_ cat $TFTPROOT/file)
135 # Check that reset command was executed
136 WVPASS test "$TS" = "$(sudo_ cat "$NBT_HOME/reset.stamp")"
138 WVSTART "Novaboot --ssh remote config"
139 WVPASS sudo_ rm -rf "$TFTPROOT"
140 WVPASS sudo_ tee "$SHELLRC" <<EOF
149 WVPASS novaboot --ssh novaboot-test@localhost <<EOF
152 WVPASS diff -u file <(sudo_ cat "$TFTPROOT/file")
153 WVPASS sudo_ grep /prefix/file "$TFTPROOT/grub.cfg"
155 WVSTART "Novaboot --ssh remote config fails on non-safe options"
156 WVPASS sudo_ tee "$SHELLRC" <<EOF
164 WVFAIL novaboot --ssh novaboot-test@localhost <<<"load file < date"
165 novaboot --ssh novaboot-test@localhost <<<"load file < date" 2>&1 >/dev/null |\
166 tee >(WVPASS grep -q -F 'Unknown option: make') \
167 >(WVPASS grep -q -F 'Error processing configuration from the server')
169 WVSTART "Novaboot --ssh remote config fails on unknown arguments"
170 WVPASS sudo_ tee "$SHELLRC" <<EOF
178 WVFAIL novaboot --ssh novaboot-test@localhost <<<"load file < date"
179 novaboot --ssh novaboot-test@localhost <<<"load file < date" 2>&1 >/dev/null |\
180 WVPASS grep -F "Unsuported configuration received from the server: blablabla"
182 WVSTART "add-key subcommand"
183 WVPASS ssh-keygen -t ed25519 -N '' -f key
184 WVFAIL sudo_ grep new_user "$AUTH"
185 WVPASS ssh novaboot-test@localhost add-key new_user < key.pub
186 WVPASS sudo_ grep -F "user new_user" "$AUTH"
188 WVSTART "add-key user must not contain spaces"
189 WVPASS sudo_ cat "$AUTH" > auth
190 WVFAIL ssh novaboot-test@localhost add-key "new user" < /dev/null
191 WVPASS diff -u <(sudo_ cat "$AUTH") auth
193 WVSTART "add-key requires username"
194 WVPASS sudo_ cat "$AUTH" > auth
195 WVFAIL ssh novaboot-test@localhost add-key < /dev/null
196 WVPASS diff -u <(sudo_ cat "$AUTH") auth
198 WVSTART "Suggest using ssh -t for shell"
199 WVPASS ssh novaboot-test@localhost shell < /dev/null | WVPASS grep -e 'ssh -t'
200 echo exit|WVPASS ssh -tt novaboot-test@localhost shell | WVFAIL grep -e 'ssh -t'
204 # Hi-lock: (("^.*\\(?:WVSTART\\).*$" (0 (quote hi-black-b) t)))