]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Test that sqlippool does not clobber existing assigned address
authorNick Porter <nick@portercomputing.co.uk>
Tue, 20 May 2025 15:54:05 +0000 (16:54 +0100)
committerNick Porter <nick@portercomputing.co.uk>
Tue, 20 May 2025 15:54:05 +0000 (16:54 +0100)
src/tests/modules/sqlippool/no_overwrite.attrs [new file with mode: 0644]
src/tests/modules/sqlippool/no_overwrite.unlang [new file with mode: 0644]

diff --git a/src/tests/modules/sqlippool/no_overwrite.attrs b/src/tests/modules/sqlippool/no_overwrite.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/sqlippool/no_overwrite.unlang b/src/tests/modules/sqlippool/no_overwrite.unlang
new file mode 100644 (file)
index 0000000..c874e0d
--- /dev/null
@@ -0,0 +1,41 @@
+#
+#  Test sqlippool does not overwrite existing values in the target attribute.
+#
+integer count
+control.IP-Pool.Name := 'no_overwrite'
+
+#
+#  Add a dynamic IP addresses
+#
+%sql("DELETE FROM fr_ippool WHERE pool_name = '%{control.IP-Pool.Name}'")
+%sql("INSERT INTO fr_ippool (pool_name, address, expiry_time) VALUES ('%{control.IP-Pool.Name}', '192.168.0.99', datetime('now', '-00:20'))")
+
+#
+#  Manually set the Framed-IP-Address
+#
+reply.Framed-IP-Address := 10.1.0.10
+
+#
+#  Check sqlippool does nothing
+#
+sqlippool.allocate
+if (!noop) {
+       test_fail
+}
+
+if !(reply.Framed-IP-Address == 10.1.0.10) {
+       test_fail
+}
+
+#
+#  Check that the address has not been allocated
+#
+count = %sql("SELECT COUNT(*) FROM fr_ippool WHERE pool_name = '%{control.IP-Pool.Name}' AND expiry_time < datetime('now', '-00:01')")
+
+if (count != 1) {
+       test_fail
+}
+
+reply := {}
+
+test_pass