-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_build
executable file
·125 lines (96 loc) · 2.21 KB
/
test_build
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
#!/bin/sh
t="./openvpn_radauth"
radius_conf="$( pwd )/test/radius.conf"
ok_username="okuser"
ok_password="okpass"
bad_username="baduser"
bad_password="badpass"
nonexistent_username="nouser"
success=0
failure=1
errors=0
: ${MAKE:=make}
${MAKE} distclean
${MAKE} -C test || { echo "picohash test failed"; exit 1; }
[ -e ./configure ] || autoreconf -ivf
./configure --with-radius-config="${radius_conf}" --enable-debug
${MAKE}
test_via_env()
{
username="$1"
password="$2"
exp=$3
for ipparam in "" untrusted_ip="127.0.0.1"
do
env -i \
username="${username}" \
password="${password}" \
${ipparam} \
"${t}"
done
if [ $? -ne ${exp} ]
then
echo "via-env failed test username=[${username}] password=[${password}]"
fi
}
test_via_file()
{
username="$1"
password="$2"
exp=$3
passfile="$( mktemp /tmp/${0##*/}.XXXXXX )"
printf '%s\r\n' "${username}" > "${passfile}"
printf '%s\r\n' "${password}" >> "${passfile}"
for ipparam in "" untrusted_ip="127.0.0.1"
do
env -i \
${ipparam} \
"${t}" "${passfile}"
done
if [ $? -ne ${exp} ]
then
echo "via-file failed test username=[${username}] password=[${password}]"
errors=$(( errors + 1 ))
fi
rm -f "${passfile}"
}
test()
{
echo "testing username=[${1}] password=[${2}] via-file"
test_via_file "$@"
echo "testing username=[${1}] password=[${2}] via-env"
test_via_env "$@"
}
if [ ! -x ${t} ]
then
echo "test subject ${t} is awol"
exit
fi
if [ ! -r ${radius_conf} ]
then
echo "${radius_conf} is missing or unreadable"
exit
fi
echo "started testing, watch authlog"
test "" "" ${failure}
test "" "${ok_password}" ${failure}
test "" "${bad_password}" ${failure}
test "${ok_username}" "" ${failure}
test "${ok_username}" "${bad_password}" ${failure}
test "${ok_username}" "${ok_password}" ${success}
test "${bad_username}" "" ${failure}
test "${bad_username}" "${bad_password}" ${failure}
test "${bad_username}" "${ok_password}" ${failure}
test "${nonexistent_username}" "" ${failure}
test "${nonexistent_username}" "${bad_password}" ${failure}
test "${nonexistent_username}" "${ok_password}" ${failure}
echo "finished testing"
${MAKE} clean
if [ ${errors} -eq 0 ]
then
echo "all tests successful"
exit 0
else
echo "some tests failed"
exit 1
fi