]> rtime.felk.cvut.cz Git - novaboot.git/blob - tests/server.wv
Properly terminate remote command even when it ignores SIGHUP
[novaboot.git] / tests / server.wv
1 #!/bin/bash
2
3 cd $(dirname $0)
4 . wvtest.sh
5
6 export WV_BASE_DIR
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
12 EOF
13
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}"
16 }
17
18 function exec_server() {
19     local exec
20     exec=exec
21     run_server "$@"
22 }
23
24 WVSTART Help subcommand
25 run_server help > log
26 WVPASS grep 'Target commands:' log
27 WVFAIL grep 'add-key' log
28
29 WVSTART Help is printed without any arguments
30 run_server > log
31 WVPASS grep 'Target commands:' log
32
33 WVSTART Get-config command works
34 run_server get-config > log
35 WVPASS grep -e '^--prefix=asdf$' log
36
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
41
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
48
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
55
56 WVSTART Admin sees help for admin subcommands
57 admin=1 run_server help > log
58 WVPASS grep 'add-key' log
59
60 WVSTART Only admin can run shell
61 WVFAIL run_server shell
62 admin=1 WVPASS run_server shell < /dev/null
63
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
71
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
76 WVPASS test -e reset
77 WVPASS kill $COPROC_PID
78
79 WVSTART "Quoting of config variables"
80 (
81     export NOVABOOT_SHELL_CONFIG="./.novaboot-shell"
82
83     WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'reset_cmd="touch file1 file2"'
84     WVPASS run_server reset
85     WVPASS test -e file1 -a -e file2
86
87     WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'reset_cmd="touch \"file1 file2\""'
88     WVPASS run_server reset
89     WVPASS test -e "file1 file2"
90
91     WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'reset_cmd="touch \"file1   file2\""'
92     WVPASS run_server reset
93     WVPASS test -e "file1   file2"
94
95     WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'reset_cmd="touch \"\\\"file1 file2\\\"\""'
96     WVPASS run_server reset
97     WVPASS test -e '"file1 file2"'
98 )
99
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"
103
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
110
111 WVSTART "Novaboot --ssh option (connect, rsync, reset)"
112 WVPASS rm -rf $TFTPROOT
113 TS=$(date --rfc-3339=ns)
114 WVPASS tee $SHELLRC <<EOF
115 console_cmd=cat
116 reset_cmd="echo $TS > reset.stamp"
117 target_config() :
118 EOF
119 date > file
120 WVPASS novaboot --ssh novaboot-test@localhost <<EOF
121 copy file
122 EOF
123 WVPASS diff -u file $TFTPROOT/file
124 WVPASS diff -u <(echo $TS) "$WV_BASE_DIR/home-novaboot-test/reset.stamp"
125
126
127 WVSTART "Novaboot --ssh remote config"
128 WVPASS rm -rf $TFTPROOT
129 WVPASS tee $SHELLRC <<EOF
130 console_cmd=cat
131 reset_cmd=true
132 target_config() { echo --prefix=/prefix; echo --grub2; }
133 EOF
134 date > file
135 WVPASS novaboot --ssh novaboot-test@localhost <<EOF
136 load file
137 EOF
138 WVPASS diff -u file $TFTPROOT/file
139 WVPASS grep /prefix/file $TFTPROOT/grub.cfg
140
141 WVSTART "Novaboot --ssh remote config fails on non-safe options"
142 WVPASS tee $SHELLRC <<EOF
143 console_cmd=cat
144 reset_cmd=true
145 config() { echo --prefix=/prefix; echo --make; }
146 EOF
147 WVFAIL novaboot --ssh novaboot-test@localhost <<EOF
148 load file < date
149 EOF
150
151 WVSTART "Novaboot --ssh remote config fails on unknown arguments"
152 WVPASS tee $SHELLRC <<EOF
153 console_cmd=cat
154 reset_cmd=true
155 target_config() { echo --prefix=/prefix; echo blablabla; }
156 EOF
157 WVFAIL novaboot --ssh novaboot-test@localhost <<EOF
158 load file < date
159 EOF
160
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
166
167 WVSTART "add-key user must not contain spaces"
168 WVPASS cp $AUTH auth
169 WVFAIL ssh novaboot-test@localhost add-key "new user" < /dev/null
170 WVPASS diff -u $AUTH auth
171
172 WVSTART "add-key requires username"
173 WVPASS cp $AUTH auth
174 WVFAIL ssh novaboot-test@localhost add-key < /dev/null
175 WVPASS diff -u $AUTH auth