]> rtime.felk.cvut.cz Git - novaboot.git/blob - tests/server.wv
server: Give configuration variables more descriptive names
[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 export MAIN_PID=$$
15
16 function run_server() {
17     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}"
18 }
19
20 function exec_server() {
21     local exec
22     exec=exec
23     run_server "$@"
24 }
25
26 WVSTART Help subcommand
27 run_server help > log
28 WVPASS grep 'Target commands:' log
29 WVFAIL grep 'add-key' log
30
31 WVSTART Help is printed without any arguments
32 run_server > log
33 WVPASS grep 'Target commands:' log
34
35 WVSTART Get-config command works
36 run_server get-config > log
37 WVPASS grep -e '^--prefix=asdf$' log
38
39 WVSTART "Console prints a 'connected' message"
40 coproc exec_server console
41 WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${COPROC[0]}
42 kill $COPROC_PID; wait
43
44 WVSTART 'Second connection to console prints queue'
45 coproc console1 { exec_server console; }
46 WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${console1[0]}
47 coproc console2 { exec_server console; }
48 WVPASS sed -e '/Target is occupied by:/q0' <&${console2[0]}
49 kill $console1_PID $console2_PID; wait
50
51 WVSTART 'Printed queue contains correct username'
52 coproc console1 { username=my_cool_username exec_server console; }
53 WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${console1[0]}
54 coproc console2 { username=another_username exec_server console; }
55 WVPASS sed -e '/my_cool_username/q0' -e '3q1' <&${console2[0]}
56 kill $console1_PID $console2_PID; wait
57
58 WVSTART Admin sees help for admin subcommands
59 admin=1 run_server help > log
60 WVPASS grep 'add-key' log
61
62 WVSTART 'Cannot reset when somebody else is connected to console'
63 coproc console1 { exec_server console; }
64 WVPASS sed -e '/novaboot-shell: Connected/q0' -e '3q1' <&${console1[0]}
65 coproc console2 { run_server reset; }
66 WVPASS sed -e '/Target is occupied by:/q0' <&${console2[0]}
67 WVPASS test ! -e reset
68 WVPASS kill $console1_PID $console2_PID; wait
69
70 WVSTART "Can reset when I'm connected to console"
71 coproc exec_server console
72 WVPASS sed -e '/novaboot-shell: Connected/q0' <&${COPROC[0]}
73 WVPASS run_server reset
74 WVPASS test -e reset
75 WVPASS kill $COPROC_PID
76
77
78
79 SHELLRC="$WV_BASE_DIR/home-novaboot-test/.novaboot-shell"
80 TFTPROOT="$WV_BASE_DIR/home-novaboot-test/tftproot"
81 AUTH="$WV_BASE_DIR/home-novaboot-test/.ssh/authorized_keys"
82
83 WVSTART "Setup SSH server's admin key"
84 WVPASS ssh-add -L > keys
85 WVPASS test $(wc -l < keys) -gt 0
86 WVPASS echo 'command="user test admin"' $(tail -n 1 keys) > $AUTH
87
88 WVSTART "Novaboot --ssh option (connect, rsync, reset)"
89 WVPASS rm -rf $TFTPROOT
90 TS=$(date --rfc-3339=ns)
91 WVPASS tee $SHELLRC <<EOF
92 console_cmd=cat
93 reset_cmd="echo $TS > reset.stamp"
94 target_config() :
95 EOF
96 date > file
97 WVPASS novaboot --ssh novaboot-test@localhost <<EOF
98 copy file
99 EOF
100 WVPASS diff -u file $TFTPROOT/file
101 WVPASS diff -u <(echo $TS) "$WV_BASE_DIR/home-novaboot-test/reset.stamp"
102
103
104 WVSTART "Novaboot --ssh remote config"
105 WVPASS rm -rf $TFTPROOT
106 WVPASS tee $SHELLRC <<EOF
107 console_cmd=cat
108 reset_cmd=true
109 target_config() { echo --prefix=/prefix; echo --grub2; }
110 EOF
111 date > file
112 WVPASS novaboot --ssh novaboot-test@localhost <<EOF
113 load file
114 EOF
115 WVPASS diff -u file $TFTPROOT/file
116 WVPASS grep /prefix/file $TFTPROOT/grub.cfg
117
118 WVSTART "Novaboot --ssh remote config fails on non-safe options"
119 WVPASS tee $SHELLRC <<EOF
120 console_cmd=cat
121 reset_cmd=true
122 config() { echo --prefix=/prefix; echo --make; }
123 EOF
124 WVFAIL novaboot --ssh novaboot-test@localhost <<EOF
125 load file < date
126 EOF
127
128 WVSTART "Novaboot --ssh remote config fails on unknown arguments"
129 WVPASS tee $SHELLRC <<EOF
130 console_cmd=cat
131 reset_cmd=true
132 target_config() { echo --prefix=/prefix; echo blablabla; }
133 EOF
134 WVFAIL novaboot --ssh novaboot-test@localhost <<EOF
135 load file < date
136 EOF
137
138 WVSTART "add-key subcommand"
139 WVPASS ssh-keygen -t ed25519 -N '' -f key
140 WVFAIL grep new_user $AUTH
141 WVPASS ssh novaboot-test@localhost add-key new_user < key.pub
142 WVPASS grep new_user $AUTH
143
144 WVSTART "add-key user must not contain spaces"
145 WVPASS cp $AUTH auth
146 WVFAIL ssh novaboot-test@localhost add-key "new user" < /dev/null
147 WVPASS diff -u $AUTH auth
148
149 WVSTART "add-key requires username"
150 WVPASS cp $AUTH auth
151 WVFAIL ssh novaboot-test@localhost add-key < /dev/null
152 WVPASS diff -u $AUTH auth