From ccc654a80e5d6c0ed901620f9b0c0e255aa0c9d5 Mon Sep 17 00:00:00 2001 From: Nick Porter Date: Mon, 21 Oct 2024 15:05:03 +0100 Subject: [PATCH] Add test of NULL SQL value handling --- src/tests/modules/sql/map.unlang | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/tests/modules/sql/map.unlang b/src/tests/modules/sql/map.unlang index 341256d15ec2e..ebc1517cc4bdc 100644 --- a/src/tests/modules/sql/map.unlang +++ b/src/tests/modules/sql/map.unlang @@ -295,4 +295,28 @@ if (!notfound) { test_fail } +# Clear the control list +&control -= &User-Name[*] +&control -= &Filter-Id[*] + +# Check behaviour of NULL vs empty string returns. +# radacct is used here as the default schema allows NULL in many columns +%sql("DELETE FROM radacct WHERE acctuniqueid = 'nullmap'") +%sql("INSERT INTO radacct (acctuniqueid, acctsessionid, nasipaddress, username) VALUES ('nullmap', 'nullmap', '10.11.12.13', '')") +map sql "SELECT username, connectinfo_start, nasipaddress FROM radacct WHERE acctuniqueid = 'nullmap'" { + &control.User-Name := 'username' + &control.Filter-Id := 'connectinfo_start' + &control.NAS-IP-Address := 'nasipaddress' +} + +if !(&control.User-Name == '') { + test_fail +} +if (&control.Filter-Id) { + test_fail +} +if !(&control.NAS-IP-Address == 10.11.12.13) { + test_fail +} + test_pass