From: Nick Porter Date: Thu, 25 May 2023 14:32:25 +0000 (+0100) Subject: Tidy other redis_ippool tests X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8b490ca2b99d1afdcbb3c9c01a1a90428f44808c;p=thirdparty%2Ffreeradius-server.git Tidy other redis_ippool tests --- diff --git a/src/tests/modules/redis_ippool/alloc.unlang b/src/tests/modules/redis_ippool/alloc.unlang index b56ccbb53de..9b48c3cd272 100644 --- a/src/tests/modules/redis_ippool/alloc.unlang +++ b/src/tests/modules/redis_ippool/alloc.unlang @@ -14,15 +14,11 @@ $INCLUDE cluster_reset.inc # Check allocation # redis_ippool -if (updated) { - test_pass -} else { +if (!updated) { test_fail } -if (&reply.Framed-IP-Address == 192.168.0.1) { - test_pass -} else { +if !(&reply.Framed-IP-Address == 192.168.0.1) { test_fail } @@ -31,60 +27,44 @@ if (&reply.Framed-IP-Address == 192.168.0.1) { # &Tmp-Date-0 := "%l" -if ("%{expr:%(redis:ZSCORE "{%{control.IP-Pool.Name}}:pool" %{reply.Framed-IP-Address}) - %(integer:%{Tmp-Date-0})}" > 20) { - test_pass -} else { +if ("%{expr:%(redis:ZSCORE "{%{control.IP-Pool.Name}}:pool" %{reply.Framed-IP-Address}) - %(integer:%{Tmp-Date-0})}" < 20) { test_fail } -if ("%{expr:%(redis:ZSCORE "{%{control.IP-Pool.Name}}:pool" %{reply.Framed-IP-Address}) - %(integer:%{Tmp-Date-0})}" < 40) { - test_pass -} else { +if ("%{expr:%(redis:ZSCORE "{%{control.IP-Pool.Name}}:pool" %{reply.Framed-IP-Address}) - %(integer:%{Tmp-Date-0})}" > 40) { test_fail } # # Verify the IP hash has been set # -if ("%(redis:HGET {%{control.IP-Pool.Name}}:ip:%{reply.Framed-IP-Address} 'device')" == '00:11:22:33:44:55') { - test_pass -} else { +if !("%(redis:HGET {%{control.IP-Pool.Name}}:ip:%{reply.Framed-IP-Address} 'device')" == '00:11:22:33:44:55') { test_fail } -if ("%(redis:HGET {%{control.IP-Pool.Name}}:ip:%{reply.Framed-IP-Address} gateway)" == '127.0.0.1') { - test_pass -} else { +if !("%(redis:HGET {%{control.IP-Pool.Name}}:ip:%{reply.Framed-IP-Address} gateway)" == '127.0.0.1') { test_fail } -if ("%(redis:HGET {%{control.IP-Pool.Name}}:ip:%{reply.Framed-IP-Address} range)" == '192.168.0.0') { - test_pass -} else { +if !("%(redis:HGET {%{control.IP-Pool.Name}}:ip:%{reply.Framed-IP-Address} range)" == '192.168.0.0') { test_fail } -if (&reply.IP-Pool.Range == '192.168.0.0') { - test_pass -} else { +if !(&reply.IP-Pool.Range == '192.168.0.0') { test_fail } # # Verify the lease has been associated with the device # -if (&reply.Framed-IP-Address == "%(redis:GET {%{control.IP-Pool.Name}}:device:%{Calling-Station-ID})") { - test_pass -} else { +if !(&reply.Framed-IP-Address == "%(redis:GET {%{control.IP-Pool.Name}}:device:%{Calling-Station-ID})") { test_fail } # # Check we got the correct lease time back # -if (&reply.Session-Timeout == 30) { - test_pass -} else { +if !(&reply.Session-Timeout == 30) { test_fail } @@ -102,27 +82,21 @@ if (&reply.Session-Timeout == 30) { # Check we get the same lease, with the same lease time # redis_ippool -if (updated) { - test_pass -} else { +if (!updated) { test_fail } # # Check the ranges are the same # -if (&IP-Pool.Range == &reply.IP-Pool.Range) { - test_pass -} else { +if !(&IP-Pool.Range == &reply.IP-Pool.Range) { test_fail } # # Check the IP addresses are the same # -if (&Framed-IP-Address == &reply.Framed-IP-Address) { - test_pass -} else { +if !(&Framed-IP-Address == &reply.Framed-IP-Address) { test_fail } @@ -132,9 +106,7 @@ if (&Framed-IP-Address == &reply.Framed-IP-Address) { # The fudge factor is to allow for delays running ippool tool and script interpretation # as we should be allocating the same lesase as before, but its TTL could be slightly lower. # -if ("%{expr:&Session-Timeout - &reply.Session-Timeout}" < 5) { - test_pass -} else { +if ("%{expr:&Session-Timeout - &reply.Session-Timeout}" > 5) { test_fail } @@ -146,19 +118,17 @@ if ("%{expr:&Session-Timeout - &reply.Session-Timeout}" < 5) { &Calling-Station-ID := 'another_mac' redis_ippool -if (updated) { - test_pass -} else { +if (!updated) { test_fail } # # Check we got the right lease # -if (&reply.Framed-IP-Address == 192.168.1.1) { - test_pass -} else { +if !(&reply.Framed-IP-Address == 192.168.1.1) { test_fail } &reply := {} + +test_pass diff --git a/src/tests/modules/redis_ippool/pool_tool_delete.unlang b/src/tests/modules/redis_ippool/pool_tool_delete.unlang index c2f5840ae3b..ebc65fd6351 100644 --- a/src/tests/modules/redis_ippool/pool_tool_delete.unlang +++ b/src/tests/modules/redis_ippool/pool_tool_delete.unlang @@ -16,15 +16,11 @@ $INCLUDE cluster_reset.inc redis_ippool { invalid = 1 } -if (updated) { - test_pass -} else { +if (!updated) { test_fail } -if (&reply.Framed-IP-Address == 192.168.0.1) { - test_pass -} else { +if !(&reply.Framed-IP-Address == 192.168.0.1) { test_fail } @@ -36,26 +32,22 @@ if (&reply.Framed-IP-Address == 192.168.0.1) { # # Verify the association with the device has been removed # -if ("%(redis:EXISTS {%{control.IP-Pool.Name}}:device:%{Calling-Station-ID})" == '0') { - test_pass -} else { +if !("%(redis:EXISTS {%{control.IP-Pool.Name}}:device:%{Calling-Station-ID})" == '0') { test_fail } # # Verify the hash information is removed # -if ("%(redis:EXISTS {%{control.IP-Pool.Name}}:ip:%{reply.Framed-IP-Address})" == '0') { - test_pass -} else { +if !("%(redis:EXISTS {%{control.IP-Pool.Name}}:ip:%{reply.Framed-IP-Address})" == '0') { test_fail } # Check the ZSCORE -if ("%(redis:ZCOUNT {%{control.IP-Pool.Name}%}:pool -inf +inf)" == 0) { - test_pass -} else { +if !("%(redis:ZCOUNT {%{control.IP-Pool.Name}%}:pool -inf +inf)" == 0) { test_fail } &reply := {} + +test_pass diff --git a/src/tests/modules/redis_ippool/pool_tool_modify.unlang b/src/tests/modules/redis_ippool/pool_tool_modify.unlang index 89eaf9a8732..9c52ab08a5e 100644 --- a/src/tests/modules/redis_ippool/pool_tool_modify.unlang +++ b/src/tests/modules/redis_ippool/pool_tool_modify.unlang @@ -13,9 +13,7 @@ $INCLUDE cluster_reset.inc # # Verify the range was set OK # -if ("%(redis:HGET {%{control.IP-Pool.Name}}:ip:192.168.0.1 range)" == '192.168.0.0') { - test_pass -} else { +if !("%(redis:HGET {%{control.IP-Pool.Name}}:ip:192.168.0.1 range)" == '192.168.0.0') { test_fail } @@ -27,8 +25,8 @@ if ("%(redis:HGET {%{control.IP-Pool.Name}}:ip:192.168.0.1 range)" == '192.168.0 # # Check it was updated # -if ("%(redis:HGET {%{control.IP-Pool.Name}}:ip:192.168.0.1 range)" == '10.0.0.0') { - test_pass -} else { +if !("%(redis:HGET {%{control.IP-Pool.Name}}:ip:192.168.0.1 range)" == '10.0.0.0') { test_fail } + +test_pass diff --git a/src/tests/modules/redis_ippool/pool_tool_release.unlang b/src/tests/modules/redis_ippool/pool_tool_release.unlang index 2621275b9c3..b9c856268ab 100644 --- a/src/tests/modules/redis_ippool/pool_tool_release.unlang +++ b/src/tests/modules/redis_ippool/pool_tool_release.unlang @@ -16,15 +16,11 @@ $INCLUDE cluster_reset.inc redis_ippool { invalid = 1 } -if (updated) { - test_pass -} else { +if (!updated) { test_fail } -if (&reply.Framed-IP-Address == 192.168.0.1) { - test_pass -} else { +if !(&reply.Framed-IP-Address == 192.168.0.1) { test_fail } @@ -36,38 +32,30 @@ if (&reply.Framed-IP-Address == 192.168.0.1) { # # Verify the association with the device has been removed # -if ("%(redis:EXISTS {%{control.IP-Pool.Name}}:device:%{Calling-Station-ID})" == '0') { - test_pass -} else { +if !("%(redis:EXISTS {%{control.IP-Pool.Name}}:device:%{Calling-Station-ID})" == '0') { test_fail } # # Verify the hash information is retained # -if ("%(redis:HGET {%{control.IP-Pool.Name}}:ip:%{reply.Framed-IP-Address} device)" == '00:11:22:33:44:55') { - test_pass -} else { +if !("%(redis:HGET {%{control.IP-Pool.Name}}:ip:%{reply.Framed-IP-Address} device)" == '00:11:22:33:44:55') { test_fail } -if ("%(redis:HGET {%{control.IP-Pool.Name}}:ip:%{reply.Framed-IP-Address} gateway)" == '127.0.0.1') { - test_pass -} else { +if !("%(redis:HGET {%{control.IP-Pool.Name}}:ip:%{reply.Framed-IP-Address} gateway)" == '127.0.0.1') { test_fail } -if ("%(redis:HGET {%{control.IP-Pool.Name}}:ip:%{reply.Framed-IP-Address} range)" == '192.168.0.0') { - test_pass -} else { +if !("%(redis:HGET {%{control.IP-Pool.Name}}:ip:%{reply.Framed-IP-Address} range)" == '192.168.0.0') { test_fail } # Check the ZSCORE -if ("%(redis:ZSCORE {%{control.IP-Pool.Name}}:pool %{reply.Framed-IP-Address})" == 0) { - test_pass -} else { +if !("%(redis:ZSCORE {%{control.IP-Pool.Name}}:pool %{reply.Framed-IP-Address})" == 0) { test_fail } &reply := {} + +test_pass diff --git a/src/tests/modules/redis_ippool/update.unlang b/src/tests/modules/redis_ippool/update.unlang index 3e028ab0571..b627afbb6ef 100644 --- a/src/tests/modules/redis_ippool/update.unlang +++ b/src/tests/modules/redis_ippool/update.unlang @@ -12,30 +12,22 @@ $INCLUDE cluster_reset.inc # 1. Check allocation redis_ippool -if (updated) { - test_pass -} else { +if (!updated) { test_fail } # 2. -if (&reply.Framed-IP-Address == 192.168.0.1) { - test_pass -} else { +if !(&reply.Framed-IP-Address == 192.168.0.1) { test_fail } # 3. Check the expiry attribute is present and correct -if (&reply.Session-Timeout == 30) { - test_pass -} else { +if !(&reply.Session-Timeout == 30) { test_fail } # 4. Verify the gateway was set -if ("%(redis:HGET {%{control.IP-Pool.Name}}:ip:%{reply.Framed-IP-Address} gateway)" == '127.0.0.1') { - test_pass -} else { +if !("%(redis:HGET {%{control.IP-Pool.Name}}:ip:%{reply.Framed-IP-Address} gateway)" == '127.0.0.1') { test_fail } @@ -48,60 +40,44 @@ if ("%(redis:HGET {%{control.IP-Pool.Name}}:ip:%{reply.Framed-IP-Address} gatewa &control.IP-Pool.Action := Renew redis_ippool -if (updated) { - test_pass -} else { +if (!updated) { test_fail } # 7. Lease time should now be 60 seconds -if (&reply.Session-Timeout == 60) { - test_pass -} else { +if !(&reply.Session-Timeout == 60) { test_fail } # 8. Check ZSCORE reflects that &Tmp-Date-0 := "%l" -if ("%{expr:%(redis:ZSCORE {%{control.IP-Pool.Name}}:pool %{reply.Framed-IP-Address}) - %(integer:%{Tmp-Date-0})}" > 50) { - test_pass -} else { +if !("%{expr:%(redis:ZSCORE {%{control.IP-Pool.Name}}:pool %{reply.Framed-IP-Address}) - %(integer:%{Tmp-Date-0})}" > 50) { test_fail } # 9. -if ("%{expr:%(redis:ZSCORE {%{control.IP-Pool.Name}}:pool %{reply.Framed-IP-Address}) - %(integer:%{Tmp-Date-0})}" < 70) { - test_pass -} else { +if !("%{expr:%(redis:ZSCORE {%{control.IP-Pool.Name}}:pool %{reply.Framed-IP-Address}) - %(integer:%{Tmp-Date-0})}" < 70) { test_fail } # 10. Verify the lease is still associated with the device -if (&reply.Framed-IP-Address == "%(redis:GET {%{control.IP-Pool.Name}}:device:%{Calling-Station-ID})") { - test_pass -} else { +if !(&reply.Framed-IP-Address == "%(redis:GET {%{control.IP-Pool.Name}}:device:%{Calling-Station-ID})") { test_fail } # 11. And that the device object will expire a suitable number of seconds into the future -if ("%(redis:TTL {%{control.IP-Pool.Name}}:device:%{Calling-Station-ID})" == 60) { - test_pass -} else { +if !("%(redis:TTL {%{control.IP-Pool.Name}}:device:%{Calling-Station-ID})" == 60) { test_fail } # 12. Verify the gateway was updated -if ("%(redis:HGET {%{control.IP-Pool.Name}}:ip:%{Framed-IP-Address} gateway)" == '127.0.0.2') { - test_pass -} else { +if !("%(redis:HGET {%{control.IP-Pool.Name}}:ip:%{Framed-IP-Address} gateway)" == '127.0.0.2') { test_fail } # 13. and that the range attribute was set -if (&reply.IP-Pool.Range && (&reply.IP-Pool.Range == '192.168.0.0')) { - test_pass -} else { +if !(&reply.IP-Pool.Range && (&reply.IP-Pool.Range == '192.168.0.0')) { test_fail } @@ -112,9 +88,7 @@ redis_ippool { invalid = 1 } # 14. -if (notfound) { - test_pass -} else { +if (!notfound) { test_fail } &Framed-IP-Address := 192.168.0.1 @@ -125,17 +99,15 @@ if (notfound) { redis_ippool { invalid = 1 } -if (invalid) { - test_pass -} else { +if (!invalid) { test_fail } # 16. Verify the lease is still associated with the previous device -if (&reply.Framed-IP-Address == "%(redis:GET {%{control.IP-Pool.Name}}:device:00:11:22:33:44:55)") { - test_pass -} else { +if !(&reply.Framed-IP-Address == "%(redis:GET {%{control.IP-Pool.Name}}:device:00:11:22:33:44:55)") { test_fail } &reply := {} + +test_pass diff --git a/src/tests/modules/redis_ippool/update_alloc.unlang b/src/tests/modules/redis_ippool/update_alloc.unlang index dba65105942..042ebf0aca3 100644 --- a/src/tests/modules/redis_ippool/update_alloc.unlang +++ b/src/tests/modules/redis_ippool/update_alloc.unlang @@ -12,9 +12,7 @@ $INCLUDE cluster_reset.inc # 1. Check allocation redis_ippool -if (updated) { - test_pass -} else { +if (!updated) { test_fail } @@ -28,24 +26,20 @@ if (updated) { redis_ippool # 3. Check the expiry attribute is present and correct -if (&reply.Session-Timeout == 60) { - test_pass -} else { +if !(&reply.Session-Timeout == 60) { test_fail } # 4. Verify the gateway was set -if ("%(redis:HGET {%{control.IP-Pool.Name}}:ip:%{reply.Framed-IP-Address} gateway)" == '127.0.0.1') { - test_pass -} else { +if !("%(redis:HGET {%{control.IP-Pool.Name}}:ip:%{reply.Framed-IP-Address} gateway)" == '127.0.0.1') { test_fail } # 5. Verify we got an IP -if (&reply.Framed-IP-Address == 192.168.0.1) { - test_pass -} else { +if !(&reply.Framed-IP-Address == 192.168.0.1) { test_fail } &reply := {} + +test_pass