]> rtime.felk.cvut.cz Git - novaboot.git/blob - tests/server.wv
server: Make console the default command
[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 WVPASS diff -u file $TFTPROOT/file
134 WVPASS diff -u <(echo $TS) "$WV_BASE_DIR/home-novaboot-test/reset.stamp"
135
136
137 WVSTART "Novaboot --ssh remote config"
138 WVPASS rm -rf $TFTPROOT
139 WVPASS tee $SHELLRC <<EOF
140 console_cmd=cat
141 reset_cmd=true
142 target_config="\
143 --prefix=/prefix
144 --grub2
145 "
146 EOF
147 date > file
148 WVPASS novaboot --ssh novaboot-test@localhost <<EOF
149 load file
150 EOF
151 WVPASS diff -u file $TFTPROOT/file
152 WVPASS grep /prefix/file $TFTPROOT/grub.cfg
153
154 WVSTART "Novaboot --ssh remote config fails on non-safe options"
155 WVPASS tee $SHELLRC <<EOF
156 console_cmd=cat
157 reset_cmd=true
158 target_config="\
159 --prefix=/prefix
160 --make
161 "
162 EOF
163 WVFAIL novaboot --ssh novaboot-test@localhost <<EOF
164 load file < date
165 EOF
166
167 WVSTART "Novaboot --ssh remote config fails on unknown arguments"
168 WVPASS tee $SHELLRC <<EOF
169 console_cmd=cat
170 reset_cmd=true
171 target_config="\
172 --prefix=/prefix
173 blablabla
174 "
175 EOF
176 WVFAIL novaboot --ssh novaboot-test@localhost <<EOF
177 load file < date
178 EOF
179
180 WVSTART "add-key subcommand"
181 WVPASS ssh-keygen -t ed25519 -N '' -f key
182 WVFAIL grep new_user $AUTH
183 WVPASS ssh novaboot-test@localhost add-key new_user < key.pub
184 WVPASS grep new_user $AUTH
185
186 WVSTART "add-key user must not contain spaces"
187 WVPASS cp $AUTH auth
188 WVFAIL ssh novaboot-test@localhost add-key "new user" < /dev/null
189 WVPASS diff -u $AUTH auth
190
191 WVSTART "add-key requires username"
192 WVPASS cp $AUTH auth
193 WVFAIL ssh novaboot-test@localhost add-key < /dev/null
194 WVPASS diff -u $AUTH auth
195
196 WVSTART Suggest using ssh -t for shell
197 WVPASS ssh novaboot-test@localhost shell < /dev/null | WVPASS grep -e 'ssh -t'
198 echo exit|WVPASS ssh -tt novaboot-test@localhost shell | WVFAIL grep -e 'ssh -t'
199
200
201
202 # Hi-lock: (("^.*\\(?:WVSTART\\).*$" (0 (quote hi-black-b) t)))