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() echo --prefix=asdf
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 function exec_server() {
26 WVSTART Help subcommand
28 WVPASS grep 'Target commands:' log
29 WVFAIL grep 'add-key' log
31 WVSTART Help is printed without any arguments
33 WVPASS grep 'Target commands:' log
35 WVSTART Get-config command works
36 run_server get-config > log
37 WVPASS grep -e '^--prefix=asdf$' log
39 WVSTART "Console prints a 'connected' message"
40 coproc exec_server console
41 WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${COPROC[0]}
42 kill $COPROC_PID; wait
44 WVSTART 'Second connection to console prints queue'
45 coproc console1 { exec_server console; }
46 WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${console1[0]}
47 coproc console2 { exec_server console; }
48 WVPASS sed -e '/Target is occupied by:/q0' <&${console2[0]}
49 kill $console1_PID $console2_PID; wait
51 WVSTART 'Printed queue contains correct username'
52 coproc console1 { username=my_cool_username exec_server console; }
53 WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${console1[0]}
54 coproc console2 { username=another_username exec_server console; }
55 WVPASS sed -e '/my_cool_username/q0' -e '3q1' <&${console2[0]}
56 kill $console1_PID $console2_PID; wait
58 WVSTART Admin sees help for admin subcommands
59 admin=1 run_server help > log
60 WVPASS grep 'add-key' log
62 WVSTART 'Cannot reset when somebody else is connected to console'
63 coproc console1 { exec_server console; }
64 WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${console1[0]}
65 coproc console2 { run_server reset; }
66 WVPASS sed -e '/Target is occupied by:/q0' <&${console2[0]}
67 WVPASS test ! -e reset
68 WVPASS kill $console1_PID $console2_PID; wait
70 WVSTART "Can reset when I'm connected to console"
71 coproc exec_server console
72 WVPASS sed -e '/novaboot-shell: Connected/q0' <&${COPROC[0]}
73 WVPASS run_server reset
75 WVPASS kill $COPROC_PID
79 SHELLRC="$WV_BASE_DIR/home-novaboot-test/.novaboot-shell"
80 TFTPROOT="$WV_BASE_DIR/home-novaboot-test/tftproot"
81 AUTH="$WV_BASE_DIR/home-novaboot-test/.ssh/authorized_keys"
83 WVSTART "Setup SSH server's admin key"
84 WVPASS ssh-add -L > keys
85 WVPASS test $(wc -l < keys) -gt 0
86 WVPASS echo 'command="user test admin"' $(tail -n 1 keys) > $AUTH
88 WVSTART "Novaboot --ssh option (connect, rsync, reset)"
89 WVPASS rm -rf $TFTPROOT
90 TS=$(date --rfc-3339=ns)
91 WVPASS tee $SHELLRC <<EOF
93 reset_cmd="echo $TS > reset.stamp"
97 WVPASS novaboot --ssh novaboot-test@localhost <<EOF
100 WVPASS diff -u file $TFTPROOT/file
101 WVPASS diff -u <(echo $TS) "$WV_BASE_DIR/home-novaboot-test/reset.stamp"
104 WVSTART "Novaboot --ssh remote config"
105 WVPASS rm -rf $TFTPROOT
106 WVPASS tee $SHELLRC <<EOF
109 target_config() { echo --prefix=/prefix; echo --grub2; }
112 WVPASS novaboot --ssh novaboot-test@localhost <<EOF
115 WVPASS diff -u file $TFTPROOT/file
116 WVPASS grep /prefix/file $TFTPROOT/grub.cfg
118 WVSTART "Novaboot --ssh remote config fails on non-safe options"
119 WVPASS tee $SHELLRC <<EOF
122 config() { echo --prefix=/prefix; echo --make; }
124 WVFAIL novaboot --ssh novaboot-test@localhost <<EOF
128 WVSTART "Novaboot --ssh remote config fails on unknown arguments"
129 WVPASS tee $SHELLRC <<EOF
132 target_config() { echo --prefix=/prefix; echo blablabla; }
134 WVFAIL novaboot --ssh novaboot-test@localhost <<EOF
138 WVSTART "add-key subcommand"
139 WVPASS ssh-keygen -t ed25519 -N '' -f key
140 WVFAIL grep new_user $AUTH
141 WVPASS ssh novaboot-test@localhost add-key new_user < key.pub
142 WVPASS grep new_user $AUTH
144 WVSTART "add-key user must not contain spaces"
146 WVFAIL ssh novaboot-test@localhost add-key "new user" < /dev/null
147 WVPASS diff -u $AUTH auth
149 WVSTART "add-key requires username"
151 WVFAIL ssh novaboot-test@localhost add-key < /dev/null
152 WVPASS diff -u $AUTH auth