]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add tests of %bin() and multi valued %hex()
authorNick Porter <nick@portercomputing.co.uk>
Mon, 4 Mar 2024 19:42:58 +0000 (19:42 +0000)
committerNick Porter <nick@portercomputing.co.uk>
Mon, 4 Mar 2024 19:42:58 +0000 (19:42 +0000)
src/tests/keywords/bin [new file with mode: 0644]
src/tests/keywords/hex

diff --git a/src/tests/keywords/bin b/src/tests/keywords/bin
new file mode 100644 (file)
index 0000000..14a6ea7
--- /dev/null
@@ -0,0 +1,56 @@
+#
+# PRE: if
+#
+octets result_octets
+
+&result_octets := %bin('39383730')
+if !(&result_octets == 0x39383730) {
+       test_fail
+}
+
+&result_octets := %bin('0x39383731')
+if !(&result_octets == 0x39383731) {
+       test_fail
+}
+
+&result_octets := %bin('012')
+if (&result_octets) {
+       test_fail
+}
+
+&result_octets := %bin('0x')
+if (&result_octets) {
+       test_fail
+}
+
+&result_octets := %bin('0x234')
+if (&result_octets) {
+       test_fail
+}
+
+&result_octets := %bin('fg')
+if (&result_octets) {
+       test_fail
+}
+
+&result_octets := %bin('0x23450x1234')
+if (&result_octets) {
+       test_fail
+}
+
+&request += {
+       &NAS-Identifier = '0001'
+       &NAS-Identifier = '0x030405'
+}
+
+&Class := %bin(%{NAS-Identifier[*]})
+
+if (&Class[#] != 2) {
+       test_fail
+}
+
+if !((&Class[0] == 0x0001) && (&Class[1] == 0x030405)) {
+       test_fail
+}
+
+success
index c5d753b6caf65f9168134ab6f5ae4bcc8596ea69..02645dc850ecc2eac961562c024cec5f8cdb7b98 100644 (file)
@@ -101,4 +101,20 @@ if (!(&result_string == '203938373e')) {
        test_fail
 }
 
+&request += {
+       &Class = 0x0101
+       &Class = 0x010203
+       &Class = 0x0405
+}
+
+&NAS-Identifier := %hex(%{Class[*]})
+
+if (&NAS-Identifier[#] != 3) {
+       test_fail
+}
+
+if !((&NAS-Identifier[0] == '0101') && (&NAS-Identifier[1] == '010203') && (&NAS-Identifier[2] == '0405')) {
+       test_fail
+}
+
 success