]> rtime.felk.cvut.cz Git - novaboot.git/blob - tests/server.wv
491eebbd23924928a3b839d3129e19ad45723c31
[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_done"
11 target_config='--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 WVPASS run_server help | WVPASS tee log
26 WVPASS grep 'Target commands:' log
27 WVFAIL grep 'add-key' log
28
29 WVSTART Get-config command works
30 run_server get-config > log
31 WVPASS grep -e '^--prefix=asdf$' log
32
33 WVSTART "Multi-word commands work when user not specified"
34 WVPASS $WV_BASE_DIR/../server/novaboot-shell -c "help xxx" | WVPASS tee log
35 WVPASS grep 'Target commands:' 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 "Console command is executed without any argument"
43 coproc exec_server
44 WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${COPROC[0]}
45 kill $COPROC_PID; wait
46
47 WVSTART 'Second connection to console prints queue'
48 coproc console1 { exec_server console; }
49 WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${console1[0]}
50 coproc console2 { exec_server console; }
51 WVPASS sed -e '/Target is occupied by:/q0' <&${console2[0]}
52 kill $console1_PID $console2_PID; wait
53
54 WVSTART 'Printed queue contains correct username'
55 coproc console1 { username=my_cool_username exec_server console; }
56 WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${console1[0]}
57 coproc console2 { username=another_username exec_server console; }
58 WVPASS sed -e '/my_cool_username/q0' -e '3q1' <&${console2[0]}
59 kill $console1_PID $console2_PID; wait
60
61 WVSTART Admin sees help for admin subcommands
62 admin=1 run_server help > log
63 WVPASS grep 'add-key' log
64
65 WVSTART Only admin can run shell
66 WVFAIL run_server shell
67 admin=1 WVPASS run_server shell < /dev/null
68
69 WVSTART 'Cannot reset when somebody else is connected to console'
70 coproc console1 { exec_server console; }
71 WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${console1[0]}
72 coproc console2 { run_server reset; }
73 WVPASS sed -e '/Target is occupied by:/q0' <&${console2[0]}
74 WVPASS test ! -e reset_done
75 WVPASS kill $console1_PID $console2_PID; wait
76
77 WVSTART "Can reset when I'm connected to console"
78 coproc exec_server console
79 WVPASS sed -e '/novaboot-shell: Connected/q0' <&${COPROC[0]}
80 WVPASS run_server reset
81 WVPASS test -e reset_done
82 WVPASS kill $COPROC_PID
83
84 WVSTART "Quoting of config variables"
85 (
86     export NOVABOOT_SHELL_CONFIG="./.novaboot-shell"
87
88     WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'reset_cmd="touch file1 file2"'
89     WVPASS run_server reset
90     WVPASS test -e file1 -a -e file2
91
92     WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'reset_cmd="touch \"file1 file2\""'
93     WVPASS run_server reset
94     WVPASS test -e "file1 file2"
95
96     WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'reset_cmd="touch \"file1   file2\""'
97     WVPASS run_server reset
98     WVPASS test -e "file1   file2"
99
100     WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'reset_cmd="touch \"\\\"file1 file2\\\"\""'
101     WVPASS run_server reset
102     WVPASS test -e '"file1 file2"'
103 )
104
105 SHELLRC="$WV_BASE_DIR/home-novaboot-test/.novaboot-shell"
106 TFTPROOT="$WV_BASE_DIR/home-novaboot-test/tftproot"
107 AUTH="$WV_BASE_DIR/home-novaboot-test/.ssh/authorized_keys"
108
109 if [ -z "$SSH_AUTH_SOCK" ]; then
110     WVSTART "!!! Skipping SSH tests because no ssh-agent was detected !!!"
111     exit 0
112 fi
113
114 WVSTART "Setup SSH server's admin key"
115 WVPASS ssh-add -L > keys
116 WVPASS test $(wc -l < keys) -gt 0
117 WVPASS mkdir -p $(dirname $AUTH)
118 WVPASS chmod 700 $(dirname $AUTH)
119 WVPASS echo 'command="user test admin"' $(tail -n 1 keys) > $AUTH
120
121 WVSTART "Novaboot --ssh option (connect, rsync, reset)"
122 WVPASS rm -rf $TFTPROOT
123 TS=$(date --rfc-3339=ns)
124 WVPASS tee $SHELLRC <<EOF
125 console_cmd=cat
126 reset_cmd="echo $TS > reset.stamp"
127 target_config=""
128 EOF
129 date > file
130 WVPASS novaboot --ssh novaboot-test@localhost <<EOF
131 copy file
132 EOF
133 # Check that file was copied to tftproot
134 WVPASS diff -u file $TFTPROOT/file
135 # Check that reset command was executed
136 WVPASS diff -u <(echo $TS) "$WV_BASE_DIR/home-novaboot-test/reset.stamp"
137
138
139 WVSTART "Novaboot --ssh remote config"
140 WVPASS rm -rf $TFTPROOT
141 WVPASS tee $SHELLRC <<EOF
142 console_cmd=cat
143 reset_cmd=true
144 target_config="\
145 --prefix=/prefix
146 --grub2
147 "
148 EOF
149 date > file
150 WVPASS novaboot --ssh novaboot-test@localhost <<EOF
151 load file
152 EOF
153 WVPASS diff -u file $TFTPROOT/file
154 WVPASS grep /prefix/file $TFTPROOT/grub.cfg
155
156 WVSTART "Novaboot --ssh remote config fails on non-safe options"
157 WVPASS tee $SHELLRC <<EOF
158 console_cmd=cat
159 reset_cmd=true
160 target_config="\
161 --prefix=/prefix
162 --make
163 "
164 EOF
165 WVFAIL novaboot --ssh novaboot-test@localhost <<<"load file < date"
166 novaboot --ssh novaboot-test@localhost <<<"load file < date" 2>&1 >/dev/null |\
167     tee >(WVPASS grep -q -F 'Unknown option: make') |\
168     tee >(WVPASS grep -q -F 'Error processing configuration from the server')
169
170 WVSTART "Novaboot --ssh remote config fails on unknown arguments"
171 WVPASS tee $SHELLRC <<EOF
172 console_cmd=cat
173 reset_cmd=true
174 target_config="\
175 --prefix=/prefix
176 blablabla
177 "
178 EOF
179 WVFAIL novaboot --ssh novaboot-test@localhost <<<"load file < date"
180 novaboot --ssh novaboot-test@localhost <<<"load file < date" 2>&1 >/dev/null |\
181     WVPASS grep --color=always -q .
182
183
184 WVSTART "add-key subcommand"
185 WVPASS ssh-keygen -t ed25519 -N '' -f key
186 WVFAIL grep new_user $AUTH
187 WVPASS ssh novaboot-test@localhost add-key new_user < key.pub
188 WVPASS grep new_user $AUTH
189
190 WVSTART "add-key user must not contain spaces"
191 WVPASS cp $AUTH auth
192 WVFAIL ssh novaboot-test@localhost add-key "new user" < /dev/null
193 WVPASS diff -u $AUTH auth
194
195 WVSTART "add-key requires username"
196 WVPASS cp $AUTH auth
197 WVFAIL ssh novaboot-test@localhost add-key < /dev/null
198 WVPASS diff -u $AUTH auth
199
200 WVSTART Suggest using ssh -t for shell
201 WVPASS ssh novaboot-test@localhost shell < /dev/null | WVPASS grep -e 'ssh -t'
202 echo exit|WVPASS ssh -tt novaboot-test@localhost shell | WVFAIL grep -e 'ssh -t'
203
204
205
206 # Hi-lock: (("^.*\\(?:WVSTART\\).*$" (0 (quote hi-black-b) t)))