]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add tests of static redis_ippool assignments
authorNick Porter <nick@portercomputing.co.uk>
Thu, 25 May 2023 12:44:08 +0000 (13:44 +0100)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 8 Jun 2023 14:13:48 +0000 (10:13 -0400)
src/tests/modules/redis_ippool/static.attrs [new file with mode: 0644]
src/tests/modules/redis_ippool/static.unlang [new file with mode: 0644]
src/tests/modules/redis_ippool/static_dynamic.attrs [new file with mode: 0644]
src/tests/modules/redis_ippool/static_dynamic.unlang [new file with mode: 0644]

diff --git a/src/tests/modules/redis_ippool/static.attrs b/src/tests/modules/redis_ippool/static.attrs
new file mode 100644 (file)
index 0000000..4bb429e
--- /dev/null
@@ -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 (file)
index 0000000..a9cf8a0
--- /dev/null
@@ -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 (file)
index 0000000..871a106
--- /dev/null
@@ -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 (file)
index 0000000..116827a
--- /dev/null
@@ -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