]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add redis xlat tests
authorNick Porter <nick@portercomputing.co.uk>
Mon, 28 Apr 2025 12:12:56 +0000 (13:12 +0100)
committerNick Porter <nick@portercomputing.co.uk>
Mon, 28 Apr 2025 12:24:52 +0000 (13:24 +0100)
Checking for:

 - basic SET / GET
 - return of NULL can fall back to an alternate value
 - return of multiple values with HMGET

src/tests/modules/redis/xlat.attrs [new file with mode: 0644]
src/tests/modules/redis/xlat.unlang [new file with mode: 0644]

diff --git a/src/tests/modules/redis/xlat.attrs b/src/tests/modules/redis/xlat.attrs
new file mode 100644 (file)
index 0000000..2376770
--- /dev/null
@@ -0,0 +1,11 @@
+#
+#  Input packet
+#
+Packet-Type = Access-Request
+User-Name = 'john'
+User-Password = 'testing123'
+
+#
+#  Expected answer
+#
+Packet-Type == Access-Accept
diff --git a/src/tests/modules/redis/xlat.unlang b/src/tests/modules/redis/xlat.unlang
new file mode 100644 (file)
index 0000000..70ca7cb
--- /dev/null
@@ -0,0 +1,31 @@
+#
+#  Call redis commands as xlat
+#
+integer dummy_number
+$INCLUDE cluster_reset.inc
+
+%redis('SET', 'value1', 100)
+
+dummy_number = %redis('GET', 'value1')
+
+if (dummy_number != 100) {
+       test_fail
+}
+
+# Regression test - ensure that NULL returned by missing redis value
+# will cause fallback to alternation value
+dummy_number := %{%redis('GET', 'value2') || 200}
+if (dummy_number != 200) {
+       test_fail
+}
+
+%redis('HSET', 'hash1', 'foo', 'fooval', 'baa', 'baaval', 'baz', 300)
+
+# Ensure we can return multiple values
+control.Tmp-String-0 := %redis('HMGET', 'hash1', 'foo', 'baz', 'baa')
+
+if ((control.Tmp-String-0[0] != 'fooval') || (control.Tmp-String-0[1] != '300') || (control.Tmp-String-0[2] != 'baaval')) {
+       test_fail
+}
+
+test_pass