From: Nick Porter Date: Tue, 20 May 2025 15:54:05 +0000 (+0100) Subject: Test that sqlippool does not clobber existing assigned address X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0e9ad782a05eaf267d4bd01d7d657ce87f0de0db;p=thirdparty%2Ffreeradius-server.git Test that sqlippool does not clobber existing assigned address --- diff --git a/src/tests/modules/sqlippool/no_overwrite.attrs b/src/tests/modules/sqlippool/no_overwrite.attrs new file mode 100644 index 00000000000..4bb429e8b63 --- /dev/null +++ b/src/tests/modules/sqlippool/no_overwrite.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/sqlippool/no_overwrite.unlang b/src/tests/modules/sqlippool/no_overwrite.unlang new file mode 100644 index 00000000000..c874e0d9365 --- /dev/null +++ b/src/tests/modules/sqlippool/no_overwrite.unlang @@ -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