From: Nick Porter Date: Tue, 30 May 2023 15:13:09 +0000 (+0100) Subject: Add test of removing static IP assignment X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=46a8cf184a2cc4542f6cbe8c435be4150d1a17e6;p=thirdparty%2Ffreeradius-server.git Add test of removing static IP assignment --- diff --git a/src/tests/modules/redis_ippool/static_unassign.attrs b/src/tests/modules/redis_ippool/static_unassign.attrs new file mode 100644 index 00000000000..4bb429e8b63 --- /dev/null +++ b/src/tests/modules/redis_ippool/static_unassign.attrs @@ -0,0 +1,13 @@ +# +# Input packet +# +Packet-Type = Access-Request +User-Name = 'john' +User-Password = 'testing123' +NAS-IP-Address = 127.0.0.1 +Calling-Station-Id = aa:bb:cc:dd:ee:ff + +# +# Expected answer +# +Packet-Type == Access-Accept diff --git a/src/tests/modules/redis_ippool/static_unassign.unlang b/src/tests/modules/redis_ippool/static_unassign.unlang new file mode 100644 index 00000000000..42812366bae --- /dev/null +++ b/src/tests/modules/redis_ippool/static_unassign.unlang @@ -0,0 +1,131 @@ +# +# Test static IP allocation followed by un-assignment using redis_ippool +# +$INCLUDE cluster_reset.inc + +&control.IP-Pool.Name := 'test_static_unassign' + +# +# Add a dynamic IP addresses +# +&Tmp-String-0 := `./build/bin/local/rlm_redis_ippool_tool -a 192.168.0.1/32 $ENV{REDIS_IPPOOL_TEST_SERVER}:30001 %{control.IP-Pool.Name} 192.168.0.0` + +# +# Add a static IP assigned to the calling station in the request +# +&Tmp-String-0 := `./build/bin/local/rlm_redis_ippool_tool -A 192.168.0.10/32 -O aa:bb:cc:dd:ee:ff $ENV{REDIS_IPPOOL_TEST_SERVER}:30001 %{control.IP-Pool.Name} 192.168.0.0` + +# +# Check allocation +# +redis_ippool { + invalid = 1 +} +if (!updated) { + test_fail +} + +if (!(&reply.Framed-IP-Address == 192.168.0.10)) { + test_fail +} + +# +# Check the expiry attribute is present and correct - although the allocation is static +# we report the expiry as if it were dynamic e.g. to drive DHCP renewals +# +if (!(&reply.Session-Timeout == 30)) { + test_fail +} + +# +# Un-assign static allocation +# +&Tmp-String-0 := `./build/bin/local/rlm_redis_ippool_tool -U 192.168.0.10/32 -O aa:bb:cc:dd:ee:ff $ENV{REDIS_IPPOOL_TEST_SERVER}:30001 %{control.IP-Pool.Name}` + +# +# Check ZSCORE is now < 2^52 - the "static bit" +# +if (%(redis:ZSCORE {%{control.IP-Pool.Name}}:pool %{reply.Framed-IP-Address}) >= %(cast:uint64 0x10000000000000)) { + test_fail +} + +# +# Verify there is now an expiry on the device. +# This is based on the initial lease duration given (of 30 sec) but will have reduced +# due to elapsed time since the allocation. +# +if ("%(redis:TTL {%{control.IP-Pool.Name}}:device:%{Calling-Station-Id})" < 20) { + test_fail +} + +# +# Check that renewal still works as we are within the exipiry time +# +&Framed-IP-Address := &reply.Framed-IP-Address +&control.IP-Pool.Action := Renew + +redis_ippool { + invalid = 1 +} + +# +# Check that releasing now frees +# +&control.IP-Pool.Action := Release + +redis_ippool { + invalid = 1 +} +if (!updated) { + test_fail +} + +# +# Verify the association with the device is removed +# +if ("%(redis:EXISTS {%{control.IP-Pool.Name}}:device:%{Calling-Station-ID})" != '0') { + test_fail +} + +# Check the ZSCORE +&Tmp-Date-0 := "%l" +if ("%(redis:ZSCORE {%{control.IP-Pool.Name}%}:pool %{reply.Framed-IP-Address})" > %(integer:%{Tmp-Date-0})) { + test_fail +} + +# +# Delete original dynamic address - so only the previously static one remains +# +&Tmp-String-0 := `./build/bin/local/rlm_redis_ippool_tool -d 192.168.0.1/32 $ENV{REDIS_IPPOOL_TEST_SERVER}:30001 %{control.IP-Pool.Name}` + +# +# Perform IP allocation for alternative device +# Should be allocated the previously static address as that is the only one in the pool +# +&reply -= &Framed-IP-Address[*] +&request -= &Framed-IP-Address[*] +&Calling-Station-Id := '00:11:22:33:44:55' + +&control.IP-Pool.Action := Allocate +redis_ippool { + invalid = 1 +} + +if (!updated) { + test_fail +} + +if !(&reply.Framed-IP-Address == '192.168.0.10') { + test_fail +} + +# +# Verify the IP hash has been set to point to the new device +# +if !("%(redis:HGET {%{control.IP-Pool.Name}}:ip:%{reply.Framed-IP-Address} 'device')" == '00:11:22:33:44:55') { + test_fail +} + +&reply := {} + +test_pass