Speed up the authentication protocol security tests.
[tinc] / test / integration / security-legacy.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=30110
12 bar_port=30111
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 ExperimentalProtocol no
50 set AutoConnect no
51 set Subnet 10.96.96.1
52 EOF
53
54 tinc bar <<EOF
55 init bar
56 set DeviceType dummy
57 set Port $bar_port
58 set PingTimeout 3
59 set MaxTimeout 3
60 set ExperimentalProtocol no
61 set AutoConnect no
62 set Subnet 10.96.96.2
63 EOF
64
65 echo [STEP] Exchange host config files
66
67 tinc foo export | tinc bar exchange | tinc foo import
68
69 create_script foo subnet-up
70 start_tinc foo
71 wait_script foo subnet-up
72
73 create_script bar subnet-up
74 start_tinc bar
75 wait_script bar subnet-up
76
77 echo [STEP] No splicing allowed, legacy protocol
78
79 splice 17.7
80 pid=$!
81
82 require_nodes foo 1
83 require_nodes bar 1
84
85 kill $pid
86
87 tinc bar stop
88 tinc foo stop