Commit bf998dd8 authored by Matthew Smith's avatar Matthew Smith
Browse files

Unit test for ip address allocation

parent 5d8d65c3
#!/usr/bin/env bash
. ../scripts/make-static-ip
TESTDIR="/tmp/openvpn-server_unit-tests"
CCDDIR="$TESTDIR/ccd"
SHOREWALLVARS="$TESTDIR/shorewall.vars"
rm -rf $TESTDIR
mkdir $TESTDIR
mkdir $CCDDIR
echo "Test ip range generation:"
for i in {1..50} ; do
get_new_ip 10.0.0.1 255.255.255.0 > $CCDDIR/range_a$i
done
for i in {51..100} ; do
get_new_ip 10.0.0.1 255.255.254.0 > $CCDDIR/range_b$i
done
echo -n "Start ip: "
if [ `cat $CCDDIR/range_a1` -eq "10.0.0.5" ] ; then
echo PASSED
else
echo FAILED
fi
echo -n "boundary ip: "
if [ `cat $CCDDIR/range_b63` -eq "10.0.0.253" ] && [ `cat $CCDDIR/range_b64` -eq "10.0.1.1" ] ; then
echo PASSED
else
echo FAILED
fi
echo -n "End ip: "
if [ `cat $CCDDIR/range_b100` -eq "10.0.1.145" ] ; then
echo PASSED
else
echo FAILED
fi
echo -n "Test reallocation to removed ip:"
rm $CCDDIR/range_a2
rm $CCDDIR/range_b99
get_new_ip 10.0.0.1 255.255.254.0 > $CCDDIR/allocate_a2
get_new_ip 10.0.0.1 255.255.254.0 > $CCDDIR/allocate_b99
if [ `cat $CCDDIR/allocate_a2` -eq "10.0.0.9" ] && [ `cat $CCDDIR/allocate_b99` -eq "10.0.1.141" ] ; then
echo PASSED
else
echo FAILED
fi
echo -n "Test server ip:"
testip=$(get_new_ip 10.0.0.1 255.255.254.0)
testendpointip=$(get_server_endpoint_ip $ip)
if [ $testip -eq "10.0.1.149" ] && [ $testendpointip -eq "10.0.1.150" ] ; then
echo PASSED
else
echo FAILED
fi
echo -n "Test no available ip's:"
if [ `get_new_ip 10.0.0.1 255.255.255.0` -ue "" ] ; then
echo PASSED
else
echo FAILED
fi
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment