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
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
26 WVPASS grep 'Target commands:' log
27 WVFAIL grep 'add-key' log
29 WVSTART Help is printed without any arguments
31 WVPASS grep 'Target commands:' log
33 WVSTART Get-config command works
34 run_server get-config > log
35 WVPASS grep -e '^--prefix=asdf$' log
37 WVSTART "Console prints a 'connected' message"
38 coproc exec_server console
39 WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${COPROC[0]}
40 kill $COPROC_PID; wait
42 WVSTART 'Second connection to console prints queue'
43 coproc console1 { exec_server console; }
44 WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${console1[0]}
45 coproc console2 { exec_server console; }
46 WVPASS sed -e '/Target is occupied by:/q0' <&${console2[0]}
47 kill $console1_PID $console2_PID; wait
49 WVSTART 'Printed queue contains correct username'
50 coproc console1 { username=my_cool_username exec_server console; }
51 WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${console1[0]}
52 coproc console2 { username=another_username exec_server console; }
53 WVPASS sed -e '/my_cool_username/q0' -e '3q1' <&${console2[0]}
54 kill $console1_PID $console2_PID; wait
56 WVSTART Admin sees help for admin subcommands
57 admin=1 run_server help > log
58 WVPASS grep 'add-key' log
60 WVSTART Only admin can run shell
61 WVFAIL run_server shell
62 admin=1 WVPASS run_server shell < /dev/null
64 WVSTART 'Cannot reset when somebody else is connected to console'
65 coproc console1 { exec_server console; }
66 WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${console1[0]}
67 coproc console2 { run_server reset; }
68 WVPASS sed -e '/Target is occupied by:/q0' <&${console2[0]}
69 WVPASS test ! -e reset
70 WVPASS kill $console1_PID $console2_PID; wait
72 WVSTART "Can reset when I'm connected to console"
73 coproc exec_server console
74 WVPASS sed -e '/novaboot-shell: Connected/q0' <&${COPROC[0]}
75 WVPASS run_server reset
77 WVPASS kill $COPROC_PID
79 WVSTART "Quoting of config variables"
81 export NOVABOOT_SHELL_CONFIG="./.novaboot-shell"
83 WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'reset_cmd="touch file1 file2"'
84 WVPASS run_server reset
85 WVPASS test -e file1 -a -e file2
87 WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'reset_cmd="touch \"file1 file2\""'
88 WVPASS run_server reset
89 WVPASS test -e "file1 file2"
91 WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'reset_cmd="touch \"file1 file2\""'
92 WVPASS run_server reset
93 WVPASS test -e "file1 file2"
95 WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'reset_cmd="touch \"\\\"file1 file2\\\"\""'
96 WVPASS run_server reset
97 WVPASS test -e '"file1 file2"'
100 SHELLRC="$WV_BASE_DIR/home-novaboot-test/.novaboot-shell"
101 TFTPROOT="$WV_BASE_DIR/home-novaboot-test/tftproot"
102 AUTH="$WV_BASE_DIR/home-novaboot-test/.ssh/authorized_keys"
104 WVSTART "Setup SSH server's admin key"
105 WVPASS ssh-add -L > keys
106 WVPASS test $(wc -l < keys) -gt 0
107 WVPASS mkdir -p $(dirname $AUTH)
108 WVPASS chmod 700 $(dirname $AUTH)
109 WVPASS echo 'command="user test admin"' $(tail -n 1 keys) > $AUTH
111 WVSTART "Novaboot --ssh option (connect, rsync, reset)"
112 WVPASS rm -rf $TFTPROOT
113 TS=$(date --rfc-3339=ns)
114 WVPASS tee $SHELLRC <<EOF
116 reset_cmd="echo $TS > reset.stamp"
120 WVPASS novaboot --ssh novaboot-test@localhost <<EOF
123 WVPASS diff -u file $TFTPROOT/file
124 WVPASS diff -u <(echo $TS) "$WV_BASE_DIR/home-novaboot-test/reset.stamp"
127 WVSTART "Novaboot --ssh remote config"
128 WVPASS rm -rf $TFTPROOT
129 WVPASS tee $SHELLRC <<EOF
132 target_config() { echo --prefix=/prefix; echo --grub2; }
135 WVPASS novaboot --ssh novaboot-test@localhost <<EOF
138 WVPASS diff -u file $TFTPROOT/file
139 WVPASS grep /prefix/file $TFTPROOT/grub.cfg
141 WVSTART "Novaboot --ssh remote config fails on non-safe options"
142 WVPASS tee $SHELLRC <<EOF
145 config() { echo --prefix=/prefix; echo --make; }
147 WVFAIL novaboot --ssh novaboot-test@localhost <<EOF
151 WVSTART "Novaboot --ssh remote config fails on unknown arguments"
152 WVPASS tee $SHELLRC <<EOF
155 target_config() { echo --prefix=/prefix; echo blablabla; }
157 WVFAIL novaboot --ssh novaboot-test@localhost <<EOF
161 WVSTART "add-key subcommand"
162 WVPASS ssh-keygen -t ed25519 -N '' -f key
163 WVFAIL grep new_user $AUTH
164 WVPASS ssh novaboot-test@localhost add-key new_user < key.pub
165 WVPASS grep new_user $AUTH
167 WVSTART "add-key user must not contain spaces"
169 WVFAIL ssh novaboot-test@localhost add-key "new user" < /dev/null
170 WVPASS diff -u $AUTH auth
172 WVSTART "add-key requires username"
174 WVFAIL ssh novaboot-test@localhost add-key < /dev/null
175 WVPASS diff -u $AUTH auth