Use auto-clone device /dev/{tun,tap} as default on FreeBSD/DragonFly
[tinc] / test / scripts.test
1 #!/bin/sh
2
3 . "${0%/*}/testlib.sh"
4
5 echo Initializing node...
6
7 # Initialize server node
8
9 $tinc $c1 <<EOF
10 init foo
11 set DeviceType dummy
12 set Port 32759
13 set Address 127.0.0.1
14 add Subnet 10.0.0.1
15 add Subnet fec0::/64
16 EOF
17
18 # Set up scripts
19
20 echo Setting up scripts...
21
22 OUT=$d1/scripts.out
23 rm -f $OUT 
24
25 for script in tinc-up tinc-down host-up host-down subnet-up subnet-down hosts/foo-up hosts/foo-down hosts/bar-up hosts/bar-down invitation-created invitation-accepted; do
26 cat >$d1/$script << EOF
27 #!/bin/sh
28 echo $script \$NETNAME,\$NAME,\$DEVICE,\$IFACE,\$NODE,\$REMOTEADDRESS,\$REMOTEPORT,\$SUBNET,\$WEIGHT,\$INVITATION_FILE,\$INVITATION_URL,\$DEBUG >>$OUT
29 EOF
30 chmod u+x $d1/$script
31
32 cat >$d1/$script.cmd << EOF
33 echo $script %NETNAME%,%NAME%,%DEVICE%,%IFACE%,%NODE%,%REMOTEADDRESS%,%REMOTEPORT%,%SUBNET%,%WEIGHT%,%INVITATION_FILE%,%INVITATION_URL%,%DEBUG% >>$OUT
34 EOF
35 done
36
37 # Start server node
38
39 echo Starting server node...
40
41 $tinc $c1 -n netname start $r1
42
43 echo foo-started >>$OUT
44
45 # Invite client node
46
47 echo Inviting client node...
48
49 url=`$tinc $c1 -n netname2 invite bar | sed 's/\r//'`
50 file=`cd $d1/invitations; ls | grep -v ed25519_key.priv`
51 echo bar-invited >>$OUT
52
53 echo Joining client node...
54
55 $tinc $c2 -n netname3 join $url
56 echo bar-joined >>$OUT
57
58 # Start and stop client node
59
60 echo Starting client node...
61
62 $tinc $c2 << EOF
63 set DeviceType dummy
64 set Port 32760
65 add Subnet 10.0.0.2
66 add Subnet fec0::/64#5
67 start $r2
68 EOF
69
70 sleep 1
71
72 echo bar-started >>$OUT
73
74 $tinc $c1 debug 4
75 $tinc $c2 stop
76
77 sleep 1
78
79 echo bar-stopped >>$OUT
80
81 $tinc $c1 debug 5
82 $tinc $c2 start $r2
83
84 sleep 1
85
86 echo bar-started >>$OUT
87
88 # Stop server node
89
90 $tinc $c1 stop
91 sleep 1
92 $tinc $c2 stop
93
94 # Check if the script output is what is expected
95
96 cat >$OUT.expected << EOF
97 tinc-up netname,foo,dummy,,,,,,,,,5
98 subnet-up netname,foo,dummy,,foo,,,10.0.0.1,,,,5
99 subnet-up netname,foo,dummy,,foo,,,fec0::/64,,,,5
100 foo-started
101 invitation-created netname2,foo,,,bar,,,,,$d1/invitations/$file,$url,
102 bar-invited
103 invitation-accepted netname,foo,dummy,,bar,127.0.0.1,,,,,,5
104 bar-joined
105 host-up netname,foo,dummy,,bar,127.0.0.1,32760,,,,,5
106 hosts/bar-up netname,foo,dummy,,bar,127.0.0.1,32760,,,,,5
107 subnet-up netname,foo,dummy,,bar,127.0.0.1,32760,10.0.0.2,,,,5
108 subnet-up netname,foo,dummy,,bar,127.0.0.1,32760,fec0::/64,5,,,5
109 bar-started
110 host-down netname,foo,dummy,,bar,127.0.0.1,32760,,,,,4
111 hosts/bar-down netname,foo,dummy,,bar,127.0.0.1,32760,,,,,4
112 subnet-down netname,foo,dummy,,bar,127.0.0.1,32760,10.0.0.2,,,,4
113 subnet-down netname,foo,dummy,,bar,127.0.0.1,32760,fec0::/64,5,,,4
114 bar-stopped
115 host-up netname,foo,dummy,,bar,127.0.0.1,32760,,,,,5
116 hosts/bar-up netname,foo,dummy,,bar,127.0.0.1,32760,,,,,5
117 subnet-up netname,foo,dummy,,bar,127.0.0.1,32760,10.0.0.2,,,,5
118 subnet-up netname,foo,dummy,,bar,127.0.0.1,32760,fec0::/64,5,,,5
119 bar-started
120 host-down netname,foo,dummy,,bar,127.0.0.1,32760,,,,,5
121 hosts/bar-down netname,foo,dummy,,bar,127.0.0.1,32760,,,,,5
122 subnet-down netname,foo,dummy,,bar,127.0.0.1,32760,10.0.0.2,,,,5
123 subnet-down netname,foo,dummy,,bar,127.0.0.1,32760,fec0::/64,5,,,5
124 subnet-down netname,foo,dummy,,foo,,,10.0.0.1,,,,5
125 subnet-down netname,foo,dummy,,foo,,,fec0::/64,,,,5
126 tinc-down netname,foo,dummy,,,,,,,,,5
127 EOF
128
129 sed -i 's/\r//' $OUT
130 cmp $OUT $OUT.expected