From: Nick Porter Date: Fri, 30 Jun 2023 07:32:14 +0000 (+0100) Subject: Test redis_ippool_tool static assignment behaviour X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1681bb57108b7252a65f7ed6eca9477fa543061e;p=thirdparty%2Ffreeradius-server.git Test redis_ippool_tool static assignment behaviour --- diff --git a/src/tests/modules/redis_ippool/pool_tool_static.attrs b/src/tests/modules/redis_ippool/pool_tool_static.attrs new file mode 100644 index 00000000000..4bb429e8b63 --- /dev/null +++ b/src/tests/modules/redis_ippool/pool_tool_static.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/pool_tool_static.unlang b/src/tests/modules/redis_ippool/pool_tool_static.unlang new file mode 100644 index 00000000000..efd35a24da9 --- /dev/null +++ b/src/tests/modules/redis_ippool/pool_tool_static.unlang @@ -0,0 +1,126 @@ +# +# Test static IP allocation using redis_ippool +# +$INCLUDE cluster_reset.inc + +&control.IP-Pool.Name := 'test_tool_static' + +# +# 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 +} + +# +# Fetch the ZSCORE now on the address +# +&Tmp-uint64-0 := %(redis:ZSCORE {%{control.IP-Pool.Name}}:pool %{reply.Framed-IP-Address}) + +# +# Attempt to re-assign static lease +# +&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 the ZSCORE hasn't changed +# +if !(%(redis:ZSCORE {%{control.IP-Pool.Name}}:pool %{reply.Framed-IP-Address}) == %{Tmp-uint64-0}) { + test_fail +} + +# +# Remove the static assignment - leaves the lease with its remaining time to expire +# +&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}` + +# +# Attempt to assign the address to another device - should fail +# +&Tmp-String-0 := `./build/bin/local/rlm_redis_ippool_tool -A 192.168.0.10/32 -O aa:bb:cc:dd:ee:00 $ENV{REDIS_IPPOOL_TEST_SERVER}:30001 %{control.IP-Pool.Name} 192.168.0.0` + +# +# Check the original device is still assigned to the address +# +if !(%(redis:HGET {%{control.IP-Pool.Name}}:ip:192.168.0.10 'device') == 'aa:bb:cc:dd:ee:ff') { + test_fail +} +if !(%(redis:GET {%{control.IP-Pool.Name}}:device:aa:bb:cc:dd:ee:ff) == '192.168.0.10') { + test_fail +} + +# +# Change device to grab the dynamic address +&Calling-Station-ID := '11:22:33:44:55:66' +&reply -= &Framed-IP-Address[*] + +redis_ippool { + invalid = 1 +} +if (!updated) { + test_fail +} + +if !(&reply.Framed-IP-Address == 192.168.0.1) { + test_fail +} + +# +# Attempt to statically assign this to another device +# +&Tmp-String-0 := `./build/bin/local/rlm_redis_ippool_tool -A 192.168.0.1/32 -O aa:bb:cc:dd:ee:00 $ENV{REDIS_IPPOOL_TEST_SERVER}:30001 %{control.IP-Pool.Name} 192.168.0.0` + +# +# Check the original device is still assigned to the address and the lease is dynamic +# +if !(%(redis:HGET {%{control.IP-Pool.Name}}:ip:192.168.0.1 'device') == %{Calling-Station-Id}) { + test_fail +} +if !(%(redis:GET {%{control.IP-Pool.Name}}:device:11:22:33:44:55:66) == '192.168.0.1') { + test_fail +} + +&Tmp-uint64-1 := %(redis:ZSCORE {%{control.IP-Pool.Name}}:pool 192.168.0.1) +if !(&Tmp-uint64-1 < %(cast:uint64 0x10000000000000)) { + test_fail +} + +# +# Now assign it as a static lease for the current device +# +&Tmp-String-0 := `./build/bin/local/rlm_redis_ippool_tool -A 192.168.0.1/32 -O %{Calling-Station-Id} $ENV{REDIS_IPPOOL_TEST_SERVER}:30001 %{control.IP-Pool.Name} 192.168.0.0` + +# +# Check that the ZSCORE is maintained, simply with the static bit set +# +if !(%(redis:ZSCORE {%{control.IP-Pool.Name}}:pool 192.168.0.1) == (&Tmp-uint64-1 + %(cast:uint64 0x10000000000000))) { + test_fail +} + +# +# And that the expiry is now removed on the device +# +if ("%(redis:TTL {%{control.IP-Pool.Name}}:device:%{Calling-Station-Id})" != '-1') { + test_fail +} + +&reply := {} + +test_pass