From: Nick Porter Date: Thu, 25 May 2023 12:44:08 +0000 (+0100) Subject: Add tests of static redis_ippool assignments X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b27cb9c59f71412a8a70eca35d781dd0c396ddb1;p=thirdparty%2Ffreeradius-server.git Add tests of static redis_ippool assignments --- diff --git a/src/tests/modules/redis_ippool/static.attrs b/src/tests/modules/redis_ippool/static.attrs new file mode 100644 index 00000000000..4bb429e8b63 --- /dev/null +++ b/src/tests/modules/redis_ippool/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/static.unlang b/src/tests/modules/redis_ippool/static.unlang new file mode 100644 index 00000000000..a9cf8a0c0a9 --- /dev/null +++ b/src/tests/modules/redis_ippool/static.unlang @@ -0,0 +1,98 @@ +# +# Test static IP allocation using redis_ippool +# +$INCLUDE cluster_reset.inc + +&control.IP-Pool.Name := 'test_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 +} + +# +# 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 +} + +# +# Check that renewal does not mess with static IP +# +&Framed-IP-Address := &reply.Framed-IP-Address +&control.IP-Pool.Action := Renew + +redis_ippool { + invalid = 1 +} + +# +# Verify no expiry has been set on device +# +if ("%(redis:TTL {%{control.IP-Pool.Name}}:device:%{Calling-Station-Id})" != '-1') { + test_fail +} + +# +# And that the expected expiry is now set +# +if (!(&reply.Session-Timeout == 60)) { + test_fail +} + +# +# Check that releasing does not mess with static IP +# +&control.IP-Pool.Action := Release + +redis_ippool { + invalid = 1 +} +if (!(updated)) { + test_fail +} + +# +# Verify the association with the device remains +# +if ("%(redis:EXISTS {%{control.IP-Pool.Name}}:device:%{Calling-Station-ID})" == '0') { + test_fail +} + +# +# Verify the hash information is retained +# +if ("%(redis:EXISTS {%{control.IP-Pool.Name}}:ip:%{reply.Framed-IP-Address})" == '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 +} + +&reply := {} + +test_pass diff --git a/src/tests/modules/redis_ippool/static_dynamic.attrs b/src/tests/modules/redis_ippool/static_dynamic.attrs new file mode 100644 index 00000000000..871a106ce7c --- /dev/null +++ b/src/tests/modules/redis_ippool/static_dynamic.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 = 00:11:22:33:44:55 + +# +# Expected answer +# +Packet-Type == Access-Accept diff --git a/src/tests/modules/redis_ippool/static_dynamic.unlang b/src/tests/modules/redis_ippool/static_dynamic.unlang new file mode 100644 index 00000000000..116827a8fc1 --- /dev/null +++ b/src/tests/modules/redis_ippool/static_dynamic.unlang @@ -0,0 +1,44 @@ +# +# Test static IP allocation not given to dynamic users +# +$INCLUDE cluster_reset.inc + +&control.IP-Pool.Name := 'test_static_dynamic' + +# +# Add a static IP assigned to a calling station not 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 fails - pool only contains an address assigned to another owner +# +redis_ippool { + invalid = 1 +} +if (!notfound) { + test_fail +} + +# +# 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` + +# +# Check allocation +# +redis_ippool { + invalid = 1 +} +if (!updated) { + test_fail +} + +if (!(&reply.Framed-IP-Address == 192.168.0.1)) { + test_fail +} + +&reply := {} + +test_pass