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"
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 Help is printed without any arguments
30 # Invocation with SSH_ORIGINAL_COMMAND
31 WVPASS run_server help | WVPASS tee log
32 WVPASS grep 'Target commands:' log
33 # Invocation without SSH_ORIGINAL_COMMAND
34 WVPASS $WV_BASE_DIR/../server/novaboot-shell | WVPASS tee log2
35 WVPASS grep 'Target commands:' log2
37 WVSTART Get-config command works
38 run_server get-config > log
39 WVPASS grep -e '^--prefix=asdf$' log
41 WVSTART "Multi-word commands work when user not specified"
42 WVPASS $WV_BASE_DIR/../server/novaboot-shell -c "help xxx" | WVPASS tee log
43 WVPASS grep 'Target commands:' log
45 WVSTART "Console prints a 'connected' message"
46 coproc exec_server console
47 WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${COPROC[0]}
48 kill $COPROC_PID; wait
50 WVSTART 'Second connection to console prints queue'
51 coproc console1 { exec_server console; }
52 WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${console1[0]}
53 coproc console2 { exec_server console; }
54 WVPASS sed -e '/Target is occupied by:/q0' <&${console2[0]}
55 kill $console1_PID $console2_PID; wait
57 WVSTART 'Printed queue contains correct username'
58 coproc console1 { username=my_cool_username exec_server console; }
59 WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${console1[0]}
60 coproc console2 { username=another_username exec_server console; }
61 WVPASS sed -e '/my_cool_username/q0' -e '3q1' <&${console2[0]}
62 kill $console1_PID $console2_PID; wait
64 WVSTART Admin sees help for admin subcommands
65 admin=1 run_server help > log
66 WVPASS grep 'add-key' log
68 WVSTART Only admin can run shell
69 WVFAIL run_server shell
70 admin=1 WVPASS run_server shell < /dev/null
72 WVSTART 'Cannot reset when somebody else is connected to console'
73 coproc console1 { exec_server console; }
74 WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${console1[0]}
75 coproc console2 { run_server reset; }
76 WVPASS sed -e '/Target is occupied by:/q0' <&${console2[0]}
77 WVPASS test ! -e reset
78 WVPASS kill $console1_PID $console2_PID; wait
80 WVSTART "Can reset when I'm connected to console"
81 coproc exec_server console
82 WVPASS sed -e '/novaboot-shell: Connected/q0' <&${COPROC[0]}
83 WVPASS run_server reset
85 WVPASS kill $COPROC_PID
87 WVSTART "Quoting of config variables"
89 export NOVABOOT_SHELL_CONFIG="./.novaboot-shell"
91 WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'reset_cmd="touch file1 file2"'
92 WVPASS run_server reset
93 WVPASS test -e file1 -a -e file2
95 WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'reset_cmd="touch \"file1 file2\""'
96 WVPASS run_server reset
97 WVPASS test -e "file1 file2"
99 WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'reset_cmd="touch \"file1 file2\""'
100 WVPASS run_server reset
101 WVPASS test -e "file1 file2"
103 WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'reset_cmd="touch \"\\\"file1 file2\\\"\""'
104 WVPASS run_server reset
105 WVPASS test -e '"file1 file2"'
108 SHELLRC="$WV_BASE_DIR/home-novaboot-test/.novaboot-shell"
109 TFTPROOT="$WV_BASE_DIR/home-novaboot-test/tftproot"
110 AUTH="$WV_BASE_DIR/home-novaboot-test/.ssh/authorized_keys"
112 WVSTART "Setup SSH server's admin key"
113 WVPASS ssh-add -L > keys
114 WVPASS test $(wc -l < keys) -gt 0
115 WVPASS mkdir -p $(dirname $AUTH)
116 WVPASS chmod 700 $(dirname $AUTH)
117 WVPASS echo 'command="user test admin"' $(tail -n 1 keys) > $AUTH
119 WVSTART "Novaboot --ssh option (connect, rsync, reset)"
120 WVPASS rm -rf $TFTPROOT
121 TS=$(date --rfc-3339=ns)
122 WVPASS tee $SHELLRC <<EOF
124 reset_cmd="echo $TS > reset.stamp"
128 WVPASS novaboot --ssh novaboot-test@localhost <<EOF
131 WVPASS diff -u file $TFTPROOT/file
132 WVPASS diff -u <(echo $TS) "$WV_BASE_DIR/home-novaboot-test/reset.stamp"
135 WVSTART "Novaboot --ssh remote config"
136 WVPASS rm -rf $TFTPROOT
137 WVPASS tee $SHELLRC <<EOF
146 WVPASS novaboot --ssh novaboot-test@localhost <<EOF
149 WVPASS diff -u file $TFTPROOT/file
150 WVPASS grep /prefix/file $TFTPROOT/grub.cfg
152 WVSTART "Novaboot --ssh remote config fails on non-safe options"
153 WVPASS tee $SHELLRC <<EOF
161 WVFAIL novaboot --ssh novaboot-test@localhost <<EOF
165 WVSTART "Novaboot --ssh remote config fails on unknown arguments"
166 WVPASS tee $SHELLRC <<EOF
174 WVFAIL novaboot --ssh novaboot-test@localhost <<EOF
178 WVSTART "add-key subcommand"
179 WVPASS ssh-keygen -t ed25519 -N '' -f key
180 WVFAIL grep new_user $AUTH
181 WVPASS ssh novaboot-test@localhost add-key new_user < key.pub
182 WVPASS grep new_user $AUTH
184 WVSTART "add-key user must not contain spaces"
186 WVFAIL ssh novaboot-test@localhost add-key "new user" < /dev/null
187 WVPASS diff -u $AUTH auth
189 WVSTART "add-key requires username"
191 WVFAIL ssh novaboot-test@localhost add-key < /dev/null
192 WVPASS diff -u $AUTH auth
194 # Hi-lock: (("^.*\\(?:WVSTART\\).*$" (0 (quote hi-black-b) t)))