-
Notifications
You must be signed in to change notification settings - Fork 31
/
shunit2_test_integ.sh
executable file
·207 lines (161 loc) · 5.38 KB
/
shunit2_test_integ.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/bin/bash
#
# Copyright (C) 2013 Dan Fruehauf <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# integration tests for check_vpn
##########
# IODINE #
##########
# test l2tp integration
test_iodine_vpn_integration() {
_test_root || return
local -i retval=0
local domain=www.something.com
local password=`pwmake $RANDOM`
local tmp_output=`mktemp`
# setup iodine on the other end
ssh root@$VPN_SERVER_IODINE "pkill iodined; iodined -P '$password' 10.1.1.2/24 $domain >& /dev/null"
$CHECK_VPN -l -t iodine -H $VPN_SERVER_IODINE -u $domain -p $password -d dns50 -- -m 500 > $tmp_output
retval=$?
assertTrue "iodine vpn connection" \
"[ $retval -eq 0 ]"
local expected_string="OK: VPN to '$VPN_SERVER_IODINE' up and running on 'dns50', 'http://www.google.com' reachable"
local output=`cut -d\| -f1 $tmp_output`
assertTrue "iodine vpn connection output" \
"[ x'$output' = x'$expected_string' ]"
rm -f $tmp_output
}
########
# L2TP #
########
# test l2tp integration
test_l2tp_vpn_integration() {
_test_root || return
local -i retval=0
local username=root
local password=`pwmake $RANDOM`
local tmp_output=`mktemp`
# setup the vpn server, using ssh :)
ssh root@$VPN_SERVER_L2TP "echo '$username * $password *' > /etc/ppp/chap-secrets"
$CHECK_VPN -l -t l2tp -H $VPN_SERVER_L2TP -u $username -p $password -d ppp6 -- noccp > $tmp_output
retval=$?
assertTrue "l2tp vpn connection" \
"[ $retval -eq 0 ]"
local expected_string="OK: VPN to '$VPN_SERVER_L2TP' up and running on 'ppp6', 'http://www.google.com' reachable"
local output=`cut -d\| -f1 $tmp_output`
assertTrue "l2tp vpn connection output" \
"[ x'$output' = x'$expected_string' ]"
rm -f $tmp_output
}
###########
# OPENVPN #
###########
# test l2tp integration
test_openvpn_vpn_integration() {
_test_root || return
local -i retval=0
local username=root
local password=`pwmake $RANDOM`
local tmp_output=`mktemp`
local tmp_server_cert=`mktemp`
# setup the vpn server, using ssh :)
ssh root@$VPN_SERVER_OPENVPN \
"echo '$username' > /etc/openvpn/passwd && echo '$password' >> /etc/openvpn/passwd"
# get server certificate
scp root@$VPN_SERVER_OPENVPN:/etc/openvpn/ca.crt $tmp_server_cert > /dev/null
retval=$?
assertTrue "openvpn vpn server certificate copy" \
"[ $retval -eq 0 ]"
$CHECK_VPN -l -t openvpn -H $VPN_SERVER_OPENVPN -u $username -p $password -d tun91 -- --ca $tmp_server_cert --proto tcp --cipher AES-256-CBC --comp-lzo > $tmp_output
retval=$?
assertTrue "openvpn vpn connection" \
"[ $retval -eq 0 ]"
local expected_string="OK: VPN to '$VPN_SERVER_OPENVPN' up and running on 'tun91', 'http://www.google.com' reachable"
local output=`cut -d\| -f1 $tmp_output`
assertTrue "openvpn vpn connection output" \
"[ x'$output' = x'$expected_string' ]"
rm -f $tmp_output $tmp_server_cert
}
########
# PPTP #
########
# test pptp integration
test_pptp_vpn_integration() {
_test_root || return
local -i retval=0
local username=root
local password=`pwmake $RANDOM`
local tmp_output=`mktemp`
# setup the vpn server, using ssh :)
ssh root@$VPN_SERVER_PPTP "echo '$username * $password *' > /etc/ppp/chap-secrets"
$CHECK_VPN -l -t pptp -H $VPN_SERVER_PPTP -u $username -p $password -d ppp40 -- require-mppe-128 refuse-pap refuse-eap refuse-chap refuse-mschap novj novjccomp nobsdcomp > $tmp_output
retval=$?
assertTrue "pptp vpn connection" \
"[ $retval -eq 0 ]"
local expected_string="OK: VPN to '$VPN_SERVER_PPTP' up and running on 'ppp40', 'http://www.google.com' reachable"
local output=`cut -d\| -f1 $tmp_output`
assertTrue "pptp vpn connection output" \
"[ x'$output' = x'$expected_string' ]"
rm -f $tmp_output
}
#######
# SSH #
#######
# test ssh integration
test_ssh_vpn_integration() {
_test_root || return
local -i retval=0
local tmp_output=`mktemp`
./check_vpn -l -t ssh -H $VPN_SERVER_SSH -u root -p uga -d tun1 > $tmp_output
retval=$?
assertTrue "ssh vpn connection" \
"[ $retval -eq 0 ]"
local expected_string="OK: VPN to '$VPN_SERVER_PPTP' up and running on 'tun1', 'http://www.google.com' reachable"
local output=`cut -d\| -f1 $tmp_output`
assertTrue "ssh vpn connection output" \
"[ x'$output' = x'$expected_string' ]"
rm -f $tmp_output
}
####################
# COMMON FUNCTIONS #
####################
_test_root() {
assertTrue "test running as root" "[ `id -u` -eq 0 ]"
}
##################
# SETUP/TEARDOWN #
##################
oneTimeSetUp() {
CHECK_VPN=`dirname $0`/check_vpn
echo "Please set your VPN server in order to run these tests" && exit 2
VPN_SERVER_IODINE=$VPN_SERVER
VPN_SERVER_L2TP=$VPN_SERVER
VPN_SERVER_OPENVPN=$VPN_SERVER
VPN_SERVER_PPTP=$VPN_SERVER
VPN_SERVER_SSH=$VPN_SERVER
}
oneTimeTearDown() {
true
}
setUp() {
true
}
tearDown() {
true
}
# load and run shUnit2
. /usr/share/shunit2/shunit2