tinc/test/scripts.test

131 lines
3.2 KiB
Text
Raw Normal View History

2019-08-26 11:44:52 +00:00
#!/bin/sh
2019-08-26 11:44:53 +00:00
. "${0%/*}/testlib.sh"
2019-08-26 11:44:52 +00:00
2022-04-22 18:24:15 +00:00
echo Initializing node...
2019-08-26 11:44:52 +00:00
# Initialize server node
$tinc $c1 <<EOF
init foo
set DeviceType dummy
set Port 32759
set Address 127.0.0.1
add Subnet 10.0.0.1
add Subnet fec0::/64
EOF
# Set up scripts
2022-04-22 18:24:15 +00:00
echo Setting up scripts...
2019-08-26 11:44:52 +00:00
OUT=$d1/scripts.out
rm -f $OUT
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
cat >$d1/$script << EOF
#!/bin/sh
echo $script \$NETNAME,\$NAME,\$DEVICE,\$IFACE,\$NODE,\$REMOTEADDRESS,\$REMOTEPORT,\$SUBNET,\$WEIGHT,\$INVITATION_FILE,\$INVITATION_URL,\$DEBUG >>$OUT
EOF
chmod u+x $d1/$script
2022-04-22 18:24:15 +00:00
cat >$d1/$script.cmd << EOF
echo $script %NETNAME%,%NAME%,%DEVICE%,%IFACE%,%NODE%,%REMOTEADDRESS%,%REMOTEPORT%,%SUBNET%,%WEIGHT%,%INVITATION_FILE%,%INVITATION_URL%,%DEBUG% >>$OUT
EOF
2019-08-26 11:44:52 +00:00
done
# Start server node
2022-04-22 18:24:15 +00:00
echo Starting server node...
$tinc $c1 -n netname start $r1
2019-08-26 11:44:52 +00:00
echo foo-started >>$OUT
# Invite client node
2022-04-22 18:24:15 +00:00
echo Inviting client node...
url=`$tinc $c1 -n netname2 invite bar | sed 's/\r//'`
2019-08-26 11:44:52 +00:00
file=`cd $d1/invitations; ls | grep -v ed25519_key.priv`
echo bar-invited >>$OUT
2022-04-22 18:24:15 +00:00
echo Joining client node...
$tinc $c2 -n netname3 join $url
2019-08-26 11:44:52 +00:00
echo bar-joined >>$OUT
# Start and stop client node
2022-04-22 18:24:15 +00:00
echo Starting client node...
2019-08-26 11:44:52 +00:00
$tinc $c2 << EOF
set DeviceType dummy
set Port 32760
add Subnet 10.0.0.2
add Subnet fec0::/64#5
start $r2
EOF
sleep 1
echo bar-started >>$OUT
$tinc $c1 debug 4
$tinc $c2 stop
sleep 1
echo bar-stopped >>$OUT
$tinc $c1 debug 5
$tinc $c2 start $r2
sleep 1
echo bar-started >>$OUT
# Stop server node
$tinc $c1 stop
sleep 1
$tinc $c2 stop
# Check if the script output is what is expected
cat >$OUT.expected << EOF
tinc-up netname,foo,dummy,,,,,,,,,5
subnet-up netname,foo,dummy,,foo,,,10.0.0.1,,,,5
subnet-up netname,foo,dummy,,foo,,,fec0::/64,,,,5
foo-started
invitation-created netname2,foo,,,bar,,,,,$d1/invitations/$file,$url,
bar-invited
invitation-accepted netname,foo,dummy,,bar,127.0.0.1,,,,,,5
bar-joined
host-up netname,foo,dummy,,bar,127.0.0.1,32760,,,,,5
hosts/bar-up netname,foo,dummy,,bar,127.0.0.1,32760,,,,,5
subnet-up netname,foo,dummy,,bar,127.0.0.1,32760,10.0.0.2,,,,5
subnet-up netname,foo,dummy,,bar,127.0.0.1,32760,fec0::/64,5,,,5
bar-started
host-down netname,foo,dummy,,bar,127.0.0.1,32760,,,,,4
hosts/bar-down netname,foo,dummy,,bar,127.0.0.1,32760,,,,,4
subnet-down netname,foo,dummy,,bar,127.0.0.1,32760,10.0.0.2,,,,4
subnet-down netname,foo,dummy,,bar,127.0.0.1,32760,fec0::/64,5,,,4
bar-stopped
host-up netname,foo,dummy,,bar,127.0.0.1,32760,,,,,5
hosts/bar-up netname,foo,dummy,,bar,127.0.0.1,32760,,,,,5
subnet-up netname,foo,dummy,,bar,127.0.0.1,32760,10.0.0.2,,,,5
subnet-up netname,foo,dummy,,bar,127.0.0.1,32760,fec0::/64,5,,,5
bar-started
host-down netname,foo,dummy,,bar,127.0.0.1,32760,,,,,5
hosts/bar-down netname,foo,dummy,,bar,127.0.0.1,32760,,,,,5
subnet-down netname,foo,dummy,,bar,127.0.0.1,32760,10.0.0.2,,,,5
subnet-down netname,foo,dummy,,bar,127.0.0.1,32760,fec0::/64,5,,,5
subnet-down netname,foo,dummy,,foo,,,10.0.0.1,,,,5
subnet-down netname,foo,dummy,,foo,,,fec0::/64,,,,5
tinc-down netname,foo,dummy,,,,,,,,,5
EOF
2022-04-22 18:24:15 +00:00
sed -i 's/\r//' $OUT
2019-08-26 11:44:52 +00:00
cmp $OUT $OUT.expected