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