From: Nick Porter Date: Mon, 4 Mar 2024 19:42:58 +0000 (+0000) Subject: Add tests of %bin() and multi valued %hex() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=34dd40d114d4e1c022a67c3f27600ceb9a5ed1c2;p=thirdparty%2Ffreeradius-server.git Add tests of %bin() and multi valued %hex() --- diff --git a/src/tests/keywords/bin b/src/tests/keywords/bin new file mode 100644 index 00000000000..14a6ea7366e --- /dev/null +++ b/src/tests/keywords/bin @@ -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 diff --git a/src/tests/keywords/hex b/src/tests/keywords/hex index c5d753b6caf..02645dc850e 100644 --- a/src/tests/keywords/hex +++ b/src/tests/keywords/hex @@ -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