ff0e565fd88351ba17c53e99e75125b0b5704e11
[tinc] / test / scripts.test
1 #!/bin/sh
2
3 # shellcheck disable=SC1090
4 . "$TESTLIB_PATH"
5
6 echo [STEP] Initializing server node
7
8 port_foo=30040
9 port_bar=30041
10
11 tinc foo <<EOF
12 init foo
13 set DeviceType dummy
14 set Port $port_foo
15 set Address 127.0.0.1
16 add Subnet 10.0.0.1
17 add Subnet fec0::/64
18 EOF
19
20 echo [STEP] Setting up scripts
21
22 OUT=$DIR_FOO/scripts.out
23 rm -f "$OUT"
24
25 for script in \
26   tinc-up tinc-down \
27   host-up host-down \
28   subnet-up subnet-down \
29   hosts/foo-up hosts/foo-down \
30   hosts/bar-up hosts/bar-down \
31   invitation-created invitation-accepted; do
32
33   commands=$(
34     cat <<EOF
35       if is_windows && [ -n "\$INVITATION_FILE" ]; then
36         INVITATION_FILE=\$(cygpath --unix -- "\$INVITATION_FILE")
37       fi
38       echo >>'$OUT' "$script" "$TINC_SCRIPT_VARS"
39 EOF
40   )
41
42   create_script foo "$script" "$commands"
43 done
44
45 echo [STEP] Starting server node
46
47 start_tinc foo -n netname
48 wait_script foo subnet-up 2
49 echo foo-started >>"$OUT"
50
51 echo [STEP] Inviting client node
52
53 url=$(tinc foo -n netname2 invite bar)
54 file=$(basename "$(find "$DIR_FOO/invitations" -type f ! -name ed25519_key.priv)")
55
56 if is_windows; then
57   file=$(cygpath --unix -- "$file")
58 fi
59
60 wait_script foo invitation-created
61 echo bar-invited >>"$OUT"
62
63 echo [STEP] Joining client node
64
65 tinc bar -n netname3 join "$url"
66 wait_script foo invitation-accepted
67 echo bar-joined >>"$OUT"
68
69 echo [STEP] Starting client node
70
71 tinc bar <<EOF
72 set DeviceType dummy
73 set Port $port_bar
74 add Subnet 10.0.0.2
75 add Subnet fec0::/64#5
76 EOF
77
78 start_tinc bar
79 wait_script foo subnet-up 2
80 echo bar-started-1 >>"$OUT"
81
82 tinc foo debug 4
83 tinc bar stop
84 wait_script foo subnet-down 2
85 echo bar-stopped >>"$OUT"
86
87 tinc foo debug 5
88 start_tinc bar
89 wait_script foo subnet-up 2
90 echo bar-started-2 >>"$OUT"
91
92 echo [STEP] Stop server node
93
94 tinc foo stop
95 tinc bar stop
96 wait_script foo tinc-down
97
98 echo [STEP] Check if the script output is what is expected
99
100 cat >"$OUT.expected" <<EOF
101 tinc-up netname,foo,dummy,,,,,,,,,5
102 subnet-up netname,foo,dummy,,foo,,,10.0.0.1,,,,5
103 subnet-up netname,foo,dummy,,foo,,,fec0::/64,,,,5
104 foo-started
105 invitation-created netname2,foo,,,bar,,,,,$DIR_FOO/invitations/$file,$url,
106 bar-invited
107 invitation-accepted netname,foo,dummy,,bar,127.0.0.1,,,,,,5
108 bar-joined
109 host-up netname,foo,dummy,,bar,127.0.0.1,$port_bar,,,,,5
110 hosts/bar-up netname,foo,dummy,,bar,127.0.0.1,$port_bar,,,,,5
111 subnet-up netname,foo,dummy,,bar,127.0.0.1,$port_bar,10.0.0.2,,,,5
112 subnet-up netname,foo,dummy,,bar,127.0.0.1,$port_bar,fec0::/64,5,,,5
113 bar-started-1
114 host-down netname,foo,dummy,,bar,127.0.0.1,$port_bar,,,,,4
115 hosts/bar-down netname,foo,dummy,,bar,127.0.0.1,$port_bar,,,,,4
116 subnet-down netname,foo,dummy,,bar,127.0.0.1,$port_bar,10.0.0.2,,,,4
117 subnet-down netname,foo,dummy,,bar,127.0.0.1,$port_bar,fec0::/64,5,,,4
118 bar-stopped
119 host-up netname,foo,dummy,,bar,127.0.0.1,$port_bar,,,,,5
120 hosts/bar-up netname,foo,dummy,,bar,127.0.0.1,$port_bar,,,,,5
121 subnet-up netname,foo,dummy,,bar,127.0.0.1,$port_bar,10.0.0.2,,,,5
122 subnet-up netname,foo,dummy,,bar,127.0.0.1,$port_bar,fec0::/64,5,,,5
123 bar-started-2
124 host-down netname,foo,dummy,,bar,127.0.0.1,$port_bar,,,,,5
125 hosts/bar-down netname,foo,dummy,,bar,127.0.0.1,$port_bar,,,,,5
126 subnet-down netname,foo,dummy,,bar,127.0.0.1,$port_bar,10.0.0.2,,,,5
127 subnet-down netname,foo,dummy,,bar,127.0.0.1,$port_bar,fec0::/64,5,,,5
128 subnet-down netname,foo,dummy,,foo,,,10.0.0.1,,,,5
129 subnet-down netname,foo,dummy,,foo,,,fec0::/64,,,,5
130 tinc-down netname,foo,dummy,,,,,,,,,5
131 EOF
132
133 diff -w "$OUT" "$OUT.expected"