]> rtime.felk.cvut.cz Git - novaboot.git/blob - tests/server.wv
tests: Convert server tests to use the account from last commit
[novaboot.git] / tests / server.wv
1 #!/bin/bash
2
3 cd $(dirname $0)
4 . wvtest.sh
5
6 NBT_HOME=$(getent passwd novaboot-test|cut -d: -f6)
7 export WV_BASE_DIR
8 export NOVABOOT_SHELL_CONFIG="$WV_BASE_DIR/.novaboot-shell"
9 cat <<EOF > $NOVABOOT_SHELL_CONFIG
10 console_cmd="/bin/sh -c 'while :; do sleep 0.1; date; done'"
11 reset_cmd="touch reset_done"
12 target_config='--prefix=asdf'
13 EOF
14
15 function run_server() {
16     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}"
17 }
18
19 function exec_server() {
20     local exec
21     exec=exec
22     run_server "$@"
23 }
24
25 WVSTART Help subcommand
26 WVPASS run_server help | WVPASS tee log
27 WVPASS grep 'Target commands:' log
28 WVFAIL grep 'add-key' log
29
30 WVSTART Get-config command works
31 run_server get-config > log
32 WVPASS grep -e '^--prefix=asdf$' log
33
34 WVSTART "Multi-word commands work when user not specified"
35 WVPASS $WV_BASE_DIR/../server/novaboot-shell -c "help xxx" | WVPASS tee log
36 WVPASS grep 'Target commands:' log
37
38 WVSTART "Console prints a 'connected' message"
39 coproc exec_server console
40 WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${COPROC[0]}
41 kill $COPROC_PID; wait
42
43 WVSTART "Console command is executed without any argument"
44 coproc exec_server
45 WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${COPROC[0]}
46 kill $COPROC_PID; wait
47
48 WVSTART 'Second connection to console prints queue'
49 coproc console1 { exec_server console; }
50 WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${console1[0]}
51 coproc console2 { exec_server console; }
52 WVPASS sed -e '/Target is occupied by:/q0' <&${console2[0]}
53 kill $console1_PID $console2_PID; wait
54
55 WVSTART 'Printed queue contains correct username'
56 coproc console1 { username=my_cool_username exec_server console; }
57 WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${console1[0]}
58 coproc console2 { username=another_username exec_server console; }
59 WVPASS sed -e '/my_cool_username/q0' -e '3q1' <&${console2[0]}
60 kill $console1_PID $console2_PID; wait
61
62 WVSTART Admin sees help for admin subcommands
63 admin=1 run_server help > log
64 WVPASS grep 'add-key' log
65
66 WVSTART Only admin can run shell
67 WVFAIL run_server shell
68 admin=1 WVPASS run_server shell < /dev/null
69
70 WVSTART 'Cannot reset when somebody else is connected to console'
71 coproc console1 { exec_server console; }
72 WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${console1[0]}
73 coproc console2 { run_server reset; }
74 WVPASS sed -e '/Target is occupied by:/q0' <&${console2[0]}
75 WVPASS test ! -e reset_done
76 WVPASS kill $console1_PID $console2_PID; wait
77
78 WVSTART "Can reset when I'm connected to console"
79 coproc exec_server console
80 WVPASS sed -e '/novaboot-shell: Connected/q0' <&${COPROC[0]}
81 WVPASS run_server reset
82 WVPASS test -e reset_done
83 WVPASS kill $COPROC_PID
84
85 WVSTART "Quoting of config variables"
86 (
87     export NOVABOOT_SHELL_CONFIG="./.novaboot-shell"
88
89     WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'reset_cmd="touch file1 file2"'
90     WVPASS run_server reset
91     WVPASS test -e file1 -a -e file2
92
93     WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'reset_cmd="touch \"file1 file2\""'
94     WVPASS run_server reset
95     WVPASS test -e "file1 file2"
96
97     WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'reset_cmd="touch \"file1   file2\""'
98     WVPASS run_server reset
99     WVPASS test -e "file1   file2"
100
101     WVPASS tee "$NOVABOOT_SHELL_CONFIG" <<<'reset_cmd="touch \"\\\"file1 file2\\\"\""'
102     WVPASS run_server reset
103     WVPASS test -e '"file1 file2"'
104 )
105
106 SHELLRC="$NBT_HOME/.novaboot-shell"
107 TFTPROOT="$NBT_HOME/tftproot"
108 AUTH="$NBT_HOME/.ssh/authorized_keys"
109 sudo_() { sudo -u novaboot-test "$@"; }
110
111 WVSTART "Check that ssh-agent needed for following tests is running"
112 WVPASS test -n "$SSH_AUTH_SOCK" || exit 1
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 sudo_ mkdir -p $(dirname "$AUTH")
118 WVPASS sudo_ chmod 700 $(dirname "$AUTH")
119 WVPASS sudo_ tee "$AUTH" <<<"command=\"user test admin\" $(tail -n 1 keys)"
120
121 WVSTART "Novaboot --ssh option (connect, rsync, reset)"
122 WVPASS sudo_ rm -rf "$TFTPROOT"
123 TS=$(date --rfc-3339=ns)
124 WVPASS sudo_ 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 <(sudo_ cat $TFTPROOT/file)
135 # Check that reset command was executed
136 WVPASS test "$TS" = "$(sudo_ cat "$NBT_HOME/reset.stamp")"
137
138 WVSTART "Novaboot --ssh remote config"
139 WVPASS sudo_ rm -rf "$TFTPROOT"
140 WVPASS sudo_ tee "$SHELLRC" <<EOF
141 console_cmd=cat
142 reset_cmd=true
143 target_config="\
144 --prefix=/prefix
145 --grub2
146 "
147 EOF
148 date > file
149 WVPASS novaboot --ssh novaboot-test@localhost <<EOF
150 load file
151 EOF
152 WVPASS diff -u file <(sudo_ cat "$TFTPROOT/file")
153 WVPASS sudo_ grep /prefix/file "$TFTPROOT/grub.cfg"
154
155 WVSTART "Novaboot --ssh remote config fails on non-safe options"
156 WVPASS sudo_ tee "$SHELLRC" <<EOF
157 console_cmd=cat
158 reset_cmd=true
159 target_config="\
160 --prefix=/prefix
161 --make
162 "
163 EOF
164 WVFAIL novaboot --ssh novaboot-test@localhost <<<"load file < date"
165 novaboot --ssh novaboot-test@localhost <<<"load file < date" 2>&1 >/dev/null |\
166     tee >(WVPASS grep -q -F 'Unknown option: make') \
167         >(WVPASS grep -q -F 'Error processing configuration from the server')
168
169 WVSTART "Novaboot --ssh remote config fails on unknown arguments"
170 WVPASS sudo_ tee "$SHELLRC" <<EOF
171 console_cmd=cat
172 reset_cmd=true
173 target_config="\
174 --prefix=/prefix
175 blablabla
176 "
177 EOF
178 WVFAIL novaboot --ssh novaboot-test@localhost <<<"load file < date"
179 novaboot --ssh novaboot-test@localhost <<<"load file < date" 2>&1 >/dev/null |\
180     WVPASS grep -F "Unsuported configuration received from the server: blablabla"
181
182 WVSTART "add-key subcommand"
183 WVPASS ssh-keygen -t ed25519 -N '' -f key
184 WVFAIL sudo_ grep new_user "$AUTH"
185 WVPASS ssh novaboot-test@localhost add-key new_user < key.pub
186 WVPASS sudo_ grep -F "user new_user" "$AUTH"
187
188 WVSTART "add-key user must not contain spaces"
189 WVPASS sudo_ cat "$AUTH" > auth
190 WVFAIL ssh novaboot-test@localhost add-key "new user" < /dev/null
191 WVPASS diff -u <(sudo_ cat "$AUTH") auth
192
193 WVSTART "add-key requires username"
194 WVPASS sudo_ cat "$AUTH" > auth
195 WVFAIL ssh novaboot-test@localhost add-key < /dev/null
196 WVPASS diff -u <(sudo_ cat "$AUTH") auth
197
198 WVSTART "Suggest using ssh -t for shell"
199 WVPASS ssh novaboot-test@localhost shell < /dev/null | WVPASS grep -e 'ssh -t'
200 echo exit|WVPASS ssh -tt novaboot-test@localhost shell | WVFAIL grep -e 'ssh -t'
201
202
203
204 # Hi-lock: (("^.*\\(?:WVSTART\\).*$" (0 (quote hi-black-b) t)))