Speed up the authentication protocol security tests.
[tinc] / test / integration / security-sptps.test
1 #!/bin/sh
2
3 # shellcheck disable=SC1090
4 . "$TESTLIB_PATH"
5
6 echo [STEP] Skip this test if tools are missing
7
8 command -v nc >/dev/null || exit "$EXIT_SKIP_TEST"
9 command -v timeout >/dev/null || exit "$EXIT_SKIP_TEST"
10
11 foo_port=30120
12 bar_port=30121
13
14 # usage: splice protocol_version
15 splice() {
16   "$SPLICE_PATH" foo localhost $foo_port bar localhost $bar_port "$1" &
17   sleep 10
18 }
19
20 # usage: send_with_timeout "data to send" "data expected to receive"
21 send_with_timeout() {
22   data=$1
23   expected=$3
24
25   result=$(
26     (
27       sleep 6
28       printf "%s\n" "$data"
29     ) | timeout 10 nc localhost $foo_port
30   ) && exit 1
31
32   test $? = "$EXIT_TIMEOUT"
33
34   if [ -z "$expected" ]; then
35     test -z "$result"
36   else
37     echo "$result" | grep -q "^$expected"
38   fi
39 }
40
41 echo [STEP] Initialize two nodes
42
43 tinc foo <<EOF
44 init foo
45 set DeviceType dummy
46 set Port $foo_port
47 set Address localhost
48 set PingTimeout 3
49 set AutoConnect no
50 set Subnet 10.96.96.1
51 EOF
52
53 tinc bar <<EOF
54 init bar
55 set DeviceType dummy
56 set Port $bar_port
57 set PingTimeout 3
58 set MaxTimeout 3
59 set AutoConnect no
60 set Subnet 10.96.96.2
61 EOF
62
63 echo [STEP] Exchange host config files
64
65 tinc foo export | tinc bar exchange | tinc foo import
66
67 create_script foo subnet-up
68 start_tinc foo
69 wait_script foo subnet-up
70
71 create_script bar subnet-up
72 start_tinc bar
73 wait_script bar subnet-up
74
75 echo [STEP] No splicing allowed, SPTPS
76
77 splice 17.7
78 pid=$!
79
80 require_nodes foo 1
81 require_nodes bar 1
82
83 kill $pid
84
85 tinc bar stop
86 tinc foo stop